From dbinks at codeaurora.org Sun Jan 1 00:12:04 2012 From: dbinks at codeaurora.org (Dominic Binks) Date: Sat, 31 Dec 2011 21:12:04 -0800 Subject: Python education survey In-Reply-To: References: <06423dd7-4fbb-4e7a-b529-e697ea862b05@f11g2000yql.googlegroups.com> <36065956-359d-42cf-a5fc-75fdea830737@y7g2000vbe.googlegroups.com> <470c9b9b-780f-4b00-8fef-adba8b036c2b@32g2000yqp.googlegroups.com> <74b1ed63-f755-49e3-a275-92b2658ef991@o14g2000vbo.googlegroups.com> Message-ID: <4EFFEB24.8000406@codeaurora.org> On 12/27/2011 6:42 PM, Rick Johnson wrote: > On Dec 27, 8:21 pm, Tim Chase wrote: > >> I'm glad you're open to learning more about English as "used to" >> is perfectly acceptable according to the World English Dictionary[1] >> [...] >> May you be found better for learning and come to give others the >> benefit of the doubt. > > I don't care what ANY dictionary says. Much less a "world" dictionary. (Shouldn't this be |||world|||?) > I don't validate or invalidate a word based on some phony baloney I doubt you could validate or invalidate a word. A word is, there is no validation necessary. You could potentially try to validate it's use but again that's not in your power. > group of pseudo intellectuals who decided one to day that writing a > dictionary "might be cool". I think you need to go back to school to understand what a dictionary is. (FYI, a dictionary codifies usage, not the other way around.) I am against these words and phrases I think you mean these words and phrases being used in this way - the words and phrases themselves are just that. They imply no meaning unless used in some kind of context. > because we already have words that work just fine. Why rock the boat? Perhaps you mean, because more precise words or phrases for these uses exist? By your token 'work' should refer to physical activity which is not appropriate in this context and probably 'fine' should refer to a payment that is made having broken some rule or regulation thus leading to monetary reparation. I think, herein lies the problem - abject denial of all evidence to the contrary simply because it disagrees with your limited point of view. > > Why would you use a word like "hard" (which describes the physical > properties of a tangible object), Because many words have more than one meaning and their context describes the meaning. For example 'Time flies like an arrow, fruit flies like a banana'. I know you can parse and understand that but the sentences are precisely alike, yet completely different. to describe how "difficult" a task > may be? Because it's a perfectly legitimate thing to do. Many problems are described as 'HARD' in technical documentation when examining their complexity. I don't always like the terms used for things, but at least let's be consistent in our usage. If you insist on this lunacy, then why not use "soft" to > describe how easy a task may be? Seems ridiculous now, huh? Soft is used in this context - as in choosing the soft option - i.e. the easy way out. And your problem is, precisely? > > Garbage Verbiage Translator: For Garbage Verbiage, read 'common English' > Used to -> previously|before Though used to is perfect acceptable in any English speaking country. > Supposed to -> required|expected probably 'intended' would be better here since 'supposed to' indicates that you should do this, but it is not required (pretty much the opposite for your given translation). > Use to -> accustomed|acquainted Sorry to be picky, but "use to" refers to application as in "When I say 'idiot', in this context 'idiot' I use to mean 'person who cannot speak English as it is commonly used'.", not accustomed|acquainted. In the example you give, it's probably mistyped, maybe by a non-native English speaker. (oh bother, I just used " and ' to denote separate spoken phrases, maybe I should use ||| instead.) For what it's worth in English (i.e. British, the language I was brought up to speak) we say, for example: * get on/off a bus * get up in the morning * get down to some music * get around an obstacle * get over a broken relationship * get back to our previous place in a story * get through a difficult time/bush * get into a really good book * get about town * put up our Christmas lights and put down an idiot that doesn't understand that English has lots of compound verbs that are not poorly written, just commonly used and understood. > Right (OOC) -> Correct While I agree 'right' can be annoying it's usage as in 'you are correct' can be traced back to 1588, I think we're going to have to allow for it's usage in 2011 (very nearly 2012 for me and definitely 2012 for anyone east of New York City). > Hard (OOC) -> Difficult Phrases to mean 'difficult' or 'tough' come from at least 1886 so again, it's use in this context is hardly new. (And remember Charles Dickens' book Hard Times uses 'hard' to mean difficult not physically solid.) In fact looking into this a little more carefully, "hard of hearing" maintains the now largely obsolete meaning of hard from Middle English to mean have difficult doing something. I don't really think we can claim it's usage is wrong. > Pretty (OOC) -> very Pretty on it's own doesn't mean very at all. (God knows where you got that idea from.) When combined with another adjective, such as hard, pretty does enhance the adjective. However, pretty difficult is not the same as very difficult. Pretty, in this context would probably be better defined as 'somewhat' or 'quite'. (Oh and it's use in this context can be traced back to 1565.) While you're here you might want to investigate what nice and liaise mean cause they probably don't mean what you think they do. > > This is group has the most dumbest smart people i have ever met! I don't know what planet you come from, but I would refrain from picking arguments over tedious detail of words when it is perfectly clear what people mean. -- Dominic Binks: dbinks at codeaurora.org Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum From bahamutzero8825 at gmail.com Sun Jan 1 00:44:11 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sat, 31 Dec 2011 23:44:11 -0600 Subject: Python education survey In-Reply-To: <4EFF5D1D.4000905@web.de> References: <06423dd7-4fbb-4e7a-b529-e697ea862b05@f11g2000yql.googlegroups.com> <36065956-359d-42cf-a5fc-75fdea830737@y7g2000vbe.googlegroups.com> <470c9b9b-780f-4b00-8fef-adba8b036c2b@32g2000yqp.googlegroups.com> <74b1ed63-f755-49e3-a275-92b2658ef991@o14g2000vbo.googlegroups.com> <4efabe42$0$29966$c3e8da3$5496439d@news.astraweb.com> <4EFF5D1D.4000905@web.de> Message-ID: <4EFFF2AB.6050006@gmail.com> On 12/31/2011 1:06 PM, Alexander Kapps wrote: > xkcd/386 has been the excuse for replying to RR for ages and I still > don't understand why he gets that much advertence. Charity? Sympathy > for the lone and broken? > > FWIW, it undermines all my attempts to block him. Sigh. Do what I do: laugh at the joke. He's a troll and the posts are jokes. Personally, I enjoy his posts; the silliness is good for a laugh. Once you stop taking it seriously, it goes from irritation to entertainment. -- CPython 3.2.2 | Windows NT 6.1.7601.17640 From rosuav at gmail.com Sun Jan 1 00:50:53 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 1 Jan 2012 16:50:53 +1100 Subject: Python education survey In-Reply-To: <4EFFEB24.8000406@codeaurora.org> References: <06423dd7-4fbb-4e7a-b529-e697ea862b05@f11g2000yql.googlegroups.com> <36065956-359d-42cf-a5fc-75fdea830737@y7g2000vbe.googlegroups.com> <470c9b9b-780f-4b00-8fef-adba8b036c2b@32g2000yqp.googlegroups.com> <74b1ed63-f755-49e3-a275-92b2658ef991@o14g2000vbo.googlegroups.com> <4EFFEB24.8000406@codeaurora.org> Message-ID: On Sun, Jan 1, 2012 at 4:12 PM, Dominic Binks wrote: > While I agree 'right' can be annoying it's usage as in 'you are correct' can > be traced back to 1588, I think we're going to have to allow for it's usage > in 2011 (very nearly 2012 for me and definitely 2012 for anyone east of New > York City). And I am right, And you are right, And everything is quite correct! -- http://math.boisestate.edu/gas/mikado/webopera/mk103.html Context matters, words have multiple meanings. Can we agree on this point and move on? Otherwise, we're still going to be arguing this come 2013... ChrisA From mail at timgolden.me.uk Sun Jan 1 04:37:52 2012 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 01 Jan 2012 09:37:52 +0000 Subject: [Windows 7, Python 2.6] Can't write to a directory made w/ os.makedirs In-Reply-To: <50693cc2-93c9-481d-9fb1-42312e69b2d9@c42g2000prb.googlegroups.com> References: <50693cc2-93c9-481d-9fb1-42312e69b2d9@c42g2000prb.googlegroups.com> Message-ID: <4F002970.3010609@timgolden.me.uk> On 31/12/2011 22:13, OlyDLG wrote: > Hi! I'm working on a script utilizing os.makedirs to make directories > to which I'm then trying to write files created by exe's spawned w/ > subprocess.call; I'm developing in Stani's Python Editor, debugging > using Winpdb. I've gotten to the point where > subprocess.Popen._execute_child is raising a WindowsError(5,'Access is > denied') exception. I've tried: setting the mode in the makedirs > call; using os.chmod(, stat.S_IWRITE); and even setting a > breakpoint before the subprocess.call and unsetting the read-only > attribute of the pertinent directory tree using the Windows directory > Properties dialog--which doesn't "take," if that's a clue--all to no > avail. Whatever you're trying to do, resetting the read-only bit on the Windows directory is not the answer. It has, bizarrely, nothing to do with the read/write-ness of a directory; rather, it reflects the system-ness of a folder. There's no general answer I can see to give, without knowing what the security is on your folders or what other thing might impede your processes from writing files in them. Is it definite that the ERROR_ACCESS_DENIED is in fact the result of attempting to write a file into one of the newly-created directories? Can you do something like this (adapt for your own environment): import os, sys import subprocess os.makedirs ("c:/temp/a/b/c") with open ("c:/temp/a/b/c/test1.txt", "w"): pass subprocess.call ([ sys.executable, "-c", "open ('c:/temp/a/b/c/test2.txt', 'w').close ()" ]) ie can the Python process creating the directories, and a subprocess called from it create a simple file? Depending on where you are in the filesystem, it may indeed be necessary to be running as administrator. But don't try to crack every security nut with an elevated sledgehammer. TJG From eulergaussriemann at gmail.com Sun Jan 1 07:05:13 2012 From: eulergaussriemann at gmail.com (David Goldsmith) Date: Sun, 1 Jan 2012 04:05:13 -0800 (PST) Subject: Can't write to a directory made w/ os.makedirs References: <50693cc2-93c9-481d-9fb1-42312e69b2d9@c42g2000prb.googlegroups.com> Message-ID: <91830ffb-00d9-4fd1-b771-ad59374334ec@n22g2000prh.googlegroups.com> On Jan 1, 1:37?am, Tim Golden wrote: > On 31/12/2011 22:13, OlyDLG wrote: > ?> Hi! ?I'm working on a script utilizing os.makedirs to make directories > ?> to which I'm then trying to write files created by exe's spawned w/ > ?> subprocess.call; I'm developing in Stani's Python Editor, debugging > ?> using Winpdb. ?I've gotten to the point where > ?> subprocess.Popen._execute_child is raising a WindowsError(5,'Access is > ?> denied') exception. ?I've tried: setting the mode in the makedirs > ?> call; using os.chmod(, stat.S_IWRITE); and even setting a > ?> breakpoint before the subprocess.call and unsetting the read-only > ?> attribute of the pertinent directory tree using the Windows directory > ?> Properties dialog--which doesn't "take," if that's a clue--all to no > ?> avail. > > Whatever you're trying to do, resetting the read-only bit > on the Windows directory is not the answer. It has, bizarrely, > nothing to do with the read/write-ness of a directory; rather, > it reflects the system-ness of a folder. > > There's no general answer I can see to give, without > knowing what the security is on your folders or what > other thing might impede your processes from writing > files in them. Is it definite that the ERROR_ACCESS_DENIED > is in fact the result of attempting to write a file into > one of the newly-created directories? > > Can you do something like this (adapt for your own environment): > > > import os, sys > import subprocess > > os.makedirs ("c:/temp/a/b/c") > > with open ("c:/temp/a/b/c/test1.txt", "w"): > ? ?pass > > subprocess.call ([ > ? ?sys.executable, > ? ?"-c", > ? ?"open ('c:/temp/a/b/c/test2.txt', 'w').close ()" > ]) > > > > ie can the Python process creating the directories, Yes. > and a subprocess called from it create a simple file? No. > Depending on where you are in the filesystem, it may indeed > be necessary to be running as administrator. But don't try > to crack every security nut with an elevated sledgehammer. If you mean running as admin., those were my sentiments exactly. So, there isn't something specific I should be doing to assure that my subproceses can write to directories? > > TJG From akhi3030 at gmail.com Sun Jan 1 07:42:02 2012 From: akhi3030 at gmail.com (akhilesh singhania) Date: Sun, 1 Jan 2012 12:42:02 +0000 Subject: Creating a binary only python distribution of a C extension module and including some additional python and c files in it Message-ID: Hi, I have a extension module in C which I want to distribute in binary format, ideally an rpm. Additionally, I want to include some python files (examples on how to use the extension module) and source for a library the module dynamically links to (c,h, and make files). How do I specify the example python file in setup.py so that it will be included in the rpm? If I specify it as scripts, I get the following error: $ python setup.py bdist --format=rpm running build_scripts creating build/scripts-2.6 error: file 'foo.py' does not exist error: Bad exit status from /var/tmp/rpm-tmp.yjws9x (%build) If I specify it as data_files, I get the following error: $ python setup.py bdist --format=rpm error: Installed (but unpackaged) file(s) found: /usr/foo.pyc /usr/foo.pyo If I specify it as py_modules, I do not get errors but it is not included in the resulting rpm. Specifying it as a script works if I use $ python setup.py bdist --format=gztar Additionally, can I control the hierarchy of how the files are laid out in the rpm? Currently, I am specifying the c,h,make files as data_files and they get placed in /usr, which is not desirable. Regards, akhi From __peter__ at web.de Sun Jan 1 07:51:05 2012 From: __peter__ at web.de (Peter Otten) Date: Sun, 01 Jan 2012 13:51:05 +0100 Subject: pickling instances of metaclass generated classes References: <2d221d0f-458e-4821-8786-f064b44b3125@p16g2000yqd.googlegroups.com> Message-ID: lars van gemerden wrote: >> import pickle >> import sys >> >> class MetaClass(type): >> pass >> >> class M(object): >> def __init__(self, module): >> self.__module = module >> def __getattr__(self, name): >> print "creating class", name >> class_ = MetaClass(name, (), {"__module__": self.__module}) >> setattr(self, name, class_) >> return class_ >> >> sys.modules["m"] = M("m") >> import m >> c = m.x >> s = pickle.dumps(c) >> print repr(s) >> d = pickle.loads(s) >> >> assert c is d >> >> sys.modules["m"] = M("m") >> e = pickle.loads(s) >> >> assert c is not e >> >> The official way is probably what Robert mentioned, via the copy_reg >> module, but I didn't get it to work. > > I will look further into this. does "sys.modules["m"] = M("m")" create > a new module? Assigning to sys.modules[modulename] can put arbitrary objects into the module cache, in this case an M instance. To drive the point home: >>> import sys >>> sys.modules["x"] = 42 >>> import x >>> x 42 >>> sys.modules["x"] = "spam" >>> import x >>> x 'spam' > Cheers, Lars > > PS: I get an error when posting this to the usenet group Sorry, that seems to happen when I post via gmane and don't manually clear the follow-up that my newsreader helpfully (knode) inserts. I've not yet found a permanent fix, but if that was the problem you should be able to answer this post. From mail at timgolden.me.uk Sun Jan 1 10:05:58 2012 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 01 Jan 2012 15:05:58 +0000 Subject: Can't write to a directory made w/ os.makedirs In-Reply-To: <91830ffb-00d9-4fd1-b771-ad59374334ec@n22g2000prh.googlegroups.com> References: <50693cc2-93c9-481d-9fb1-42312e69b2d9@c42g2000prb.googlegroups.com> <91830ffb-00d9-4fd1-b771-ad59374334ec@n22g2000prh.googlegroups.com> Message-ID: <4F007656.6000708@timgolden.me.uk> On 01/01/2012 12:05, David Goldsmith wrote: >> ie can the Python process creating the directories, > > Yes. > >> and a subprocess called from it create a simple file? > > No. > >> Depending on where you are in the filesystem, it may indeed >> be necessary to be running as administrator. But don't try >> to crack every security nut with an elevated sledgehammer. > > If you mean running as admin., those were my sentiments exactly. So, > there isn't something specific I should be doing to assure that my > subproceses can write to directories? In the general case, no. By default, a subprocess will have the same security context as its parent. The exception is where the parent (the Python processing invoking subprocess.call in this example) is already impersonating a different user; in that case, the subprocess will inherit its grandparent's context. But unless you're doing something very deliberate here then I doubt if that's biting you. Can I ask: are you absolutely certain that the processes you're calling are doing what you think they are and failing where you think they're failing? TJG From miki.tebeka at gmail.com Sun Jan 1 16:11:44 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sun, 1 Jan 2012 13:11:44 -0800 (PST) Subject: .format vs. % In-Reply-To: References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <3779937.289.1325357048110.JavaMail.geo-discussion-forums@vbtv37> Message-ID: <2939615.568.1325452304773.JavaMail.geo-discussion-forums@vbdz6> > >>> s = "{0} {1} {2} {3}" > >>> s.format(1, 2, 3, 4) > '1 2 3 4' Or even In [4]: fmt = '{0} {1} {2} {3}'.format In [5]: print(fmt(1, 2, 3, 4)) 1 2 3 4 From miki.tebeka at gmail.com Sun Jan 1 16:11:44 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sun, 1 Jan 2012 13:11:44 -0800 (PST) Subject: .format vs. % In-Reply-To: References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <3779937.289.1325357048110.JavaMail.geo-discussion-forums@vbtv37> Message-ID: <2939615.568.1325452304773.JavaMail.geo-discussion-forums@vbdz6> > >>> s = "{0} {1} {2} {3}" > >>> s.format(1, 2, 3, 4) > '1 2 3 4' Or even In [4]: fmt = '{0} {1} {2} {3}'.format In [5]: print(fmt(1, 2, 3, 4)) 1 2 3 4 From matt at whoosh.ca Sun Jan 1 17:18:00 2012 From: matt at whoosh.ca (Matt Chaput) Date: Sun, 1 Jan 2012 17:18:00 -0500 Subject: Spamming PyPI with stupid packages Message-ID: Someone seems to be spamming PyPI by uploading multiple stupid packages. Not sure if it's some form of advertising spam or just idiocy. Don't know if we should care though... maybe policing uploads is worse than cluttering PyPI's disk space and RSS feed with dumb 1 KB packages. > girlfriend 1.0.1 10 A really simple module that allow everyone to do "import girlfriend" > girlfriends 1.0 4 Girl Friends > car 1.0 2 Car, a depended simple module that allow everyone to do "import girlfriend" > house 1.0 2 House, a depended simple module that allow everyone to do "import girlfriend" > money 1.0 2 Money, a depended simple module that allow everyone to do "import girlfriend" > workhard 1.0 2 Keep working hard, a depended simple module that allow everyone to do "import girlfriend" Matt From robert.kern at gmail.com Sun Jan 1 17:33:19 2012 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 01 Jan 2012 22:33:19 +0000 Subject: Spamming PyPI with stupid packages In-Reply-To: References: Message-ID: On 1/1/12 10:18 PM, Matt Chaput wrote: > Someone seems to be spamming PyPI by uploading multiple stupid packages. Not sure if it's some form of advertising spam or just idiocy. > > Don't know if we should care though... maybe policing uploads is worse than cluttering PyPI's disk space and RSS feed with dumb 1 KB packages. > >> girlfriend 1.0.1 10 A really simple module that allow everyone to do "import girlfriend" >> girlfriends 1.0 4 Girl Friends >> car 1.0 2 Car, a depended simple module that allow everyone to do "import girlfriend" >> house 1.0 2 House, a depended simple module that allow everyone to do "import girlfriend" >> money 1.0 2 Money, a depended simple module that allow everyone to do "import girlfriend" >> workhard 1.0 2 Keep working hard, a depended simple module that allow everyone to do "import girlfriend" I'm betting on a joke, like antigravity only significantly less funny and more sexist. The author is a legitimate Python programmer, and the links go to his blog where he talks about Python stuff. https://bitbucket.org/felinx You can tell him that you don't appreciate his abuse of PyPI here if you like: http://feilong.me/2012/01/python-import-girlfriend -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From alex.kapps at web.de Sun Jan 1 18:24:48 2012 From: alex.kapps at web.de (Alexander Kapps) Date: Mon, 02 Jan 2012 00:24:48 +0100 Subject: Spamming PyPI with stupid packages In-Reply-To: References: Message-ID: <4F00EB40.5040906@web.de> Uh oh, should I really send this? ... Yes. Yes, I should! Sorry, I cannot resists. >>> allow everyone to do "import girlfriend" > I'm betting on a joke, like antigravity only significantly less > funny and more sexist. Absolutely not funny. I hope that someday people will understand that sexism is just another form of racism. I was about to write a really harsh reply, but cooled down before I got a chance to hit the Send button. Felinx Lee: Do apologize and rename your package/module or I'm going to make a racist comment against Chinese people. From jeanpierreda at gmail.com Sun Jan 1 19:05:17 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 1 Jan 2012 19:05:17 -0500 Subject: Spamming PyPI with stupid packages In-Reply-To: <4F00EB40.5040906@web.de> References: <4F00EB40.5040906@web.de> Message-ID: > Absolutely not funny. I hope that someday people will understand that sexism > is just another form of racism. One can understand that sexism is a terrible thing, and at the same time make sexist jokes. > Felinx Lee: Do apologize and rename your package/module or I'm going to make > a racist comment against Chinese people. This is a joke, right? Making some kind of racist remark about Chinese people wouldn't help anything at all, and it's hypocritical given your stance on sexist jokes. It's one thing to make a joke, to make people laugh, and inadvertently hurt someone's feelings. It's much worse to make a malicious comment to try to hurt someone deliberately. On a slightly different note, PyPI uploads are in fact already policed. See http://holdenweb.blogspot.com/2011/07/childish-behavior.html for an example Coincidentally, it also involved a joke that the PyPI maintainers found in poor taste. It's also a good example, if you read deeper into the history of the name and project, of how overzealous policing of these jokes can drive people away from your community, just as underzealous policing can. Please be less angry and more careful, and appreciate that, most likely, nobody here is operating under evil intentions. They are just operating under what you might call poor taste. -- Devin On Sun, Jan 1, 2012 at 6:24 PM, Alexander Kapps wrote: > Uh oh, should I really send this? ... Yes. Yes, I should! Sorry, I cannot > resists. > > >>>> allow everyone to do "import girlfriend" > > >> I'm betting on a joke, like antigravity only significantly less >> funny and more sexist. > > > Absolutely not funny. I hope that someday people will understand that sexism > is just another form of racism. > > I was about to write a really harsh reply, but cooled down before I got a > chance to hit the Send button. > > Felinx Lee: Do apologize and rename your package/module or I'm going to make > a racist comment against Chinese people. > -- > http://mail.python.org/mailman/listinfo/python-list From lie.1296 at gmail.com Sun Jan 1 19:12:28 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 02 Jan 2012 11:12:28 +1100 Subject: Spamming PyPI with stupid packages In-Reply-To: References: Message-ID: On 01/02/2012 09:33 AM, Robert Kern wrote: > On 1/1/12 10:18 PM, Matt Chaput wrote: >> Someone seems to be spamming PyPI by uploading multiple stupid >> packages. Not sure if it's some form of advertising spam or just idiocy. >> >> Don't know if we should care though... maybe policing uploads is worse >> than cluttering PyPI's disk space and RSS feed with dumb 1 KB packages. >> >>> girlfriend 1.0.1 10 A really simple module that allow everyone to do >>> "import girlfriend" >>> girlfriends 1.0 4 Girl Friends >>> car 1.0 2 Car, a depended simple module that allow everyone to do >>> "import girlfriend" >>> house 1.0 2 House, a depended simple module that allow everyone to do >>> "import girlfriend" >>> money 1.0 2 Money, a depended simple module that allow everyone to do >>> "import girlfriend" >>> workhard 1.0 2 Keep working hard, a depended simple module that allow >>> everyone to do "import girlfriend" > > I'm betting on a joke, like antigravity only significantly less funny > and more sexist. The author is a legitimate Python programmer, and the > links go to his blog where he talks about Python stuff. Legitimate python programmer or not, that does not legitimize spamming PyPI. From jeanpierreda at gmail.com Sun Jan 1 19:12:54 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 1 Jan 2012 19:12:54 -0500 Subject: Spamming PyPI with stupid packages In-Reply-To: References: <4F00EB40.5040906@web.de> Message-ID: Sorry, I lied. It's been a while and I misremembered. The package mentioned in the blog post was removed of the author's free will, and PyPI doesn't police submissions. -- Devin On Sun, Jan 1, 2012 at 7:05 PM, Devin Jeanpierre wrote: >> Absolutely not funny. I hope that someday people will understand that sexism >> is just another form of racism. > > One can understand that sexism is a terrible thing, and at the same > time make sexist jokes. > >> Felinx Lee: Do apologize and rename your package/module or I'm going to make >> a racist comment against Chinese people. > > This is a joke, right? Making some kind of racist remark about Chinese > people wouldn't help anything at all, and it's hypocritical given your > stance on sexist jokes. It's one thing to make a joke, to make people > laugh, and inadvertently hurt someone's feelings. It's much worse to > make a malicious comment to try to hurt someone deliberately. > > On a slightly different note, PyPI uploads are in fact already > policed. See http://holdenweb.blogspot.com/2011/07/childish-behavior.html > for an example > > Coincidentally, it also involved a joke that the PyPI maintainers > found in poor taste. It's also a good example, if you read deeper into > the history of the name and project, of how overzealous policing of > these jokes can drive people away from your community, just as > underzealous policing can. Please be less angry and more careful, and > appreciate that, most likely, nobody here is operating under evil > intentions. They are just operating under what you might call poor > taste. > > -- Devin > > On Sun, Jan 1, 2012 at 6:24 PM, Alexander Kapps wrote: >> Uh oh, should I really send this? ... Yes. Yes, I should! Sorry, I cannot >> resists. >> >> >>>>> allow everyone to do "import girlfriend" >> >> >>> I'm betting on a joke, like antigravity only significantly less >>> funny and more sexist. >> >> >> Absolutely not funny. I hope that someday people will understand that sexism >> is just another form of racism. >> >> I was about to write a really harsh reply, but cooled down before I got a >> chance to hit the Send button. >> >> Felinx Lee: Do apologize and rename your package/module or I'm going to make >> a racist comment against Chinese people. >> -- >> http://mail.python.org/mailman/listinfo/python-list From rich at noir.com Sun Jan 1 19:49:59 2012 From: rich at noir.com (K Richard Pixley) Date: Sun, 01 Jan 2012 16:49:59 -0800 Subject: readline for mac python? (really, reproducing mac python packages) Message-ID: I'm having trouble finding a reasonable python environment on mac. The supplied binaries, (2.7.2, 3.2.2), are built with old versions of macosx and are not capable of building any third party packages that require gcc. The source builds easily enough out of the box, (./configure --enable-framework && make && sudo make install), but when I do that, I end up with a python interpreter that lacks readline. How do I get readline involved? Or better... is there an instruction sheet somewhere on how to reproduce the python.org binary packages? --rich From ben+python at benfinney.id.au Sun Jan 1 19:52:27 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 02 Jan 2012 11:52:27 +1100 Subject: Spamming PyPI with stupid packages References: Message-ID: <87k45b2aes.fsf@benfinney.id.au> Alexander Kapps writes: > Absolutely not funny. I hope that someday people will understand that > sexism is just another form of racism. That's not right. Racism and sexism are not forms of each other. Instead, racism and sexism are both forms of bigotry. And yes, I agree that the packages at issue are unfunny and the intent is bigoted. > I was about to write a really harsh reply, but cooled down before I got a > chance to hit the Send button. You would do better to send it to the author, rather than here. > Felinx Lee: Do apologize and rename your package/module or I'm going > to make a racist comment against Chinese people. Please don't. We must be better than the bigots whose behaiour you rightly deplore. -- \ ?God was invented to explain mystery. God is always invented to | `\ explain those things that you do not understand.? ?Richard P. | _o__) Feynman, 1988 | Ben Finney From ben+python at benfinney.id.au Sun Jan 1 20:43:00 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 02 Jan 2012 12:43:00 +1100 Subject: Spamming PyPI with stupid packages References: <87k45b2aes.fsf@benfinney.id.au> Message-ID: <878vlq3mmz.fsf@benfinney.id.au> Ben Finney writes: > Alexander Kapps writes: > > > Absolutely not funny. I hope that someday people will understand > > that sexism is just another form of racism. > > That's not right. Racism and sexism are not forms of each other. > > Instead, racism and sexism are both forms of bigotry. Hmm, even that's not really true. Racism and sexism are both forms of prejudice. Bigotry always entails prejudice, but not vice versa. How complex are the ways humans mistreat each other :-) -- \ ?Everyone is entitled to their own opinions, but they are not | `\ entitled to their own facts.? ?US Senator Pat Moynihan | _o__) | Ben Finney From rich at noir.com Sun Jan 1 22:04:09 2012 From: rich at noir.com (K Richard Pixley) Date: Sun, 01 Jan 2012 19:04:09 -0800 Subject: readline for mac python? (really, reproducing mac python packages) In-Reply-To: References: Message-ID: On 1/1/12 16:49 , K Richard Pixley wrote: > I'm having trouble finding a reasonable python environment on mac. > > The supplied binaries, (2.7.2, 3.2.2), are built with old versions of > macosx and are not capable of building any third party packages that > require gcc. > > The source builds easily enough out of the box, (./configure > --enable-framework && make && sudo make install), but when I do that, I > end up with a python interpreter that lacks readline. > > How do I get readline involved? > > Or better... is there an instruction sheet somewhere on how to reproduce > the python.org binary packages? > > --rich Bah. I just needed to dig a little deeper into the source. All the doc I wanted is in there. --rich From eulergaussriemann at gmail.com Sun Jan 1 22:14:24 2012 From: eulergaussriemann at gmail.com (David Goldsmith) Date: Sun, 1 Jan 2012 19:14:24 -0800 (PST) Subject: Can't write to a directory made w/ os.makedirs References: <50693cc2-93c9-481d-9fb1-42312e69b2d9@c42g2000prb.googlegroups.com> <91830ffb-00d9-4fd1-b771-ad59374334ec@n22g2000prh.googlegroups.com> Message-ID: <6348b96c-f7a9-4ca6-a704-c90d25f07788@y25g2000prg.googlegroups.com> On Jan 1, 7:05?am, Tim Golden wrote: > On 01/01/2012 12:05, David Goldsmith wrote: > ?>> ie can the Python process creating the directories, > ?> > ?> Yes. > ?> > ?>> and a subprocess called from it create a simple file? > ?> > ?> No. > ?> > ?>> Depending on where you are in the filesystem, it may indeed > ?>> be necessary to be running as administrator. But don't try > ?>> to crack every security nut with an elevated sledgehammer. > ?> > ?> If you mean running as admin., those were my sentiments exactly. ?So, > ?> there isn't something specific I should be doing to assure that my > ?> subproceses can write to directories? > > In the general case, no. By default, a subprocess will have > the same security context as its parent. The exception is > where the parent (the Python processing invoking subprocess.call > in this example) is already impersonating a different user; > in that case, the subprocess will inherit its grandparent's > context. > > But unless you're doing something very deliberate here then > I doubt if that's biting you. > > Can I ask: are you absolutely certain that the processes > you're calling are doing what you think they are and failing > where you think they're failing? > > TJG I'm a mathematician: the only thing I'm absolutely certain of is nothing. Here's my script, in case that helps: import os import sys import stat import os.path as op import subprocess as sub from os import remove from os import listdir as ls from os import makedirs as mkdir def doFlac2Mp3(arg, d, fl): if '.flac' in [f[-5:] for f in fl]: newD = d.replace('FLACS', 'MP3s') mkdir(newD) for f in fl: if f[-5:]=='.flac': root = f.replace('.flac', '') cmd = ['"C:\\Program Files (x86)\\aTunes\\win_tools\ \flac.exe" -d ' + '--output-prefix=' + newD + '\\', f] res = sub.call(cmd)#, env={'PATH': os.defpath}) if not res: cmd = ['"C:\\Program Files (x86)\\aTunes\\win_tools \\lame.exe" -h', newD + root + '.wav', newD + root + '.mp3'] res = sub.call(cmd)#, env={'PATH': os.defpath}) if not res: rf = newD + root + '.wav' remove(rf) top=sys.argv[1] op.walk(top, doFlac2Mp3, None) From python at mrabarnett.plus.com Sun Jan 1 22:43:43 2012 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 02 Jan 2012 03:43:43 +0000 Subject: Can't write to a directory made w/ os.makedirs In-Reply-To: <6348b96c-f7a9-4ca6-a704-c90d25f07788@y25g2000prg.googlegroups.com> References: <50693cc2-93c9-481d-9fb1-42312e69b2d9@c42g2000prb.googlegroups.com> <91830ffb-00d9-4fd1-b771-ad59374334ec@n22g2000prh.googlegroups.com> <6348b96c-f7a9-4ca6-a704-c90d25f07788@y25g2000prg.googlegroups.com> Message-ID: <4F0127EF.8070303@mrabarnett.plus.com> On 02/01/2012 03:14, David Goldsmith wrote: > On Jan 1, 7:05 am, Tim Golden wrote: >> On 01/01/2012 12:05, David Goldsmith wrote: >> >> ie can the Python process creating the directories, >> > >> > Yes. >> > >> >> and a subprocess called from it create a simple file? >> > >> > No. >> > >> >> Depending on where you are in the filesystem, it may indeed >> >> be necessary to be running as administrator. But don't try >> >> to crack every security nut with an elevated sledgehammer. >> > >> > If you mean running as admin., those were my sentiments exactly. So, >> > there isn't something specific I should be doing to assure that my >> > subproceses can write to directories? >> >> In the general case, no. By default, a subprocess will have >> the same security context as its parent. The exception is >> where the parent (the Python processing invoking subprocess.call >> in this example) is already impersonating a different user; >> in that case, the subprocess will inherit its grandparent's >> context. >> >> But unless you're doing something very deliberate here then >> I doubt if that's biting you. >> >> Can I ask: are you absolutely certain that the processes >> you're calling are doing what you think they are and failing >> where you think they're failing? >> >> TJG > > I'm a mathematician: the only thing I'm absolutely certain of is > nothing. > > Here's my script, in case that helps: > > import os > import sys > import stat > import os.path as op > import subprocess as sub > from os import remove > from os import listdir as ls > from os import makedirs as mkdir > > def doFlac2Mp3(arg, d, fl): > if '.flac' in [f[-5:] for f in fl]: > newD = d.replace('FLACS', 'MP3s') > mkdir(newD) > for f in fl: > if f[-5:]=='.flac': > root = f.replace('.flac', '') > cmd = ['"C:\\Program Files (x86)\\aTunes\\win_tools\ > \flac.exe" -d ' + > '--output-prefix=' + newD + '\\', f] > res = sub.call(cmd)#, env={'PATH': os.defpath}) > if not res: > cmd = ['"C:\\Program Files (x86)\\aTunes\\win_tools > \\lame.exe" -h', > newD + root + '.wav', newD + root + > '.mp3'] > res = sub.call(cmd)#, env={'PATH': os.defpath}) > if not res: > rf = newD + root + '.wav' > remove(rf) > > top=sys.argv[1] > op.walk(top, doFlac2Mp3, None) I think that if the command line should be something like: "C:\Program Files (x86)\aTunes\win_tools\flac.exe" -d --output-prefix=FOO\ BAR then the cmd should be something like: cmd = ['C:\\Program Files (x86)\\aTunes\\win_tools\\flac.exe', '-d', '--output-prefix="' + newD + '\\"', f] From python.list at tim.thechases.com Sun Jan 1 22:58:09 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 01 Jan 2012 21:58:09 -0600 Subject: Idiot-proof installs for python+pygame+pyopenal+app Message-ID: <4F012B51.4070403@tim.thechases.com> I'm looking at developing some tools that involve pygame+pyopenal and would like to make cross-platform distribution as painless as possible. Is there a "best practice" for doing this without forcing the user to install Python, install (say) pip, pull down pygame & pyopenal and install those, install my (simple) app, and then finally run it? On Debian, installation of all the prerequisites would just be apt-get install pygame python-openal (which, via a local apt repository, I could flag as dependencies of my app and package it as .deb) but it gets hairier on Mac & Win32. -tkc From austinbaiy at gmail.com Mon Jan 2 00:47:19 2012 From: austinbaiy at gmail.com (austinbaiy) Date: Sun, 1 Jan 2012 21:47:19 -0800 (PST) Subject: CMS Web Design & Development India Message-ID: <788675e3-6a65-4b83-b9c0-4a1ad1835469@y25g2000prg.googlegroups.com> Searching for Best Web Design, Development or Affordable SEO Service in USA? Bestwebsol.com provides professional full-cycle services: web development, custom web design & Best SEO services with guaranteed traffic increase and higher ranking. http://www.bestwebsol.com From steve+comp.lang.python at pearwood.info Mon Jan 2 02:08:22 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Jan 2012 07:08:22 GMT Subject: Spamming PyPI with stupid packages References: Message-ID: <4f0157e5$0$29966$c3e8da3$5496439d@news.astraweb.com> On Mon, 02 Jan 2012 00:24:48 +0100, Alexander Kapps wrote: > Uh oh, should I really send this? ... Yes. Yes, I should! Sorry, I > cannot resists. > >>>> allow everyone to do "import girlfriend" > >> I'm betting on a joke, like antigravity only significantly less funny >> and more sexist. > > Absolutely not funny. I hope that someday people will understand that > sexism is just another form of racism. Perhaps I'm just slow, but what is sexist about this package? Do you even know what the package does? > Felinx Lee: Do apologize and rename your package/module So the package itself is not offensive, just the name "girlfriend"? Or is it the very concept of "girlfriend" that offends you? > or I'm going to > make a racist comment against Chinese people. I'm sure he's quaking in his boots. Some random guy on the Internet is going to insult him based on a wild assumption about his nationality. -- Steven From steve+comp.lang.python at pearwood.info Mon Jan 2 02:16:07 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Jan 2012 07:16:07 GMT Subject: Spamming PyPI with stupid packages References: Message-ID: <4f0159b7$0$29966$c3e8da3$5496439d@news.astraweb.com> On Mon, 02 Jan 2012 11:12:28 +1100, Lie Ryan wrote: > Legitimate python programmer or not, that does not legitimize spamming > PyPI. I don't see that half a dozen trivial (pointless) modules should be classified as spam. Personally, I've looked at the modules, and if I were the author, I'd be embarrassed to make them public. They aren't useful; they are rather immature; they don't demonstrate good Python knowledge or programming skill. -- Steven From p_s_d_a_s_i_l_v_a at netcabo.pt Mon Jan 2 02:24:01 2012 From: p_s_d_a_s_i_l_v_a at netcabo.pt (Paulo da Silva) Date: Mon, 02 Jan 2012 07:24:01 +0000 Subject: Generating sin/square waves sound References: Message-ID: Em 30-12-2011 10:05, Dave Angel escreveu: > On 12/30/2011 02:17 AM, Paulo da Silva wrote: >> Hi, >> Sorry if this is a FAQ, but I have googled and didn't find any >> satisfatory answer. >> >> Is there a simple way, preferably multiplataform (or linux), of >> generating sinusoidal/square waves sound in python? >> >> Thanks for any answers/suggestions. > If you're willing to be Linux-only, then I believe you can do it without > any extra libraries. > > You build up a string (8 bit char, on Python 2.x) of samples, and write > it to "/dev/audio". When i experimented, I was only interested in a > few seconds, so a single write was all I needed. > > Note that the samples are 8 bits, and they are offset by 128. So a zero > signal would be a string of 128 values. A very quiet square wave might > be a bunch of 126, followed by a bunch of 130. and so on. And the > loudest might be a bunch of 2's followed by a bunch of 253's. > > You'll have to experiment with data rate; The data is sent out at a > constant rate from your string, but I don't know what that rate is. > > This sounds nice, but then is 8 bits the limit for /dev/audio? What about stereo? I don't need this one ... just for curiosity. Thanks. From p_s_d_a_s_i_l_v_a at netcabo.pt Mon Jan 2 02:31:13 2012 From: p_s_d_a_s_i_l_v_a at netcabo.pt (Paulo da Silva) Date: Mon, 02 Jan 2012 07:31:13 +0000 Subject: Generating sin/square waves sound References: Message-ID: Em 30-12-2011 11:23, mblume escreveu: > Am Fri, 30 Dec 2011 07:17:13 +0000 schrieb Paulo da Silva: ... > Alternatively you might just generate (t,signal) samples, write them to > a file and convert them using "sox" (under Linux, might also be available > under Windows) to another format. > As much as I could understand at a 1st look you are writing to a wav file and then play the file. It would be nice if I could play directly the samples. Anyway I'll take a look at the wave module. Thanks From p_s_d_a_s_i_l_v_a at netcabo.pt Mon Jan 2 02:34:24 2012 From: p_s_d_a_s_i_l_v_a at netcabo.pt (Paulo da Silva) Date: Mon, 02 Jan 2012 07:34:24 +0000 Subject: Generating sin/square waves sound References: Message-ID: Em 31-12-2011 01:19, K Richard Pixley escreveu: > On 12/29/11 23:17 , Paulo da Silva wrote: >> Hi, >> Sorry if this is a FAQ, but I have googled and didn't find any >> satisfatory answer. >> >> Is there a simple way, preferably multiplataform (or linux), of >> generating sinusoidal/square waves sound in python? >> >> Thanks for any answers/suggestions. > > I just posted on this elsewhere. Look for a thread titled: "Which > library for audio playback ?" > > --rich Thank you. I have just seen it using google and saved the bookmark of the link. It's too late now but I'll read it tomorrow. From jeanpierreda at gmail.com Mon Jan 2 02:52:06 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Mon, 2 Jan 2012 02:52:06 -0500 Subject: Spamming PyPI with stupid packages In-Reply-To: <4f0157e5$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <4f0157e5$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: > Perhaps I'm just slow, but what is sexist about this package? Do you even > know what the package does? The dependencies are "car", "house", and "money" (and "workhard", of course). The joke being that women only care about how wealthy you are. If it's just about naming a package "girlfriend", though, I agree. And honestly that's much better material for a joke anyway. -- Devin On Mon, Jan 2, 2012 at 2:08 AM, Steven D'Aprano wrote: > On Mon, 02 Jan 2012 00:24:48 +0100, Alexander Kapps wrote: > >> Uh oh, should I really send this? ... Yes. Yes, I should! Sorry, I >> cannot resists. >> >>>>> allow everyone to do "import girlfriend" >> >>> I'm betting on a joke, like antigravity only significantly less funny >>> and more sexist. >> >> Absolutely not funny. I hope that someday people will understand that >> sexism is just another form of racism. > > Perhaps I'm just slow, but what is sexist about this package? Do you even > know what the package does? > > >> Felinx Lee: Do apologize and rename your package/module > > So the package itself is not offensive, just the name "girlfriend"? > > Or is it the very concept of "girlfriend" that offends you? > > >> or I'm going to >> make a racist comment against Chinese people. > > I'm sure he's quaking in his boots. Some random guy on the Internet is > going to insult him based on a wild assumption about his nationality. > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list From peter at www.pjb.com.au Mon Jan 2 05:05:43 2012 From: peter at www.pjb.com.au (Peter Billam) Date: 02 Jan 2012 10:05:43 GMT Subject: Generating sin/square waves sound References: Message-ID: On 2012-01-02, Paulo da Silva wrote: > Em 30-12-2011 11:23, mblume escreveu: >> Am Fri, 30 Dec 2011 07:17:13 +0000 schrieb Paulo da Silva: >> Alternatively you might just generate (t,signal) samples, write >> them to a file and convert them using "sox" (under Linux, might >> also be available under Windows) to another format. That's how I'd do it. Sox can cope with raw samples, provided you tell it stuff like the sample-rate, sample-size, channels etc. E.g. from "man sox" sox -r 16k -e signed -b 8 -c 1 voice-memo.raw voice-memo.wav (Once it's in wav form the wav header contains that information.) > As much as I could understand at a 1st look you are > writing to a wav file and then play the file. > It would be nice if I could play directly the samples. "-d" as an output-file means the "default" output, which means it plays to your sound card. E.g.: sox -r 48k -e float -b 32 -c 2 input.raw -d The input file can be "-" so you can pipe directly to it: sox -r 44100 -e float -b 32 -c 2 - -d It should also run under windows and macos, and can generate lots of formats, see "man soxformat". It also has a "synth" effect which can generate simple waveforms easily. Sox is useful. Regards, Peter -- Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html From tjreedy at udel.edu Mon Jan 2 05:29:58 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 02 Jan 2012 05:29:58 -0500 Subject: .format vs. % In-Reply-To: <2939615.568.1325452304773.JavaMail.geo-discussion-forums@vbdz6> References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <3779937.289.1325357048110.JavaMail.geo-discussion-forums@vbtv37> <2939615.568.1325452304773.JavaMail.geo-discussion-forums@vbdz6> Message-ID: On 1/1/2012 4:11 PM, Miki Tebeka wrote: >>>>> s = "{0} {1} {2} {3}" >>>>> s.format(1, 2, 3, 4) >> '1 2 3 4' > Or even > In [4]: fmt = '{0} {1} {2} {3}'.format > In [5]: print(fmt(1, 2, 3, 4)) > 1 2 3 4 I have done this, except for using a more informative name, like 'emsg' for error message. except XError as e: print(emsg(a,b,c,e)) makes for pretty clear code. -- Terry Jan Reedy From felinx.lee at gmail.com Mon Jan 2 06:03:25 2012 From: felinx.lee at gmail.com (Felinx Lee) Date: Mon, 2 Jan 2012 19:03:25 +0800 Subject: Spamming PyPI with stupid packages Message-ID: Hi guys, I am the author of girlfriend module, a serious Python programmer. This project is nothing about sexist or racism, it is just a joke, a famous joke in China, please be cool down. And now, I have removed money, car, house packages from PyPi, and remove their dependences in girlfriend module, the website is also updated. The girlfriend module just depends on workhard module now. I will remove girlfriend module forever if you still think it is a spam or illegal. I'm sorry for that I abused the PyPi, but I should say again that it is nothing about sexist or racism as you assumption. Felinx Lee On 1/1/12 10:18 PM, Matt Chaput wrote: > Someone seems to be spamming PyPI by uploading multiple stupid packages. > Not sure if it's some form of advertising spam or just idiocy. > > Don't know if we should care though... maybe policing uploads is worse > than cluttering PyPI's disk space and RSS feed with dumb 1 KB packages. > > girlfriend 1.0.1 10 A really simple module that allow everyone >> to do "import girlfriend" >> girlfriends 1.0 4 Girl Friends >> car 1.0 2 Car, a depended simple module that allow everyone to do >> "import girlfriend" >> house 1.0 2 House, a depended simple module that allow >> everyone to do "import girlfriend" >> money 1.0 2 Money, a depended simple module that allow >> everyone to do "import girlfriend" >> workhard 1.0 2 Keep working hard, a depended simple module that >> allow everyone to do "import girlfriend" >> > I'm betting on a joke, like antigravity only significantly less funny and more sexist. The author is a legitimate Python programmer, and the links go to his blog where he talks about Python stuff. https://bitbucket.org/felinx You can tell him that you don't appreciate his abuse of PyPI here if you like: http://feilong.me/2012/01/**python-import-girlfriend -- 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 -- What can change the nature of a man?(Planescape Torment) ---------------------------------------------------------------------------------------- http://feilong.me Felinx Lee's Blog (Chinese Only) http://www.zhimaq.com IT Q&A (Chinese Only) http://poweredsites.org What powered your sites? PHP, Ruby or Python? -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Mon Jan 2 06:11:27 2012 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 02 Jan 2012 11:11:27 +0000 Subject: Can't write to a directory made w/ os.makedirs In-Reply-To: <6348b96c-f7a9-4ca6-a704-c90d25f07788@y25g2000prg.googlegroups.com> References: <50693cc2-93c9-481d-9fb1-42312e69b2d9@c42g2000prb.googlegroups.com> <91830ffb-00d9-4fd1-b771-ad59374334ec@n22g2000prh.googlegroups.com> <6348b96c-f7a9-4ca6-a704-c90d25f07788@y25g2000prg.googlegroups.com> Message-ID: <4F0190DF.2060401@timgolden.me.uk> On 02/01/2012 03:14, David Goldsmith wrote: > Here's my script, in case that helps: It certainly does. A few things occur to me. First, you shouldn't need to double-quote the path; the subprocess.call should do that for you as long as you're using the list version of the param -- which you are. Second, you almost certainly don't want to be using the env param, at least not in the way you are. Depending on the way in which your app runs, either pass the appropriate directory as the cwd= param, or copy and override the current environ dict, ie either do this: subprocess.call ( ['c:/program files/somewhere/app.exe', 'blah1', 'blah2'], cwd="c:/somewhere/else" ) or this: env = dict (os.environ) env['PATH'] = "c:/somewhere/else" # or env['PATH'] += ";c:/somewhere/else" subprocess.call ( ['c:/program files/somewhere/app.exe', 'blah1', 'blah2'], env=env ) See if any of that helps TJG From kai.diefenbach at iqpp.de Mon Jan 2 06:22:26 2012 From: kai.diefenbach at iqpp.de (Kai Diefenbach) Date: Mon, 2 Jan 2012 12:22:26 +0100 Subject: Spamming PyPI with stupid packages References: Message-ID: Hi, On 2012-01-02 11:03:25 +0000, Felinx Lee said: > I am the author of girlfriend module, a serious Python programmer. > This project is nothing about sexist or racism,? > it is just a joke, a famous joke in China, please be cool down. Yeah, quite funny. Why not put this on an own web server? > And now, I have removed money, car, house packages from PyPi,? > and remove their dependences in girlfriend module, the website is also updated. > The girlfriend module just depends on workhard module now. > I will remove girlfriend module forever if you still think it is a spam > or illegal. I think it's fucking spam. Please remove this crap. kthxbye Kai From felinx.lee at gmail.com Mon Jan 2 06:37:23 2012 From: felinx.lee at gmail.com (Felinx Lee) Date: Mon, 2 Jan 2012 19:37:23 +0800 Subject: Spamming PyPI with stupid packages Message-ID: Hi, On 2012-01-02 11:03:25 +0000, Felinx Lee said: > I am the author of girlfriend module, a serious Python programmer. > This project is nothing about sexist or racism, > it is just a joke, a famous joke in China, please be cool down. Yeah, quite funny. Why not put this on an own web server? > And now, I have removed money, car, house packages from PyPi, > and remove their dependences in girlfriend module, the website is also updated. > The girlfriend module just depends on workhard module now. > I will remove girlfriend module forever if you still think it is a spam > or illegal. I think it's fucking spam. Please remove this crap. OK, Removed. I apologize again. kthxbye Kai -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris at simplistix.co.uk Mon Jan 2 06:49:55 2012 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 02 Jan 2012 11:49:55 +0000 Subject: Spamming PyPI with stupid packages In-Reply-To: References: Message-ID: <4F0199E3.7010608@simplistix.co.uk> On 02/01/2012 11:03, Felinx Lee wrote: > The girlfriend module just depends on workhard module now. > I will remove girlfriend module forever if you still think it is a spam > or illegal. What is the point of these packages? Why do they exist? Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From felinx.lee at gmail.com Mon Jan 2 07:09:07 2012 From: felinx.lee at gmail.com (Felinx Lee) Date: Mon, 2 Jan 2012 20:09:07 +0800 Subject: Spamming PyPI with stupid packages Message-ID: I have removed those packages (girlfriend and others) from PyPI forever, I apologize for that. -- Felinx Lee -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Mon Jan 2 07:20:24 2012 From: __peter__ at web.de (Peter Otten) Date: Mon, 02 Jan 2012 13:20:24 +0100 Subject: Spamming PyPI with stupid packages References: Message-ID: Felinx Lee wrote: > I have removed those packages (girlfriend and others) from PyPI forever, I > apologize for that. The thought police has won :( From monaghand.david at gmail.com Mon Jan 2 08:00:48 2012 From: monaghand.david at gmail.com (David Monaghan) Date: Mon, 02 Jan 2012 13:00:48 +0000 Subject: Spamming PyPI with stupid packages References: <4f0157e5$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, 2 Jan 2012 02:52:06 -0500, Devin Jeanpierre wrote: >> Perhaps I'm just slow, but what is sexist about this package? Do you even >> know what the package does? > >The dependencies are "car", "house", and "money" (and "workhard", of >course). The joke being that women only care about how wealthy you >are. That's not a joke, it's a stereotype - and a stereotype with a biological truth in it. DaveM From rosuav at gmail.com Mon Jan 2 08:20:46 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Jan 2012 00:20:46 +1100 Subject: Spamming PyPI with stupid packages In-Reply-To: References: Message-ID: On Mon, Jan 2, 2012 at 11:20 PM, Peter Otten <__peter__ at web.de> wrote: > Felinx Lee wrote: > >> I have removed those packages (girlfriend and others) from PyPI forever, I >> apologize for that. > > The thought police has won :( There's nothing wrong with cracking jokes, but sometimes a large central repository is the wrong place for them. If I made a joke package whose name happened to be very similar to some other package, then no matter how funny and non-offensive the joke is, it would be a poor submission to PyPI. But that's not "thought police"; there are plenty of other avenues for publication. Felinx Lee still has the freedom to think his joke, to write his joke in code, and to share his joke with others - but other people have the freedom to get offended when it's published in places that they think are racist, or whatever it was. (I never did follow how sexism is somehow a subset of racism, to be honest. Are women a different race from nerds?) Chris Angelico From nikos.kouras at gmail.com Mon Jan 2 08:25:02 2012 From: nikos.kouras at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Mon, 2 Jan 2012 05:25:02 -0800 (PST) Subject: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error References: <920839e5-58fa-4fdf-9c88-7bed9a7448fd@d10g2000vbh.googlegroups.com> <1f45fa2a-0c4f-4362-bc75-e73ce16595ab@o9g2000vbc.googlegroups.com> <144a4387-e80e-4782-a6eb-aecc1e742dc6@v14g2000yqh.googlegroups.com> Message-ID: <5c874675-ec98-445f-af91-9741413c512d@z1g2000vbx.googlegroups.com> On 23 ??? 2011, 19:14, ???????? ?????? wrote: > On 23 ???, 12:41, becky_lewis wrote: > > > Is there any possibility that you can tell us what the script actually > > is or provide a code listing (use pastebin if it's big)? > > The script is about retrieving and storing the visitros hostnames to > mysql database creating a log file. > > I dont know why this line host = > socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] fails sometimes > and some other times works ok retrieving the hostnames correctly. > > What do you understand from the traceback?! Please i need some help. My webpage doesn't work due to this error... From modelnine at modelnine.org Mon Jan 2 09:00:26 2012 From: modelnine at modelnine.org (Heiko Wundram) Date: Mon, 02 Jan 2012 15:00:26 +0100 Subject: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error In-Reply-To: <5c874675-ec98-445f-af91-9741413c512d@z1g2000vbx.googlegroups.com> References: <920839e5-58fa-4fdf-9c88-7bed9a7448fd@d10g2000vbh.googlegroups.com> <1f45fa2a-0c4f-4362-bc75-e73ce16595ab@o9g2000vbc.googlegroups.com> <144a4387-e80e-4782-a6eb-aecc1e742dc6@v14g2000yqh.googlegroups.com> <5c874675-ec98-445f-af91-9741413c512d@z1g2000vbx.googlegroups.com> Message-ID: <4F01B87A.9000700@modelnine.org> Am 02.01.2012 14:25, schrieb ???????? ??????: > On 23 ??? 2011, 19:14, ???????? ?????? wrote: >> I dont know why this line host = >> socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] fails sometimes >> and some other times works ok retrieving the hostnames correctly. > > Please i need some help. My webpage doesn't work due to this error... The error "herror: (1, ...)" says it all: the DNS-name (i.e., the .in-addr.arpa name) you're trying to resolve is unknown. Not all hosts (or rather, IPs) on the internet have reverse lookups: try the IP 81.14.209.35 from which I'm posting, and dig/nslookup will tell you that it has no reverse resolution, which would result in gethostbyaddr() throwing an herror-instance. Basically: make the reverse lookup conditional by wrapping it in a try:/except herror: and assigning an appropriate default for host in case reverse lookup fails. -- --- Heiko. From d at davea.name Mon Jan 2 09:09:27 2012 From: d at davea.name (Dave Angel) Date: Mon, 02 Jan 2012 09:09:27 -0500 Subject: Can't write to a directory made w/ os.makedirs In-Reply-To: <6348b96c-f7a9-4ca6-a704-c90d25f07788@y25g2000prg.googlegroups.com> References: <50693cc2-93c9-481d-9fb1-42312e69b2d9@c42g2000prb.googlegroups.com> <91830ffb-00d9-4fd1-b771-ad59374334ec@n22g2000prh.googlegroups.com> <6348b96c-f7a9-4ca6-a704-c90d25f07788@y25g2000prg.googlegroups.com> Message-ID: <4F01BA97.1050604@davea.name> On 01/01/2012 10:14 PM, David Goldsmith wrote: > On Jan 1, 7:05 am, Tim Golden wrote: >> On 01/01/2012 12:05, David Goldsmith wrote: >> >> ie can the Python process creating the directories, >> > >> > Yes. >> > >> >> and a subprocess called from it create a simple file? >> > >> > No. >> > >> >> Depending on where you are in the filesystem, it may indeed >> >> be necessary to be running as administrator. But don't try >> >> to crack every security nut with an elevated sledgehammer. >> > >> > If you mean running as admin., those were my sentiments exactly. So, >> > there isn't something specific I should be doing to assure that my >> > subproceses can write to directories? >> >> In the general case, no. By default, a subprocess will have >> the same security context as its parent. The exception is >> where the parent (the Python processing invoking subprocess.call >> in this example) is already impersonating a different user; >> in that case, the subprocess will inherit its grandparent's >> context. >> >> But unless you're doing something very deliberate here then >> I doubt if that's biting you. >> >> Can I ask: are you absolutely certain that the processes >> you're calling are doing what you think they are and failing >> where you think they're failing? >> >> TJG > I'm a mathematician: the only thing I'm absolutely certain of is > nothing. > > Here's my script, in case that helps: > > import os > import sys > import stat > import os.path as op > import subprocess as sub > from os import remove > from os import listdir as ls > from os import makedirs as mkdir > > def doFlac2Mp3(arg, d, fl): > if '.flac' in [f[-5:] for f in fl]: > newD = d.replace('FLACS', 'MP3s') > mkdir(newD) > for f in fl: > if f[-5:]=='.flac': > root = f.replace('.flac', '') > cmd = ['"C:\\Program Files (x86)\\aTunes\\win_tools\ > \flac.exe" -d ' + > '--output-prefix=' + newD + '\\', f] > res = sub.call(cmd)#, env={'PATH': os.defpath}) > if not res: > cmd = ['"C:\\Program Files (x86)\\aTunes\\win_tools > \\lame.exe" -h', > newD + root + '.wav', newD + root + > '.mp3'] > res = sub.call(cmd)#, env={'PATH': os.defpath}) > if not res: > rf = newD + root + '.wav' > remove(rf) > > top=sys.argv[1] > op.walk(top, doFlac2Mp3, None) The line cmd= is bogus. You're trying to run a program with a -h after the filename. The reason you're passing a list to sub.call is to separate the parameters from the program name, not to mention with quotes in its name. So the -h has to be a separate list item. (Although Windows will probably handle it correctly if you combine the -h with the FOLLOWING argument, it's still bad practice] cmd = [ "c:\\program files .... \\lame.exe", "-h", newD + root + ....." -- DaveA From nikos.kouras at gmail.com Mon Jan 2 10:29:10 2012 From: nikos.kouras at gmail.com (=?UTF-8?B?zp3Ouc66z4zOu86xzr/PgiDOms6/z43Pgc6xz4I=?=) Date: Mon, 2 Jan 2012 07:29:10 -0800 (PST) Subject: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error References: <920839e5-58fa-4fdf-9c88-7bed9a7448fd@d10g2000vbh.googlegroups.com> <1f45fa2a-0c4f-4362-bc75-e73ce16595ab@o9g2000vbc.googlegroups.com> <144a4387-e80e-4782-a6eb-aecc1e742dc6@v14g2000yqh.googlegroups.com> <5c874675-ec98-445f-af91-9741413c512d@z1g2000vbx.googlegroups.com> Message-ID: <6b787f23-5813-4831-a349-02883f564da4@q7g2000yqn.googlegroups.com> On 2 ???, 16:00, Heiko Wundram wrote: > Am 02.01.2012 14:25, schrieb ???????? ??????: > > > On 23 ??? 2011, 19:14, ???????? ?????? ?wrote: > >> I dont know why this line host = > >> socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] fails sometimes > >> and some other times works ok retrieving the hostnames correctly. > > > Please i need some help. My webpage doesn't work due to this error... > > The error "herror: (1, ...)" says it all: the DNS-name (i.e., the > .in-addr.arpa name) you're trying to resolve is unknown. Not > all hosts (or rather, IPs) on the internet have reverse lookups: try the > IP 81.14.209.35 from which I'm posting, and dig/nslookup will tell you > that it has no reverse resolution, which would result in gethostbyaddr() > throwing an herror-instance. I see > Basically: make the reverse lookup conditional by wrapping it in a > try:/except herror: and assigning an appropriate default for host in > case reverse lookup fails. Can tou show me how to write this please? From roy at panix.com Mon Jan 2 10:47:09 2012 From: roy at panix.com (Roy Smith) Date: Mon, 02 Jan 2012 10:47:09 -0500 Subject: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error References: <920839e5-58fa-4fdf-9c88-7bed9a7448fd@d10g2000vbh.googlegroups.com> <1f45fa2a-0c4f-4362-bc75-e73ce16595ab@o9g2000vbc.googlegroups.com> <144a4387-e80e-4782-a6eb-aecc1e742dc6@v14g2000yqh.googlegroups.com> <5c874675-ec98-445f-af91-9741413c512d@z1g2000vbx.googlegroups.com> <6b787f23-5813-4831-a349-02883f564da4@q7g2000yqn.googlegroups.com> Message-ID: In article <6b787f23-5813-4831-a349-02883f564da4 at q7g2000yqn.googlegroups.com>, ?????????????????????? ???????????? wrote: > On 2 ????????????, 16:00, Heiko Wundram wrote: > > Am 02.01.2012 14:25, schrieb ?????????????????????? ????????????: > > > > > On 23 ?????? 2011, 19:14, ???????????????? ???????????? ??wrote: > > >> I dont know why this line host = > > >> socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] fails sometimes > > >> and some other times works ok retrieving the hostnames correctly. > > > > > Please i need some help. My webpage doesn't work due to this error... > > > > The error "herror: (1, ...)" says it all: the DNS-name (i.e., the > > .in-addr.arpa name) you're trying to resolve is unknown. Not > > all hosts (or rather, IPs) on the internet have reverse lookups: try the > > IP 81.14.209.35 from which I'm posting, and dig/nslookup will tell you > > that it has no reverse resolution, which would result in gethostbyaddr() > > throwing an herror-instance. > > I see > > > Basically: make the reverse lookup conditional by wrapping it in a > > try:/except herror: and assigning an appropriate default for host in > > case reverse lookup fails. > > Can tou show me how to write this please? try: host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] except socket.herror: host = "" From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Mon Jan 2 10:49:01 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Mon, 02 Jan 2012 16:49:01 +0100 Subject: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error In-Reply-To: References: Message-ID: Am 22.12.2011 15:40 schrieb ???????? ??????: > Hello when i try to visit my webpage i get the error it displays. Iam > not posting it since you can see it by visiting my webpage at > http://superhost.gr > > Please if you can tell me what might be wrong. What is wrong on this site? Mainly the unwanted sound. Are you trying to sell something? Then you should try not to scare your potential customers away. From invalid at invalid.invalid Mon Jan 2 12:02:15 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 2 Jan 2012 17:02:15 +0000 (UTC) Subject: Python education survey References: <06423dd7-4fbb-4e7a-b529-e697ea862b05@f11g2000yql.googlegroups.com> <36065956-359d-42cf-a5fc-75fdea830737@y7g2000vbe.googlegroups.com> <470c9b9b-780f-4b00-8fef-adba8b036c2b@32g2000yqp.googlegroups.com> <74b1ed63-f755-49e3-a275-92b2658ef991@o14g2000vbo.googlegroups.com> <4efabe42$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2012-01-01, Alexander Kapps wrote: > On 01.01.2012 03:36, Grant Edwards wrote: >> On 2011-12-31, Alexander Kapps wrote: >>> On 31.12.2011 19:23, Roy Smith wrote: >>> >>>>>> Why do I waste my time reading your pretentious self-important nonsense? >>>>> >>>>> http://xkcd.com/386/ >>>>> >>>>> ;) >>>> >>>> Why ROFLMAO when double-plus funny works just as well? >>> >>> xkcd/386 has been the excuse for replying to RR for ages and I still >>> don't understand why he gets that much advertence. Charity? Sympathy >>> for the lone and broken? >> >> Sadly, RR's post are often (in the supposed words of Wolfgang Pauli) >> "not even wrong". > > I'm sure, RR is now jumping up high in rapture for being compared to > high-profile scientist geniuses. I'm not comparing RR to Pauli. I'm quoting somethin Pauli said when criticising something that was so confusing and ill conceived that "it wasn't even wrong". -- Grant From d at davea.name Mon Jan 2 12:12:32 2012 From: d at davea.name (Dave Angel) Date: Mon, 02 Jan 2012 12:12:32 -0500 Subject: Generating sin/square waves sound In-Reply-To: References: Message-ID: <4F01E580.7000006@davea.name> On 01/02/2012 02:24 AM, Paulo da Silva wrote: > Em 30-12-2011 10:05, Dave Angel escreveu: >> On 12/30/2011 02:17 AM, Paulo da Silva wrote: >>> Hi, >>> Sorry if this is a FAQ, but I have googled and didn't find any >>> satisfatory answer. >>> >>> Is there a simple way, preferably multiplataform (or linux), of >>> generating sinusoidal/square waves sound in python? >>> >>> Thanks for any answers/suggestions. >> If you're willing to be Linux-only, then I believe you can do it without >> any extra libraries. >> >> You build up a string (8 bit char, on Python 2.x) of samples, and write >> it to "/dev/audio". When i experimented, I was only interested in a >> few seconds, so a single write was all I needed. >> >> Note that the samples are 8 bits, and they are offset by 128. So a zero >> signal would be a string of 128 values. A very quiet square wave might >> be a bunch of 126, followed by a bunch of 130. and so on. And the >> loudest might be a bunch of 2's followed by a bunch of 253's. >> >> You'll have to experiment with data rate; The data is sent out at a >> constant rate from your string, but I don't know what that rate is. >> >> > This sounds nice, but then is 8 bits the limit for /dev/audio? What > about stereo? I don't need this one ... just for curiosity. > Thanks. I don't even remember where I got the information, but it sufficed for my needs. I wanted to be able to generate arbitrary tones at a high volume, bypassing any volume control system settings. I assume there's some way (ioctl ?) to tell the device to interpret differently. It's even possible that it's already stereo (left/right samples stored in adjacent 16bit locations -- it wouldn't change the effect I hear, except for the frequency being cut in half. Interesting link from1991, it's from Guido, but doesn't mention Python http://wiretap.area.com/Gopher/Library/Techdoc/Misc/audiofor.faq Also, a lot has changed since then. Now I wonder whether I should be sending u-law values, rather than linear ones. I'm generating sine waves, and they don't really sound flutelike. This link probably has all our answers. http://www.faqs.org/docs/Linux-HOWTO/Sound-HOWTO.html I suspect that my approach will simply use the latest setup values (eg. sampling rate) and thus runs the risk of sometimes not working. That hasn't been my experience, The only problem I see is that sometimes the device is "busy". When that happens, other programs don't seem to work either. I need to find the rogue process which is hogging the device, using fuser. -- DaveA From lie.1296 at gmail.com Mon Jan 2 12:44:03 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 03 Jan 2012 04:44:03 +1100 Subject: Spamming PyPI with stupid packages In-Reply-To: References: Message-ID: On 01/02/2012 11:20 PM, Peter Otten wrote: > Felinx Lee wrote: > >> I have removed those packages (girlfriend and others) from PyPI forever, I >> apologize for that. > > The thought police has won :( I think the community has a right to defend themselves against trolls. If it's just bad naming, we can probably just laugh it off; but when a failed joke spans a half dozen module and just opens a browser to his website, there is no value for it to stay at PyPI. Additionally, it may fuel copycats: http://pypi.python.org/pypi/kimwoohyeon1/1.3.0 (do anyone have any idea who submitted that one?) From p_s_d_a_s_i_l_v_a at netcabo.pt Mon Jan 2 13:09:07 2012 From: p_s_d_a_s_i_l_v_a at netcabo.pt (Paulo da Silva) Date: Mon, 02 Jan 2012 18:09:07 +0000 Subject: Generating sin/square waves sound References: Message-ID: Em 30-12-2011 07:17, Paulo da Silva escreveu: > Hi, > Sorry if this is a FAQ, but I have googled and didn't find any > satisfatory answer. > > Is there a simple way, preferably multiplataform (or linux), of > generating sinusoidal/square waves sound in python? > > Thanks for any answers/suggestions. Thank you very much to all who responded. There is enough material here to spend some time searching for the best solution for me. In the meanwhile I also found http://www.speech.kth.se/snack. May be it could also be useful. Thank you. From nikos.kouras at gmail.com Mon Jan 2 13:17:13 2012 From: nikos.kouras at gmail.com (=?UTF-8?B?zp3Ouc66z4zOu86xzr/PgiDOms6/z43Pgc6xz4I=?=) Date: Mon, 2 Jan 2012 10:17:13 -0800 (PST) Subject: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error References: <920839e5-58fa-4fdf-9c88-7bed9a7448fd@d10g2000vbh.googlegroups.com> <1f45fa2a-0c4f-4362-bc75-e73ce16595ab@o9g2000vbc.googlegroups.com> <144a4387-e80e-4782-a6eb-aecc1e742dc6@v14g2000yqh.googlegroups.com> <5c874675-ec98-445f-af91-9741413c512d@z1g2000vbx.googlegroups.com> <6b787f23-5813-4831-a349-02883f564da4@q7g2000yqn.googlegroups.com> Message-ID: <7a9e8fce-3a6a-4b16-b8f0-411106a1d1e3@e2g2000vbb.googlegroups.com> On 2 ???, 17:47, Roy Smith wrote: > In article > <6b787f23-5813-4831-a349-02883f564... at q7g2000yqn.googlegroups.com>, > ???????????? ?????? wrote: > > > > > > > > > > > On 2 ??????, 16:00, Heiko Wundram wrote: > > > Am 02.01.2012 14:25, schrieb ??????????? ??????: > > > > > On 23 ??? 2011, 19:14, ???????? ?????? ?wrote: > > > >> I dont know why this line host = > > > >> socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] fails sometimes > > > >> and some other times works ok retrieving the hostnames correctly. > > > > > Please i need some help. My webpage doesn't work due to this error... > > > > The error "herror: (1, ...)" says it all: the DNS-name (i.e., the > > > .in-addr.arpa name) you're trying to resolve is unknown. Not > > > all hosts (or rather, IPs) on the internet have reverse lookups: try the > > > IP 81.14.209.35 from which I'm posting, and dig/nslookup will tell you > > > that it has no reverse resolution, which would result in gethostbyaddr() > > > throwing an herror-instance. > > > I see > > > > Basically: make the reverse lookup conditional by wrapping it in a > > > try:/except herror: and assigning an appropriate default for host in > > > case reverse lookup fails. > > > Can tou show me how to write this please? > > try: > ? ?host = ?socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] > except socket.herror: > ? ?host = "" Thank you very much. From wm at localhost.localdomain Mon Jan 2 13:18:23 2012 From: wm at localhost.localdomain (Waldek M.) Date: Mon, 2 Jan 2012 19:18:23 +0100 Subject: InvalidResponseError: headers must be str References: <18871670.1096.1325307490244.JavaMail.geo-discussion-forums@yqdx38> <4efeae6a$0$29966$c3e8da3$5496439d@news.astraweb.com> <4eff057d$0$29966$c3e8da3$5496439d@news.astraweb.com> <9589290.553.1325338274423.JavaMail.geo-discussion-forums@yqcb25> <4eff1cdb$0$29966$c3e8da3$5496439d@news.astraweb.com> <19725208.758.1325382015274.JavaMail.geo-discussion-forums@yqja5> Message-ID: <1ewqzx7xq0r15.dlg@localhost.localdomain> On Sat, 31 Dec 2011 17:40:15 -0800 (PST), Niklas Rosencrantz wrote: > Thanks for the replies here. I will have patience but this bug > is blocking my integration efforts. I tried logging the TCP > packets with tcpdump and nothing special appeared. Well, it's free software, isn't it? You may either wait a little, fix it yourself or pay someone to fix it for you, if you're in a hurry. Or stay with 2.5 / try upgrading to 3.x. The Python community is usually very helpful and friendly, but by *demanding& a fix ASAP you may accidentily step on people's toes :-) Best regards, Waldek From nikos.kouras at gmail.com Mon Jan 2 13:18:28 2012 From: nikos.kouras at gmail.com (=?UTF-8?B?zp3Ouc66z4zOu86xzr/PgiDOms6/z43Pgc6xz4I=?=) Date: Mon, 2 Jan 2012 10:18:28 -0800 (PST) Subject: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error References: Message-ID: On 2 ???, 17:49, Thomas Rachel wrote: > Am 22.12.2011 15:40 schrieb ???????? ??????: > > > Hello when i try to visit my webpage i get the error it displays. Iam > > not posting it since you can see it by visiting my webpage at > >http://superhost.gr > > > Please if you can tell me what might be wrong. > > What is wrong on this site? Mainly the unwanted sound. > > Are you trying to sell something? Then you should try not to scare your > potential customers away. I'am trying to present myself through my webpage as computer tech. Is the background music so bad?! :-) From roy at panix.com Mon Jan 2 13:42:48 2012 From: roy at panix.com (Roy Smith) Date: Mon, 02 Jan 2012 13:42:48 -0500 Subject: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error References: Message-ID: In article , ?????????????????????? ???????????? wrote: > I'am trying to present myself through my webpage as computer tech. > Is the background music so bad?! :-) Yes. Background music on web sites is evil. From hazemdahab119822011 at gmail.com Mon Jan 2 14:11:56 2012 From: hazemdahab119822011 at gmail.com (hazem dahab) Date: Mon, 2 Jan 2012 11:11:56 -0800 (PST) Subject: The Ultimate Computer Software Source - Download Everything You Need For Your PC For Free Message-ID: <7dcabbe0-7f2a-4f8d-8cfb-d07d964126b4@cs7g2000vbb.googlegroups.com> The Ultimate Computer Software Source - Download Everything You Need For Your PC For Free FrinzoO Computer Forum provides a place where all members can ask for help and discuss a wide variety of technical topics: 1- Computer Software 2- Computer Hardware 3- Computer Problems' Solutions 4- Laptops and Netbooks Reviews 5- Computer Games 6- Web Design and Development 7- Mobile Phones, Tablets and other Handheld Devices 8- Search Engines 9- Online Internet Marketing 10- Online Internet Business 11- Search Engine Optimization 12- Affiliate Marketing 13- Movies 14- Music Membership is free, so sign up today and join in on the discussions! Visit us at http://www.frinzoo.com Visit our Facebook Page to get our latest updates at: http://www.facebook.com/FrinzoO.Computer.Software.Forum Follow us on Twitter at: http://twitter.com/#!/FrinzoOForums Note: We need Forum Moderators to manage different FrinzoO Computer Software & Hardware Forums. We need active moderators to make this Forum rocks! If you think that you are the ONE for us, please leave us a post here http://www.frinzoo.com/forum-moderator-request/ From hazemdahab119822011 at gmail.com Mon Jan 2 14:17:48 2012 From: hazemdahab119822011 at gmail.com (hazem dahab) Date: Mon, 2 Jan 2012 11:17:48 -0800 (PST) Subject: The Ultimate Computer Software Source - Download Everything You Need For Your PC For Free Message-ID: The Ultimate Computer Software Source - Download Everything You Need For Your PC For Free FrinzoO Computer Forum provides a place where all members can ask for help and discuss a wide variety of technical topics: 1- Computer Software 2- Computer Hardware 3- Computer Problems' Solutions 4- Laptops and Netbooks Reviews 5- Computer Games 6- Web Design and Development 7- Mobile Phones, Tablets and other Handheld Devices 8- Search Engines 9- Online Internet Marketing 10- Online Internet Business 11- Search Engine Optimization 12- Affiliate Marketing 13- Movies 14- Music Membership is free, so sign up today and join in on the discussions! Visit us at http://www.frinzoo.com Visit our Facebook Page to get our latest updates at: http://www.facebook.com/FrinzoO.Computer.Software.Forum Follow us on Twitter at: http://twitter.com/#!/FrinzoOForums Note: We need Forum Moderators to manage different FrinzoO Computer Software & Hardware Forums. We need active moderators to make this Forum rocks! If you think that you are the ONE for us, please leave us a post here http://www.frinzoo.com/forum-moderator-request/ From rich at noir.com Mon Jan 2 14:26:00 2012 From: rich at noir.com (K Richard Pixley) Date: Mon, 02 Jan 2012 11:26:00 -0800 Subject: readline for mac python? (really, reproducing mac python packages) In-Reply-To: References: Message-ID: On 1/1/12 19:04 , K Richard Pixley wrote: > On 1/1/12 16:49 , K Richard Pixley wrote: >> I'm having trouble finding a reasonable python environment on mac. >> >> The supplied binaries, (2.7.2, 3.2.2), are built with old versions of >> macosx and are not capable of building any third party packages that >> require gcc. >> >> The source builds easily enough out of the box, (./configure >> --enable-framework && make && sudo make install), but when I do that, I >> end up with a python interpreter that lacks readline. >> >> How do I get readline involved? >> >> Or better... is there an instruction sheet somewhere on how to reproduce >> the python.org binary packages? >> >> --rich > > Bah. I just needed to dig a little deeper into the source. All the doc I > wanted is in there. Well, partial victory. 2.7.2 builds. 3.2 doesn't. --rich From rich at noir.com Mon Jan 2 14:32:25 2012 From: rich at noir.com (K Richard Pixley) Date: Mon, 02 Jan 2012 11:32:25 -0800 Subject: Python3 on MacOsX Lion? Message-ID: Where would I look to find the current expected status of python3 on MacOsX Lion? The distributed binaries aren't capable of allowing extensions that use gcc. I can build the source naked, but then it lacks some libraries, notably, readline. Attempting to build the full Mac packages fails, even with the few tiny patches I used for 2.7.2. Is anyone working on this? Are there pre-release patches available? Should I be asking elsewhere? --rich From ben+python at benfinney.id.au Mon Jan 2 14:45:15 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Jan 2012 06:45:15 +1100 Subject: Spamming PyPI with stupid packages References: Message-ID: <87hb0d28j8.fsf@benfinney.id.au> Peter Otten <__peter__ at web.de> writes: > Felinx Lee wrote: > > > I have removed those packages (girlfriend and others) from PyPI > > forever, I apologize for that. > > The thought police has won :( Nonsense. Felinx is free to make sexist jokes, and others are free to howl him down when he does so. PyPI has no obligation to be a platform to amplify anyone's prejudice. -- \ ?I have never imputed to Nature a purpose or a goal, or | `\ anything that could be understood as anthropomorphic.? ?Albert | _o__) Einstein, unsent letter, 1955 | Ben Finney From nikos.kouras at gmail.com Mon Jan 2 14:51:03 2012 From: nikos.kouras at gmail.com (=?UTF-8?B?zp3Ouc66z4zOu86xzr/PgiDOms6/z43Pgc6xz4I=?=) Date: Mon, 2 Jan 2012 11:51:03 -0800 (PST) Subject: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error References: Message-ID: <24123dfe-b2fc-4f4c-8dfe-23bfef19b205@m10g2000vbc.googlegroups.com> On 2 ???, 20:42, Roy Smith wrote: > In article > , > ???????????? ?????? wrote: > > > I'am trying to present myself through my webpage as computer tech. > > Is the background music so bad?! :-) > > Yes. ?Background music on web sites is evil. Evil?!?! How come? :) From nikos.kouras at gmail.com Mon Jan 2 14:54:08 2012 From: nikos.kouras at gmail.com (=?UTF-8?B?zp3Ouc66z4zOu86xzr/PgiDOms6/z43Pgc6xz4I=?=) Date: Mon, 2 Jan 2012 11:54:08 -0800 (PST) Subject: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error References: Message-ID: <9d7740a3-90e2-44bf-ab46-9d98f3c5518c@x20g2000yqe.googlegroups.com> On 2 ???, 20:42, Roy Smith wrote: > In article > , > ???????????? ?????? wrote: > > > I'am trying to present myself through my webpage as computer tech. > > Is the background music so bad?! :-) > > Yes. ?Background music on web sites is evil. Evil?!?! How come? :) From roy at panix.com Mon Jan 2 15:31:41 2012 From: roy at panix.com (Roy Smith) Date: Mon, 02 Jan 2012 15:31:41 -0500 Subject: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error References: <24123dfe-b2fc-4f4c-8dfe-23bfef19b205@m10g2000vbc.googlegroups.com> Message-ID: In article <24123dfe-b2fc-4f4c-8dfe-23bfef19b205 at m10g2000vbc.googlegroups.com>, ?????????????????????? ???????????? wrote: > On 2 ????????????, 20:42, Roy Smith wrote: > > In article > > , > > ????????????????????????? ???????????? wrote: > > > > > I'am trying to present myself through my webpage as computer tech. > > > Is the background music so bad?! :-) > > > > Yes. ??Background music on web sites is evil. > > Evil?!?! How come? :) Because people hate going to web sites and having background music start to play. But, there are better fora than here for discussions of web site best practices. From jeanpierreda at gmail.com Mon Jan 2 15:56:43 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Mon, 2 Jan 2012 15:56:43 -0500 Subject: Spamming PyPI with stupid packages In-Reply-To: <87hb0d28j8.fsf@benfinney.id.au> References: <87hb0d28j8.fsf@benfinney.id.au> Message-ID: > Nonsense. Felinx is free to make sexist jokes, and others are free to > howl him down when he does so. PyPI has no obligation to be a platform > to amplify anyone's prejudice. A module named "girlfriend" won't amplify anyone's prejudice. It is, at that point, just a joke. The punchline is "import girlfriend", and the joke makes fun of geeky losers, not women. But, hey, inertia. As long as we're trying to make this dude get rid of the offensive part, might as well get rid of the rest too. Why not make him get rid of everything he's written, too? Woo, party time! -- Devin On Mon, Jan 2, 2012 at 2:45 PM, Ben Finney wrote: > Peter Otten <__peter__ at web.de> writes: > >> Felinx Lee wrote: >> >> > I have removed those packages (girlfriend and others) from PyPI >> > forever, I apologize for that. >> >> The thought police has won :( > > Nonsense. Felinx is free to make sexist jokes, and others are free to > howl him down when he does so. PyPI has no obligation to be a platform > to amplify anyone's prejudice. > > -- > ?\ ? ? ? ? ? ? ?I have never imputed to Nature a purpose or a goal, or | > ?`\ ? ?anything that could be understood as anthropomorphic.? ?Albert | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Einstein, unsent letter, 1955 | > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list From benjamin.kaplan at case.edu Mon Jan 2 16:03:37 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 2 Jan 2012 16:03:37 -0500 Subject: Python3 on MacOsX Lion? In-Reply-To: References: Message-ID: On Mon, Jan 2, 2012 at 2:32 PM, K Richard Pixley wrote: > Where would I look to find the current expected status of python3 on MacOsX > Lion? > > The distributed binaries aren't capable of allowing extensions that use gcc. > > I can build the source naked, but then it lacks some libraries, notably, > readline. > > Attempting to build the full Mac packages fails, even with the few tiny > patches I used for 2.7.2. > > Is anyone working on this? ?Are there pre-release patches available? > > Should I be asking elsewhere? > > --rich > -- Have you tried building through Macports? From rich at noir.com Mon Jan 2 16:23:01 2012 From: rich at noir.com (K Richard Pixley) Date: Mon, 02 Jan 2012 13:23:01 -0800 Subject: Python3 on MacOsX Lion? In-Reply-To: References: Message-ID: On 1/2/12 13:03 , Benjamin Kaplan wrote: > On Mon, Jan 2, 2012 at 2:32 PM, K Richard Pixley wrote: >> Where would I look to find the current expected status of python3 on MacOsX >> Lion? >> >> The distributed binaries aren't capable of allowing extensions that use gcc. >> >> I can build the source naked, but then it lacks some libraries, notably, >> readline. >> >> Attempting to build the full Mac packages fails, even with the few tiny >> patches I used for 2.7.2. >> >> Is anyone working on this? Are there pre-release patches available? >> >> Should I be asking elsewhere? >> >> --rich >> -- > > Have you tried building through Macports? No, I haven't. Macports scares me. When I tried them, or fink, in the past, they rapidly polluted my boot disk and I didn't have any way to unpollute it other than reloading from scratch. In freebsd, netbsd, or any of the linux distributions, I can trivially create a virtual machine in about 20 minutes, screw with it as I like, and toss it in seconds. In modern linux, I can create a root file system with btrfs, snapshot, chroot to the snapshot and munge away. When I'm done, I can just toss the snapshot. (Can do snapshots in vmware too). If I screw up my boot drive in MacOsX, I'm in for hours of recovery time reloading from Time Machine. While that's a lot better than it used to be now that Time Machine is available, (reloading can now be done largely unattended), it's not a price I'm willing to pay in order to attempt to use Macports. --rich From ben+python at benfinney.id.au Mon Jan 2 16:59:53 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Jan 2012 08:59:53 +1100 Subject: Spamming PyPI with stupid packages References: <87hb0d28j8.fsf@benfinney.id.au> Message-ID: <87aa6522au.fsf@benfinney.id.au> Devin Jeanpierre writes: > > Nonsense. Felinx is free to make sexist jokes, and others are free > > to howl him down when he does so. PyPI has no obligation to be a > > platform to amplify anyone's prejudice. > > A module named "girlfriend" won't amplify anyone's prejudice. It is, > at that point, just a joke. I agree that it's a joke. It is a joke at the expense of women: promoting the view that, like a car or a house (the other modules that were part of the joke), a girlfriend is a possession to be acquired. > The punchline is "import girlfriend" Yes, exactly. The next time someone asks why the ratio of women becoming programmers is disproportionately low, please recall episodes where men here give defenses of jokes that objectify women. Instead, the more we marginalise sexism and reject normalising it through sexist jokes, the safer this community can become for anyone of any sex. -- \ ?If trees could scream, would we be so cavalier about cutting | `\ them down? We might, if they screamed all the time, for no good | _o__) reason.? ?Jack Handey | Ben Finney From ethan at stoneleaf.us Mon Jan 2 17:00:07 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 02 Jan 2012 14:00:07 -0800 Subject: .format vs. % In-Reply-To: <4EFF559E.1050408@gmail.com> References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <4EFF559E.1050408@gmail.com> Message-ID: <4F0228E7.6040300@stoneleaf.us> Andrew Berg wrote: > On 12/31/2011 12:19 PM, davidfx wrote: >> Should we always be using .format() for formatting strings or %? >> > %-style formatting will eventually go away, but > probably not for a long time. %-style formatting isn't going away. ~Ethan~ From robert.kern at gmail.com Mon Jan 2 17:43:56 2012 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 02 Jan 2012 22:43:56 +0000 Subject: Spamming PyPI with stupid packages In-Reply-To: References: <87hb0d28j8.fsf@benfinney.id.au> Message-ID: On 1/2/12 8:56 PM, Devin Jeanpierre wrote: > But, hey, inertia. As long as we're trying to make this dude get rid > of the offensive part, might as well get rid of the rest too. Why not > make him get rid of everything he's written, too? Because that's something that no one desires, nor is it the logical conclusion of anything that anyone has expressed here. Please don't invent strawmen. -- 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 th982a at googlemail.com Mon Jan 2 18:03:05 2012 From: th982a at googlemail.com (Tamer Higazi) Date: Tue, 03 Jan 2012 00:03:05 +0100 Subject: Python3 on MacOsX Lion? In-Reply-To: References: Message-ID: <4F0237A9.2010801@googlemail.com> Hi Rich! Why don't you ask the maintainer who built the macport?! Why don't you try to to figure out with "WHAT" kind of tools they have built the mac port and "WHERE" to get them either. And ask him also how to set the flags to build the 64bit edition. Then you don't have to be afraid of any prebuild mac port editions. This is how I would do it. Tamer Am 02.01.2012 22:23, schrieb K Richard Pixley: > On 1/2/12 13:03 , Benjamin Kaplan wrote: >> On Mon, Jan 2, 2012 at 2:32 PM, K Richard Pixley wrote: >>> Where would I look to find the current expected status of python3 on >>> MacOsX >>> Lion? >>> >>> The distributed binaries aren't capable of allowing extensions that >>> use gcc. >>> >>> I can build the source naked, but then it lacks some libraries, >>> notably, >>> readline. >>> >>> Attempting to build the full Mac packages fails, even with the few tiny >>> patches I used for 2.7.2. >>> >>> Is anyone working on this? Are there pre-release patches available? >>> >>> Should I be asking elsewhere? >>> >>> --rich >>> -- >> >> Have you tried building through Macports? > > No, I haven't. Macports scares me. When I tried them, or fink, in > the past, they rapidly polluted my boot disk and I didn't have any way > to unpollute it other than reloading from scratch. > > In freebsd, netbsd, or any of the linux distributions, I can trivially > create a virtual machine in about 20 minutes, screw with it as I like, > and toss it in seconds. In modern linux, I can create a root file > system with btrfs, snapshot, chroot to the snapshot and munge away. > When I'm done, I can just toss the snapshot. (Can do snapshots in > vmware too). > > If I screw up my boot drive in MacOsX, I'm in for hours of recovery > time reloading from Time Machine. While that's a lot better than it > used to be now that Time Machine is available, (reloading can now be > done largely unattended), it's not a price I'm willing to pay in order > to attempt to use Macports. > > --rich From jerome at jolimont.fr Mon Jan 2 18:09:14 2012 From: jerome at jolimont.fr (=?UTF-8?B?SsOpcsO0bWU=?=) Date: Tue, 3 Jan 2012 00:09:14 +0100 Subject: Avoid race condition with Popen.send_signal Message-ID: <20120103000914.79f2ac94@bouzin.lan> Hi all. When a subprocess is running, it can be sent a signal with the send_signal method : process = Popen( args) process.send_signal(signal.SIGINT) If the SIGINT is sent while the process has already finished, an error is raised : File "/usr/lib/python2.7/subprocess.py", line 1457, in send_signal os.kill(self.pid, sig) OSError: [Errno 3] Aucun processus de ce type To avoid this, I can check that the process is still alive : process = Popen( args) process.poll() if (None == process.returncode): process.send_signal(signal.SIGINT) It makes safer, but there is still an issue if the process ends between poll() and send_signal(). What is the clean way to avoid this race condition ? Should I use try/except to catch the error or is there a more elegant way to go ? Thanks. -- J?r?me From python at mrabarnett.plus.com Mon Jan 2 18:51:37 2012 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 02 Jan 2012 23:51:37 +0000 Subject: Avoid race condition with Popen.send_signal In-Reply-To: <20120103000914.79f2ac94@bouzin.lan> References: <20120103000914.79f2ac94@bouzin.lan> Message-ID: <4F024309.1060706@mrabarnett.plus.com> On 02/01/2012 23:09, J?r?me wrote: > Hi all. > > When a subprocess is running, it can be sent a signal with the send_signal > method : > > process = Popen( args) > process.send_signal(signal.SIGINT) > > If the SIGINT is sent while the process has already finished, an error is > raised : > > File "/usr/lib/python2.7/subprocess.py", line 1457, in send_signal > os.kill(self.pid, sig) > OSError: [Errno 3] Aucun processus de ce type > > To avoid this, I can check that the process is still alive : > > process = Popen( args) > process.poll() > if (None == process.returncode): > process.send_signal(signal.SIGINT) > > It makes safer, but there is still an issue if the process ends between > poll() and send_signal(). > > What is the clean way to avoid this race condition ? > > Should I use try/except to catch the error or is there a more elegant way to > go ? > I think that catching the exception is probably the most Pythonic way. From jeanpierreda at gmail.com Mon Jan 2 19:10:17 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Mon, 2 Jan 2012 19:10:17 -0500 Subject: Spamming PyPI with stupid packages In-Reply-To: References: <87hb0d28j8.fsf@benfinney.id.au> Message-ID: > Because that's something that no one desires, nor is it the logical > conclusion of anything that anyone has expressed here. Please don't invent > strawmen. You're right, sorry. I let myself say something dumb. I'll try not to do it again. -- Devin On Mon, Jan 2, 2012 at 5:43 PM, Robert Kern wrote: > On 1/2/12 8:56 PM, Devin Jeanpierre wrote: > >> But, hey, inertia. As long as we're trying to make this dude get rid >> of the offensive part, might as well get rid of the rest too. Why not >> make him get rid of everything he's written, too? > > > Because that's something that no one desires, nor is it the logical > conclusion of anything that anyone has expressed here. Please don't invent > strawmen. > > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless enigma > ?that is made terrible by our own mad attempt to interpret it as though it > had > ?an underlying truth." > ?-- Umberto Eco > > -- > http://mail.python.org/mailman/listinfo/python-list From askutt at gmail.com Mon Jan 2 20:19:09 2012 From: askutt at gmail.com (Adam Skutt) Date: Mon, 2 Jan 2012 17:19:09 -0800 (PST) Subject: Avoid race condition with Popen.send_signal References: Message-ID: On Jan 2, 6:09?pm, J?r?me wrote: > Hi all. > > When a subprocess is running, it can be sent a signal with the send_signal > method : > > process = Popen( args) > process.send_signal(signal.SIGINT) > > If the SIGINT is sent while the process has already finished, an error is > raised : > > ? File "/usr/lib/python2.7/subprocess.py", line 1457, in send_signal > ? ? os.kill(self.pid, sig) > OSError: [Errno 3] Aucun processus de ce type > > To avoid this, I can check that the process is still alive : > > process = Popen( args) > process.poll() > if (None == process.returncode): > ? ? process.send_signal(signal.SIGINT) > > It makes safer, but there is still an issue if the process ends between > poll() and send_signal(). > > What is the clean way to avoid this race condition ? The fundamental race condition cannot be removed nor avoided. Ideally, avoid the need to send the subprocess a signal in the first place. If it cannot be avoided, then trap the exception. Adam From jeanpierreda at gmail.com Mon Jan 2 20:31:29 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Mon, 2 Jan 2012 20:31:29 -0500 Subject: Avoid race condition with Popen.send_signal In-Reply-To: <4F024309.1060706@mrabarnett.plus.com> References: <20120103000914.79f2ac94@bouzin.lan> <4F024309.1060706@mrabarnett.plus.com> Message-ID: > I think that catching the exception is probably the most Pythonic way. It's the only correct way. -- Devin On Mon, Jan 2, 2012 at 6:51 PM, MRAB wrote: > On 02/01/2012 23:09, J?r?me wrote: >> >> Hi all. >> >> When a subprocess is running, it can be sent a signal with the send_signal >> method : >> >> process = Popen( args) >> process.send_signal(signal.SIGINT) >> >> If the SIGINT is sent while the process has already finished, an error is >> raised : >> >> ? File "/usr/lib/python2.7/subprocess.py", line 1457, in send_signal >> ? ? os.kill(self.pid, sig) >> OSError: [Errno 3] Aucun processus de ce type >> >> To avoid this, I can check that the process is still alive : >> >> process = Popen( args) >> process.poll() >> if (None == process.returncode): >> ? ? process.send_signal(signal.SIGINT) >> >> It makes safer, but there is still an issue if the process ends between >> poll() and send_signal(). >> >> What is the clean way to avoid this race condition ? >> >> Should I use try/except to catch the error or is there a more elegant way >> to >> go ? >> > I think that catching the exception is probably the most Pythonic way. > -- > http://mail.python.org/mailman/listinfo/python-list From wuwei23 at gmail.com Mon Jan 2 20:41:30 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 2 Jan 2012 17:41:30 -0800 (PST) Subject: Idiot-proof installs for python+pygame+pyopenal+app References: Message-ID: <450035e6-cbc8-47b4-aeb8-3cea2be01d7c@r13g2000prr.googlegroups.com> On Jan 2, 1:58?pm, Tim Chase wrote: > I'm looking at developing some tools that involve pygame+pyopenal > and would like to make cross-platform distribution as painless as > possible. Hey Tim, I don't have an answer, sorry, just two suggestions: 1. Maybe PyInstaller could be useful: http://www.pyinstaller.org/ 2. Also ask on the Pygame mailing list: http://pygame.org/wiki/info Good luck! From cs at zip.com.au Mon Jan 2 20:44:58 2012 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 3 Jan 2012 12:44:58 +1100 Subject: Avoid race condition with Popen.send_signal In-Reply-To: References: Message-ID: <20120103014458.GA26520@cskk.homeip.net> On 02Jan2012 20:31, Devin Jeanpierre wrote: | > I think that catching the exception is probably the most Pythonic way. | | It's the only correct way. Indeed, but be precise - chek that it _is_ error 3, or more portably, errno.ESRCH. POSIX probably mandates that that is a 3, but the symbol should track the local system if it differs. Example: import errno ... try: ...signal... except OSError, e: if e.errno == errno.ESRCH: pass # or maybe an info log message else: raise # something else wrong - raise exception anyway Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ WHAT"S A ""K3WL D00D"" AND WH3R3 CAN 1 G3T S0M3!!!!!!!!!!!???????? - Darren Embry From rantingrickjohnson at gmail.com Mon Jan 2 20:51:48 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 2 Jan 2012 17:51:48 -0800 (PST) Subject: .format vs. % References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> Message-ID: <130f76f6-d4c1-4456-a1f6-c40e2d2381ba@q7g2000yqn.googlegroups.com> On Dec 31 2011, 12:19?pm, davidfx wrote: > Hello everyone, > I just have a quick question about .format and %r %s %d. > > Should we always be using .format() for formatting strings or %? ALWAYS use the format method over the old and dumpy string interpolation. Why? Well because the format method is so much more powerful, elegant, and the way of the future. Some might argue that format is slower than interpolation (and i can't comment in favor of either) HOWEVER, if speed is your concern than interpolation is NOT the answer. > If I wanted to put .format into a variable, how would I do that. That question has been answered many times in this thread already. You may find the format spec to be cryptic at first. Well, most find regexes cryptic also -- but would anyone recommend NOT using regexes just because of crypti-ness? I think not. It's a non-starter. From rantingrickjohnson at gmail.com Mon Jan 2 20:59:43 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 2 Jan 2012 17:59:43 -0800 (PST) Subject: .format vs. % References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <4EFF559E.1050408@gmail.com> Message-ID: On Jan 2, 4:00?pm, Ethan Furman wrote: > %-style formatting isn't going away. You may want to freshen up on the definition of "deprecation". If it was NOT going away, why the need to deprecate it? hmm? It would be more beneficial if you DO NOT encourage continued usage of this "end- of-life" feature. http://en.wikipedia.org/wiki/Deprecation From benjamin.kaplan at case.edu Mon Jan 2 21:23:07 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 2 Jan 2012 21:23:07 -0500 Subject: Python3 on MacOsX Lion? In-Reply-To: <4F0237A9.2010801@googlemail.com> References: <4F0237A9.2010801@googlemail.com> Message-ID: On Mon, Jan 2, 2012 at 6:03 PM, Tamer Higazi wrote: > Hi Rich! > Why don't you ask the maintainer who built the macport?! > Why don't you try to to figure out with "WHAT" kind of tools they have built > the mac port and "WHERE" to get them either. And ask him also how to set the > flags to build the 64bit edition. > > Then you don't have to be afraid of any prebuild mac port editions. This is > how I would do it. > > Tamer > That's not quite how Macports works. Macports is a package manager. Each package has a port file with (among other things) 1) A location to download the source tarball 2) A list of patches to apply 3) A list of dependencies 4) Sets of config arguments and build scripts for different variants Richard, if something goes wrong with Macports, nuking /opt/local does a pretty good job of cleaning it up. And even if you don't want to use Macports, you can still grab their patches. They're all here: http://trac.macports.org/browser/trunk/dports/lang/python32. You can dig through the portfile to see what patches and config flags they're using to build it. > > Am 02.01.2012 22:23, schrieb K Richard Pixley: >> >> On 1/2/12 13:03 , Benjamin Kaplan wrote: >>> >>> On Mon, Jan 2, 2012 at 2:32 PM, K Richard Pixley ?wrote: >>>> >>>> Where would I look to find the current expected status of python3 on >>>> MacOsX >>>> Lion? >>>> >>>> The distributed binaries aren't capable of allowing extensions that use >>>> gcc. >>>> >>>> I can build the source naked, but then it lacks some libraries, notably, >>>> readline. >>>> >>>> Attempting to build the full Mac packages fails, even with the few tiny >>>> patches I used for 2.7.2. >>>> >>>> Is anyone working on this? ?Are there pre-release patches available? >>>> >>>> Should I be asking elsewhere? >>>> >>>> --rich >>>> -- >>> >>> >>> Have you tried building through Macports? >> >> >> No, I haven't. ?Macports scares me. ?When I tried them, or fink, in the >> past, they rapidly polluted my boot disk and I didn't have any way to >> unpollute it other than reloading from scratch. >> >> In freebsd, netbsd, or any of the linux distributions, I can trivially >> create a virtual machine in about 20 minutes, screw with it as I like, and >> toss it in seconds. ?In modern linux, I can create a root file system with >> btrfs, snapshot, chroot to the snapshot and munge away. When I'm done, I can >> just toss the snapshot. ?(Can do snapshots in vmware too). >> >> If I screw up my boot drive in MacOsX, I'm in for hours of recovery time >> reloading from Time Machine. ?While that's a lot better than it used to be >> now that Time Machine is available, (reloading can now be done largely >> unattended), it's not a price I'm willing to pay in order to attempt to use >> Macports. >> >> --rich > > > -- > http://mail.python.org/mailman/listinfo/python-list From eulergaussriemann at gmail.com Mon Jan 2 21:34:16 2012 From: eulergaussriemann at gmail.com (David Goldsmith) Date: Mon, 2 Jan 2012 18:34:16 -0800 (PST) Subject: Can't write to a directory made w/ os.makedirs References: <50693cc2-93c9-481d-9fb1-42312e69b2d9@c42g2000prb.googlegroups.com> <91830ffb-00d9-4fd1-b771-ad59374334ec@n22g2000prh.googlegroups.com> <6348b96c-f7a9-4ca6-a704-c90d25f07788@y25g2000prg.googlegroups.com> Message-ID: <97a1137b-047f-48d7-bf09-9be5c39b19c1@u10g2000prl.googlegroups.com> On Jan 2, 6:09?am, Dave Angel wrote: > On 01/01/2012 10:14 PM, David Goldsmith wrote: > > > > > > > > > On Jan 1, 7:05 am, Tim Golden ?wrote: > >> On 01/01/2012 12:05, David Goldsmith wrote: > >> ? >> ?ie can the Python process creating the directories, > > >> ? > ?Yes. > > >> ? >> ?and a subprocess called from it create a simple file? > > >> ? > ?No. > > >> ? >> ?Depending on where you are in the filesystem, it may indeed > >> ? >> ?be necessary to be running as administrator. But don't try > >> ? >> ?to crack every security nut with an elevated sledgehammer. > > >> ? > ?If you mean running as admin., those were my sentiments exactly. ?So, > >> ? > ?there isn't something specific I should be doing to assure that my > >> ? > ?subproceses can write to directories? > > >> In the general case, no. By default, a subprocess will have > >> the same security context as its parent. The exception is > >> where the parent (the Python processing invoking subprocess.call > >> in this example) is already impersonating a different user; > >> in that case, the subprocess will inherit its grandparent's > >> context. > > >> But unless you're doing something very deliberate here then > >> I doubt if that's biting you. > > >> Can I ask: are you absolutely certain that the processes > >> you're calling are doing what you think they are and failing > >> where you think they're failing? > > >> TJG > > I'm a mathematician: the only thing I'm absolutely certain of is > > nothing. > > > Here's my script, in case that helps: > > > import os > > import sys > > import stat > > import os.path as op > > import subprocess as sub > > from os import remove > > from os import listdir as ls > > from os import makedirs as mkdir > > > def doFlac2Mp3(arg, d, fl): > > ? ? ?if '.flac' in [f[-5:] for f in fl]: > > ? ? ? ? ?newD = d.replace('FLACS', 'MP3s') > > ? ? ? ? ?mkdir(newD) > > ? ? ? ? ?for f in fl: > > ? ? ? ? ? ? ?if f[-5:]=='.flac': > > ? ? ? ? ? ? ? ? ?root = f.replace('.flac', '') > > ? ? ? ? ? ? ? ? ?cmd = ['"C:\\Program Files (x86)\\aTunes\\win_tools\ > > \flac.exe" -d ' + > > ? ? ? ? ? ? ? ? ? ? ? ? '--output-prefix=' + newD + '\\', f] > > ? ? ? ? ? ? ? ? ?res = sub.call(cmd)#, env={'PATH': os.defpath}) > > ? ? ? ? ? ? ? ? ?if not res: > > ? ? ? ? ? ? ? ? ? ? ?cmd = ['"C:\\Program Files (x86)\\aTunes\\win_tools > > \\lame.exe" -h', > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?newD + root + '.wav', ?newD + root + > > '.mp3'] > > ? ? ? ? ? ? ? ? ? ? ?res = sub.call(cmd)#, env={'PATH': os.defpath}) > > ? ? ? ? ? ? ? ? ? ? ?if not res: > > ? ? ? ? ? ? ? ? ? ? ? ? ?rf = newD + root + '.wav' > > ? ? ? ? ? ? ? ? ? ? ? ? ?remove(rf) > > > top=sys.argv[1] > > op.walk(top, doFlac2Mp3, None) > > The line cmd= is bogus. ?You're trying to run a program with a -h after > the filename. ?The reason you're passing a list to sub.call is to > separate the parameters from the program name, not to mention with > quotes in its name. ?So the -h has to be ?a separate list item. > (Although Windows will probably handle it correctly if you combine the > -h with the FOLLOWING argument, it's still bad practice] > > cmd = [ "c:\\program files .... \\lame.exe", "-h", newD + root + ....." > > -- > > DaveA Thanks, this is the kind of feedback I was hoping for--the documentation for subprocess.call is notably "sparing" to put it politely. However, having not yet tried it, I'm skeptical, as what doc there is says: "subprocess.call(args, *, stdin=None, stdout=None, stderr=None, shell=False) Run the command described by args. Wait for command to complete, then return the returncode attribute. The arguments shown above are merely the most common ones, described below in Frequently Used Arguments (hence the slightly odd notation in the abbreviated signature). The full function signature is the same as that of the Popen constructor - this functions passes all supplied arguments directly through to that interface. : : "class subprocess.Popen(args, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0) Arguments are: args should be a string, or a sequence of program arguments...On Windows: the Popen class uses CreateProcess() to execute the child child program, which operates on strings. If args is a sequence, it will be converted to a string in a manner described in Converting an argument sequence to a string on Windows." Thus I didn't really see the point of separating out the -h string--which tells lame to use high quality encoding--into another sequence element, but as per your advice, I'll try it (along with Tim's and MRAB's suggestions; I'll report back what works). From wuwei23 at gmail.com Mon Jan 2 21:38:11 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 2 Jan 2012 18:38:11 -0800 (PST) Subject: Pythonification of the asterisk-based collection packing/unpacking syntax References: <841f4d29-f50b-4b0b-912b-b497fb6e60ec@t16g2000vba.googlegroups.com> <4ef32cd9$0$29973$c3e8da3$5496439d@news.astraweb.com> <4ef71ae2$0$29973$c3e8da3$5496439d@news.astraweb.com> <2a248812-d0ea-424a-93f0-0f496d130414@o14g2000vbo.googlegroups.com> <4ef74c1d$0$29973$c3e8da3$5496439d@news.astraweb.com> <6f5a3dba-bb7e-44df-8c8f-a0d56441d807@i8g2000vbh.googlegroups.com> <21fe3e6f-9e02-43cd-bd4c-cfce1fdaf0d7@d10g2000vbh.googlegroups.com> <5aadbf8b-c905-4115-972c-b37d093126b4@p4g2000vbt.googlegroups.com> <1f1f2b88-a3f8-4fdb-be71-a3e5597aaf15@p42g2000vbt.googlegroups.com> Message-ID: On Dec 27 2011, 8:01?pm, Eelco wrote: > But I consider it a reasonable change for a > 'python 4', or whatever the next major version change will be called. You do realise there were 8 years between 2 & 3? You might be waiting for quite some time. Conversely, you could pitch in behind Rick Johnson's Python 4000 fork, I sure it's progressing nicely given how long Rick has been talking it up. > Writing a code-conversion tool to convert from *args to args::tuple > would be quite easy indeed. You might want to ask people maintaining libraries in both 2.x & 3.x via 2to3 just how well that's working out for them. If the impact of changes was trivially obvious, the programming landscape would look very different indeed. From askutt at gmail.com Mon Jan 2 22:16:50 2012 From: askutt at gmail.com (Adam Skutt) Date: Mon, 2 Jan 2012 19:16:50 -0800 (PST) Subject: Avoid race condition with Popen.send_signal References: Message-ID: <63817f2b-ccf8-4d7d-92a6-c1d622986d8a@j10g2000vbe.googlegroups.com> On Jan 2, 8:44?pm, Cameron Simpson wrote: > On 02Jan2012 20:31, Devin Jeanpierre wrote: > | > I think that catching the exception is probably the most Pythonic way. > | > | It's the only correct way. > > Indeed, but be precise - chek that it _is_ error 3, or more portably, > errno.ESRCH. POSIX probably mandates that that is a 3, but the symbol > should track the local system if it differs. Example: > No. It is possible (however unlikely) for EPERM to be legitimately returned in this case. Anything other than EINVAL should be interpreted as "The child process is dead". Hence why you should avoid sending the signal in the first place: the situations where you don't run the risk of possibly killing an innocent bystander are pretty narrow. While unlikely on modern UNiX and Linux, IMO it's best to avoid the issue altogether whenever possible. Adam From steve+comp.lang.python at pearwood.info Mon Jan 2 22:47:37 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Jan 2012 03:47:37 GMT Subject: .format vs. % References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <130f76f6-d4c1-4456-a1f6-c40e2d2381ba@q7g2000yqn.googlegroups.com> Message-ID: <4f027a59$0$29880$c3e8da3$5496439d@news.astraweb.com> On Mon, 02 Jan 2012 17:51:48 -0800, Rick Johnson wrote: > You may find the format spec to be cryptic at first. Well, most find > regexes cryptic also -- but would anyone recommend NOT using regexes > just because of crypti-ness? I think not. It's a non-starter. I would. If you have a task that doesn't *need* a regular expression solution, don't use a regular expression. For what it's worth, I like the syntax of % formatting. It's nice and simple and compact while still being readable. format() is more powerful, but when I don't need that power, I stick to % formatting. -- Steven From steve+comp.lang.python at pearwood.info Mon Jan 2 22:52:25 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Jan 2012 03:52:25 GMT Subject: .format vs. % References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <4EFF559E.1050408@gmail.com> Message-ID: <4f027b79$0$29880$c3e8da3$5496439d@news.astraweb.com> On Mon, 02 Jan 2012 17:59:43 -0800, Rick Johnson wrote: > On Jan 2, 4:00?pm, Ethan Furman wrote: >> %-style formatting isn't going away. > > You may want to freshen up on the definition of "deprecation". I'm sure Ethan knows the definition of deprecation. I'm sure he also knows that % formatting is NOT deprecated. Please stop spreading FUD about Python features. -- Steven From cs at zip.com.au Mon Jan 2 23:53:07 2012 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 3 Jan 2012 15:53:07 +1100 Subject: Avoid race condition with Popen.send_signal In-Reply-To: <63817f2b-ccf8-4d7d-92a6-c1d622986d8a@j10g2000vbe.googlegroups.com> References: <63817f2b-ccf8-4d7d-92a6-c1d622986d8a@j10g2000vbe.googlegroups.com> Message-ID: <20120103045307.GA17076@cskk.homeip.net> On 02Jan2012 19:16, Adam Skutt wrote: | On Jan 2, 8:44?pm, Cameron Simpson wrote: | > On 02Jan2012 20:31, Devin Jeanpierre wrote: | > | > I think that catching the exception is probably the most Pythonic way. | > | | > | It's the only correct way. | > | > Indeed, but be precise - chek that it _is_ error 3, or more portably, | > errno.ESRCH. POSIX probably mandates that that is a 3, but the symbol | > should track the local system if it differs. Example: | | No. It is possible (however unlikely) for EPERM to be legitimately | returned in this case. Anything other than EINVAL should be | interpreted as "The child process is dead". Sure. I was more taking the line: catch and accept only the specific errors you understand. Of course he can catch EPERM also. But any other variant should at the least generate a warning to stderr or a log - it is _unexpected_. I take your point that reraising the exception may be overkill for failed signal delivery (if that was your point). But I am arguing for being very careful about what you silently pass as an ok thing. | Hence why you should | avoid sending the signal in the first place: the situations where you | don't run the risk of possibly killing an innocent bystander are | pretty narrow. While unlikely on modern UNiX and Linux, IMO it's best | to avoid the issue altogether whenever possible. Fair enough too. But sometimes you need to nail a rogue child. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Death is life's way of telling you you've been fired. - R. Geis From nad at acm.org Tue Jan 3 00:21:29 2012 From: nad at acm.org (Ned Deily) Date: Mon, 02 Jan 2012 21:21:29 -0800 Subject: Python3 on MacOsX Lion? References: Message-ID: In article , K Richard Pixley wrote: > Where would I look to find the current expected status of python3 on > MacOsX Lion? > > The distributed binaries aren't capable of allowing extensions that use gcc. > > I can build the source naked, but then it lacks some libraries, notably, > readline. > > Attempting to build the full Mac packages fails, even with the few tiny > patches I used for 2.7.2. > > Is anyone working on this? Are there pre-release patches available? The short answer is: yes, it is being worked on but it has been taking longer than it should. The 64-bit/32-bit installers from python.org for Python 2.7.x and Python 3.2.x have been being built on 10.6 with gcc-4.2. OSX 10.7 (Lion) was initially released with Xcode 4.1 which still included a version of gcc-4.2 similar to what has been available all along in 10.6 (Snow Leopard). However, more recently, Apple has released Xcode 4.2 which finally removed gcc-4.2 and now only includes updated versions of llvm-gcc-4.2 (gcc front-end with an llvm code generator backend) and clang (clang front-end with an llvm backend). Apple has made it clear that they want developers and other users to move eventually to clang and that llvm-gcc is an interim step towards the migration to clang. While there are other reasons for that move (like the change in gcc licensing), I believe Apple believes that clang will provide an all-around better build experience (better code, better checking, better diagnostics, more flexibility). But, as with any major change to a build compiler and environment, lots of nitty and often knotty problems are to be expected. (For an idea of the breadth of them, peruse the MacPorts project mailing lists for all the issues they've been discovering in the many open source packages they support since they've moved to using clang by default.) Python is no exception. There are already a couple of fixes that have been applied for upcoming Python releases to deal with either llvm-gcc or clang issues. To further complicate things, prior to the release of Lion, Apple made a preliminary version of Xcode 4 available for Snow Leopard through the Mac App Store but appears to have removed it for new purchases after Lion was released although it seems that previous purchasers and paying members of the Mac Developer program can get updates for it. So, now some 10.6 users also no longer have gcc-4.2, although they do have the supported option of reverting to the most recent Xcode 3 release for 10.6 which is free and still available through the Apple Developer Connection website. The PSF (via python.org) also supplies 32-bit-only installer variants for OS X 10.3+ which were great for building applications to run on multiple versions of OS X. But since Xcode 4 doesn't ship the necessary SDK (10.4u) and gcc-4.0, that installer version is also problematic on 10.7. We need to be careful in developing any fixes that we don't inadvertently break anything for older OS X releases like 10.5. So, it's all a bit of mess at the moment with *a lot* of variables. I had hoped to complete a comprehensive set of tests of the most important combinations of build environments with the three current active branches of python development (2.7.x, 3.2.x, and the future 3.3) for 10.7, 10.6, as well as baselines on 10.5 and 10.4 several weeks ago but, unfortunately, other events intervened. Such is the downside of all-volunteer projects. But I will be working on completing this over the next couple of weeks and, after review by the other core developers, will summarize the known issues and suggested fixes on the python.org website (with pointers posted here). I expect that we will then need to push maintenance releases of 2.7.x and 3.2.x. In the meantime, the safest approach is to continue to build on OS X 10.6 with Xcode 3 installed. -- Ned Deily, nad at acm.org From rantingrickjohnson at gmail.com Tue Jan 3 00:27:14 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 2 Jan 2012 21:27:14 -0800 (PST) Subject: Python education survey References: <06423dd7-4fbb-4e7a-b529-e697ea862b05@f11g2000yql.googlegroups.com> <36065956-359d-42cf-a5fc-75fdea830737@y7g2000vbe.googlegroups.com> <470c9b9b-780f-4b00-8fef-adba8b036c2b@32g2000yqp.googlegroups.com> <74b1ed63-f755-49e3-a275-92b2658ef991@o14g2000vbo.googlegroups.com> Message-ID: <9d9d27b6-2fa0-49c8-8237-28b4cc91843a@q8g2000yqa.googlegroups.com> On Dec 31 2011, 11:12?pm, Dominic Binks wrote: > I doubt you could validate or invalidate a word. ?A word is, there is no > validation necessary. ?You could potentially try to validate it's use > but again that's not in your power. Usage begets validation. By using words in a manner that is improper we validate the continued existence of stupidity. > I think you need to go back to school to understand what a dictionary > is. (FYI, a dictionary codifies usage, not the other way around.) So there are no standards by which a dictionary must meet? The sheeple should just read and accept any garage that the dictionary writers dictate? Sadly, a dictionary has the power to give legitimacy to a word. When we expand the definitions of words like "pretty" and reduce those definitions to the absurd AND then include those absurd definitions in a "dictionary" NOW we have just given lunacy the justification it so desires. > Perhaps you mean, because more precise words or phrases for these uses > exist? ?By your token 'work' should refer to physical activity which is > not appropriate in this context and probably 'fine' should refer to a > payment that is made having broken some rule or regulation thus leading > to monetary reparation. Yes, i used the word "work" improperly here. Just another example of the corrupting influence of garage verbiage. Thanks for bring this to my attention! > > Why would you use a word like "hard" (which describes the physical > > properties of a tangible object), > > Because many words have more than one meaning and their context > describes the meaning. ?For example 'Time flies like an arrow, fruit > flies like a banana'. ?I know you can parse and understand that but the > sentences are precisely alike, yet completely different. And that is just my point: by adopting so many meanings of a word that are dependent on context, we obfuscate our communication. > rr said: """Supposed to -> ?required|expected""" > > probably 'intended' would be better here since 'supposed to' indicates > that you should do this, but it is not required (pretty much the > opposite for your given translation). Actually, no. Consider this sentence: "We are supposed to-->[required to|expected] follow the law, but sometimes i just cannot get used to it!" > rr said: """?Use to -> ?accustomed|acquainted""" > > Sorry to be picky, but "use to" refers to application as in "When I say > 'idiot', in this context 'idiot' I use to mean 'person who cannot speak > English as it is commonly used'." Completely wrong! Consider this: "I USED TO wear a tutu however i just never could get USE TO the ridicule from others" > rr said: ?"""Right (OOC) -> ?Correct""" > > While I agree 'right' can be annoying it's usage as in 'you are correct' > can be traced back to 1588, I think we're going to have to allow for > it's usage in 2011 So just because people have been using a word out of context we should just continue? Why? > rr said: """Hard (OOC) -> ?Difficult""" > > Phrases to mean 'difficult' or 'tough' come from at least 1886 so again, > it's use in this context is hardly new. New or not, it's wrong! > rr said: """Pretty (OOC) -> ?very""" > > Pretty on it's own doesn't mean very at all. ?(God knows where you got > that idea from.) When combined with another adjective, such as hard, > pretty does enhance the adjective. ?However, pretty difficult is not the > same as very difficult. ?Pretty, in this context would probably be > better defined as 'somewhat' or 'quite'. ?(Oh and it's use in this > context can be traced back to 1565.) Pretty is by far the most ubiquitous use of a word in a manner that is "out of context". If you don't believe me, grep this group for all the occurrences of the word "pretty", and see if ANY instances of this word are used to describe "the pleasurable physical attributes of a tangible object". I would safely say that 99% are used out of context. :-( Why do people use pretty when we already have words that carry more specific meaning? Because they are lazy! And laziness begets stupidity. Do any of you remember the Unicode thread from way back? If so, you will remember all the well known trolls who ranted about "how the words you use shape the way your brain processes information". Choosing the easy way out is detrimental to your future evolution. Stop propagating your stupidity memes and use your F'in brain for once! From nad at acm.org Tue Jan 3 00:32:21 2012 From: nad at acm.org (Ned Deily) Date: Mon, 02 Jan 2012 21:32:21 -0800 Subject: readline for mac python? (really, reproducing mac python packages) References: Message-ID: In article , K Richard Pixley wrote: > On 1/1/12 19:04 , K Richard Pixley wrote: > > On 1/1/12 16:49 , K Richard Pixley wrote: > >> I'm having trouble finding a reasonable python environment on mac. > >> > >> The supplied binaries, (2.7.2, 3.2.2), are built with old versions of > >> macosx and are not capable of building any third party packages that > >> require gcc. > >> > >> The source builds easily enough out of the box, (./configure > >> --enable-framework && make && sudo make install), but when I do that, I > >> end up with a python interpreter that lacks readline. > >> > >> How do I get readline involved? > >> > >> Or better... is there an instruction sheet somewhere on how to reproduce > >> the python.org binary packages? > >> > >> --rich > > > > Bah. I just needed to dig a little deeper into the source. All the doc I > > wanted is in there. > > Well, partial victory. 2.7.2 builds. 3.2 doesn't. As you may have discovered, by default the python.org Python 2.7.x and 3.2.x on OS X 10.6 and above will link with the readline compatibility layer supplied with BSD editline (libedit) shipped by Apple. The Apple-suppled system Pythons also link with editline. While it is possible to link with your own version of GNU readline, there is also a readline project listed on PyPI that supplies pre-compiled versions of the Python readline module linked with GNU readline. I believe they are intended primarily for the system Pythons; I have not tried them myself with the python.org versions. http://pypi.python.org/pypi/readline -- Ned Deily, nad at acm.org From rantingrickjohnson at gmail.com Tue Jan 3 00:39:31 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 2 Jan 2012 21:39:31 -0800 (PST) Subject: Pythonification of the asterisk-based collection packing/unpacking syntax References: <841f4d29-f50b-4b0b-912b-b497fb6e60ec@t16g2000vba.googlegroups.com> <4ef71ae2$0$29973$c3e8da3$5496439d@news.astraweb.com> <2a248812-d0ea-424a-93f0-0f496d130414@o14g2000vbo.googlegroups.com> <4ef74c1d$0$29973$c3e8da3$5496439d@news.astraweb.com> <6f5a3dba-bb7e-44df-8c8f-a0d56441d807@i8g2000vbh.googlegroups.com> <21fe3e6f-9e02-43cd-bd4c-cfce1fdaf0d7@d10g2000vbh.googlegroups.com> <5aadbf8b-c905-4115-972c-b37d093126b4@p4g2000vbt.googlegroups.com> <1f1f2b88-a3f8-4fdb-be71-a3e5597aaf15@p42g2000vbt.googlegroups.com> Message-ID: On Jan 2, 8:38?pm, alex23 wrote: > Conversely, you could pitch in behind Rick Johnson's Python 4000 fork, > I sure it's progressing nicely given how long Rick has been talking it > up. It's NOT a fork Alex. It IS in fact the next logical step in Python's future evolution. From nad at acm.org Tue Jan 3 00:43:03 2012 From: nad at acm.org (Ned Deily) Date: Mon, 02 Jan 2012 21:43:03 -0800 Subject: Python3 on MacOsX Lion? References: Message-ID: In article , K Richard Pixley wrote: > On 1/2/12 13:03 , Benjamin Kaplan wrote: [...] > > Have you tried building through Macports? > No, I haven't. Macports scares me. When I tried them, or fink, in the > past, they rapidly polluted my boot disk and I didn't have any way to > unpollute it other than reloading from scratch. > > In freebsd, netbsd, or any of the linux distributions, I can trivially > create a virtual machine in about 20 minutes, screw with it as I like, > and toss it in seconds. In modern linux, I can create a root file > system with btrfs, snapshot, chroot to the snapshot and munge away. > When I'm done, I can just toss the snapshot. (Can do snapshots in > vmware too). > > If I screw up my boot drive in MacOsX, I'm in for hours of recovery time > reloading from Time Machine. While that's a lot better than it used to > be now that Time Machine is available, (reloading can now be done > largely unattended), it's not a price I'm willing to pay in order to > attempt to use Macports. Whether you use a third-party package manager like MacPorts or Fink is a personal decision, of course, and there pros or cons for using either. But both MacPorts and Fink are specifically designed *not* to pollute your existing system. They both go to great lengths to install everything under their own unique directory subtrees, by default, /opt/local for MacPorts and /sw for Fink. I don't have much recent experience with Fink but I do with MacPorts. Other than a very few and documented exceptions, *everything* that MacPorts installs is under that /opt/local prefix and there are no conflicts with any Apple-installed files so it is really quite trivial to install and remove without fear of corrupting your base system. The whole process is documented here: http://guide.macports.org/chunked/installing.macports.uninstalling.html -- Ned Deily, nad at acm.org From ashton at fagg.id.au Tue Jan 3 00:45:20 2012 From: ashton at fagg.id.au (Ashton Fagg) Date: Tue, 03 Jan 2012 15:45:20 +1000 Subject: Setting an environment variable. Message-ID: <4F0295F0.5000808@fagg.id.au> Hi list. A bit new to Python so please forgive my potential ignorance. I'm working with an embedded machine, which is using a Python script to oversee the acquisition of some data. The supervisor script, which is run by crontab every 5 minutes, relies on an environment variable to be set. I've tried to set the environment variable inside crontab, however this doesn't work when the script runs. Is there a nice way to do this inside the supervisor script itself? Would an os.system("export foo=/bar/foo/bar") at the very beginning of the script do what I want? I would just like to check before I make changes, as being an embedded machine it's a bit of a pain to update things like this...(read only file system) Note: This is for Python 2.4. I have no ability to update to anything newer as this is what our codebase relies upon. Thanks and regards, Ashton. -- Ashton Fagg (ashton at fagg.id.au) Web: http://www.fagg.id.au/~ashton/ Keep calm and call Batman. From ian.g.kelly at gmail.com Tue Jan 3 00:58:23 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 2 Jan 2012 22:58:23 -0700 Subject: .format vs. % In-Reply-To: <4f027b79$0$29880$c3e8da3$5496439d@news.astraweb.com> References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <4EFF559E.1050408@gmail.com> <4f027b79$0$29880$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jan 2, 2012 at 8:52 PM, Steven D'Aprano wrote: > On Mon, 02 Jan 2012 17:59:43 -0800, Rick Johnson wrote: > >> On Jan 2, 4:00?pm, Ethan Furman wrote: >>> %-style formatting isn't going away. >> >> You may want to freshen up on the definition of "deprecation". > > I'm sure Ethan knows the definition of deprecation. I'm sure he also > knows that % formatting is NOT deprecated. Please stop spreading FUD > about Python features. I can't believe I'm taking Rick's side here, but the docs do say: "Note: The formatting operations described here are obsolete and may go away in future versions of Python. Use the new String Formatting in new code." http://docs.python.org/py3k/library/stdtypes.html#old-string-formatting-operations I consider that a statement of deprecation, even if it doesn't use the term explicitly or describe a definite timeline for removal. Cheers, Ian From dbinks at codeaurora.org Tue Jan 3 01:03:25 2012 From: dbinks at codeaurora.org (Dominic Binks) Date: Mon, 02 Jan 2012 22:03:25 -0800 Subject: Python education survey In-Reply-To: <9d9d27b6-2fa0-49c8-8237-28b4cc91843a@q8g2000yqa.googlegroups.com> References: <06423dd7-4fbb-4e7a-b529-e697ea862b05@f11g2000yql.googlegroups.com> <36065956-359d-42cf-a5fc-75fdea830737@y7g2000vbe.googlegroups.com> <470c9b9b-780f-4b00-8fef-adba8b036c2b@32g2000yqp.googlegroups.com> <74b1ed63-f755-49e3-a275-92b2658ef991@o14g2000vbo.googlegroups.com> <9d9d27b6-2fa0-49c8-8237-28b4cc91843a@q8g2000yqa.googlegroups.com> Message-ID: <4F029A2D.7050707@codeaurora.org> On 1/2/2012 9:27 PM, Rick Johnson wrote: > On Dec 31 2011, 11:12 pm, Dominic Binks wrote: > >> I doubt you could validate or invalidate a word. A word is, there is no ... taken off list -- Dominic Binks: dbinks at codeaurora.org Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum From steve+comp.lang.python at pearwood.info Tue Jan 3 01:15:59 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Jan 2012 06:15:59 GMT Subject: .format vs. % References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <4EFF559E.1050408@gmail.com> <4f027b79$0$29880$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f029d1e$0$29880$c3e8da3$5496439d@news.astraweb.com> On Mon, 02 Jan 2012 22:58:23 -0700, Ian Kelly wrote: > On Mon, Jan 2, 2012 at 8:52 PM, Steven D'Aprano > wrote: >> On Mon, 02 Jan 2012 17:59:43 -0800, Rick Johnson wrote: >> >>> On Jan 2, 4:00?pm, Ethan Furman wrote: >>>> %-style formatting isn't going away. >>> >>> You may want to freshen up on the definition of "deprecation". >> >> I'm sure Ethan knows the definition of deprecation. I'm sure he also >> knows that % formatting is NOT deprecated. Please stop spreading FUD >> about Python features. > > I can't believe I'm taking Rick's side here, but the docs do say: > > "Note: The formatting operations described here are obsolete and may go > away in future versions of Python. Use the new String Formatting in new > code." > > http://docs.python.org/py3k/library/stdtypes.html#old-string-formatting- operations > > I consider that a statement of deprecation, even if it doesn't use the > term explicitly or describe a definite timeline for removal. Which is exactly why it is not deprecated: it doesn't say it is deprecated and has no timeline for removal. It may not even be removed: "may" go away is not "will" go away. Going around saying that features are deprecated just because they may (or may not) some day in the distant future become deprecated is FUD. It simply isn't true that % formatting is deprecated: Python Dev has a formal process for deprecating code, and that process has not been applied to % and there are no plans to do so in the foreseeable future. There is a huge code base using this feature, including the standard library, and Python does not arbitrarily deprecate features used by real code without good reason. Just because a number of Python devs want to encourage people to use format doesn't imply that % will go away any time before Python 4000. -- Steven From edriscoll at wisc.edu Tue Jan 3 01:31:39 2012 From: edriscoll at wisc.edu (Evan Driscoll) Date: Tue, 03 Jan 2012 01:31:39 -0500 Subject: Python education survey In-Reply-To: <9d9d27b6-2fa0-49c8-8237-28b4cc91843a@q8g2000yqa.googlegroups.com> References: <06423dd7-4fbb-4e7a-b529-e697ea862b05@f11g2000yql.googlegroups.com> <36065956-359d-42cf-a5fc-75fdea830737@y7g2000vbe.googlegroups.com> <470c9b9b-780f-4b00-8fef-adba8b036c2b@32g2000yqp.googlegroups.com> <74b1ed63-f755-49e3-a275-92b2658ef991@o14g2000vbo.googlegroups.com> <9d9d27b6-2fa0-49c8-8237-28b4cc91843a@q8g2000yqa.googlegroups.com> Message-ID: <4F02A0CB.3070205@wisc.edu> On 1/3/2012 0:27, Rick Johnson wrote: > Yes, i used the word "work" improperly here. Just another example of > the corrupting influence of garage verbiage. Thanks for bring this to > my attention! "Diction" would be a far better word than "verbiage" there. 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 wuwei23 at gmail.com Tue Jan 3 02:01:15 2012 From: wuwei23 at gmail.com (alex23) Date: Mon, 2 Jan 2012 23:01:15 -0800 (PST) Subject: Pythonification of the asterisk-based collection packing/unpacking syntax References: <841f4d29-f50b-4b0b-912b-b497fb6e60ec@t16g2000vba.googlegroups.com> <4ef71ae2$0$29973$c3e8da3$5496439d@news.astraweb.com> <2a248812-d0ea-424a-93f0-0f496d130414@o14g2000vbo.googlegroups.com> <4ef74c1d$0$29973$c3e8da3$5496439d@news.astraweb.com> <6f5a3dba-bb7e-44df-8c8f-a0d56441d807@i8g2000vbh.googlegroups.com> <21fe3e6f-9e02-43cd-bd4c-cfce1fdaf0d7@d10g2000vbh.googlegroups.com> <5aadbf8b-c905-4115-972c-b37d093126b4@p4g2000vbt.googlegroups.com> <1f1f2b88-a3f8-4fdb-be71-a3e5597aaf15@p42g2000vbt.googlegroups.com> Message-ID: On Jan 3, 3:39?pm, Rick Johnson wrote: > It's NOT a fork Alex. It IS in fact the next logical step in Python's > future evolution. Link to the repo please, or STFU. From ian.g.kelly at gmail.com Tue Jan 3 03:16:13 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 3 Jan 2012 01:16:13 -0700 Subject: .format vs. % In-Reply-To: <4f029d1e$0$29880$c3e8da3$5496439d@news.astraweb.com> References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <4EFF559E.1050408@gmail.com> <4f027b79$0$29880$c3e8da3$5496439d@news.astraweb.com> <4f029d1e$0$29880$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jan 2, 2012 at 11:15 PM, Steven D'Aprano wrote: > Which is exactly why it is not deprecated: it doesn't say it is > deprecated and has no timeline for removal. It may not even be removed: > "may" go away is not "will" go away. > > Going around saying that features are deprecated just because they may > (or may not) some day in the distant future become deprecated is FUD. It > simply isn't true that % formatting is deprecated: Python Dev has a > formal process for deprecating code, and that process has not been > applied to % and there are no plans to do so in the foreseeable future. So it's not formally deprecated, but it is nonetheless labeled obsolete and discouraged, or "informally deprecated" if you will. I'm not sure it's true that "there are no plans to do so in the foreseeable future." According to the release notes from Python 3.0, % formatting was supposed to be deprecated in Python 3.1. Why that didn't happen, I don't know. Maybe there was a discussion on py-dev where it was decided that % formatting would not be deprecated after all (in which case the misleading "obsolete" note really ought to be removed from the documentation). Maybe that discussion has been tabled for the time being. Or maybe it hasn't been deprecated simply because nobody has gotten around to actually doing it yet. In any case the statement of obsolescence and the lack of clarity about the feature's future is enough cause for me to avoid the feature, although you of course are free to use it however you want. > There is a huge code base using this feature, including the standard > library, and Python does not arbitrarily deprecate features used by real > code without good reason. Just because a number of Python devs want to > encourage people to use format doesn't imply that % will go away any time > before Python 4000. The reason for deprecating it is because Python currently has no fewer than three mechanisms for string formatting (not even including ordinary string concatenation), which according to the Zen of Python is two too many. In my view, % formatting has a lot in common with the print statement -- it's warty syntax that is better implemented as a function. In Python 3 we could have kept the print statement and avoided breaking a feature commonly used by "real code" by adding the print function as a supplement to the statement (probably with a slightly different name). But the devs went a step further and actually removed the print statement, and IMO that was a good thing. The same thing should be done with % formatting (although I agree on one point, it likely won't happen before Python 4). Cheers, Ian From steve+comp.lang.python at pearwood.info Tue Jan 3 03:21:33 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Jan 2012 08:21:33 GMT Subject: Spamming PyPI with stupid packages References: <87hb0d28j8.fsf@benfinney.id.au> <87aa6522au.fsf@benfinney.id.au> Message-ID: <4f02ba8d$0$29880$c3e8da3$5496439d@news.astraweb.com> On Tue, 03 Jan 2012 08:59:53 +1100, Ben Finney wrote: > Devin Jeanpierre writes: > >> > Nonsense. Felinx is free to make sexist jokes, and others are free to >> > howl him down when he does so. PyPI has no obligation to be a >> > platform to amplify anyone's prejudice. >> >> A module named "girlfriend" won't amplify anyone's prejudice. It is, at >> that point, just a joke. > > I agree that it's a joke. It is a joke at the expense of women: > promoting the view that, like a car or a house (the other modules that > were part of the joke), a girlfriend is a possession to be acquired. How do you get that reading? Yes, in the English language, we talk about "getting a girlfriend", but we also talk about "getting a boyfriend". Does that imply that *men* are nothing more than a possession to be acquired? Clearly not. There is no implication re social status -- we can talk about "the nation has finally got a king" without any implication that kings are low status, mere "possessions" to be acquired. If there is anything "offensive" about the "joke", it is the implication that women are shallow creatures only interested in men for their earning potential. But why should that be more offensive than the idea that men are so desperate for a relationship that they are happy to hand over their earnings to anything female that pretends an interest in them? The joke cuts both ways. It is the nature of jokes to exaggerate character traits. In real life, many women *are* interested in the earning potential of men, not exclusive of all other factors of course, and many men *are* push-overs to any gold-digger with a pretty face. But neither is a universal trait: they are mere generalisations. There are exceptions, of course, people are complex and reality doesn't fit nicely into the pigeon holes we invent, but generalities do apply in general. We're lying to ourselves if we don't acknowledge the truth that in general the status of a man depends on his wealth and power and that of a woman on her fecundity, looks and youth. Acknowledging that reality is no more sexist than acknowledging the reality that on average men are bigger than women and that women can conceive but men can't. Stan: I want to have babies. Reg: You want to have babies?!?! Stan: It's every man's right to have babies if he wants them. Reg: But ... you can't HAVE babies! Stan: Don't you oppress me! Reg: I'm not oppressing you, Stan. You haven't got a womb! Where's the fetus gonna gestate? You gonna keep it in a box? - Life of Brian -- Steven From __peter__ at web.de Tue Jan 3 03:23:09 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 03 Jan 2012 09:23:09 +0100 Subject: Spamming PyPI with stupid packages References: Message-ID: Lie Ryan wrote: > On 01/02/2012 11:20 PM, Peter Otten wrote: >> Felinx Lee wrote: >> >>> I have removed those packages (girlfriend and others) from PyPI forever, >>> I apologize for that. >> >> The thought police has won :( > > I think the community has a right to defend themselves against trolls. > If it's just bad naming, we can probably just laugh it off; but when a > failed joke spans a half dozen module and just opens a browser to his > website, there is no value for it to stay at PyPI. Additionally, it may > fuel copycats: http://pypi.python.org/pypi/kimwoohyeon1/1.3.0 (do anyone > have any idea who submitted that one?) I think it's a judgment call. "maybe policing uploads is worse than cluttering PyPI's disk space and RSS feed with dumb 1 KB packages." (Matt Chaput) I'd drop the "maybe". From jerome at jolimont.fr Tue Jan 3 03:44:15 2012 From: jerome at jolimont.fr (=?UTF-8?B?SsOpcsO0bWU=?=) Date: Tue, 3 Jan 2012 09:44:15 +0100 Subject: Avoid race condition with Popen.send_signal In-Reply-To: <63817f2b-ccf8-4d7d-92a6-c1d622986d8a@j10g2000vbe.googlegroups.com> References: <63817f2b-ccf8-4d7d-92a6-c1d622986d8a@j10g2000vbe.googlegroups.com> Message-ID: <20120103094415.072db024@bouzin.lan> Mon, 2 Jan 2012 19:16:50 -0800 (PST) Adam Skutt a ?crit: > No. It is possible (however unlikely) for EPERM to be legitimately > returned in this case. Anything other than EINVAL should be > interpreted as "The child process is dead". Hence why you should > avoid sending the signal in the first place: the situations where you > don't run the risk of possibly killing an innocent bystander are > pretty narrow. While unlikely on modern UNiX and Linux, IMO it's best > to avoid the issue altogether whenever possible. Should I understand that Popen.send_signal blindly sends the signal to the process of PID Popen.pid, and therefore could kill a new process of the same PID that would have been launched by the same user in another program ? In other words, if a user launches my python program, which in its turn launches a subprocess of PID N, then the subprocess dies, then the same user launches a terminal that gets the same PID (N), what happens if my python program calls Popen.send_signal(SIGINT) ? Does it kill the terminal ? If so, I don't see how I can protect myself from that. Checking the process is alive and then hoping that the time interval for the race condition is so small that there are few chances for that to happen (because the OS quarantines PID numbers for a while, for instance) ? -- J?r?me From candide at free.invalid Tue Jan 3 03:46:32 2012 From: candide at free.invalid (candide) Date: Tue, 03 Jan 2012 09:46:32 +0100 Subject: Repeating assertions in regular expression Message-ID: <4f02c069$0$690$426a74cc@news.free.fr> The regular expression HOWTO (http://docs.python.org/howto/regex.html#more-metacharacters) explains the following # ------------------------------ zero-width assertions should never be repeated, because if they match once at a given location, they can obviously be matched an infinite number of times. # ------------------------------ Why the wording is "should never" ? Repeating a zero-width assertion is not forbidden, for instance : >>> import re >>> re.compile("\\b\\b\w+\\b\\b") <_sre.SRE_Pattern object at 0xb7831140> >>> Nevertheless, the following doesn't execute : >>> re.compile("\\b{2}\w+\\b\\b") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/re.py", line 190, in compile return _compile(pattern, flags) File "/usr/lib/python2.7/re.py", line 245, in _compile raise error, v # invalid expression sre_constants.error: nothing to repeat >>> \\b\\b and \\b{2} aren't equivalent ? Surprisingly, the engine doesn't optimize repeated boundary assertions, for instance # ------------------------------ import re import time a=time.clock() len("\\b\\b\\b"*100000+"\w+") b=time.clock() print "CPU time : %.2f s" %(b - a) a=time.clock() re.compile("\\b\\b\\b"*100000+"\w+") b=time.clock() print "CPU time : %.2f s" %(b - a) # ------------------------------ outputs: # ------------------------------ CPU time : 0.00 s CPU time : 1.33 s # ------------------------------ Your comments are welcome! From __peter__ at web.de Tue Jan 3 03:47:04 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 03 Jan 2012 09:47:04 +0100 Subject: Spamming PyPI with stupid packages References: <87hb0d28j8.fsf@benfinney.id.au> <87aa6522au.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > The next time someone asks why the ratio of women becoming programmers > is disproportionately low, please recall episodes where men here give > defenses of jokes that objectify women. What's that? The butterfly effect of diversity? If you want more women in IT go to a local school and show the girls things they can do with a computer that they find fun and interesting. If you have a daughter try more Lego and less Barbies. Don't insist if it doesn't work out. Your ideas may not be in alignment with the pursuit of happiness... From rosuav at gmail.com Tue Jan 3 03:58:57 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Jan 2012 19:58:57 +1100 Subject: Avoid race condition with Popen.send_signal In-Reply-To: <20120103094415.072db024@bouzin.lan> References: <63817f2b-ccf8-4d7d-92a6-c1d622986d8a@j10g2000vbe.googlegroups.com> <20120103094415.072db024@bouzin.lan> Message-ID: On Tue, Jan 3, 2012 at 7:44 PM, J?r?me wrote: > If so, I don't see how I can protect myself from that. Checking the process > is alive and then hoping that the time interval for the race condition is so > small that there are few chances for that to happen (because the OS > quarantines PID numbers for a while, for instance) ? The probability is extremely small. PIDs are generally allocated sequentially, and obviously one won't be reallocated until the previous process has terminated. You're looking at a narrow window of opportunity between a check and an action; you don't really need to worry about PID reuse within that window, unless there's a particular reason to fear it (eg your process is very low priority, or there's a lot of "process spinning" happening). Under normal circumstances, you won't see a new process start up with the same PID for some time. (I can't make a statement on Python's module, though.) ChrisA From jerome at jolimont.fr Tue Jan 3 04:38:03 2012 From: jerome at jolimont.fr (=?UTF-8?B?SsOpcsO0bWU=?=) Date: Tue, 3 Jan 2012 10:38:03 +0100 Subject: Avoid race condition with Popen.send_signal In-Reply-To: References: <63817f2b-ccf8-4d7d-92a6-c1d622986d8a@j10g2000vbe.googlegroups.com> <20120103094415.072db024@bouzin.lan> Message-ID: <20120103103803.6ae2df9d@bouzin.lan> Tue, 3 Jan 2012 19:58:57 +1100 Chris Angelico a ?crit: > On Tue, Jan 3, 2012 at 7:44 PM, J?r?me wrote: > > If so, I don't see how I can protect myself from that. Checking the > > process is alive and then hoping that the time interval for the race > > condition is so small that there are few chances for that to happen > > (because the OS quarantines PID numbers for a while, for instance) ? > > The probability is extremely small. PIDs are generally allocated > sequentially, and obviously one won't be reallocated until the > previous process has terminated. You're looking at a narrow window of > opportunity between a check and an action; you don't really need to > worry about PID reuse within that window, unless there's a particular > reason to fear it (eg your process is very low priority, or there's a > lot of "process spinning" happening). Under normal circumstances, you > won't see a new process start up with the same PID for some time. > > (I can't make a statement on Python's module, though.) Thanks for clarifying this. (Out of curiosity, what would be the way to be sure when not in "normal circumstances" ?) So I rely on the OS for not allocating a "recently released" PID. However, if the PID was released long ago, I still need to cover myself up as Popen won't do it for me. E.g.: I have an application that can spawn a subprocess to play a beep. I want it to kill the subprocess when exiting. To do so, my close() method must a/ Check if any subprocess has actually been launched (I store the Popen in a variable called _beep_process. If Popen has not been called, the variable is init to 0 and the call to send_signal will fail.) b/ Check if the process is still alive using Popen.poll() and returncode (otherwise, I might kill a new process) c/ Catch the exception in case the process would be dead since the last check (otherwise, I might get an error from send_signal) It looks like this : ##################################################################### # Close ##################################################################### def _close (self, widget): # If self._beep_process != 0, a subprocess was launched at some point if (0 != self._beep_process): print "process launched" self._beep_process.poll() # If process still alive if (None == self._beep_process.returncode): print "process stil alive" # Send signal try: self._beep_process.send_signal(signal.SIGINT) except OSError, e: if e.errno == errno.ESRCH: print "process just died" pass # process already dead else: raise # something else wrong - raise exception else: print "signal sent" # wait for process to complete self._beep_process.wait() else: print "process already dead" # Close application Gtk.main_quit() ##################################################################### I would have expected something shorter. For instance, Popen.send_signal() should not be able to send a signal to a subprocess that has already returned, should it ? Is there any good reason for allowing it to do so ? If not, it would spare me check b/ in this example. -- J?r?me From jeanpierreda at gmail.com Tue Jan 3 04:45:40 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Tue, 3 Jan 2012 04:45:40 -0500 Subject: Repeating assertions in regular expression In-Reply-To: <4f02c069$0$690$426a74cc@news.free.fr> References: <4f02c069$0$690$426a74cc@news.free.fr> Message-ID: > \\b\\b and \\b{2} aren't equivalent ? This sounds suspiciously like a bug! > Why the wording is "should never" ? Repeating a zero-width assertion is not > forbidden, for instance : > >>>> import re >>>> re.compile("\\b\\b\w+\\b\\b") > <_sre.SRE_Pattern object at 0xb7831140> >>>> I believe this is meant to refer to arbitrary-length repetitions, such as r'\b*', not simple concatenations like that. r'\b*' will abort the whole match if is run on a boundary, because Python detects a repetition of a zero-width match and decides this is an error. A little OT: I'm not really sure why Python does it this way. It's possible to match r'\b*' fairly painlessly: instead of aborting the whole match on a repeat of nothing, it can backtrack. So what should happen is that the RE engine looks at \b* and does the following: Is there one \b? Yes. Is there another \b? Backtrack: You haven't read any more characters since the last match in the * operation # The result now is that we've matched '\b*' with exactly one '\b' and can move on to the rest of the input This is possible (I haven't tried implementing it, but it's e.g. mentioned in Russ Cox's regular expression papers), you need to augment the backtracking search with a notion of the regular expression having "progress" so that you can require progress at certain points. Otherwise you obviously get problems with nested stars and things like that. (As it happens, Python's regex engine can't handle nested stars either). I'd be appreciative if anyone who works on re or regex can discuss this a little. -- Devin On Tue, Jan 3, 2012 at 3:46 AM, candide wrote: > The regular expression HOWTO > (http://docs.python.org/howto/regex.html#more-metacharacters) explains the > following > > # ------------------------------ > zero-width assertions should never be repeated, because if they match once > at a given location, they can obviously be matched an infinite number of > times. > # ------------------------------ > > > Why the wording is "should never" ? Repeating a zero-width assertion is not > forbidden, for instance : > >>>> import re >>>> re.compile("\\b\\b\w+\\b\\b") > <_sre.SRE_Pattern object at 0xb7831140> >>>> > > Nevertheless, the following doesn't execute : > >>>> re.compile("\\b{2}\w+\\b\\b") > Traceback (most recent call last): > ?File "", line 1, in > ?File "/usr/lib/python2.7/re.py", line 190, in compile > ? ?return _compile(pattern, flags) > ?File "/usr/lib/python2.7/re.py", line 245, in _compile > ? ?raise error, v # invalid expression > sre_constants.error: nothing to repeat >>>> > > > \\b\\b and \\b{2} aren't equivalent ? > > > Surprisingly, the engine doesn't optimize repeated boundary assertions, for > instance > > # ------------------------------ > import re > import time > > a=time.clock() > len("\\b\\b\\b"*100000+"\w+") > b=time.clock() > print "CPU time : %.2f s" %(b - a) > > a=time.clock() > re.compile("\\b\\b\\b"*100000+"\w+") > b=time.clock() > print "CPU time : %.2f s" %(b - a) > # ------------------------------ > > outputs: > > # ------------------------------ > CPU time : 0.00 s > CPU time : 1.33 s > # ------------------------------ > > > Your comments are welcome! > -- > http://mail.python.org/mailman/listinfo/python-list From bahamutzero8825 at gmail.com Tue Jan 3 05:55:16 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Tue, 03 Jan 2012 04:55:16 -0600 Subject: .format vs. % In-Reply-To: References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <4EFF559E.1050408@gmail.com> <4f027b79$0$29880$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F02DE94.8000506@gmail.com> On 1/2/2012 11:58 PM, Ian Kelly wrote: > I can't believe I'm taking Rick's side here, but the docs do say: > > "Note: The formatting operations described here are obsolete and may > go away in future versions of Python. Use the new String Formatting in > new code." > > http://docs.python.org/py3k/library/stdtypes.html#old-string-formatting-operations And that is mainly what I based my statement on. As I said, it's not likely to be any time soon. I highly doubt it will even become deprecated in 3.3, but it wouldn't surprise me if it becomes deprecated in 3.4 and removed in 4.0. In any case, I should've said "will probably go away". To add my opinion on it, I find format() much more readable and easier to understand (with the exception of the {} {} {} {} syntax), and would love to see %-style formatting phased out. -- CPython 3.2.2 | Windows NT 6.1.7601.17640 From candide at free.invalid Tue Jan 3 06:14:35 2012 From: candide at free.invalid (candide) Date: Tue, 03 Jan 2012 12:14:35 +0100 Subject: Regular expression : non capturing groups are faster ? Message-ID: <4f02e31c$0$15724$426a74cc@news.free.fr> Excerpt from the Regular Expression HOWTO (http://docs.python.org/howto/regex.html#non-capturing-and-named-groups) : ----------------------------------------------- It should be mentioned that there?s no performance difference in searching between capturing and non-capturing groups; neither form is any faster than the other. ----------------------------------------------- Now from the Perl Regular Expression tutorial (http://perldoc.perl.org/perlretut.html#Non-capturing-groupings) : ----------------------------------------------- Because there is no extraction, non-capturing groupings are faster than capturing groupings. ----------------------------------------------- The second assertion sounds more likely. It seems very odd that Python and Perl implementations are divergent on this point. Any opinion ? From hoogendoorn.eelco at gmail.com Tue Jan 3 06:21:40 2012 From: hoogendoorn.eelco at gmail.com (Eelco) Date: Tue, 3 Jan 2012 03:21:40 -0800 (PST) Subject: Pythonification of the asterisk-based collection packing/unpacking syntax References: <841f4d29-f50b-4b0b-912b-b497fb6e60ec@t16g2000vba.googlegroups.com> <4ef71ae2$0$29973$c3e8da3$5496439d@news.astraweb.com> <2a248812-d0ea-424a-93f0-0f496d130414@o14g2000vbo.googlegroups.com> <4ef74c1d$0$29973$c3e8da3$5496439d@news.astraweb.com> <6f5a3dba-bb7e-44df-8c8f-a0d56441d807@i8g2000vbh.googlegroups.com> <21fe3e6f-9e02-43cd-bd4c-cfce1fdaf0d7@d10g2000vbh.googlegroups.com> <5aadbf8b-c905-4115-972c-b37d093126b4@p4g2000vbt.googlegroups.com> <1f1f2b88-a3f8-4fdb-be71-a3e5597aaf15@p42g2000vbt.googlegroups.com> Message-ID: On Jan 3, 3:38?am, alex23 wrote: > On Dec 27 2011, 8:01?pm, Eelco wrote: > > > But I consider it a reasonable change for a > > 'python 4', or whatever the next major version change will be called. > > You do realise there were 8 years between 2 & 3? You might be waiting > for quite some time. Yes, I realize this discussion is quite theoretical in nature. Some of the more 'emotionally engaged' participants might do well to keep that in mind as well. > Conversely, you could pitch in behind Rick Johnson's Python 4000 fork, > I sure it's progressing nicely given how long Rick has been talking it > up. Would you be so kind as to leave your personal feuds at the door? > > Writing a code-conversion tool to convert from *args to args::tuple > > would be quite easy indeed. > > You might want to ask people maintaining libraries in both 2.x & 3.x > via 2to3 just how well that's working out for them. If the impact of > changes was trivially obvious, the programming landscape would look > very different indeed. Of course if a conversion tool falters on even a single construct, automated conversion is not going to be reliable, and thats going to be a pain. But whatever python 4 will be like, its not going to be backwards compatible by definition; and at least I dont think this proposed change will contribute to the trouble of conversion between the two. It is really quite a superficial syntax tweak. From lars at rational-it.com Tue Jan 3 06:43:17 2012 From: lars at rational-it.com (lars van gemerden) Date: Tue, 3 Jan 2012 03:43:17 -0800 (PST) Subject: pickling instances of metaclass generated classes References: <2d221d0f-458e-4821-8786-f064b44b3125@p16g2000yqd.googlegroups.com> Message-ID: On Dec 29 2011, 10:55?am, lars van gemerden wrote: > Hello, > > Can someone help me with the following: > > I am using metaclasses to make classes and these classes to make > instances. Now I want to use multiprocessing, which needs to pickle > these instances. > > Pickle cannot find the class definitions of the instances. I am trying > to add a line to the __new__ of the metaclass to add the new class > under the right name in the right module/place, so pickle can find > it. > > Is this the right approach? Can anyone explain to me where/how to add > these classes for pickle to find and maybe why? > > Thanks in advance, > > Lars Ok, After reading all posts (thanks a lot), I am considering to use the following base metaclass for all metaclasses that must lead to pickleable instances (not pickleable classes): import sys class Meta(type): def __new__(mcls, name, bases, attrs): cls = type.__new__(mcls, name, bases, attrs) setattr(sys.modules[__name__], name, cls) return cls if __name__ == '__main__': instance = Meta("Klass", (str,),{})("apple") s = pickle.dumps(instance) delattr(sys.modules[__name__], "Klass") Meta("Klass", (str,),{}) inst = pickle.loads(s) print instance print inst print type(instance) is type(inst) Can anyone see any drawbacks to this approach? I've also tested the case where the Meta metaclass is defined in another module. Cheers, Lars From stefan-usenet at bytereef.org Tue Jan 3 06:47:16 2012 From: stefan-usenet at bytereef.org (Stefan Krah) Date: Tue, 3 Jan 2012 12:47:16 +0100 Subject: .format vs. % In-Reply-To: <4F02DE94.8000506@gmail.com> References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <4EFF559E.1050408@gmail.com> <4f027b79$0$29880$c3e8da3$5496439d@news.astraweb.com> <4F02DE94.8000506@gmail.com> Message-ID: <20120103114716.GA24859@sleipnir.bytereef.org> Andrew Berg wrote: > To add my opinion on it, I find format() much more readable and easier > to understand (with the exception of the {} {} {} {} syntax), and would > love to see %-style formatting phased out. For me the %-style is much more readable. Also, it is significantly faster: $ ./python -m timeit -n 1000000 '"%s" % 7.928137192' 1000000 loops, best of 3: 0.0164 usec per loop $ ./python -m timeit -n 1000000 '"{}".format(7.928137192)' 1000000 loops, best of 3: 1.01 usec per loop In the real-world telco benchmark for _decimal, replacing the single line outfil.write("%s\n" % t) with outfil.write("{}\n".format(t)) adds 23% to the runtime. I think %-style formatting should not be deprecated at all. Stefan Krah From jeanpierreda at gmail.com Tue Jan 3 06:56:44 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Tue, 3 Jan 2012 06:56:44 -0500 Subject: Regular expression : non capturing groups are faster ? In-Reply-To: <4f02e31c$0$15724$426a74cc@news.free.fr> References: <4f02e31c$0$15724$426a74cc@news.free.fr> Message-ID: > The second assertion sounds more likely. It seems very odd that Python and > Perl implementations are divergent on this point. Any opinion ? The Python documentation oversimplifies. What it means to say is that while one might expect capturing matches to do extra work proportional to the capture, they do not. They don't do anything other than mark down where to extract submatches, and the extra work done is pretty much negligible. (That is, the work done for submatch extraction is a polynomial (looks like quadratic) in the number of capturing groups (which is very small almost always), with a small coefficient). The Perl documentation is technically correct, but if the HOWTO said it, it would give the wrong impression. You shouldn't care about capturing vs noncapturing except with regards to how it interferes with your group numbering scheme. -- Devin On Tue, Jan 3, 2012 at 6:14 AM, candide wrote: > Excerpt from the Regular Expression HOWTO > (http://docs.python.org/howto/regex.html#non-capturing-and-named-groups) : > > > ----------------------------------------------- > It should be mentioned that there?s no performance difference in searching > between capturing and non-capturing groups; neither form is any faster than > the other. > ----------------------------------------------- > > > Now from the Perl Regular Expression tutorial > (http://perldoc.perl.org/perlretut.html#Non-capturing-groupings) : > > > ----------------------------------------------- > Because there is no extraction, non-capturing groupings are faster than > capturing groupings. > ----------------------------------------------- > > > The second assertion sounds more likely. It seems very odd that Python and > Perl implementations are divergent on this point. Any opinion ? > > > -- > http://mail.python.org/mailman/listinfo/python-list From orasnita at gmail.com Tue Jan 3 06:59:27 2012 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 3 Jan 2012 13:59:27 +0200 Subject: Regular expression : non capturing groups are faster ? References: <4f02e31c$0$15724$426a74cc@news.free.fr> Message-ID: From: "candide" Subject: Regular expression : non capturing groups are faster ? Excerpt from the Regular Expression HOWTO (http://docs.python.org/howto/regex.html#non-capturing-and-named-groups) : ----------------------------------------------- It should be mentioned that there?s no performance difference in searching between capturing and non-capturing groups; neither form is any faster than the other. ----------------------------------------------- Now from the Perl Regular Expression tutorial (http://perldoc.perl.org/perlretut.html#Non-capturing-groupings) : ----------------------------------------------- Because there is no extraction, non-capturing groupings are faster than capturing groupings. ----------------------------------------------- The second assertion sounds more likely. It seems very odd that Python and Perl implementations are divergent on this point. Any opinion ? -- ** At least in Perl's case, it is true. I tested and using (?:...) is much faster than (). Of course, it takes a few seconds for dozen million matches... Octavian From modelnine at modelnine.org Tue Jan 3 07:31:55 2012 From: modelnine at modelnine.org (Heiko Wundram) Date: Tue, 03 Jan 2012 13:31:55 +0100 Subject: Avoid race condition with Popen.send_signal In-Reply-To: References: Message-ID: <4F02F53B.1060903@modelnine.org> Am 03.01.2012 02:19, schrieb Adam Skutt: > On Jan 2, 6:09 pm, J?r?me wrote: >> What is the clean way to avoid this race condition ? > > The fundamental race condition cannot be removed nor avoided. Ideally, > avoid the need to send the subprocess a signal in the first place. If > it cannot be avoided, then trap the exception. Yes, it can be avoided, that's what the default SIGCHLD-handling (keeping the process as a zombie until it's explicitly collected by a wait*()) is for, which forces the PID not to be reused by the operating system until the parent has acknowledged (by actively calling wait*()) that the child has terminated. -- --- Heiko. From hoogendoorn.eelco at gmail.com Tue Jan 3 07:33:45 2012 From: hoogendoorn.eelco at gmail.com (Eelco) Date: Tue, 3 Jan 2012 04:33:45 -0800 (PST) Subject: Python education survey References: <06423dd7-4fbb-4e7a-b529-e697ea862b05@f11g2000yql.googlegroups.com> <36065956-359d-42cf-a5fc-75fdea830737@y7g2000vbe.googlegroups.com> <470c9b9b-780f-4b00-8fef-adba8b036c2b@32g2000yqp.googlegroups.com> <74b1ed63-f755-49e3-a275-92b2658ef991@o14g2000vbo.googlegroups.com> <9d9d27b6-2fa0-49c8-8237-28b4cc91843a@q8g2000yqa.googlegroups.com> Message-ID: > Why do people use pretty when we already have words that carry more > specific meaning? Because they are lazy! And laziness begets > stupidity. No, that would be because they are not autistic. Most people like having a repertoire of words with subtly different meanings in their natural language, because there is a demand for this semantic richness. From marko at pacujo.net Tue Jan 3 07:57:00 2012 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 03 Jan 2012 14:57:00 +0200 Subject: Locale bug? Message-ID: Mysterious 8-bit characters appear in the string returned by strftime. $ python Python 2.7.2 (default, Oct 27 2011, 01:36:46) [GCC 4.6.1 20111003 (Red Hat 4.6.1-10)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import time, locale >>> locale.setlocale(locale.LC_TIME, ('fi_FI', 'UTF-8')) 'fi_FI.UTF-8' >>> time.strftime("%a, %d %b %Y %H:%M:%S %z (%Z)") 'ti, 03 tammi\xc2\xa0 2012 14:52:47 +0200 (EET)' >>> $ python3 Python 3.2.1 (default, Jul 11 2011, 18:55:33) [GCC 4.6.1 20110627 (Red Hat 4.6.1-1)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import time, locale >>> locale.setlocale(locale.LC_TIME, ('fi_FI', 'UTF-8')) 'fi_FI.UTF-8' >>> time.strftime("%a, %d %b %Y %H:%M:%S %z (%Z)") 'ti, 03 tammi\xa0 2012 14:51:57 +0200 (EET)' >>> From rosuav at gmail.com Tue Jan 3 08:04:31 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Jan 2012 00:04:31 +1100 Subject: .format vs. % In-Reply-To: <20120103114716.GA24859@sleipnir.bytereef.org> References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <4EFF559E.1050408@gmail.com> <4f027b79$0$29880$c3e8da3$5496439d@news.astraweb.com> <4F02DE94.8000506@gmail.com> <20120103114716.GA24859@sleipnir.bytereef.org> Message-ID: On Tue, Jan 3, 2012 at 10:47 PM, Stefan Krah wrote: > For me the %-style is much more readable. It's also very similar to C's printf, which means it's similar to everything else that's similar to printf. That makes it instantly grokkable to many many people, which is a Good Thing. It's like using the + operator for string concatenation - there's no requirement to do so, and not all languages do (REXX, PHP, and SQL come to mind); but supporting the "obvious thing" gives a huge slab of potential Python users the chance to understand and write code with one less trip to the documentation. ChrisA From ethan at stoneleaf.us Tue Jan 3 08:08:47 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 03 Jan 2012 05:08:47 -0800 Subject: Spamming PyPI with stupid packages In-Reply-To: References: Message-ID: <4F02FDDF.8000009@stoneleaf.us> Peter Otten wrote: > Lie Ryan wrote: > >> On 01/02/2012 11:20 PM, Peter Otten wrote: >>> Felinx Lee wrote: >>> >>>> I have removed those packages (girlfriend and others) from PyPI forever, >>>> I apologize for that. >>> The thought police has won :( >> I think the community has a right to defend themselves against trolls. >> If it's just bad naming, we can probably just laugh it off; but when a >> failed joke spans a half dozen module and just opens a browser to his >> website, there is no value for it to stay at PyPI. Additionally, it may >> fuel copycats: http://pypi.python.org/pypi/kimwoohyeon1/1.3.0 (do anyone >> have any idea who submitted that one?) > > I think it's a judgment call. > > "maybe policing uploads is worse than cluttering PyPI's disk space and RSS > feed with dumb 1 KB packages." (Matt Chaput) > > I'd drop the "maybe". It's hard enough finding what one wants without having to wade through crap. PyPI is not the place for it. ~Ethan~ From ethan at stoneleaf.us Tue Jan 3 08:26:57 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 03 Jan 2012 05:26:57 -0800 Subject: .format vs. % In-Reply-To: References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <4EFF559E.1050408@gmail.com> <4f027b79$0$29880$c3e8da3$5496439d@news.astraweb.com> <4f029d1e$0$29880$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F030221.3050902@stoneleaf.us> Ian Kelly wrote: > I'm not sure it's true that "there are no plans to do so in the > foreseeable future." According to the release notes from Python 3.0, > % formatting was supposed to be deprecated in Python 3.1. Eric Smith wrote (from a thread on pydev in 02-2011): > The last thread on this I have a reference to was in September 2009. I > think was basically the outcome: > http://mail.python.org/pipermail/python-dev/2009-September/092399.html > > So there will be no deprecation, just a gradual shift to PEP 3101 > formatting. Ian Kelly wrote: > Maybe there was a discussion on py-dev > where it was decided that % formatting would not be deprecated after > all (in which case the misleading "obsolete" note really ought to be > removed from the documentation). Agreed that this is a documentation bug. Ian Kelly wrote: > The reason for deprecating it is because Python currently has no fewer > than three mechanisms for string formatting (not even including > ordinary string concatenation), which according to the Zen of Python > is two too many. "one obvious way" != "only one way" ~Ethan~ From askutt at gmail.com Tue Jan 3 08:40:05 2012 From: askutt at gmail.com (Adam Skutt) Date: Tue, 3 Jan 2012 05:40:05 -0800 (PST) Subject: Avoid race condition with Popen.send_signal References: Message-ID: On Jan 3, 7:31?am, Heiko Wundram wrote: > Am 03.01.2012 02:19, schrieb Adam Skutt: > > > On Jan 2, 6:09 pm, J?r?me ?wrote: > >> What is the clean way to avoid this race condition ? > > > The fundamental race condition cannot be removed nor avoided. Ideally, > > avoid the need to send the subprocess a signal in the first place. ?If > > it cannot be avoided, then trap the exception. > > Yes, it can be avoided, that's what the default SIGCHLD-handling > (keeping the process as a zombie until it's explicitly collected by a > wait*()) is for, which forces the PID not to be reused by the operating > system until the parent has acknowledged (by actively calling wait*()) > that the child has terminated. No, you still can see ESRCH when sending signals to a zombie process. Code that sends signals to child processes via kill(2) must be prepared for the call to fail at anytime since the process can die at anytime. It can't handle the signal, so it's treated as if it doesn't exist by kill(2) in this case. However, you don't have to worry about sending the signal to the wrong process. Adam From modelnine at modelnine.org Tue Jan 3 08:56:49 2012 From: modelnine at modelnine.org (Heiko Wundram) Date: Tue, 03 Jan 2012 14:56:49 +0100 Subject: Avoid race condition with Popen.send_signal In-Reply-To: References: Message-ID: <4F030921.4010709@modelnine.org> Am 03.01.2012 14:40, schrieb Adam Skutt: > On Jan 3, 7:31 am, Heiko Wundram wrote: >> Yes, it can be avoided, that's what the default SIGCHLD-handling >> (keeping the process as a zombie until it's explicitly collected by a >> wait*()) is for, which forces the PID not to be reused by the operating >> system until the parent has acknowledged (by actively calling wait*()) >> that the child has terminated. > > No, you still can see ESRCH when sending signals to a zombie process. > Code that sends signals to child processes via kill(2) must be > prepared for the call to fail at anytime since the process can die at > anytime. It can't handle the signal, so it's treated as if it doesn't > exist by kill(2) in this case. However, you don't have to worry about > sending the signal to the wrong process. Getting an error on kill (which you can catch) is not about the race that the posters were speculating about (i.e., sending the signal to the wrong process), and that's what I was trying to put straight. The only advice that I wanted to give is: 1) before calling wait to collect the child, call kill as much as you like, and in case it errors, ignore that, 2) after calling wait, never, ever kill, and you don't need to, because you already know the process is gone. There's no race possibility in this, _except_ if you alter handling of SIGCHLD away from the default (i.e., to autocollect children), in which case you have the possibility of a race and shooting down unrelated processes (which the discussion was about). -- --- Heiko. From neilc at norwich.edu Tue Jan 3 08:58:21 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 3 Jan 2012 13:58:21 GMT Subject: .format vs. % References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <4EFF559E.1050408@gmail.com> <4f027b79$0$29880$c3e8da3$5496439d@news.astraweb.com> <4F02DE94.8000506@gmail.com> Message-ID: <9mgfrtFt0U5@mid.individual.net> On 2012-01-03, Stefan Krah wrote: > Andrew Berg wrote: >> To add my opinion on it, I find format() much more readable and easier >> to understand (with the exception of the {} {} {} {} syntax), and would >> love to see %-style formatting phased out. > > For me the %-style is much more readable. Also, it is significantly > faster: > > $ ./python -m timeit -n 1000000 '"%s" % 7.928137192' > 1000000 loops, best of 3: 0.0164 usec per loop > $ ./python -m timeit -n 1000000 '"{}".format(7.928137192)' > 1000000 loops, best of 3: 1.01 usec per loop > > In the real-world telco benchmark for _decimal, replacing the > single line > > outfil.write("%s\n" % t) > > with > > outfil.write("{}\n".format(t)) > > adds 23% to the runtime. I think %-style formatting should not > be deprecated at all. When it becomes necessary, it's possible to optimize it by hoisting out the name lookups. ... outfil_write = outfil.write append_newline = "{}\n".format ... outfil_write(append_newline(t)) ... -- Neil Cerutti From Trond.Endrestol at ximalas.info Tue Jan 3 09:08:33 2012 From: Trond.Endrestol at ximalas.info (=?us-ascii?Q?=3D=3FISO-8859-1=3FQ=3FTrond=5FEndrest=3DF8l=3F=3D?=) Date: Tue, 03 Jan 2012 15:08:33 +0100 Subject: Locale bug? References: Message-ID: <8739bwop3y.fsf@enterprise.ximalas.info> Marko Rauhamaa writes: > Mysterious 8-bit characters appear in the string returned by strftime. > > $ python > Python 2.7.2 (default, Oct 27 2011, 01:36:46) > [GCC 4.6.1 20111003 (Red Hat 4.6.1-10)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import time, locale > >>> locale.setlocale(locale.LC_TIME, ('fi_FI', 'UTF-8')) > 'fi_FI.UTF-8' > >>> time.strftime("%a, %d %b %Y %H:%M:%S %z (%Z)") > 'ti, 03 tammi\xc2\xa0 2012 14:52:47 +0200 (EET)' > >>> > $ python3 > Python 3.2.1 (default, Jul 11 2011, 18:55:33) > [GCC 4.6.1 20110627 (Red Hat 4.6.1-1)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import time, locale > >>> locale.setlocale(locale.LC_TIME, ('fi_FI', 'UTF-8')) > 'fi_FI.UTF-8' > >>> time.strftime("%a, %d %b %Y %H:%M:%S %z (%Z)") > 'ti, 03 tammi\xa0 2012 14:51:57 +0200 (EET)' > >>> It may be OS-specific. Your sample code runs fine on FreeBSD/i386 8.2-STABLE. The OS and Python 2.7.2 & 3.2.2 were recently compiled and installed on my system. trond at enterprise:~>uname -sr FreeBSD 8.2-STABLE trond at enterprise:~>python Python 2.7.2 (default, Dec 20 2011, 08:49:23) [GCC 4.2.2 20070831 prerelease [FreeBSD]] on freebsd8 Type "help", "copyright", "credits" or "license" for more information. >>> import time, locale >>> locale.setlocale(locale.LC_TIME, ('fi_FI', 'UTF-8')) 'fi_FI.UTF-8' >>> time.strftime("%a, %d %b %Y %H:%M:%S %z (%Z)") 'Ti, 03 Tam 2012 15:02:32 +0100 (CET)' >>> trond at enterprise:~>python3.2 Python 3.2.2 (default, Dec 21 2011, 14:42:29) [GCC 4.2.2 20070831 prerelease [FreeBSD]] on freebsd8 Type "help", "copyright", "credits" or "license" for more information. >>> import time, locale >>> locale.setlocale(locale.LC_TIME, ('fi_FI', 'UTF-8')) 'fi_FI.UTF-8' >>> time.strftime("%a, %d %b %Y %H:%M:%S %z (%Z)") 'Ti, 03 Tam 2012 15:03:15 +0100 (CET)' >>> trond at enterprise:~> -- ---------------------------------------------------------------------- Trond Endrest?l ACM, NAS, NUUG, SAGE, USENIX From askutt at gmail.com Tue Jan 3 09:12:59 2012 From: askutt at gmail.com (Adam Skutt) Date: Tue, 3 Jan 2012 06:12:59 -0800 (PST) Subject: Avoid race condition with Popen.send_signal References: <63817f2b-ccf8-4d7d-92a6-c1d622986d8a@j10g2000vbe.googlegroups.com> Message-ID: <8614ceb1-f31f-4904-b2b9-6ef0d2bc7cdc@m20g2000vbf.googlegroups.com> On Jan 3, 3:44?am, J?r?me wrote: > Mon, 2 Jan 2012 19:16:50 -0800 (PST) > Adam Skutt a ?crit: > > > No. It is possible (however unlikely) for EPERM to be legitimately > > returned in this case. ?Anything other than EINVAL should be > > interpreted as "The child process is dead". ?Hence why you should > > avoid sending the signal in the first place: the situations where you > > don't run the risk of possibly killing an innocent bystander are > > pretty narrow. ?While unlikely on modern UNiX and Linux, IMO it's best > > to avoid the issue altogether whenever possible. > > Should I understand that Popen.send_signal blindly sends the signal to the > process of PID Popen.pid, and therefore could kill a new process of the same > PID that would have been launched by the same user in another program ? > Or possibly one launched by another user altogether. By /default/, child processes that terminate become zombies and remain in that state until their parent reaps them via wait(2) or a related syscall. This means that until you make such a call, the signal is delivered to the desired child process. In this case, kill(2) still returns ESRCH since the child process is a zombie and cannot possibly respond to the signal. However, if SIGCHLD has been explicitly ignored or has no SA_NOCLDWAIT set, child processes are reaped automatically. Likewise, it is possible to install a signal handler for SIGCHLD that calls wait and reaps the child processes. Do you know what all of your other Python modules and extensions do? If so, then you can probably rely on the default semantics. If not, I'd strongly suggest a more conservative approach. Regardless, of whether you can rely on the presence of your zombie children or not, you should expect the kill(2) call to fail and be prepared to trap the failure. Obviously, all of this is rather UNIX / Linux specific. > If so, I don't see how I can protect myself from that. Checking the process > is alive and then hoping that the time interval for the race condition is so > small that there are few chances for that to happen (because the OS > quarantines PID numbers for a while, for instance) ? The conservative approach is to use another IPC mechanism to talk to the process, such as a pipe or a socket. Why are you trying to send the child process SIGINT in the first place? Adam From bugcy013 at gmail.com Tue Jan 3 09:13:29 2012 From: bugcy013 at gmail.com (Ganesh Kumar) Date: Tue, 3 Jan 2012 19:43:29 +0530 Subject: Parse multi line with re module. Message-ID: Hi Guys, I want parse multiple line. with re.module, this is my given string http://dpaste.com/680760/ I have try with re.compile module. I want parse two line mac address and channel, I have done with for mac address finding r = re.compile("^Searching for OPUSH on (\w\w(:\w\w)+)") for channel finding device_r = re.compile("^Channel: (\d+)") the two parsing string working. but I want combine two pattern in to one. This is my code http://www.bpaste.net/show/21323/ please guide me . -Ganesh Did I learn something today? If not, I wasted it. -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan-usenet at bytereef.org Tue Jan 3 09:17:15 2012 From: stefan-usenet at bytereef.org (Stefan Krah) Date: Tue, 3 Jan 2012 15:17:15 +0100 Subject: .format vs. % In-Reply-To: <9mgfrtFt0U5@mid.individual.net> References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <4EFF559E.1050408@gmail.com> <4f027b79$0$29880$c3e8da3$5496439d@news.astraweb.com> <4F02DE94.8000506@gmail.com> <9mgfrtFt0U5@mid.individual.net> Message-ID: <20120103141715.GA25696@sleipnir.bytereef.org> Neil Cerutti wrote: > > In the real-world telco benchmark for _decimal, replacing the > > single line > > > > outfil.write("%s\n" % t) > > > > with > > > > outfil.write("{}\n".format(t)) > > > > adds 23% to the runtime. I think %-style formatting should not > > be deprecated at all. > > When it becomes necessary, it's possible to optimize it by > hoisting out the name lookups. > ... > outfil_write = outfil.write > append_newline = "{}\n".format > ... > outfil_write(append_newline(t)) > ... Did you profile this? I did, and it still adds 22% to the runtime. Stefan Krah From askutt at gmail.com Tue Jan 3 09:20:53 2012 From: askutt at gmail.com (Adam Skutt) Date: Tue, 3 Jan 2012 06:20:53 -0800 (PST) Subject: Avoid race condition with Popen.send_signal References: <63817f2b-ccf8-4d7d-92a6-c1d622986d8a@j10g2000vbe.googlegroups.com> <20120103094415.072db024@bouzin.lan> Message-ID: <70871926-8a1e-4506-b867-cde96537dcd9@m4g2000vbc.googlegroups.com> On Jan 3, 3:58?am, Chris Angelico wrote: > On Tue, Jan 3, 2012 at 7:44 PM, J?r?me wrote: > > If so, I don't see how I can protect myself from that. Checking the process > > is alive and then hoping that the time interval for the race condition is so > > small that there are few chances for that to happen (because the OS > > quarantines PID numbers for a while, for instance) ? > > The probability is extremely small. PIDs are generally allocated > sequentially, and obviously one won't be reallocated until the > previous process has terminated. You're looking at a narrow window of > opportunity between a check and an action; you don't really need to > worry about PID reuse within that window, unless there's a particular > reason to fear it (eg your process is very low priority, or there's a > lot of "process spinning" happening). Under normal circumstances, you > won't see a new process start up with the same PID for some time. > Not all operating systems attempt to generate sequential processes IDs. The window can be rather large in certain situations, and if you cannot rely on your child processes becoming zombies and kill being called only when the child is alive or a zombie, then you should not be calling kill(2) at all. Killing an unrelated process will be considered as a bug by users. Hence why I find it easier just to avoid the problem altogether if I can. Adam From candide at free.invalid Tue Jan 3 09:50:45 2012 From: candide at free.invalid (candide) Date: Tue, 03 Jan 2012 15:50:45 +0100 Subject: Regular expression : non capturing groups are faster ? In-Reply-To: References: <4f02e31c$0$15724$426a74cc@news.free.fr> Message-ID: <4f0315c6$0$10967$426a74cc@news.free.fr> Le 03/01/2012 12:56, Devin Jeanpierre a ?crit : >> The second assertion sounds more likely. It seems very odd that Python and >> Perl implementations are divergent on this point. Any opinion ? > > The Python documentation oversimplifies. You meant Perl Documentation, didn't you ? It's a commun opinion that non-capturing groups have a price (minor), for instance Jan Goyvaerts, a well known regular expression guru, refering to Python code, tells : non-capturing groups (...) offer (slightly) better performance as the regex engine doesn't have to keep track of the text matched by non-capturing groups. [link is there : http://stackoverflow.com/questions/2703029/why-regular-expressions-non-capturing-group-is-not-working] It seems Javascript performs better respect to non-capturing groups : http://jsperf.com/regex-capture-vs-non-capture The same for java : http://eyalsch.wordpress.com/2009/05/21/regex/ (no benchmarks). For my part, Python tests didn't show any kind of significative penality. From askutt at gmail.com Tue Jan 3 09:52:05 2012 From: askutt at gmail.com (Adam Skutt) Date: Tue, 3 Jan 2012 06:52:05 -0800 (PST) Subject: Avoid race condition with Popen.send_signal References: <63817f2b-ccf8-4d7d-92a6-c1d622986d8a@j10g2000vbe.googlegroups.com> Message-ID: On Jan 2, 11:53?pm, Cameron Simpson wrote: > On 02Jan2012 19:16, Adam Skutt wrote: > | On Jan 2, 8:44?pm, Cameron Simpson wrote: > | > On 02Jan2012 20:31, Devin Jeanpierre wrote: > | > | > I think that catching the exception is probably the most Pythonic way. > | > | > | > | It's the only correct way. > | > > | > Indeed, but be precise - chek that it _is_ error 3, or more portably, > | > errno.ESRCH. POSIX probably mandates that that is a 3, but the symbol > | > should track the local system if it differs. Example: > | > | No. It is possible (however unlikely) for EPERM to be legitimately > | returned in this case. ?Anything other than EINVAL should be > | interpreted as "The child process is dead". > > Sure. I was more taking the line: catch and accept only the specific > errors you understand. That advice really only applies when we have interfaces that don't fully define their exceptional conditions. That's not the case here. Though I should correct myself and note that EPERM can only occur if SIGCHLD is being handled in a non-default fashion. That being said, I'm not sure any error code should be treated differently from another here. > Of course he can catch EPERM also. But any other > variant should at the least generate a warning to stderr or a log > it is _unexpected_. Are they really unexpected though? Even if they are, what is logging an error going to gain anyone? Even crashing may not be helpful, especially given that there have been bugs in the past with the return codes from kill(2). Certainly, I'd be far more concerned about ensuring my code doesn't accidentally kill the wrong process than worrying about ensuring it handles the return code from kill(2) correctly. > I take your point that reraising the exception may be overkill for > failed signal delivery (if that was your point). But I am arguing for > being very careful about what you silently pass as an ok thing. > Trapping too few conditions is just as erroneous as trapping too many. This is especially true when dealing with UNIX system calls. The right behavior is frequently not as simple as it may appear, unfortunately. > | Hence why you should > | avoid sending the signal in the first place: the situations where you > | don't run the risk of possibly killing an innocent bystander are > | pretty narrow. ?While unlikely on modern UNiX and Linux, IMO it's best > | to avoid the issue altogether whenever possible. > > Fair enough too. But sometimes you need to nail a rogue child. Even if I believed that were true, I wouldn't use SIGINT to do it. Adam From askutt at gmail.com Tue Jan 3 10:03:08 2012 From: askutt at gmail.com (Adam Skutt) Date: Tue, 3 Jan 2012 07:03:08 -0800 (PST) Subject: Avoid race condition with Popen.send_signal References: <63817f2b-ccf8-4d7d-92a6-c1d622986d8a@j10g2000vbe.googlegroups.com> <20120103094415.072db024@bouzin.lan> Message-ID: On Jan 3, 4:38?am, J?r?me wrote: > I have an application that can spawn a subprocess to play a beep. I want it > to kill the subprocess when exiting. Why? You shouldn't need to send a signal to tell the process to terminate: it should terminate when its stdin is closed or when it's done playing the beep in the first place. If it doesn't, I would find a better way to play a beep in the first place. What you're attempting to do sounds superfluous and unnecessary. The only thing you ought to need to do is ensure that the child process is properly reaped if it terminates before your process terminates. > To do so, my close() method must > > ? a/ Check if any subprocess has actually been launched (I store the Popen in > ? a variable called _beep_process. If Popen has not been called, the variable > ? is init to 0 and the call to send_signal will fail.) > > ? b/ Check if the process is still alive using Popen.poll() and returncode > ? (otherwise, I might kill a new process) > > ? c/ Catch the exception in case the process would be dead since the last > ? check (otherwise, I might get an error from send_signal) > Steps a and c are all that are necessary under standard SIGCHLD handling. However, all of this should be entirely unnecessary in the first place. Plus, I have a hard time imagining why something like 'gtk.gdk.beep()' isn't adequate for your needs anyway. > For instance, Popen.send_signal() should not be able to send a signal to a > subprocess that has already returned, should it ? Is there any good reason > for allowing it to do so ? If not, it would spare me check b/ in this example. > The problem is being able to distinguish "process is a zombie" from "process doesn't exist" which both return ESRCH. This is certainly possible with careful coding but I'm not sure I would bother except in the simplest programs. Too many libraries do too many questionable things with signal handlers so I find it much safer and easier just to avoid the damn things whenever possible. Adam From jerome at jolimont.fr Tue Jan 3 10:09:36 2012 From: jerome at jolimont.fr (=?UTF-8?B?SsOpcsO0bWU=?=) Date: Tue, 3 Jan 2012 16:09:36 +0100 Subject: Avoid race condition with Popen.send_signal In-Reply-To: <8614ceb1-f31f-4904-b2b9-6ef0d2bc7cdc@m20g2000vbf.googlegroups.com> References: <63817f2b-ccf8-4d7d-92a6-c1d622986d8a@j10g2000vbe.googlegroups.com> <8614ceb1-f31f-4904-b2b9-6ef0d2bc7cdc@m20g2000vbf.googlegroups.com> Message-ID: <20120103160936.6ccc0c67@bouzin.lan> Tue, 3 Jan 2012 06:12:59 -0800 (PST) Adam Skutt a ?crit: > The conservative approach is to use another IPC mechanism to talk to > the process, such as a pipe or a socket. Why are you trying to send > the child process SIGINT in the first place? Say, you've got an application that plays a sound for a few seconds, using an external program for that (beep, sox). If you close the application, you want the sound to stop as well. I don't know much about subprocess, not much more than what is in the tutorial : http://docs.python.org/library/subprocess.html (I don't know much about signalling either, I'm learning...) I naively thought kill() was the "normal" way. Then realized terminate() or even send_signal(SIGINT) would be softer. What would be a good approach, then ? Should I try something like this ? communicate(input="Ctrl+C") (I'd need to figure out how to write Ctrl+C...) Would that be cross-platform ? -- J?r?me From neilc at norwich.edu Tue Jan 3 10:15:13 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 3 Jan 2012 15:15:13 GMT Subject: .format vs. % References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <4EFF559E.1050408@gmail.com> <4f027b79$0$29880$c3e8da3$5496439d@news.astraweb.com> <4F02DE94.8000506@gmail.com> <9mgfrtFt0U5@mid.individual.net> Message-ID: <9mgkc1FtteU1@mid.individual.net> On 2012-01-03, Stefan Krah wrote: > Neil Cerutti wrote: >> > In the real-world telco benchmark for _decimal, replacing the >> > single line >> > >> > outfil.write("%s\n" % t) >> > >> > with >> > >> > outfil.write("{}\n".format(t)) >> > >> > adds 23% to the runtime. I think %-style formatting should not >> > be deprecated at all. >> >> When it becomes necessary, it's possible to optimize it by >> hoisting out the name lookups. >> ... >> outfil_write = outfil.write >> append_newline = "{}\n".format >> ... >> outfil_write(append_newline(t)) >> ... > > Did you profile this? I did, and it still adds 22% to the runtime. No, I did not. And that's disappointing. -- Neil Cerutti From eulergaussriemann at gmail.com Tue Jan 3 10:17:43 2012 From: eulergaussriemann at gmail.com (David Goldsmith) Date: Tue, 3 Jan 2012 07:17:43 -0800 (PST) Subject: Can't write to a directory made w/ os.makedirs References: <50693cc2-93c9-481d-9fb1-42312e69b2d9@c42g2000prb.googlegroups.com> <91830ffb-00d9-4fd1-b771-ad59374334ec@n22g2000prh.googlegroups.com> <6348b96c-f7a9-4ca6-a704-c90d25f07788@y25g2000prg.googlegroups.com> Message-ID: On Jan 1, 7:43?pm, MRAB wrote: > On 02/01/2012 03:14, David Goldsmith wrote: > > > > > > > > > > > On Jan 1, 7:05 am, Tim Golden ?wrote: > >> ?On 01/01/2012 12:05, David Goldsmith wrote: > >> ? ?>> ?ie can the Python process creating the directories, > > >> ? ?> ?Yes. > > >> ? ?>> ?and a subprocess called from it create a simple file? > > >> ? ?> ?No. > > >> ? ?>> ?Depending on where you are in the filesystem, it may indeed > >> ? ?>> ?be necessary to be running as administrator. But don't try > >> ? ?>> ?to crack every security nut with an elevated sledgehammer. > > >> ? ?> ?If you mean running as admin., those were my sentiments exactly. ?So, > >> ? ?> ?there isn't something specific I should be doing to assure that my > >> ? ?> ?subproceses can write to directories? > > >> ?In the general case, no. By default, a subprocess will have > >> ?the same security context as its parent. The exception is > >> ?where the parent (the Python processing invoking subprocess.call > >> ?in this example) is already impersonating a different user; > >> ?in that case, the subprocess will inherit its grandparent's > >> ?context. > > >> ?But unless you're doing something very deliberate here then > >> ?I doubt if that's biting you. > > >> ?Can I ask: are you absolutely certain that the processes > >> ?you're calling are doing what you think they are and failing > >> ?where you think they're failing? > > >> ?TJG > > > I'm a mathematician: the only thing I'm absolutely certain of is > > nothing. > > > Here's my script, in case that helps: > > > import os > > import sys > > import stat > > import os.path as op > > import subprocess as sub > > from os import remove > > from os import listdir as ls > > from os import makedirs as mkdir > > > def doFlac2Mp3(arg, d, fl): > > ? ? ?if '.flac' in [f[-5:] for f in fl]: > > ? ? ? ? ?newD = d.replace('FLACS', 'MP3s') > > ? ? ? ? ?mkdir(newD) > > ? ? ? ? ?for f in fl: > > ? ? ? ? ? ? ?if f[-5:]=='.flac': > > ? ? ? ? ? ? ? ? ?root = f.replace('.flac', '') > > ? ? ? ? ? ? ? ? ?cmd = ['"C:\\Program Files (x86)\\aTunes\\win_tools\ > > \flac.exe" -d ' + > > ? ? ? ? ? ? ? ? ? ? ? ? '--output-prefix=' + newD + '\\', f] > > ? ? ? ? ? ? ? ? ?res = sub.call(cmd)#, env={'PATH': os.defpath}) > > ? ? ? ? ? ? ? ? ?if not res: > > ? ? ? ? ? ? ? ? ? ? ?cmd = ['"C:\\Program Files (x86)\\aTunes\\win_tools > > \\lame.exe" -h', > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?newD + root + '.wav', ?newD + root + > > '.mp3'] > > ? ? ? ? ? ? ? ? ? ? ?res = sub.call(cmd)#, env={'PATH': os.defpath}) > > ? ? ? ? ? ? ? ? ? ? ?if not res: > > ? ? ? ? ? ? ? ? ? ? ? ? ?rf = newD + root + '.wav' > > ? ? ? ? ? ? ? ? ? ? ? ? ?remove(rf) > > > top=sys.argv[1] > > op.walk(top, doFlac2Mp3, None) > > I think that if the command line should be something like: > > "C:\Program Files (x86)\aTunes\win_tools\flac.exe" -d > --output-prefix=FOO\ BAR > > then the cmd should be something like: > > cmd = ['C:\\Program Files (x86)\\aTunes\\win_tools\\flac.exe', '-d', > '--output-prefix="' + newD + '\\"', f] Thanks again all! MRAB: your advice was sufficient to get me over the hump, so to speak, thanks for chiming in! From joel.goldstick at gmail.com Tue Jan 3 10:21:48 2012 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 3 Jan 2012 10:21:48 -0500 Subject: [Tutor] Parse multi line with re module. In-Reply-To: References: Message-ID: On Tue, Jan 3, 2012 at 9:13 AM, Ganesh Kumar wrote: > Hi Guys, > > I want parse multiple line. with re.module, this is my given string > http://dpaste.com/680760/ I have try with re.compile module. I want parse > two line mac address and channel, > I have done with for mac address finding > > r = re.compile("^Searching for OPUSH on (\w\w(:\w\w)+)") > > for channel finding > > device_r = re.compile("^Channel: (\d+)") > > the two parsing string working. but I want combine two pattern in to one. > > This is my code > http://www.bpaste.net/show/21323/ > > please guide me . > > > -Ganesh > > Did I learn something today? If not, I wasted it. > > _______________________________________________ > Tutor maillist ?- ?Tutor at python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > -- Do you know about str.startswith() http://docs.python.org/library/stdtypes.html#str.startswith Since your data is so well defined I think it would be simpler to just read each line, strip whitespace, use startswith() to check for "Searching for OPUSH on" and "Channel:" You can slice to pull out the mac address and the channel number like so: >>> s = "Searching for OPUSH on 00:1D:FD:06:99:99" >>> s[23:] '00:1D:FD:06:99:99' # this will work if no other text follows the mac address >>> s[23:41] '00:1D:FD:06:99:99' # this will work to just capture the mac address >>> For the Channel number, after stripping whitespace, take the slice from s[9:] Searching for OPUSH on 00:1D:FD:06:99:99 ... Channel: 9 Joel Goldstick From neilc at norwich.edu Tue Jan 3 10:24:19 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 3 Jan 2012 15:24:19 GMT Subject: .format vs. % References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <4EFF559E.1050408@gmail.com> <4f027b79$0$29880$c3e8da3$5496439d@news.astraweb.com> <4F02DE94.8000506@gmail.com> <9mgfrtFt0U5@mid.individual.net> <9mgkc1FtteU1@mid.individual.net> Message-ID: <9mgkt3F2g7U1@mid.individual.net> On 2012-01-03, Neil Cerutti wrote: > On 2012-01-03, Stefan Krah wrote: >> Neil Cerutti wrote: >>> > In the real-world telco benchmark for _decimal, replacing the >>> > single line >>> > >>> > outfil.write("%s\n" % t) >>> > >>> > with >>> > >>> > outfil.write("{}\n".format(t)) >>> > >>> > adds 23% to the runtime. I think %-style formatting should not >>> > be deprecated at all. >>> >>> When it becomes necessary, it's possible to optimize it by >>> hoisting out the name lookups. >>> ... >>> outfil_write = outfil.write >>> append_newline = "{}\n".format >>> ... >>> outfil_write(append_newline(t)) >>> ... >> >> Did you profile this? I did, and it still adds 22% to the runtime. > > No, I did not. And that's disappointing. On many levels. Thanks for the correction. -- Neil Cerutti From dihedral88888 at googlemail.com Tue Jan 3 10:47:59 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 3 Jan 2012 07:47:59 -0800 (PST) Subject: .format vs. % In-Reply-To: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> Message-ID: <5059220.15.1325605679953.JavaMail.geo-discussion-forums@prgi2> davidfx? 2012?1?1????UTC+8??2?19?34???? > Hello everyone, > I just have a quick question about .format and %r %s %d. > > Should we always be using .format() for formatting strings or %? > > Example a = 'apples' > print "I love {0}.".format(a) > > If I wanted to put .format into a variable, how would I do that. > > Thanks for your information in advance. > > David This is a good evolution in Python. It is 2012 now and the text I/O part is not as important as 10 years ago. The next move of Python could be easy integration of C++ libraries. The auto code generation part for low-paid tedious GUI tasks is still missing in the standard Python. Boa and wxpython are still not good enough. From jerome at jolimont.fr Tue Jan 3 11:24:44 2012 From: jerome at jolimont.fr (=?UTF-8?B?SsOpcsO0bWU=?=) Date: Tue, 3 Jan 2012 17:24:44 +0100 Subject: Avoid race condition with Popen.send_signal In-Reply-To: References: <63817f2b-ccf8-4d7d-92a6-c1d622986d8a@j10g2000vbe.googlegroups.com> <20120103094415.072db024@bouzin.lan> Message-ID: <20120103172444.3d56ebf4@bouzin.lan> Tue, 3 Jan 2012 07:03:08 -0800 (PST) Adam Skutt a ?crit: > On Jan 3, 4:38?am, J?r?me wrote: > > I have an application that can spawn a subprocess to play a beep. I want > > it to kill the subprocess when exiting. > > Why? You shouldn't need to send a signal to tell the process to > terminate: it should terminate when its stdin is closed or when it's > done playing the beep in the first place. If it doesn't, I would find > a better way to play a beep in the first place. What you're > attempting to do sounds superfluous and unnecessary. Probably. And somehow, I'd be glad. Once the command (say beep) is called, it does terminate when done with the beep. I just don't know if it can be stopped while playing and how. (Perhaps the only clean way would be to call it several times by period of 10ms, for instance, to be able to stop at any time. But this makes the whole thing much more complicated.) > The only thing you ought to need to do is ensure that the child > process is properly reaped if it terminates before your process > terminates. The application polls the ongoing child process until it has terminated, and fetches its returncode. I hope this is "proper reaping". The tutorial (http://docs.python.org/library/subprocess.html) didn't suggest me to do anything more than that. > Steps a and c are all that are necessary under standard SIGCHLD > handling. However, all of this should be entirely unnecessary in the > first place. That's good news, because it seems a little bit ugly. > Plus, I have a hard time imagining why something like 'gtk.gdk.beep()' > isn't adequate for your needs anyway. Short answer : I may well be, I just didn't know it. I just looked at it quickly and it does not seem as flexible. Besides, beep is just an example, I also use sox. And anyway, the whole thing is just a training exercise I'm inflicting on myself, so I'm interested in solving the subprocess issue for itself. > The problem is being able to distinguish "process is a zombie" from > "process doesn't exist" which both return ESRCH. This is certainly > possible with careful coding but I'm not sure I would bother except in > the simplest programs. Too many libraries do too many questionable > things with signal handlers so I find it much safer and easier just to > avoid the damn things whenever possible. My small program _seems to_ work with the dirty hacks I already exposed. Yet, I'd rather stay on the safe and easy side, especially in a future bigger program. Therefore, I'm still interested in a better way to proceed. Is there another way to tell beep (or sox) to stop before the end of the beep ? AFAIK, the only way to stop it on console is to feed it Ctrl+C. Should I use communicate() for that ? How ? Apparently, the following does not work : process.communicate("\C-c") It may well be that the dirtyness of my program comes from the choice of external applications that don't allow nice termination through stdin. Or perhaps is it possible and I haven't figured out how yet... -- J?r?me From jerome at jolimont.fr Tue Jan 3 12:25:46 2012 From: jerome at jolimont.fr (=?UTF-8?B?SsOpcsO0bWU=?=) Date: Tue, 3 Jan 2012 18:25:46 +0100 Subject: Avoid race condition with Popen.send_signal In-Reply-To: <20120103172444.3d56ebf4@bouzin.lan> References: <63817f2b-ccf8-4d7d-92a6-c1d622986d8a@j10g2000vbe.googlegroups.com> <20120103094415.072db024@bouzin.lan> <20120103172444.3d56ebf4@bouzin.lan> Message-ID: <20120103182546.4317120e@bouzin.lan> Tue, 3 Jan 2012 17:24:44 +0100 J?r?me a ?crit: > > Too many libraries do too many questionable things with signal handlers > > so I find it much safer and easier just to avoid the damn things whenever > > possible. > > My small program _seems to_ work with the dirty hacks I already exposed. > Yet, I'd rather stay on the safe and easy side, especially in a future > bigger program. Therefore, I'm still interested in a better way to proceed. > > Is there another way to tell beep (or sox) to stop before the end of the > beep ? > > AFAIK, the only way to stop it on console is to feed it Ctrl+C. Should I use > communicate() for that ? How ? Apparently, the following does not work : > > process.communicate("\C-c") > I've been reading more and what I wrote now appears to me as silly, as Ctrl+C, as I understand, is just a way to send SIGINT... I guess I'll have to do with the signal handling, then. But I think I'm beggining to understand what you (Adam Skutt) meant. This is just as dirty as using Ctrl+C to stop beep when using the console, as opposed to using a software that would wait for a specific keypress to stop (in which case I could use communicate()). -- J?r?me From robert.sjoblom at gmail.com Tue Jan 3 12:51:43 2012 From: robert.sjoblom at gmail.com (Robert Sjoblom) Date: Tue, 3 Jan 2012 18:51:43 +0100 Subject: [Tutor] Parse multi line with re module. In-Reply-To: References: Message-ID: On 3 January 2012 16:21, Joel Goldstick wrote: > -- Joel, when you start your emails with this (two dashes) some email readers (gmail among them) will think you're ending your email; I have to expand your post because it thinks that what is hidden is the signature. Just thought you should know. -- best regards, Robert S. From ladasky at my-deja.com Tue Jan 3 12:57:50 2012 From: ladasky at my-deja.com (John Ladasky) Date: Tue, 3 Jan 2012 09:57:50 -0800 (PST) Subject: MOST COMMON QUESTIONS ASKED BY NON-MUSLIMS ????????? References: <6c0983b6-8786-4b04-b393-a6518f65ebbb@n6g2000vbz.googlegroups.com> Message-ID: On Jan 3, 7:40?am, BV wrote: > MOST COMMON QUESTIONS ASKED BY NON-MUSLIMS Q0. Why do thousand-line religious posts appear in comp.lang.python? From askutt at gmail.com Tue Jan 3 12:58:35 2012 From: askutt at gmail.com (Adam Skutt) Date: Tue, 3 Jan 2012 09:58:35 -0800 (PST) Subject: Avoid race condition with Popen.send_signal References: <63817f2b-ccf8-4d7d-92a6-c1d622986d8a@j10g2000vbe.googlegroups.com> <8614ceb1-f31f-4904-b2b9-6ef0d2bc7cdc@m20g2000vbf.googlegroups.com> Message-ID: On Jan 3, 10:09?am, J?r?me wrote: > Tue, 3 Jan 2012 06:12:59 -0800 (PST) > Adam Skutt a ?crit: > > > The conservative approach is to use another IPC mechanism to talk to > > the process, such as a pipe or a socket. ?Why are you trying to send > > the child process SIGINT in the first place? > > Say, you've got an application that plays a sound for a few seconds, using an > external program for that (beep, sox). If you close the application, you want > the sound to stop as well. If your application wants to play audio and terminate playing audio early, it really should use an audio library and play the sound directly. Especially if you're playing so many sounds in such a fashion you need to terminate them. If you're playing a single beep or short sound, then who really cares if it occurs slightly after your processes ends? GStreamer is one such library for sound processing though it may be more complicated than you need. > Should I try something like this ? > > ? ? ? ? communicate(input="Ctrl+C") > > (I'd need to figure out how to write Ctrl+C...) > > Would that be cross-platform ? > No, that won't work at all. 'Ctrl-C' is a magic indicator to the terminal driver to send SIGINT to the appropriate processes: it never actually appears as an input and output character to a program unless it's controlling the terminal in raw mode (where it loses its special meaning). If you're really insistent on using the sox(1) command-line tools to play your sounds, then you'll have to send SIGINT or SIGTERM in order to tell it to terminate (which can be done just by calling the terminate() method). Which is fine and will probably work OK subject to three restrictions: 1. Nothing in your application modifies the default handling of SIGCHLD. This means that the child process appears as a zombie (e.g., via 'ps ax') until the parent calls poll() or wait() methods to reap it. 2. You only send signals while the process is alive or a zombie: once the poll() or wait() methods return something other than None, you cannot safely send anymore signals. 3. You trap any errors returned by the send signal call. Adam From ian.g.kelly at gmail.com Tue Jan 3 13:04:52 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 3 Jan 2012 11:04:52 -0700 Subject: pickling instances of metaclass generated classes In-Reply-To: References: <2d221d0f-458e-4821-8786-f064b44b3125@p16g2000yqd.googlegroups.com> Message-ID: > Ok, > > After reading all posts (thanks a lot), I am considering to use the > following base metaclass for all metaclasses that must lead to > pickleable instances (not pickleable classes): > > > import sys > > class Meta(type): > def __new__(mcls, name, bases, attrs): > cls = type.__new__(mcls, name, bases, attrs) > setattr(sys.modules[__name__], name, cls) > return cls > > > if __name__ == '__main__': > instance = Meta("Klass", (str,),{})("apple") > s = pickle.dumps(instance) > delattr(sys.modules[__name__], "Klass") > Meta("Klass", (str,),{}) > inst = pickle.loads(s) > print instance > print inst > print type(instance) is type(inst) > > Can anyone see any drawbacks to this approach? I've also tested the > case where the Meta metaclass is defined in another module. With this approach you'll need to be conscious of what names you allow for classes. If you create any classes named "Meta" or "sys", or that shadow any of the builtins, things could break. For that reason I think the __reduce__ approach is cleaner (plus it works with the pickle system instead of trying to fool it, so it may be more robust ib the long term), but it's your project. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ether.joe at gmail.com Tue Jan 3 13:13:26 2012 From: ether.joe at gmail.com (Sean Wolfe) Date: Tue, 3 Jan 2012 15:13:26 -0300 Subject: python philosophical question - strong vs duck typing Message-ID: Hello everybody, I'm a happy pythonista newly subscribed to the group. How is it going? I have a theoretical / philosophical question regarding strong vs duck typing in Python. Let's say we wanted to type strongly in Python and were willing to compromise our code to the extent necessary, eg not changing variable types or casting or whatever. Let's say there was a methodology in Python to declare variable types. The question is, given this possibility, would this get us closer to being able to compile down to a language like C or C++? What I am driving at is, if we are coding in python but looking for more performance, what if we had an option to 1) restrict ourselves somewhat by using strong typing to 2) make it easy to compile or convert down to C++ and thereby gain more performance. It seems to be that accepting the restrictions of strong typing might be worth it in certain circumstances. Basically the option to use a strongly-typed Python as desired. Does this get us closer to being able to convert to Cpp? Does the Cython project have anything to do with this? Thanks! -- A musician must make music, an artist must paint, a poet must write, if he is to be ultimately at peace with himself. - Abraham Maslow From ian.g.kelly at gmail.com Tue Jan 3 13:13:56 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 3 Jan 2012 11:13:56 -0700 Subject: .format vs. % In-Reply-To: <4F030221.3050902@stoneleaf.us> References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <4EFF559E.1050408@gmail.com> <4f027b79$0$29880$c3e8da3$5496439d@news.astraweb.com> <4f029d1e$0$29880$c3e8da3$5496439d@news.astraweb.com> <4F030221.3050902@stoneleaf.us> Message-ID: On Jan 3, 2012 6:55 AM, "Ethan Furman" wrote: > > Ian Kelly wrote: >> >> I'm not sure it's true that "there are no plans to do so in the >> foreseeable future." According to the release notes from Python 3.0, >> % formatting was supposed to be deprecated in Python 3.1. > > > Eric Smith wrote (from a thread on pydev in 02-2011): > > The last thread on this I have a reference to was in September 2009. I > > think was basically the outcome: > > http://mail.python.org/pipermail/python-dev/2009-September/092399.html > > > > So there will be no deprecation, just a gradual shift to PEP 3101 > > formatting. Thanks, that link is very informative. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gheskett at wdtv.com Tue Jan 3 13:24:12 2012 From: gheskett at wdtv.com (gene heskett) Date: Tue, 3 Jan 2012 13:24:12 -0500 Subject: MOST COMMON QUESTIONS ASKED BY NON-MUSLIMS ????????? In-Reply-To: References: <6c0983b6-8786-4b04-b393-a6518f65ebbb@n6g2000vbz.googlegroups.com> Message-ID: <201201031324.13090.gheskett@wdtv.com> On Tuesday, January 03, 2012 01:13:08 PM John Ladasky did opine: > On Jan 3, 7:40 am, BV wrote: > > MOST COMMON QUESTIONS ASKED BY NON-MUSLIMS > > Q0. Why do thousand-line religious posts appear in comp.lang.python? Already discussed, at considerable length & I got told off. The solution is to chop the link between google.groups and this list. But that subject has been declared verboten. Too much inconvenience to ask the googlers to subscribe to the real list I guess. Because my spamassassin has been trained on so much google (& yahoo too) originated spam, one poster here, Jerome, has his messages always caught. He comes in thru the groups coupling and I have considered moving his messages to the ham folder, but realized all that would do is poison my bayes. Since TPTB of this list don't care, neither do I, so his messages continue to be automatically fed to SA as spam, daily. Shrug. Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) My web page: I'm changing the CHANNEL ... But all I get is commercials for "RONCO MIRACLE BAMBOO STEAMERS"! From nathan.alexander.rice at gmail.com Tue Jan 3 13:28:51 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Tue, 3 Jan 2012 13:28:51 -0500 Subject: python philosophical question - strong vs duck typing In-Reply-To: References: Message-ID: On Tue, Jan 3, 2012 at 1:13 PM, Sean Wolfe wrote: > Hello everybody, I'm a happy pythonista newly subscribed to the group. > How is it going? > I have a theoretical / philosophical question regarding strong vs duck > typing in Python. Let's say we wanted to type strongly in Python and > were willing to compromise our code to the extent necessary, eg not > changing variable types or casting or whatever. Let's say there was a > methodology in Python to declare variable types. Do you think everyone who uses the code you write wants to deal with your type decisions? > The question is, given this possibility, would this get us closer to > being able to compile down to a language like C or C++? Declaring types would enable some additional optimizations, yes. No, it isn't worth it. > What I am driving at is, if we are coding in python but looking for > more performance, what if we had an option to 1) restrict ourselves > somewhat by using strong typing to 2) make it easy to compile or > convert down to C++ and thereby gain more performance. Take a look at PyPy, with RPython. That is the most future proof, forward thinking way of doing what you want. > It seems to be that accepting the restrictions of strong typing might > be worth it in certain circumstances. Basically the option to use a > strongly-typed Python as desired. Does this get us closer to being > able to convert to Cpp? Does the Cython project have anything to do > with this? Declared typing is mostly annoying. Implicit static typing is less annoying, but still has issues. Cython fills the same niche as PyPy's Rpython. Use it if you have a lot of C code you want to call, as you will get better performance than a wrapper like SWIG. Nathan From jerome at jolimont.fr Tue Jan 3 13:45:52 2012 From: jerome at jolimont.fr (=?UTF-8?B?SsOpcsO0bWU=?=) Date: Tue, 3 Jan 2012 19:45:52 +0100 Subject: Avoid race condition with Popen.send_signal In-Reply-To: References: <63817f2b-ccf8-4d7d-92a6-c1d622986d8a@j10g2000vbe.googlegroups.com> <8614ceb1-f31f-4904-b2b9-6ef0d2bc7cdc@m20g2000vbf.googlegroups.com> Message-ID: <20120103194552.23e9bf4d@bouzin.lan> Tue, 3 Jan 2012 09:58:35 -0800 (PST) Adam Skutt a ?crit: > If you're really insistent on using the sox(1) command-line tools to play > your sounds, then you'll have to send SIGINT or SIGTERM in order to tell it > to terminate (which can be done just by calling the terminate() method). > > Which is fine and will probably work OK subject to three restrictions: > 1. Nothing in your application modifies the default handling of > SIGCHLD. This means that the child process appears as a zombie (e.g., > via 'ps ax') until the parent calls poll() or wait() methods to reap > it. > 2. You only send signals while the process is alive or a zombie: once > the poll() or wait() methods return something other than None, you > cannot safely send anymore signals. > 3. You trap any errors returned by the send signal call. Thank you very much for your patient explanations. I sort of figured that out from your precedent messages and I was writing the following : ----------------------------------------------------------------------- I use poll() in idle task to follow the process's activity, then set a variable if still in progress. If I do the signalling in idle task as well, relying on that variable, there should not be any race condition collateral damage. (If I did not, however, I could send SIGINT between poll() and the variable being set.) It just makes the code even heavier with each "stop sound" callback calling GObject.idle_add() to ask for the work to be done in idle task, instead of doing it right away. ----------------------------------------------------------------------- I agree with the fact that ideally I would use another playback library. The reason of my choice is "historical". This is my first python application. I started simple and used beep for simplicity. Then, as I wanted to use the sound card, I searched for a library (I posted here about that) and realized playing a sine wave was not that straightforward. (I tried alsaaudio and had multithreading issues (posted here as well).) As it was not that important to me (after all, it's just an exercise), I decided to move on and use sox, as invoking it would be quite similar to calling beep and I had already enough difficulties to face and other priorities. I guess I can always change my mind and use an audio library some day but I was merely interested in the way signalling and processes work. Thanks again. -- J?r?me From darcy at druid.net Tue Jan 3 13:49:19 2012 From: darcy at druid.net (D'Arcy Cain) Date: Tue, 03 Jan 2012 13:49:19 -0500 Subject: MOST COMMON QUESTIONS ASKED BY NON-MUSLIMS ????????? In-Reply-To: <201201031324.13090.gheskett@wdtv.com> References: <6c0983b6-8786-4b04-b393-a6518f65ebbb@n6g2000vbz.googlegroups.com> <201201031324.13090.gheskett@wdtv.com> Message-ID: <4F034DAF.5010006@druid.net> On 12-01-03 01:24 PM, gene heskett wrote: > The solution is to chop the link between google.groups and this list. But > that subject has been declared verboten. Too much inconvenience to ask the > googlers to subscribe to the real list I guess. Because my spamassassin Perhaps they just need to be reminded from time to time that many of us have already "chopped the link" and for us there is no Google Groups on this list. I never even saw the original message because everything from GG goes straight to /dev/null on my system. Now if only I could automatically kill the replies to GG messages. :-) P.S. if you use Spamassassin: :0 Hir * ^List-Id:.*python-list.python.org * ^From:.*@gmail.com * ^Newsgroups:.* /dev/null -- 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 darcy at druid.net Tue Jan 3 13:50:43 2012 From: darcy at druid.net (D'Arcy Cain) Date: Tue, 03 Jan 2012 13:50:43 -0500 Subject: python philosophical question - strong vs duck typing In-Reply-To: References: Message-ID: <4F034E03.2090203@druid.net> On 12-01-03 01:13 PM, Sean Wolfe wrote: > Hello everybody, I'm a happy pythonista newly subscribed to the group. Welcome. > The question is, given this possibility, would this get us closer to > being able to compile down to a language like C or C++? That's "a" question. "The" question is "do you want to?" Since we already run in machine language (doesn't everything) then how can you be sure that introducing another layer will improve performance? > What I am driving at is, if we are coding in python but looking for > more performance, what if we had an option to 1) restrict ourselves > somewhat by using strong typing to 2) make it easy to compile or > convert down to C++ and thereby gain more performance. Where is your bottleneck? I have seldom found Python to be it. Remember, almost everything you run was written in C. Python is just the glue that binds it all together. Consider ls(1) (dir in Windows/DOS) for example. If you need a directory listing you type that and get it pretty quickly. Is there a bottleneck? Yes, it's you. The command can probably do all of its work much faster than you can type the command. Now put the command into a script. Entering the command is no longer the bottleneck. It's now the time it takes to access the drive. Do we care? Probably not and if we did there's probably not much we can do about it. Python is simply a more powerful and efficient way to get to that machine language in a script. If you do have a pure Python function that is a bottleneck and you believe that C can solve it, you can always write just that part in C. However, run some tests first to make sure. 99% of the time you can fix it algorithmically or else it wasn't the bottleneck that you thought it was. And if it is and no one has already written a module for it, you just found a project to contribute back to the community. :-) > It seems to be that accepting the restrictions of strong typing might > be worth it in certain circumstances. Basically the option to use a So few as to not be worth changing the language for, especially when C is always available if you need it. Cheers. -- 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 python at mrabarnett.plus.com Tue Jan 3 13:57:39 2012 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 03 Jan 2012 18:57:39 +0000 Subject: Repeating assertions in regular expression In-Reply-To: References: <4f02c069$0$690$426a74cc@news.free.fr> Message-ID: <4F034FA3.6020902@mrabarnett.plus.com> On 03/01/2012 09:45, Devin Jeanpierre wrote: >> \\b\\b and \\b{2} aren't equivalent ? > > This sounds suspiciously like a bug! > >> Why the wording is "should never" ? Repeating a zero-width assertion is not >> forbidden, for instance : >> >>>>> import re >>>>> re.compile("\\b\\b\w+\\b\\b") >> <_sre.SRE_Pattern object at 0xb7831140> >>>>> > > I believe this is meant to refer to arbitrary-length repetitions, such > as r'\b*', not simple concatenations like that. r'\b*' will abort the > whole match if is run on a boundary, because Python detects a > repetition of a zero-width match and decides this is an error. > r"\b+" can be optimised to r"\b", but r"\b*" can be optimised to r"". r"\b\b", r"\b\b\b", etc, can be optimised to r"\b". So why doesn't it optimised? Because every potential optimisation has a cost, which is the time it would take to look for it. That cost needs to be balanced against the potential benefit. How often do you see repeated r"\b"? Put simply, it doesn't occur often enough to be worth it. The cost outweighs the potential benefit. From dave at dwink.net Tue Jan 3 14:03:37 2012 From: dave at dwink.net (David Harks) Date: Tue, 03 Jan 2012 13:03:37 -0600 Subject: python philosophical question - strong vs duck typing In-Reply-To: References: Message-ID: <4F035109.4040806@dwink.net> On 1/3/2012 12:13 PM, Sean Wolfe wrote: > if we are coding in python but looking for > more performance, Are you in fact in this situation? Despite years of folks mentioning how Python is 'slower than C++', I've seen a project where a developer churned out a feature using Python's generators that performed much faster than the C++ implementation it replaced. It wasn't because the C++ was slower by nature; it's because it was harder to express the optimal algorithm in C++ so the C++ developer chose a sub-optimal approach in the interest of meeting a deadline. There's always a tradeoff. Making a language less expressive (constraining ourselves) in favor of runtime performance is not always the right tradeoff. From joel.goldstick at gmail.com Tue Jan 3 14:20:18 2012 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 3 Jan 2012 14:20:18 -0500 Subject: [Tutor] Parse multi line with re module. In-Reply-To: References: Message-ID: On Tue, Jan 3, 2012 at 12:51 PM, Robert Sjoblom wrote: > On 3 January 2012 16:21, Joel Goldstick wrote: >> -- > > Joel, when you start your emails with this (two dashes) some email > readers (gmail among them) will think you're ending your email; I have > to expand your post because it thinks that what is hidden is the > signature. Just thought you should know. > > > -- > best regards, > Robert S. Thank you. I'm not sure how that happens. I'll check my signature. Joel Goldstick From benjamin.kaplan at case.edu Tue Jan 3 14:24:39 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 3 Jan 2012 14:24:39 -0500 Subject: MOST COMMON QUESTIONS ASKED BY NON-MUSLIMS ????????? In-Reply-To: <4F034DAF.5010006@druid.net> References: <6c0983b6-8786-4b04-b393-a6518f65ebbb@n6g2000vbz.googlegroups.com> <201201031324.13090.gheskett@wdtv.com> <4F034DAF.5010006@druid.net> Message-ID: On Tue, Jan 3, 2012 at 1:49 PM, D'Arcy Cain wrote: > On 12-01-03 01:24 PM, gene heskett wrote: >> >> The solution is to chop the link between google.groups and this list. ?But >> that subject has been declared verboten. Too much inconvenience to ask the >> googlers to subscribe to the real list I guess. ?Because my spamassassin > > > Perhaps they just need to be reminded from time to time that many of us have > already "chopped the link" and for us there is no Google Groups on this > list. ?I never even saw the original message because everything from GG goes > straight to /dev/null on my system. > > Now if only I could automatically kill the replies to GG messages. ?:-) > > P.S. if you use Spamassassin: > > :0 Hir > * ^List-Id:.*python-list.python.org > * ^From:.*@gmail.com > * ^Newsgroups:.* > /dev/null > > -- Wouldn't that just kill everything sent from a gmail account? That's not the same thing as Google Groups. The mailing list posts, at least, have an "Organization: http://groups.google.com" header. You'd probably be better off filtering on that. From jeanpierreda at gmail.com Tue Jan 3 14:31:55 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Tue, 3 Jan 2012 14:31:55 -0500 Subject: Regular expression : non capturing groups are faster ? In-Reply-To: <4f0315c6$0$10967$426a74cc@news.free.fr> References: <4f02e31c$0$15724$426a74cc@news.free.fr> <4f0315c6$0$10967$426a74cc@news.free.fr> Message-ID: > You meant Perl Documentation, didn't you ? I guess that works too. I did mean Python, though -- its intent is to say "you shouldn't worry about this", but in the process it says "this does not exist" (a lie). "slightly better performance" would be accurate, as said by Goyvaerts/ -- Devin On Tue, Jan 3, 2012 at 9:50 AM, candide wrote: > Le 03/01/2012 12:56, Devin Jeanpierre a ?crit : >>> >>> The second assertion sounds more likely. It seems very odd that Python >>> and >>> Perl implementations are divergent on this point. Any opinion ? >> >> >> The Python documentation oversimplifies. > > > You meant Perl Documentation, didn't you ? > > > It's a commun opinion that non-capturing groups have a price (minor), for > instance Jan Goyvaerts, a well known regular expression guru, refering to > Python code, tells : > > > non-capturing groups (...) ?offer (slightly) better performance as the regex > engine doesn't have to keep track of the text matched by non-capturing > groups. > > > [link is there : > http://stackoverflow.com/questions/2703029/why-regular-expressions-non-capturing-group-is-not-working] > > > > It seems Javascript performs better respect to non-capturing groups : > http://jsperf.com/regex-capture-vs-non-capture > > The same for java : http://eyalsch.wordpress.com/2009/05/21/regex/ > (no benchmarks). > > For my part, Python tests didn't show any kind of significative penality. > -- > http://mail.python.org/mailman/listinfo/python-list From jeanpierreda at gmail.com Tue Jan 3 14:36:00 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Tue, 3 Jan 2012 14:36:00 -0500 Subject: Repeating assertions in regular expression In-Reply-To: <4F034FA3.6020902@mrabarnett.plus.com> References: <4f02c069$0$690$426a74cc@news.free.fr> <4F034FA3.6020902@mrabarnett.plus.com> Message-ID: > Put simply, it doesn't occur often enough to be worth it. The cost > outweighs the potential benefit. I don't buy it. You could backtrack instead of failing for \b+ and \b*, and it would be almost as fast as this optimization. -- Devin On Tue, Jan 3, 2012 at 1:57 PM, MRAB wrote: > On 03/01/2012 09:45, Devin Jeanpierre wrote: >>> >>> ?\\b\\b and \\b{2} aren't equivalent ? >> >> >> This sounds suspiciously like a bug! >> >>> ?Why the wording is "should never" ? Repeating a zero-width assertion is >>> not >>> ?forbidden, for instance : >>> >>>>>> ?import re >>>>>> ?re.compile("\\b\\b\w+\\b\\b") >>> >>> ?<_sre.SRE_Pattern object at 0xb7831140> >>>>>> >>>>>> >> >> I believe this is meant to refer to arbitrary-length repetitions, such >> as r'\b*', not simple concatenations like that. r'\b*' will abort the >> whole match if is run on a boundary, because Python detects a >> repetition of a zero-width match and decides this is an error. >> > r"\b+" can be optimised to r"\b", but r"\b*" can be optimised to r"". > r"\b\b", r"\b\b\b", etc, can be optimised to r"\b". > > So why doesn't it optimised? > > Because every potential optimisation has a cost, which is the time it > would take to look for it. > > That cost needs to be balanced against the potential benefit. > > How often do you see repeated r"\b"? > > Put simply, it doesn't occur often enough to be worth it. The cost > outweighs the potential benefit. > -- > http://mail.python.org/mailman/listinfo/python-list From ethan at stoneleaf.us Tue Jan 3 14:38:29 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 03 Jan 2012 11:38:29 -0800 Subject: .format vs. % In-Reply-To: References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <4EFF559E.1050408@gmail.com> <4f027b79$0$29880$c3e8da3$5496439d@news.astraweb.com> <4f029d1e$0$29880$c3e8da3$5496439d@news.astraweb.com> <4F030221.3050902@stoneleaf.us> Message-ID: <4F035935.8040300@stoneleaf.us> Ian Kelly wrote: >>> http://mail.python.org/pipermail/python-dev/2009-September/092399.html > > Thanks, that link is very informative. > Here's the link to the last discussion last February: http://mail.python.org/pipermail/python-dev/2011-February/108155.html ~Ethan~ From darcy at druid.net Tue Jan 3 14:40:12 2012 From: darcy at druid.net (D'Arcy Cain) Date: Tue, 03 Jan 2012 14:40:12 -0500 Subject: MOST COMMON QUESTIONS ASKED BY NON-MUSLIMS ????????? In-Reply-To: References: <6c0983b6-8786-4b04-b393-a6518f65ebbb@n6g2000vbz.googlegroups.com> <201201031324.13090.gheskett@wdtv.com> <4F034DAF.5010006@druid.net> Message-ID: <4F03599C.9000107@druid.net> On 12-01-03 02:24 PM, Benjamin Kaplan wrote: >> :0 Hir >> * ^List-Id:.*python-list.python.org >> * ^From:.*@gmail.com >> * ^Newsgroups:.* >> /dev/null >> >> -- > > Wouldn't that just kill everything sent from a gmail account? That's > not the same thing as Google Groups. The mailing list posts, at least, > have an "Organization: http://groups.google.com" header. You'd > probably be better off filtering on that. Possibly. I don't remember seeing that header at the time that I created the recipe. I'll have to try that. In any case, the above doesn't kill everything from gmail, only messages from gmail that come through the news/mlist gateway. -- 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 neilc at norwich.edu Tue Jan 3 14:40:25 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 3 Jan 2012 19:40:25 GMT Subject: python philosophical question - strong vs duck typing References: Message-ID: <9mh3t9FbvuU1@mid.individual.net> On 2012-01-03, David Harks wrote: > On 1/3/2012 12:13 PM, Sean Wolfe wrote: >> if we are coding in python but looking for >> more performance, > > Are you in fact in this situation? Despite years of folks > mentioning how Python is 'slower than C++', I've seen a project > where a developer churned out a feature using Python's > generators that performed much faster than the C++ > implementation it replaced. It wasn't because the C++ was > slower by nature; it's because it was harder to express the > optimal algorithm in C++ so the C++ developer chose a > sub-optimal approach in the interest of meeting a deadline. I was again looking through The Practice of Programming (Kernighan & Pike) today, and the chapter on the Markov chain program makes similar tradeoffs. For educational purposes they implement the program in several languages, and the C implemenation is fastest by far. The C++ implementation is surprisingly not close in performance to the C version, for two main reasons. 1. They used a std::deque to store the prefixes, when a std::list is the correct container. They point this out in a note on the poor performance of the C++ program, but do not note the irony that they had automatically used a singly-linked list in C. 2. When building the data structure in C they store only pointers to the original text, which they munge in memory to create zero-terminated strings. This is idiomatic C. But there's no reason C++ can't do a similar optimization. A std::list is certainly possible, but loses you most of the benefits of the standard containers. Best is probably to create a registry of words using a std::map, with your lists storing references to words in the registry. You still have to copy of the text, but only once. The C++ implementation starts to smell sort of like Python. ;) -- Neil Cerutti From drobinow at gmail.com Tue Jan 3 14:42:55 2012 From: drobinow at gmail.com (David Robinow) Date: Tue, 3 Jan 2012 14:42:55 -0500 Subject: MOST COMMON QUESTIONS ASKED BY NON-MUSLIMS ????????? In-Reply-To: References: <6c0983b6-8786-4b04-b393-a6518f65ebbb@n6g2000vbz.googlegroups.com> <201201031324.13090.gheskett@wdtv.com> <4F034DAF.5010006@druid.net> Message-ID: On Tue, Jan 3, 2012 at 2:24 PM, Benjamin Kaplan wrote: > On Tue, Jan 3, 2012 at 1:49 PM, D'Arcy Cain wrote: >> On 12-01-03 01:24 PM, gene heskett wrote: >>> >>> The solution is to chop the link between google.groups and this list. ?But >>> that subject has been declared verboten. Too much inconvenience to ask the >>> googlers to subscribe to the real list I guess. ?Because my spamassassin >> >> Perhaps they just need to be reminded from time to time that many of us have >> already "chopped the link" and for us there is no Google Groups on this >> list. ?I never even saw the original message because everything from GG goes >> straight to /dev/null on my system. >> >> Now if only I could automatically kill the replies to GG messages. ?:-) >> >> P.S. if you use Spamassassin: >> >> :0 Hir >> * ^List-Id:.*python-list.python.org >> * ^From:.*@gmail.com >> * ^Newsgroups:.* >> /dev/null >> > Wouldn't that just kill everything sent from a gmail account? That's > not the same thing as Google Groups. The mailing list posts, at least, > have an "Organization: http://groups.google.com" header. You'd > probably be better off filtering on that. Interesting. I read the list using gmail, and I never saw the original post. IIn fact I rarely see any spam at all. Apparently, somebody at google knows how to identify spam. I wonder why they can't do it for google groups. [I also wonder if anybody will see this post, coming from an evil source.] From neilc at norwich.edu Tue Jan 3 14:46:40 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 3 Jan 2012 19:46:40 GMT Subject: .format vs. % References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <4EFF559E.1050408@gmail.com> <4f027b79$0$29880$c3e8da3$5496439d@news.astraweb.com> <4F02DE94.8000506@gmail.com> Message-ID: <9mh490FbvuU2@mid.individual.net> On 2012-01-03, Stefan Krah wrote: > Andrew Berg wrote: >> To add my opinion on it, I find format() much more readable and easier >> to understand (with the exception of the {} {} {} {} syntax), and would >> love to see %-style formatting phased out. > > For me the %-style is much more readable. Also, it is significantly > faster: > > $ ./python -m timeit -n 1000000 '"%s" % 7.928137192' > 1000000 loops, best of 3: 0.0164 usec per loop I have done a little more investigating, and the above is arguably not fair. Python is interpolating that string at compile time, as far as I can tell. Pretty cool, and not possible with .format, but it's just regurgitating a string literal over and over, which isn't of much interest. % is faster, but not by an order of magnitude. On my machine: C:\WINDOWS>python -m timeit -n 1000000 -s "n=7.92" "'%s' % n" 1000000 loops, best of 3: 0.965 usec per loop C:\WINDOWS>python -m timeit -n 1000000 -s "n=7.92" "'{}'.format(n)" 1000000 loops, best of 3: 1.17 usec per loop -- Neil Cerutti From santosh.ssit at gmail.com Tue Jan 3 14:47:34 2012 From: santosh.ssit at gmail.com (hisan) Date: Tue, 3 Jan 2012 11:47:34 -0800 (PST) Subject: Unable to install xmldiff package on WIndows7 Message-ID: Hi All i have downloaded "xmldiff-0.6.10" from their official site (http:// www.logilab.org/859). I have tried installing the same on my 32 bit Windows 7 OS using the command "setup.py install" but below exceptions are thrown in the console. please help me out in installing this package on Windows Exceptions thrown while installing C:\Users\santosh\Downloads\xmldiff-0.6.10>setup.py build running build running build_py package init file '.\test\__init__.py' not found (or not a regular file) package init file '.\test\__init__.py' not found (or not a regular file) running build_ext building 'xmldiff.maplookup' extension gcc -mno-cygwin -mdll -O -Wall -ID:\Python26\include -ID:\Python26\PC - c extensions/maplookup.c -o b uild\temp.win32-2.6\Release\extensions\maplookup.o error: command 'gcc' failed: No such file or directory From edriscoll at wisc.edu Tue Jan 3 14:51:27 2012 From: edriscoll at wisc.edu (Evan Driscoll) Date: Tue, 03 Jan 2012 14:51:27 -0500 Subject: python philosophical question - strong vs duck typing In-Reply-To: References: Message-ID: <4F035C3F.3070404@wisc.edu> On 1/3/2012 13:13, Sean Wolfe wrote: > What I am driving at is, if we are coding in python but looking for > more performance, what if we had an option to 1) restrict ourselves > somewhat by using strong typing to 2) make it easy to compile or > convert down to C++ and thereby gain more performance. I'm not sure it helps with compiling to C or C++ (that is neither necessary nor sufficient for being a high performance language), but it has the potential for helping quite a lot with performance. If you read stuff written by evangelical Common Lisp folks, they tout CL's optional type annotations as providing a mechanism for getting near-C-like performance. I haven't tested that myself though. 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 ethan at stoneleaf.us Tue Jan 3 15:00:23 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 03 Jan 2012 12:00:23 -0800 Subject: .format vs. % In-Reply-To: <9mh490FbvuU2@mid.individual.net> References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <4EFF559E.1050408@gmail.com> <4f027b79$0$29880$c3e8da3$5496439d@news.astraweb.com> <4F02DE94.8000506@gmail.com> <9mh490FbvuU2@mid.individual.net> Message-ID: <4F035E57.1090706@stoneleaf.us> Neil Cerutti wrote: > On 2012-01-03, Stefan Krah wrote: >> Andrew Berg wrote: >>> To add my opinion on it, I find format() much more readable and easier >>> to understand (with the exception of the {} {} {} {} syntax), and would >>> love to see %-style formatting phased out. >> For me the %-style is much more readable. Also, it is significantly >> faster: >> >> $ ./python -m timeit -n 1000000 '"%s" % 7.928137192' >> 1000000 loops, best of 3: 0.0164 usec per loop > > I have done a little more investigating, and the above is > arguably not fair. Python is interpolating that string at compile > time, as far as I can tell. Pretty cool, and not possible with > .format, but it's just regurgitating a string literal over and > over, which isn't of much interest. > > % is faster, but not by an order of magnitude. > > On my machine: > > C:\WINDOWS>python -m timeit -n 1000000 -s "n=7.92" "'%s' % n" > 1000000 loops, best of 3: 0.965 usec per loop > > C:\WINDOWS>python -m timeit -n 1000000 -s "n=7.92" "'{}'.format(n)" > 1000000 loops, best of 3: 1.17 usec per loop > Good information. Thanks. ~Ethan~ From jeanpierreda at gmail.com Tue Jan 3 15:02:47 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Tue, 3 Jan 2012 15:02:47 -0500 Subject: .format vs. % In-Reply-To: <4F030221.3050902@stoneleaf.us> References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <4EFF559E.1050408@gmail.com> <4f027b79$0$29880$c3e8da3$5496439d@news.astraweb.com> <4f029d1e$0$29880$c3e8da3$5496439d@news.astraweb.com> <4F030221.3050902@stoneleaf.us> Message-ID: > "one obvious way" != "only one way" Which way is the obvious way? Why is it obvious? For me, sprintf-formatting is "obviously" easier to use (less typing) unless you're pulling values from a dictionary or object, or already have all the variables stored in a dict you can pass in with **d. -- Devin On Tue, Jan 3, 2012 at 8:26 AM, Ethan Furman wrote: > Ian Kelly wrote: >> >> I'm not sure it's true that "there are no plans to do so in the >> foreseeable future." ?According to the release notes from Python 3.0, >> % formatting was supposed to be deprecated in Python 3.1. > > > Eric Smith wrote (from a thread on pydev in 02-2011): >> The last thread on this I have a reference to was in September 2009. I >> think was basically the outcome: >> http://mail.python.org/pipermail/python-dev/2009-September/092399.html >> >> So there will be no deprecation, just a gradual shift to PEP 3101 >> formatting. > > > Ian Kelly wrote: >> >> Maybe there was a discussion on py-dev >> where it was decided that % formatting would not be deprecated after >> all (in which case the misleading "obsolete" note really ought to be >> removed from the documentation). > > > Agreed that this is a documentation bug. > > > Ian Kelly wrote: >> >> The reason for deprecating it is because Python currently has no fewer >> than three mechanisms for string formatting (not even including >> ordinary string concatenation), which according to the Zen of Python >> is two too many. > > > "one obvious way" != "only one way" > > ~Ethan~ > -- > http://mail.python.org/mailman/listinfo/python-list From joshua.landau.ws at gmail.com Tue Jan 3 15:04:34 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Tue, 3 Jan 2012 20:04:34 +0000 Subject: .format vs. % In-Reply-To: <9mh490FbvuU2@mid.individual.net> References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <4EFF559E.1050408@gmail.com> <4f027b79$0$29880$c3e8da3$5496439d@news.astraweb.com> <4F02DE94.8000506@gmail.com> <9mh490FbvuU2@mid.individual.net> Message-ID: On 3 January 2012 19:46, Neil Cerutti wrote: > On 2012-01-03, Stefan Krah wrote: > > Andrew Berg wrote: > >> To add my opinion on it, I find format() much more readable and easier > >> to understand (with the exception of the {} {} {} {} syntax), and would > >> love to see %-style formatting phased out. > > > > For me the %-style is much more readable. Also, it is significantly > > faster: > > > > $ ./python -m timeit -n 1000000 '"%s" % 7.928137192' > > 1000000 loops, best of 3: 0.0164 usec per loop > > I have done a little more investigating, and the above is > arguably not fair. Python is interpolating that string at compile > time, as far as I can tell. Pretty cool, and not possible with > .format, but it's just regurgitating a string literal over and > over, which isn't of much interest. > > % is faster, but not by an order of magnitude. > > On my machine: > > C:\WINDOWS>python -m timeit -n 1000000 -s "n=7.92" "'%s' % n" > 1000000 loops, best of 3: 0.965 usec per loop > > C:\WINDOWS>python -m timeit -n 1000000 -s "n=7.92" "'{}'.format(n)" > 1000000 loops, best of 3: 1.17 usec per loop Cool! And you can make up half the difference, too: %~> python -m timeit -n 1000000 -s "n=7.92" "'%s' % n" 1000000 loops, best of 3: 1.27 usec per loop %~> python -m timeit -n 1000000 -s "n=7.92" "'{}'.format(n)" 1000000 loops, best of 3: 1.81 usec per loop %~> python -m timeit -n 1000000 -s "n=7.92; x='{}'.format" "x(n)" 1000000 loops, best of 3: 1.51 usec per loop -------------- next part -------------- An HTML attachment was scrubbed... URL: From orasnita at gmail.com Tue Jan 3 15:07:05 2012 From: orasnita at gmail.com (Octavian Rasnita) Date: Tue, 3 Jan 2012 22:07:05 +0200 Subject: Regular expression : non capturing groups are faster ? References: <4f02e31c$0$15724$426a74cc@news.free.fr><4f0315c6$0$10967$426a74cc@news.free.fr> Message-ID: <338F7336C21B4801A4DE16740B8CC736@teddy> From: "Devin Jeanpierre" Subject: Re: Regular expression : non capturing groups are faster ? >> You meant Perl Documentation, didn't you ? > > I guess that works too. I did mean Python, though -- its intent is to > say "you shouldn't worry about this", but in the process it says "this > does not exist" (a lie). ** However, the Perl documentation doesn't lie. I tested 10 million matches on my computer using capturing groups and it took ~ 6 seconds, but only ~ 2 seconds with non-capturing params. So yes, it is very fast anyway, but ~ 3 times faster with non-capturing params, so there is a difference. Octavian From jeanpierreda at gmail.com Tue Jan 3 15:10:11 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Tue, 3 Jan 2012 15:10:11 -0500 Subject: MOST COMMON QUESTIONS ASKED BY NON-MUSLIMS ????????? In-Reply-To: References: <6c0983b6-8786-4b04-b393-a6518f65ebbb@n6g2000vbz.googlegroups.com> <201201031324.13090.gheskett@wdtv.com> <4F034DAF.5010006@druid.net> Message-ID: > Interesting. I read the list using gmail, and I never saw the > original post. IIn fact I rarely see any spam at all. Apparently, > somebody at google knows how to identify spam. I wonder why they can't > do it for google groups. > [I also wonder if anybody will see this post, coming from an evil source.] Same here. I thought I might have accidentally misconfigured my mailbox filter to not accept google group posts, but that doesn't seem to be the case -- it isn't anywhere in gmail. -- Devin On Tue, Jan 3, 2012 at 2:42 PM, David Robinow wrote: > On Tue, Jan 3, 2012 at 2:24 PM, Benjamin Kaplan > wrote: >> On Tue, Jan 3, 2012 at 1:49 PM, D'Arcy Cain wrote: >>> On 12-01-03 01:24 PM, gene heskett wrote: >>>> >>>> The solution is to chop the link between google.groups and this list. ?But >>>> that subject has been declared verboten. Too much inconvenience to ask the >>>> googlers to subscribe to the real list I guess. ?Because my spamassassin >>> >>> Perhaps they just need to be reminded from time to time that many of us have >>> already "chopped the link" and for us there is no Google Groups on this >>> list. ?I never even saw the original message because everything from GG goes >>> straight to /dev/null on my system. >>> >>> Now if only I could automatically kill the replies to GG messages. ?:-) >>> >>> P.S. if you use Spamassassin: >>> >>> :0 Hir >>> * ^List-Id:.*python-list.python.org >>> * ^From:.*@gmail.com >>> * ^Newsgroups:.* >>> /dev/null >>> >> Wouldn't that just kill everything sent from a gmail account? That's >> not the same thing as Google Groups. The mailing list posts, at least, >> have an "Organization: http://groups.google.com" header. You'd >> probably be better off filtering on that. > Interesting. I read the list using gmail, and I never saw the > original post. IIn fact I rarely see any spam at all. Apparently, > somebody at google knows how to identify spam. I wonder why they can't > do it for google groups. > [I also wonder if anybody will see this post, coming from an evil source.] > -- > http://mail.python.org/mailman/listinfo/python-list From ethan at stoneleaf.us Tue Jan 3 15:16:59 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 03 Jan 2012 12:16:59 -0800 Subject: .format vs. % In-Reply-To: References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <4EFF559E.1050408@gmail.com> <4f027b79$0$29880$c3e8da3$5496439d@news.astraweb.com> <4f029d1e$0$29880$c3e8da3$5496439d@news.astraweb.com> <4F030221.3050902@stoneleaf.us> Message-ID: <4F03623B.1070609@stoneleaf.us> Devin Jeanpierre wrote: >> "one obvious way" != "only one way" > > Which way is the obvious way? Why is it obvious? Apparently, %-style is obvious to C and similar coders, while {}-style is obvious to Java and similar coders. :) ~Ethan~ From nobody at nowhere.com Tue Jan 3 15:29:29 2012 From: nobody at nowhere.com (Nobody) Date: Tue, 03 Jan 2012 20:29:29 +0000 Subject: Setting an environment variable. References: Message-ID: On Tue, 03 Jan 2012 15:45:20 +1000, Ashton Fagg wrote: > I'm working with an embedded machine, which is using a Python script to > oversee the acquisition of some data. The supervisor script, which is > run by crontab every 5 minutes, relies on an environment variable to be > set. I've tried to set the environment variable inside crontab, however > this doesn't work when the script runs. Odd. > Is there a nice way to do this inside the supervisor script itself? > Would an os.system("export foo=/bar/foo/bar") at the very beginning of > the script do what I want? No. It would set the variable only for the child process created by os.system(), which would be pointless. To set an environment variable for the current process (and, by default, any child processes), modify os.environ, e.g.: os.environ['foo'] = '/bar/foo/bar' You can set environment variables for specific child processes created via subprocess.Popen() using the env= parameter, e.g.: env = os.environ.copy() env['foo'] = '/bar/foo/bar' p = subprocess.Popen(..., env=env) If env= isn't used, the child will inherit the parent's environment. From tjreedy at udel.edu Tue Jan 3 15:38:17 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 03 Jan 2012 15:38:17 -0500 Subject: python philosophical question - strong vs duck typing In-Reply-To: References: Message-ID: On 1/3/2012 1:13 PM, Sean Wolfe wrote: > I have a theoretical / philosophical question regarding strong vs duck > typing in Python. Let's say we wanted to type strongly in Python and Python objects are strongly typed, in any sensible meaning of the term. What you mean is statically or explicitly typing names. > were willing to compromise our code to the extent necessary, eg not > changing variable types or casting or whatever. Let's say there was a > methodology in Python to declare variable types. > > The question is, given this possibility, would this get us closer to > being able to compile down to a language like C or C++? Cython compiles Python as is to C. It also gives the option to add type annotations to names to get faster code. Shredskin compiles a subset of Python, or a subset of usages, to C, with similar benefits. -- Terry Jan Reedy From jeanpierreda at gmail.com Tue Jan 3 15:38:36 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Tue, 3 Jan 2012 15:38:36 -0500 Subject: Regular expression : non capturing groups are faster ? In-Reply-To: <338F7336C21B4801A4DE16740B8CC736@teddy> References: <4f02e31c$0$15724$426a74cc@news.free.fr> <4f0315c6$0$10967$426a74cc@news.free.fr> <338F7336C21B4801A4DE16740B8CC736@teddy> Message-ID: > I tested 10 million matches on my computer using capturing groups and it took ~ 6 seconds, but only ~ 2 seconds with non-capturing params. Are you talking about Python or Perl? I can't reproduce this in Python. Best I can do is a 3:4 ratio between running times. ('(a)* versus '(?:a)*) Also, wouldn't say "very fast". Compare those two groups with 'a*'. I'm not sure what's going on there. -- Devin On Tue, Jan 3, 2012 at 3:07 PM, Octavian Rasnita wrote: > From: "Devin Jeanpierre" > Subject: Re: Regular expression : non capturing groups are faster ? > > >>> You meant Perl Documentation, didn't you ? >> >> I guess that works too. I did mean Python, though -- its intent is to >> say "you shouldn't worry about this", but in the process it says "this >> does not exist" (a lie). > > > ** > However, the Perl documentation doesn't lie. > > I tested 10 million matches on my computer using capturing groups and it took ~ 6 seconds, but only ~ 2 seconds with non-capturing params. > > So yes, it is very fast anyway, but ~ 3 times faster with non-capturing params, so there is a difference. > > Octavian > > -- > http://mail.python.org/mailman/listinfo/python-list From stefan-usenet at bytereef.org Tue Jan 3 15:53:14 2012 From: stefan-usenet at bytereef.org (Stefan Krah) Date: Tue, 3 Jan 2012 21:53:14 +0100 Subject: .format vs. % In-Reply-To: <9mh490FbvuU2@mid.individual.net> References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <4EFF559E.1050408@gmail.com> <4f027b79$0$29880$c3e8da3$5496439d@news.astraweb.com> <4F02DE94.8000506@gmail.com> <9mh490FbvuU2@mid.individual.net> Message-ID: <20120103205314.GA27430@sleipnir.bytereef.org> Neil Cerutti wrote: > On 2012-01-03, Stefan Krah wrote: > > $ ./python -m timeit -n 1000000 '"%s" % 7.928137192' > > 1000000 loops, best of 3: 0.0164 usec per loop > > % is faster, but not by an order of magnitude. > > On my machine: > > C:\WINDOWS>python -m timeit -n 1000000 -s "n=7.92" "'%s' % n" > 1000000 loops, best of 3: 0.965 usec per loop > > C:\WINDOWS>python -m timeit -n 1000000 -s "n=7.92" "'{}'.format(n)" > 1000000 loops, best of 3: 1.17 usec per loop Indeed, I was a bit surprised by the magnitude of the difference. Your timings seem to be in line with the difference seen in the real-world benchmark. It isn't a big deal, considering that the numeric formatting functions have to so many options, e.g: >>> "{:020,}".format(712312312.2) '00,000,712,312,312.2' Still, it's nice to have a faster choice. Stefan Krah From jeanpierreda at gmail.com Tue Jan 3 16:06:24 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Tue, 3 Jan 2012 16:06:24 -0500 Subject: python philosophical question - strong vs duck typing In-Reply-To: References: Message-ID: > Python objects are strongly typed, in any sensible meaning of the term. There are people that hold definitions of strong typing that preclude Python. Those people think their definition is reasonable, but at the same time haven't confused static typing with strong typing. I guess the problem is that this boils down to opinion, but you're stating it as incontrovertible fact. > What you mean is statically or explicitly typing names. Right, yes. > Cython compiles Python as is to C. It also gives the option to add type > annotations to names to get faster code. Shredskin compiles a subset of > Python, or a subset of usages, to C, with similar benefits. I seem to remember there being a project which compiled the Python bytecode down to C in a very dumb way (basically just making C code that creates the bytecode and executes it in the CPython VM). I can't find it, though. Anyway, compiling Python to C is actually fairly trivial. People usually mean something else by it, though. -- Devin On Tue, Jan 3, 2012 at 3:38 PM, Terry Reedy wrote: > On 1/3/2012 1:13 PM, Sean Wolfe wrote: > >> I have a theoretical / philosophical question regarding strong vs duck >> typing in Python. Let's say we wanted to type strongly in Python and > > > Python objects are strongly typed, in any sensible meaning of the term. > What you mean is statically or explicitly typing names. > > >> were willing to compromise our code to the extent necessary, eg not >> changing variable types or casting or whatever. Let's say there was a >> methodology in Python to declare variable types. >> >> The question is, given this possibility, would this get us closer to >> being able to compile down to a language like C or C++? > > > Cython compiles Python as is to C. It also gives the option to add type > annotations to names to get faster code. Shredskin compiles a subset of > Python, or a subset of usages, to C, with similar benefits. > > -- > Terry Jan Reedy > > -- > http://mail.python.org/mailman/listinfo/python-list From joshua.landau.ws at gmail.com Tue Jan 3 16:25:20 2012 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Tue, 3 Jan 2012 21:25:20 +0000 Subject: python philosophical question - strong vs duck typing In-Reply-To: References: Message-ID: On 3 January 2012 20:38, Terry Reedy wrote: > On 1/3/2012 1:13 PM, Sean Wolfe wrote: > > I have a theoretical / philosophical question regarding strong vs duck >> typing in Python. Let's say we wanted to type strongly in Python and >> > > Python objects are strongly typed, in any sensible meaning of the term. > What you mean is statically or explicitly typing names. > > > were willing to compromise our code to the extent necessary, eg not >> changing variable types or casting or whatever. Let's say there was a >> methodology in Python to declare variable types. >> >> The question is, given this possibility, would this get us closer to >> being able to compile down to a language like C or C++? >> > > Cython compiles Python as is to C. It also gives the option to add type > annotations to names to get faster code. Shredskin compiles a subset of > Python, or a subset of usages, to C, with similar benefits. A minor point of clarification here: although what you wrote is technically true, it's also misleading. AFAIK both Cython and Shedskin compile only a subset of Python, but the magnitude difference they drop off is large. Almost everything is Cython compliant, and that should just grow, but there are a few flakes here and there. However, Shedskin is a well defined subset, and does not encompass the whole of Python and will never do so. Shedskin *truly* compiles to C and thus is afflicted with several restrictions such as static typing. Cython is a lot less clear. What it compiles to is basically bytecode written in C. Instead of CPython reading the bytecode and the bytecode being parsed and then executed, *the computer natively parses the bytecode which tells CPython what to do*. This reduces a lot of overhead in tight loops, but doesn't help much in the general case. So why sacrifice so much for so little gain? Well - when your bytecode is C, you can interoperate other C code right inside. If you make some C variables you can do C-math inside your Python with no real overhead. Additionally, you can call C libraries really easily inside this code. What it results in is a really easy way to optimise the 5% that's slowing your code, and instead of rewriting it in C you use C-with-python-syntax. The types are sill horrible, though ;) -------------------------------------- To answer Devin: You're probably thinking of Cython ^^. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Tue Jan 3 16:42:47 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 03 Jan 2012 16:42:47 -0500 Subject: python philosophical question - strong vs duck typing In-Reply-To: References: Message-ID: On 1/3/2012 4:06 PM, Devin Jeanpierre wrote: >> Python objects are strongly typed, in any sensible meaning of the term. > > There are people that hold definitions of strong typing that preclude > Python. Those people think their definition is reasonable, but at the Can you give an actual example of such a definition of 'strongly typed object' that excludes Python objects? > same time haven't confused static typing with strong typing. I guess > the problem is that this boils down to opinion, but you're stating it > as incontrovertible fact. This strikes me as petty hair-splitting. 1. By tacking on the qualification, I was acknowledging that someone, somewhere, might controvert it. If you allow for arbitrary redefinitions of words, you could claim that any statement is an opinion. So what? 2. It ignores the context established by the OP who began with 'Let's say we wanted to type strongly in Python' and continued with a question about declarations and compilation specifically to C or C++. In that context, I think my statement qualifies as a fact. -- Terry Jan Reedy From ben+python at benfinney.id.au Tue Jan 3 16:57:59 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 Jan 2012 08:57:59 +1100 Subject: Spamming PyPI with stupid packages References: <87hb0d28j8.fsf@benfinney.id.au> <87aa6522au.fsf@benfinney.id.au> <4f02ba8d$0$29880$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8762gs1mag.fsf@benfinney.id.au> Steven D'Aprano writes: > The joke cuts both ways. This is the Just World fallacy: you're implying that, because the same joke can be applied equally well to women or men, that therefore it is equally harmful. The fallacy is to ignore the fact that the playing field is not level. Yes, that same joke can semantically be applied equally to men. But it is disproportionately harmful to women, because there is a significantly greater level of sexism against women already. Apologetics defending sexist jokes against women delay the time when women can feel that they are as free to participate in this community as men. Actions appropriate for a level playing field are not appropriate in our case. -- \ ?We must respect the other fellow's religion, but only in the | `\ sense and to the extent that we respect his theory that his | _o__) wife is beautiful and his children smart.? ?Henry L. Mencken | Ben Finney From ben+python at benfinney.id.au Tue Jan 3 17:11:12 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 Jan 2012 09:11:12 +1100 Subject: Spamming PyPI with stupid packages References: <87hb0d28j8.fsf@benfinney.id.au> <87aa6522au.fsf@benfinney.id.au> Message-ID: <871urg1lof.fsf@benfinney.id.au> Peter Otten <__peter__ at web.de> writes: > If you want more women in IT go to a local school and show the girls > things they can do with a computer that they find fun and interesting. > If you have a daughter try more Lego and less Barbies. I have no objection to doing those things *as well as* rejecting sexist jokes in our community. -- \ ?Science is a way of trying not to fool yourself. The first | `\ principle is that you must not fool yourself, and you are the | _o__) easiest person to fool.? ?Richard P. Feynman, 1964 | Ben Finney From jjensen at worldfinancialdesk.com Tue Jan 3 17:17:03 2012 From: jjensen at worldfinancialdesk.com (Jun Jensen) Date: Tue, 3 Jan 2012 14:17:03 -0800 (PST) Subject: Python Developer Position at High Frequency Trading Firm Message-ID: <52b44a2a-8e79-4998-a01f-6dd3fad1cf5e@m4g2000vbc.googlegroups.com> Greetings Python Developers: We are a high frequency trading (HFT) firm and we are seeking accomplished python developers to join our team. Here is the info: Python Developer About Us: We are a cutting edge, high-frequency trading firm and global market maker based in New York City. We live by technology, and continuous optimization of systems, strategy, and workflow is our primary objective. We offer a competitive salary and benefits (including free lunch), as well as an engaging, casual, fun, and focused work environment. We pride ourselves in the collaborative nature of the firm, and we look for individuals who are driven and intellectually curious. Overview: We are looking for a candidate with a mix of strong python and database skills. Initial tasks for this role will involve automation and reporting of all accounting systems, including the ability to trace orders throughout the system, trade reconciliation, as well as build a framework for our risk analytics and settlement systems. There will be ample opportunity for the role to become involved in all aspects of our proprietary systems. Qualifications include: ? Extensive knowledge of Python; we use Python to run tests, generate reports, develop simulations, GUI development etc. ? Exposure to C/C++ development is a plus. ? Experience developing in a Unix/Linux environment. ? Familiarity with SQL/Postgres. ? Experience working with large datasets. ? Experience in financial services setting a big plus, but not necessary. ? Bachelor?s degree in Computer Science or related field. ? Strong interpersonal skills a must. ? Ability to work well in a dynamic and collaborative setting. We are committed to finding the right people for the job. If you have the skills and the desire to be part of a winning team, please submit a resume with a plain text cover letter in your email to http://www.wfdcareers.com/careers.htm We do not sponsor visas or support relocation. We are not a recruiting firm. From peter.milliken at gmail.com Tue Jan 3 17:21:36 2012 From: peter.milliken at gmail.com (Peter) Date: Tue, 3 Jan 2012 14:21:36 -0800 (PST) Subject: Is there anyway to selectively inherit/import a class/module? Message-ID: <2bdb5920-126b-427f-b4c0-7e14fa0700a0@b32g2000yqn.googlegroups.com> I have a program that talks to a device via a serial interface. Structurally it looks like this: Program A -> module B -> Serial I want to add a protocol layer around the serial port without modifying any of the modules above and I want to be able to use BOTH cases of the program whenever convenient, so at first it seemed like a simple case of sub-classing the Serial class and then (this is the problem) somehow use either the original serial class definition when I wanted the original program functionality or the new class when I wanted the extra layer present. Module B has import serial so my first thought was to put the new module in the current directory and call it "serial.py". This would allow me to run the program with the new Serial class and when I didn't want that extra layer, all I had to do was rename the module to something else and let Module B pick up serial from the site-package area. But (obviously) this doesn't work because the new class's first few statements are: import serial Class Serial(serial.Serial): So when Module B does the import (and gets the new class definition), I get an error message (as the new definition is loaded): AttributeError: 'module' object has no attribute 'Serial' on the Class declaration statement. Is there anyway to have Module B use the new class without modifying the content of Module B? The only other alternative I can think of is to create a copy of the original program, rename the new class file and have two complete copies of the program but that is not ideal :-) Thanks Peter From ben+python at benfinney.id.au Tue Jan 3 17:28:05 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 Jan 2012 09:28:05 +1100 Subject: python philosophical question - strong vs duck typing References: Message-ID: <87wr98zaiy.fsf@benfinney.id.au> Sean Wolfe writes: > Hello everybody, I'm a happy pythonista newly subscribed to the group. Welcome! > I have a theoretical / philosophical question regarding strong vs duck > typing in Python. Let's say we wanted to type strongly in Python There may be an unstated assumption there, and your wording confuses me. Are you aware that Python has strong typing *and* duck typing, simultaneously? Every Python object is strongly-typed: they know exactly what type they are, what operations are permitted with objects of other types, and won't pretend to be a different type. (So an object of, e.g., type ?int?, won't allow addition of itself with an object of type ?str?.) ?Strongly-typed? is one end of a spectrum whose opposite end is ?weakly-typed?. Weakly-typed objects are in languages like e.g. PHP, where an integer object can be added to a string object. Every Python object allows duck typing: its operations are available to any code that wants to use that functionality, regardless of what type the client may assume it's working with. (This allows an object of, e.g., type ?StringIO?, which has no relationship to the ?file? type, to be used by functions expecting a file object.) What do you mean to convey by ?strong vs. duck typing?? > and were willing to compromise our code to the extent necessary, eg > not changing variable types or casting or whatever. Let's say there > was a methodology in Python to declare variable types. Python does not have variables in the sense of languages like C; rather, Python has references bound to objects. A reference (e.g. a name, or a list index, etc.) never has a type. An object always has a type. You may be thinking of ?static typing? (identifiers have types, and won't allow themselves to refer to an object of a different type), versus ?dynamic typing? (identifiers are ignorant of types ? this is what you have in Python). > What I am driving at is, if we are coding in python but looking for > more performance, what if we had an option to 1) restrict ourselves > somewhat by using strong typing to 2) make it easy to compile or > convert down to C++ and thereby gain more performance. I would need to know what you mean instead of ?strong typing?, because Python already has that. -- \ ?If we ruin the Earth, there is no place else to go. This is | `\ not a disposable world, and we are not yet able to re-engineer | _o__) other planets.? ?Carl Sagan, _Cosmos_, 1980 | Ben Finney From wescpy at gmail.com Tue Jan 3 17:34:16 2012 From: wescpy at gmail.com (wesley chun) Date: Tue, 3 Jan 2012 14:34:16 -0800 Subject: [OT] Book authoring Message-ID: fwiw, i've given a related talk a couple of times on this subject, the most recent of which was at EuroPython this summer: http://ep2011.europython.eu/conference/talks/writing-books-using-python-open-source-software the content includes a couple of the tools mentioned in this thread as well as some author case studies. slide deck's available there too. cheers, --wesley On Dec 9 2011, 7:43?am, Nick Dokos wrote: > Grant Edwards wrote: > > On 2011-12-09, Miki Tebeka wrote: > > > Greetings, > > > > Any recommendations for abook authoringsystem that supports the following: > > > 1. Code examples (with syntax highlighting and line numbers) > > > 2. Output HTML, PDF, ePub ... > > > 3. Automatic TOC and index > > > 4. Search (in HTML) - this is a "nice to have" > > >http://en.wikipedia.org/wiki/Lightweight_markup_language > > > I've used asciidoc extensively and reStructuredText a little. Asciidoc > > will produce all the formats you mentioned (though I've only refularly > > used HTML and PDF). reStructuredText is what's used for Python docs > > isn't it? > > > > Can I somehow use Sphinx? > > > Don't know what Sphinx is. > > I think Sphinx is used for the python docs: it sits atop rST and does > all the transformations/processing to produce the desired output > (http://sphinx.pocoo.org) > > > And there's always the old stand-by LaTeX, but it's a bit more > > heavyweight with more of a learning curve. ?OTOH, it does produce > > text-book quality output. > > There is also orgmode, which has been used for a few books > (http://orgmode.org). I know it does HTML and PDF (the latter through > latex), but I'm not sure about ePub: ISTR somebody actually did ePub for > his book but I don't remember details. The indexing is manual: > add #+index: foo entries as required. ?But in general, imo, automatic > indexing for books sucks raw eggs (it works much better for highly > regular source code like the python source base). > > Nick -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python", Prentice Hall, (c)2007,2001 "Python Fundamentals", Prentice Hall, (c)2009 ? ? http://corepython.com wesley.chun : wescpy-gmail.com : @wescpy/+wescpy python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com From bthiell at cfa.harvard.edu Tue Jan 3 17:38:11 2012 From: bthiell at cfa.harvard.edu (Benoit Thiell) Date: Tue, 3 Jan 2012 17:38:11 -0500 Subject: Large list in memory slows Python Message-ID: Hi. I am experiencing a puzzling problem with both Python 2.4 and Python 2.6 on CentOS 5. I'm looking for an explanation of the problem and possible solutions. Here is what I did: Python 2.4.3 (#1, Sep 21 2011, 19:55:41) IPython 0.8.4 -- An enhanced Interactive Python. In [1]: def test(): ...: return [(i,) for i in range(10**6)] In [2]: %time x = test() CPU times: user 0.82 s, sys: 0.04 s, total: 0.86 s Wall time: 0.86 s In [4]: big_list = range(50 * 10**6) In [5]: %time y = test() CPU times: user 9.11 s, sys: 0.03 s, total: 9.14 s Wall time: 9.15 s As you can see, after creating a list of 50 million integers, creating the same list of 1 million tuples takes about 10 times longer than the first time. I ran these tests on a machine with 144GB of memory and it is not swapping. Before creating the big list of integers, IPython used 111MB of memory; After the creation, it used 1664MB of memory. Thanks for your time. Cheers. -- Benoit Thiell The SAO/NASA Astrophysics Data System http://adswww.harvard.edu/ From __peter__ at web.de Tue Jan 3 17:59:14 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 03 Jan 2012 23:59:14 +0100 Subject: Large list in memory slows Python References: Message-ID: Benoit Thiell wrote: > I am experiencing a puzzling problem with both Python 2.4 and Python > 2.6 on CentOS 5. I'm looking for an explanation of the problem and > possible solutions. Here is what I did: > > Python 2.4.3 (#1, Sep 21 2011, 19:55:41) > IPython 0.8.4 -- An enhanced Interactive Python. > > In [1]: def test(): > ...: return [(i,) for i in range(10**6)] > > In [2]: %time x = test() > CPU times: user 0.82 s, sys: 0.04 s, total: 0.86 s > Wall time: 0.86 s > > In [4]: big_list = range(50 * 10**6) > > In [5]: %time y = test() > CPU times: user 9.11 s, sys: 0.03 s, total: 9.14 s > Wall time: 9.15 s > > As you can see, after creating a list of 50 million integers, creating > the same list of 1 million tuples takes about 10 times longer than the > first time. > > I ran these tests on a machine with 144GB of memory and it is not > swapping. Before creating the big list of integers, IPython used 111MB > of memory; After the creation, it used 1664MB of memory. In older Pythons the heuristic used to decide when to run the cyclic garbage collection is not well suited for the creation of many objects in a row. Try switching it off temporarily with import gc gc.disable() # create many objects that are here to stay gc.enable() You may also encorporate that into your test function: def test(): gc.disable() try: return [...] finally: gc.enable() From ben+python at benfinney.id.au Tue Jan 3 18:10:44 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 Jan 2012 10:10:44 +1100 Subject: python philosophical question - strong vs duck typing References: Message-ID: <87obukz8jv.fsf@benfinney.id.au> Terry Reedy writes: > On 1/3/2012 1:13 PM, Sean Wolfe wrote: > > > I have a theoretical / philosophical question regarding strong vs > > duck typing in Python. Let's say we wanted to type strongly in > > Python > > Python objects are strongly typed, in any sensible meaning of the > term. What you mean is statically or explicitly typing names. For more on the various spectrums of type systems, and the terms to use, see . -- \ ?If I haven't seen as far as others, it is because giants were | `\ standing on my shoulders.? ?Hal Abelson | _o__) | Ben Finney From mixolydian at postersRUS Tue Jan 3 18:13:17 2012 From: mixolydian at postersRUS (mixolydian) Date: Tue, 03 Jan 2012 17:13:17 -0600 Subject: Newbie Help Message-ID: I want to get into Python progamming for both local database applications and dynamic web pages. Maybe some Q&D scripts. There is a ton of excellent language books. I have downloaded and installed 2.7.2 and got it working by pasting samples into IDLE, and uploading to my web server and doing trial CGI samples. So far, so good. I would like some advice on: 1. IDEs 2. GUI tools, tkinter and others 3. An integrated web server package for Win Vista for testing web apps before deploying. Uploading to my ISP to run is a PIA. I've installed VertrigoServ to try, but am chasing my tail around the Apache configuration. Is there something easier? Just pointers to get me started would be fine. More info.I will be migrating data base apps from MSAccess 2000. I know, I know, but it was free on my original Win 95 PC. I've been programming for 50 years and have had to learn (and unlearn) a lot, and I'm eager to learn new stuff. Thanks. From sarabareilles996 at gmail.com Tue Jan 3 18:14:48 2012 From: sarabareilles996 at gmail.com (sara bareilles) Date: Tue, 3 Jan 2012 15:14:48 -0800 (PST) Subject: Rangefinder Laser 1200S Message-ID: <59104342-ee54-4ffa-bac7-1cae15e9db78@32g2000yqp.googlegroups.com> Rangefinder Laser 1200S Rangefinder Laser 1200S features: Wide range of temperature tolerance: -10?C to +50?C Selection from 2 measurement modes (Target Priority Switch System): First Target.... http://www.info-world-mania.com/ From peter.milliken at gmail.com Tue Jan 3 18:34:24 2012 From: peter.milliken at gmail.com (Peter) Date: Tue, 3 Jan 2012 15:34:24 -0800 (PST) Subject: Book authoring References: Message-ID: On Jan 4, 9:34?am, wesley chun wrote: > fwiw, i've given a related talk a couple of times on this subject, the > most recent of which was at EuroPython this summer:http://ep2011.europython.eu/conference/talks/writing-books-using-pyth... > > the content includes a couple of the tools mentioned in this thread as > well as some author case studies. slide deck's available there too. > > cheers, > --wesley > > On Dec 9 2011, 7:43?am, Nick Dokos wrote: > > > > > > > > > > > Grant Edwards wrote: > > > On 2011-12-09, Miki Tebeka wrote: > > > > Greetings, > > > > > Any recommendations for abook authoringsystem that supports the following: > > > > 1. Code examples (with syntax highlighting and line numbers) > > > > 2. Output HTML, PDF, ePub ... > > > > 3. Automatic TOC and index > > > > 4. Search (in HTML) - this is a "nice to have" > > > >http://en.wikipedia.org/wiki/Lightweight_markup_language > > > > I've used asciidoc extensively and reStructuredText a little. Asciidoc > > > will produce all the formats you mentioned (though I've only refularly > > > used HTML and PDF). reStructuredText is what's used for Python docs > > > isn't it? > > > > > Can I somehow use Sphinx? > > > > Don't know what Sphinx is. > > > I think Sphinx is used for the python docs: it sits atop rST and does > > all the transformations/processing to produce the desired output > > (http://sphinx.pocoo.org) > > > > And there's always the old stand-by LaTeX, but it's a bit more > > > heavyweight with more of a learning curve. ?OTOH, it does produce > > > text-book quality output. > > > There is also orgmode, which has been used for a few books > > (http://orgmode.org). I know it does HTML and PDF (the latter through > > latex), but I'm not sure about ePub: ISTR somebody actually did ePub for > > his book but I don't remember details. The indexing is manual: > > add #+index: foo entries as required. ?But in general, imo, automatic > > indexing for books sucks raw eggs (it works much better for highly > > regular source code like the python source base). > > > Nick > > -- > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > "Core Python", Prentice Hall, (c)2007,2001 > "Python Fundamentals", Prentice Hall, (c)2009 > ? ?http://corepython.com > > wesley.chun : wescpy-gmail.com : @wescpy/+wescpy > python training and technical consulting > cyberweb.consulting : silicon valley, cahttp://cyberwebconsulting.com My apologies, but I just read the intro - no time to watch the video, so I am probably missing the point of your post :-) TeX/LaTeX is open source and does an excellent job - plus you can use your favourite editor to enter the text (I have never been able to understand why wordprocessors have never been extended beyond the range of simple text entry functions - most editors offer so many aids to text entry so you would think some WPs would have taken the hint and put some more features in!). So does this just re-invent the wheel (so to speak)? From irmen.NOSPAM at xs4all.nl Tue Jan 3 18:37:07 2012 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Wed, 04 Jan 2012 00:37:07 +0100 Subject: Python3 on MacOsX Lion? In-Reply-To: References: Message-ID: <4f039123$0$6861$e4fe514c@news2.news.xs4all.nl> On 2-1-2012 20:32, K Richard Pixley wrote: > Where would I look to find the current expected status of python3 on MacOsX Lion? > > The distributed binaries aren't capable of allowing extensions that use gcc. > > I can build the source naked, but then it lacks some libraries, notably, readline. > > Attempting to build the full Mac packages fails, even with the few tiny patches I used > for 2.7.2. > > Is anyone working on this? Are there pre-release patches available? > > Should I be asking elsewhere? > > --rich I suggest installing it via Homebrew. Install homebrew first if you haven't already, http://mxcl.github.com/homebrew/ Then, $ brew install python3 ....wait a bit... $ python3 ...profit! (It's probably wise to brew install gdbm, readline, and sqlite first. These will then be used by the python brew installations. If you don't, they might be unavailable or be the older system-provided versions) Regards Irmen From gheskett at wdtv.com Tue Jan 3 19:28:10 2012 From: gheskett at wdtv.com (gene heskett) Date: Tue, 3 Jan 2012 19:28:10 -0500 Subject: MOST COMMON QUESTIONS ASKED BY NON-MUSLIMS ????????? In-Reply-To: <4F034DAF.5010006@druid.net> References: <6c0983b6-8786-4b04-b393-a6518f65ebbb@n6g2000vbz.googlegroups.com> <201201031324.13090.gheskett@wdtv.com> <4F034DAF.5010006@druid.net> Message-ID: <201201031928.10847.gheskett@wdtv.com> On Tuesday, January 03, 2012 07:27:32 PM D'Arcy Cain did opine: > On 12-01-03 01:24 PM, gene heskett wrote: > > The solution is to chop the link between google.groups and this list. > > But that subject has been declared verboten. Too much inconvenience > > to ask the googlers to subscribe to the real list I guess. Because > > my spamassassin > > Perhaps they just need to be reminded from time to time that many of us > have already "chopped the link" and for us there is no Google Groups on > this list. I never even saw the original message because everything > from GG goes straight to /dev/null on my system. > > Now if only I could automatically kill the replies to GG messages. :-) > > P.S. if you use Spamassassin: > :0 Hir > > * ^List-Id:.*python-list.python.org > * ^From:.*@gmail.com > * ^Newsgroups:.* > /dev/null Dropped into my .procmailrc, thanks. Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) My web page: The major advances in civilization are processes that all but wreck the societies in which they occur. -- A.N. Whitehead From ben+python at benfinney.id.au Tue Jan 3 19:35:53 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 Jan 2012 11:35:53 +1100 Subject: Newbie Help References: Message-ID: <87fwfwz4ly.fsf@benfinney.id.au> mixolydian writes: > I want to get into Python progamming for both local database > applications and dynamic web pages. Maybe some Q&D scripts. Welcome to the Python community. You have found a good general-purpose programming language, and I hope you find the right help for what you're trying to do. > I would like some advice on: > 1. IDEs I advise against language-specific IDEs. You should learn at least one general-purpose programming environment, making sure to choose one that is: * Free software, so that its maintenance and longevity is not at the mercy of any particular organisation. * Powerful and flexible, so that it's easy for experts to make it support specific programming languages and tasks. * Mature, so that it has a great deal of such support for many languages and tasks already written by such experts. * Actively maintained by a vibrant and open developer community, so that you can be confident it will continue to adapt to changing needs. * Cross-platform, so that you're not denied the use of any popular workstation OS. For my purposes, either { GNU Screen + Bash + Emacs } or { GNU Screen + Bash + Vim } are good choices satisfying all the above criteria. There may be other good combinations. > 2. GUI tools, tkinter and others Tkinter has become much more flexible and ?modern? in recent years. See for a good tutorial on using Tk for GUI design; it focuses on Tk and presents examples in many languages, including Python. > 3. An integrated web server package for Win Vista Can't help you there, I don't find Windows to meet my criteria for a good development nor deployment environment. > More info.I will be migrating data base apps from MSAccess 2000. I > know, I know, but it was free on my original Win 95 PC. You will want to learn SQL and relational databases. As a distinct task, you *might* want to learn to operate a database server. Python comes with SQLite included, so you can learn a functional SQL database system without entangling it with the complications of running a server. Once you reach the point where a dedicated database server is needed, I would recommend going to the best: PostgreSQL. But again, you can delay that until after you are familiar with SQLite. > I've been programming for 50 years and have had to learn (and unlearn) > a lot, and I'm eager to learn new stuff. Good hunting to you. -- \ ?We can't depend for the long run on distinguishing one | `\ bitstream from another in order to figure out which rules | _o__) apply.? ?Eben Moglen, _Anarchism Triumphant_, 1999 | Ben Finney From steve+comp.lang.python at pearwood.info Tue Jan 3 19:55:21 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Jan 2012 00:55:21 GMT Subject: Newbie Help References: Message-ID: <4f03a379$0$11122$c3e8da3@news.astraweb.com> On Tue, 03 Jan 2012 17:13:17 -0600, mixolydian wrote: > I would like some advice on: > 1. IDEs Avoid them. Everything you need can be used with two applications: - a programmer's text editor; - a decent terminal (console) application. A decent text editor will allow you to have multiple files open in tabs and rich editing tools, including completion. A decent terminal will allow you to have multiple sessions open, also in tabs. I have at least one session open to an interactive interpreter, for experimenting at the Python command line, and at least one other open to run my python code, run unit tests and doc tests, and manage source code control. E.g. python -m doctest my_app.py # run the doc tests python -m unittest my_app_tests.py # run a separate test suite python my_app.py --options # and finally run the app itself For flexibility and power, no IDE can beat the command line. Some editors are integrated with the source control app of your choice (I prefer Mercurial), but I am happy to use the Mercurial command line tools. It's easier to find the answers to "how do I ..." when you aren't limited to a single editor's idiosyncrasies. Best of all, I don't have to learn a bunch of unique IDE commands which don't work anywhere else. I just use my normal tools. > 2. GUI tools, tkinter and others tkinter is pretty much the lowest common denominator. It's good, especially now that it has native widgets, but if you want something better, you might like to try wxPython. > 3. An integrated web server package for Win Vista Try cherrypy, which includes its own web server as well as a web framework. http://cherrypy.org/ -- Steven From jeanpierreda at gmail.com Tue Jan 3 20:04:41 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Tue, 3 Jan 2012 20:04:41 -0500 Subject: python philosophical question - strong vs duck typing In-Reply-To: References: Message-ID: > This strikes me as petty hair-splitting. Maybe it is! I don't know what "petty" means. > 1. By tacking on the qualification, I was acknowledging that someone, > somewhere, might controvert it. If you allow for arbitrary redefinitions of > words, you could claim that any statement is an opinion. So what? I don't know where the original definition of "strong typing" came from. My experience has been that everyone has their own definition -- some people redefine it when faced with absurd consequences of their original definition, but usually to something roughly similar. I believe that people redefine it because to say your language is "weakly typed" sounds, well, like a weakness, or like an insult. It raises my hairs when people phrase it like that, anyway. > 2. It ignores the context established by the OP who began with 'Let's say we > wanted to type strongly in Python' and continued with a question about > declarations and compilation specifically to C or C++. > > In that context, I think my statement qualifies as a fact. I agree, what I said there does ignore it. This is why I made a point of quoting you a second time, when you specifically referred to the OP, and stating my agreement. Sorry for any misunderstanding. As far as your correction to the OP goes, I am in favor. Aside from the small nit that applies to a statement if you take it out of context. > Can you give an actual example of such a definition of 'strongly typed > object' that excludes Python objects? I'd love to, but I neglected to above because I don't really know where we share ideas, and I wouldn't want to jump ahead and say something that seems outlandish. I hope I've done a decent enough job below. Stop me if I say something you don't agree with. Here's a short version: The term often refers to a continuum, where some languages are "stronger" than others, but there is no objective definition of "strong" -- it's like asking how big is "big", or how smart is "smart". The actual choice of what continuum strength refers to varies between people -- some specify it as "reinterpretation of bits in memory", in which case every dynamic language in the world is strongly typed (so I'll move on from that), or some as "implicit conversions between types", which is iffy because any function or overloaded operator can silently convert types (at least in Python), meaning the language is as weak as the user (?). But they're both kind of reasonable and held by a few people, and it's easy to see how maybe somebody used to significantly more strict rules (OCaml, for example) might accuse Python of not being all that strong. So you see it isn't really a change of definition, it's a redrawing of the lines on a continuum. The OCaml people are reasonable for saying what they say, because their point of reference is their favorite language, just as ours is ours. To us, maybe Haskell and OCaml are insanely strong/"strict", to them, we're insanely weak. Here's another take, more in line with what I really meant: the continuums expressed above aren't universal either. IME they're chosen by dynamic typing advocates, which are worried about code readability and certain styles of immensely common errors that come from lower-level languages like C. Static typing advocates (at least in the functional programming language family) are instead concerned about correctness. For them, type systems are a way to reduce the number of errors in your code _in general_, not just the specific cases of type coercion or memory-safety. In this particular sense, Python is not very far from C -- it saves us from things that can crash the entire process or give us incorrect results rather than alerting us of a problem, but usually only so that we can encounter them in a more recoverable form. For example, out-of-bounds array access can no longer alter various parts of your stack and ruin the entire program state, but it is still a possible error. Static typing advocates say that strong typing can completely eliminate some types of errors, and the sensible time to detect such errors is at compile-time. This is absolutely an origin for the conflation of static vs strong typing, and it's hard to differentiate them in this sense, primarily because this notion of strong typing basically requires static typing for powerful results. On the other hand, you can clearly have "stronger" languages at runtime -- there are plenty of errors Python prevents, that C does not, even though python is dynamically typed and C is not. So Python's type system is clearly stronger than C. I hope this illustrates that strong and static are two different things even under this definition -- it's just that, most of the time, to really prevent an error, you prevent it from ever happening at compile-time. Type systems exist which are much "stronger" in what they can protect you against. As an extreme example, one might take a dependently-typed language. A statically dependently typed language can protect you against out-of-bounds array access with a proof at compile time. In fact, a statically-dependently-typed language can do things like prove that two different implementations of the same function are in fact implementations of the same function -- this is neat for implementing a non-recursive version of a recursive function, and verifying the change doesn't influence semantics. It's definitely true that there is something here that Python's types cannot do, at least not without extremely heavily mangling (technically __instancecheck__ means that type objects are turing complete, but I request that we ignore that). These are the sorts of types that can, in a very real sense, replace unit tests. Just the fact that your program typechecks is proof that certain properties hold, and those properties can be very soothing, such as that example of proving two algorithms return the same output. (There is an argument to be made that automated tests are better value for money. I don't really know, I've never seen actual accounts of attempting this, and I've never done it myself.) One last note about static vs dynamic vs strong typing: I do believe that a strongly typed dynamic+statically typed language is possible and a good thing. For statically typed code, run-time checks are disabled (speed), for dynamically typed code they are enabled, and all the while you can make relatively sophisticated queries about the type of a thing using an interactive interpreter (somewhat similar to unifying things in the prolog interpreter, in my view). So now that we've gotten this far, here's my proposition: It is reasonable to consider type systems in terms of how many errors they eliminate in your programs, rather than just readability/memory-safety concerns. Also, it is reasonable to have relatively strict standards, if you're used to a very "strong" type system. Such a person might, very reasonably, decide that Python is quite weak. Python eliminates memory-safety concerns, and makes things like array-access problems more obvious, but it eliminates very few errors. Other type systems can eliminate much larger categories of errors -- admittedly, most likely at the expense of development speed and/or flexibility. I admit that a lot of what I said here is putting words in other peoples' mouths, if you object, pretend I said it instead. I am, after all, a fan of ATS at the moment, and thus have some interest in ridiculously strongly typed languages ;) *phew*. That took a lot of time. I hope I haven't lost your attention. [ An example of a simple dependently typed program: http://codepad.org/eLr7lLJd ] -- Devin On Tue, Jan 3, 2012 at 4:42 PM, Terry Reedy wrote: > On 1/3/2012 4:06 PM, Devin Jeanpierre wrote: >>> >>> Python objects are strongly typed, in any sensible meaning of the term. >> >> >> There are people that hold definitions of strong typing that preclude >> Python. Those people think their definition is reasonable, but at the > > > Can you give an actual example of such a definition of 'strongly typed > object' that excludes Python objects? > > >> same time haven't confused static typing with strong typing. I guess >> the problem is that this boils down to opinion, but you're stating it >> as incontrovertible fact. > > > This strikes me as petty hair-splitting. > > 1. By tacking on the qualification, I was acknowledging that someone, > somewhere, might controvert it. If you allow for arbitrary redefinitions of > words, you could claim that any statement is an opinion. So what? > > 2. It ignores the context established by the OP who began with 'Let's say we > wanted to type strongly in Python' and continued with a question about > declarations and compilation specifically to C or C++. > > In that context, I think my statement qualifies as a fact. > > > -- > Terry Jan Reedy > > -- > http://mail.python.org/mailman/listinfo/python-list From steve+comp.lang.python at pearwood.info Tue Jan 3 20:06:20 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Jan 2012 01:06:20 GMT Subject: Is there anyway to selectively inherit/import a class/module? References: <2bdb5920-126b-427f-b4c0-7e14fa0700a0@b32g2000yqn.googlegroups.com> Message-ID: <4f03a60c$0$11122$c3e8da3@news.astraweb.com> On Tue, 03 Jan 2012 14:21:36 -0800, Peter wrote: > I have a program that talks to a device via a serial interface. > Structurally it looks like this: > > Program A -> module B -> Serial I don't understand what this means. Program A points to module B, which points to ... what is Serial? Where is it? Is it a class inside the module, or another module? > I want to add a protocol layer around the serial port without modifying > any of the modules above and I want to be able to use BOTH cases of the > program whenever convenient, Where are you using them from? Program A, or another program? I don't see any way to add the extra functionality to Program A without modifying Program A. But if you're okay with that, here's a way to conditionally define a class to use: # inside Program A import moduleB if condition: Serial = moduleB.Serial # I assume moduleB has a Serial class else: class Serial(moduleB.Serial): # subclass def mymethod(self): pass connection = Serial(...) > so at first it seemed like a simple case of > sub-classing the Serial class and then (this is the problem) somehow use > either the original serial class definition when I wanted the original > program functionality or the new class when I wanted the extra layer > present. No problem. Here's another way to do it: from moduleB import Serial as SimpleSerial class ComplexSerial(SimpleSerial): ... And now you can use both at the same time. -- Steven From steve+comp.lang.python at pearwood.info Tue Jan 3 20:28:59 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Jan 2012 01:28:59 GMT Subject: Spamming PyPI with stupid packages References: Message-ID: <4f03ab5b$0$11122$c3e8da3@news.astraweb.com> On Tue, 03 Jan 2012 05:08:47 -0800, Ethan Furman wrote: [...] >> "maybe policing uploads is worse than cluttering PyPI's disk space and >> RSS feed with dumb 1 KB packages." (Matt Chaput) >> >> I'd drop the "maybe". > > It's hard enough finding what one wants without having to wade through > crap. PyPI is not the place for it. I agree. But who gets to choose which packages are "serious" enough to deserve to be on PyPI? Or good enough? The cost of allowing anyone the freedom to publish their work is that some published work will be crap. Besides, I find it hard to believe that the search facilities on PyPI are so bad that there would be any searches that come up with "girlfriend.py" or "car.py" as false positives. Seriously, the over-reaction here is something that has to be seen to be believed. The original complaint is over a couple of entries in an RSS feed and showing up on the front page of PyPI, perhaps a dozen words in total. The reaction has been thousands of words arguing back and forth. -- Steven From steve+comp.lang.python at pearwood.info Tue Jan 3 20:30:41 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Jan 2012 01:30:41 GMT Subject: Python education survey References: <06423dd7-4fbb-4e7a-b529-e697ea862b05@f11g2000yql.googlegroups.com> <36065956-359d-42cf-a5fc-75fdea830737@y7g2000vbe.googlegroups.com> <470c9b9b-780f-4b00-8fef-adba8b036c2b@32g2000yqp.googlegroups.com> <74b1ed63-f755-49e3-a275-92b2658ef991@o14g2000vbo.googlegroups.com> <9d9d27b6-2fa0-49c8-8237-28b4cc91843a@q8g2000yqa.googlegroups.com> Message-ID: <4f03abc1$0$11122$c3e8da3@news.astraweb.com> On Tue, 03 Jan 2012 04:33:45 -0800, Eelco wrote: >> Why do people use pretty when we already have words that carry more >> specific meaning? Because they are lazy! And laziness begets stupidity. > > No, that would be because they are not autistic. Most people like having > a repertoire of words with subtly different meanings in their natural > language, because there is a demand for this semantic richness. +1 QOTW -- Steven From steve+comp.lang.python at pearwood.info Tue Jan 3 20:37:58 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Jan 2012 01:37:58 GMT Subject: Spamming PyPI with stupid packages References: <87hb0d28j8.fsf@benfinney.id.au> <87aa6522au.fsf@benfinney.id.au> <4f02ba8d$0$29880$c3e8da3$5496439d@news.astraweb.com> <8762gs1mag.fsf@benfinney.id.au> Message-ID: <4f03ad75$0$11122$c3e8da3@news.astraweb.com> On Wed, 04 Jan 2012 08:57:59 +1100, Ben Finney wrote: > Steven D'Aprano writes: > >> The joke cuts both ways. > > This is the Just World fallacy: you're implying that, because the same > joke can be applied equally well to women or men, that therefore it is > equally harmful. The fallacy is to ignore the fact that the playing > field is not level. I'm not ignoring the fact of an unequal playing field. (The playing field is uneven in different directions in different places.) > Yes, that same joke can semantically be applied equally to men. But it > is disproportionately harmful to women, You're making an assumption there that I don't accept. There is no evidence that it is harmful to *anyone*, men or women. And not just because "it's only a joke" -- jokes are a wonderfully powerful weapon, and like all weapons, they can be used for good or evil. E.g. the Klu Klux Klan lost a lot of influence when the US media (and in particular the Superman television series) made them into a laughing stock. On the flip-side, Irish jokes have been both a reaction to Irish terrorism and a way of depowering the Irish. But if jokes are weapons, this particular joke is not only a water pistol, but it's a *broken* water pistol. There are barriers to women becoming programmers. Some of those barriers come from men, others come from other women, and some are internal to the specific woman in question. One might even be able to list some of those barriers. But if you think that it is self-evident that childish jokes about working hard in order to attract a girlfriend is one of those barriers, then I have to disagree strongly. [...] > Apologetics defending sexist jokes against women In what way is this a sexist joke against women? Normally, one can point out the victim of sexist or racist jokes: it makes a class of people out to be a laughing stock, incompetent or stupid or wicked. That is not the case here, unless we think that preferring a hard-worker and good provider over a lazy deadbeat is a sign of moral degeneracy (that is, "gold-digger" versus "wants the best for herself and her children"). -- Steven From ben+python at benfinney.id.au Tue Jan 3 20:54:09 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 Jan 2012 12:54:09 +1100 Subject: Spamming PyPI with stupid packages References: <87hb0d28j8.fsf@benfinney.id.au> <87aa6522au.fsf@benfinney.id.au> <4f02ba8d$0$29880$c3e8da3$5496439d@news.astraweb.com> <8762gs1mag.fsf@benfinney.id.au> <4f03ad75$0$11122$c3e8da3@news.astraweb.com> Message-ID: <878vloz0zi.fsf@benfinney.id.au> Steven D'Aprano writes: > On Wed, 04 Jan 2012 08:57:59 +1100, Ben Finney wrote: > > > Steven D'Aprano writes: > > > >> The joke cuts both ways. > > > > The fallacy is to ignore the fact that the playing field is not > > level. > > I'm not ignoring the fact of an unequal playing field. (The playing > field is uneven in different directions in different places.) Your ?the joke cuts both ways? is of no matter, then. > > Yes, that same joke can semantically be applied equally to men. But > > it is disproportionately harmful to women, > > You're making an assumption there that I don't accept. There is no > evidence that it is harmful to *anyone*, men or women. It objectifies women. If you can't see how that's harmful to women, I haven't the stamina to educate you. -- \ ?We spend the first twelve months of our children's lives | `\ teaching them to walk and talk and the next twelve years | _o__) telling them to sit down and shut up.? ?Phyllis Diller | Ben Finney From steve+comp.lang.python at pearwood.info Tue Jan 3 21:04:39 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Jan 2012 02:04:39 GMT Subject: Spamming PyPI with stupid packages References: <87hb0d28j8.fsf@benfinney.id.au> <87aa6522au.fsf@benfinney.id.au> <4f02ba8d$0$29880$c3e8da3$5496439d@news.astraweb.com> <8762gs1mag.fsf@benfinney.id.au> <4f03ad75$0$11122$c3e8da3@news.astraweb.com> <878vloz0zi.fsf@benfinney.id.au> Message-ID: <4f03b3b6$0$11122$c3e8da3@news.astraweb.com> On Wed, 04 Jan 2012 12:54:09 +1100, Ben Finney wrote: > Steven D'Aprano writes: [...] >> You're making an assumption there that I don't accept. There is no >> evidence that it is harmful to *anyone*, men or women. > > It objectifies women. So you claim. > If you can't see how that's harmful to women, I > haven't the stamina to educate you. Since you can't or won't persuade me (and anyone else reading) that this sort of joke is harmful, does that mean that you will stop claiming that it is harmful? Or do you expect us to just take your word for it and stop questioning you? -- Steven From peter.milliken at gmail.com Tue Jan 3 21:12:08 2012 From: peter.milliken at gmail.com (Peter) Date: Tue, 3 Jan 2012 18:12:08 -0800 (PST) Subject: Is there anyway to selectively inherit/import a class/module? References: <2bdb5920-126b-427f-b4c0-7e14fa0700a0@b32g2000yqn.googlegroups.com> <4f03a60c$0$11122$c3e8da3@news.astraweb.com> Message-ID: <3b39df5b-94f5-42d7-9be8-a9b4d459142a@m7g2000vbc.googlegroups.com> On Jan 4, 12:06?pm, Steven D'Aprano wrote: > On Tue, 03 Jan 2012 14:21:36 -0800, Peter wrote: > > I have a program that talks to a device via a serial interface. > > Structurally it looks like this: > > > Program A -> module B -> Serial > > I don't understand what this means. Program A points to module B, which > points to ... what is Serial? Where is it? Is it a class inside the > module, or another module? > > > I want to add a protocol layer around the serial port without modifying > > any of the modules above and I want to be able to use BOTH cases of the > > program whenever convenient, > > Where are you using them from? Program A, or another program? > > I don't see any way to add the extra functionality to Program A without > modifying Program A. But if you're okay with that, here's a way to > conditionally define a class to use: > > # inside Program A > import moduleB > > if condition: > ? ? Serial = moduleB.Serial ?# I assume moduleB has a Serial class > else: > ? ? class Serial(moduleB.Serial): ?# subclass > ? ? ? ? def mymethod(self): > ? ? ? ? ? ? pass > > connection = Serial(...) > > > so at first it seemed like a simple case of > > sub-classing the Serial class and then (this is the problem) somehow use > > either the original serial class definition when I wanted the original > > program functionality or the new class when I wanted the extra layer > > present. > > No problem. Here's another way to do it: > > from moduleB import Serial as SimpleSerial > class ComplexSerial(SimpleSerial): > ? ? ... > > And now you can use both at the same time. > > -- > Steven Thanks :-) From wuwei23 at gmail.com Tue Jan 3 21:15:08 2012 From: wuwei23 at gmail.com (alex23) Date: Tue, 3 Jan 2012 18:15:08 -0800 (PST) Subject: python philosophical question - strong vs duck typing References: Message-ID: <59305aab-7ddf-4c61-b8ba-025a2ce10b48@d10g2000vbh.googlegroups.com> On Jan 4, 6:38?am, Terry Reedy wrote: > Shredskin compiles a subset of > Python, or a subset of usages, to C, with similar benefits. That is, of course, 'Shedskin' and 'C++' :) +1 for either Cython or Shedskin as your next step for more performant Python. From wuwei23 at gmail.com Tue Jan 3 21:26:35 2012 From: wuwei23 at gmail.com (alex23) Date: Tue, 3 Jan 2012 18:26:35 -0800 (PST) Subject: .format vs. % References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <5059220.15.1325605679953.JavaMail.geo-discussion-forums@prgi2> Message-ID: <1f627dea-fc65-4d64-a594-e4ca9aade96b@e2g2000vbb.googlegroups.com> 88888 Dihedral wrote: > This is a good evolution in Python. It is 2012 now and the text I/O part > is not as important as 10 years ago. The next move of Python could > be easy integration of C++ libraries. You mean like with Py++? http://pypi.python.org/pypi/pyplusplus/ > The auto code generation part for low-paid tedious ? GUI tasks ?is still missing > in the standard Python. Wait, what? How is it the Python community's responsibility to relieve talentless code-monkeys of their tedium? Why can't they write their own damn code generators? > Boa and wxpython are still not good enough. And what are you contributing to the situation other than misinformation and markov-generated spam? From rosuav at gmail.com Tue Jan 3 21:37:24 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Jan 2012 13:37:24 +1100 Subject: Spamming PyPI with stupid packages In-Reply-To: <878vloz0zi.fsf@benfinney.id.au> References: <87hb0d28j8.fsf@benfinney.id.au> <87aa6522au.fsf@benfinney.id.au> <4f02ba8d$0$29880$c3e8da3$5496439d@news.astraweb.com> <8762gs1mag.fsf@benfinney.id.au> <4f03ad75$0$11122$c3e8da3@news.astraweb.com> <878vloz0zi.fsf@benfinney.id.au> Message-ID: On Wed, Jan 4, 2012 at 12:54 PM, Ben Finney wrote: > It objectifies women. If you can't see how that's harmful to women, I > haven't the stamina to educate you. And "import pickle" objectifies pickles. It's deplorable how few gherkins become programmers, and I think it's because of these immature jokes about pickles that have become entrenched in the Python community. These folk are on the very point of becoming programmers when they read an extremely obscure reference in one program's module collection and, as a result, choose a career elsewhere (in the case of pickles, there's always a job at McDonalds). ChrisA From ben+python at benfinney.id.au Tue Jan 3 21:42:31 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 Jan 2012 13:42:31 +1100 Subject: Spamming PyPI with stupid packages References: <87hb0d28j8.fsf@benfinney.id.au> <87aa6522au.fsf@benfinney.id.au> <4f02ba8d$0$29880$c3e8da3$5496439d@news.astraweb.com> <8762gs1mag.fsf@benfinney.id.au> <4f03ad75$0$11122$c3e8da3@news.astraweb.com> <878vloz0zi.fsf@benfinney.id.au> <4f03b3b6$0$11122$c3e8da3@news.astraweb.com> Message-ID: <87pqf0b33c.fsf@benfinney.id.au> Steven D'Aprano writes: > On Wed, 04 Jan 2012 12:54:09 +1100, Ben Finney wrote: > > It objectifies women. > > So you claim. I'm sure you have a hundred ready rationalisations for why a joke that has ?girlfriend? as a fungible object, together with ?car? and ?house? as things to mechanically import into one's life, is somehow not objectifying women. But, while those rationalisations may satisfy you, I'm not interested in hearing them. If you don't see that the joke objectifies women, that tells me quite a lot about how blinkered you are to the problem. For what it's worth, I'm very familiar with such rationalisations, having employed them many times myself. Fortunately there are women who will speak up against it and encourage men to do the same . > Since you can't or won't persuade me (and anyone else reading) that > this sort of joke is harmful, does that mean that you will stop > claiming that it is harmful? I have no idea what it would take to persuade you in particular. I do know that the combined privileges of being white, male, not-poor, and English-fluent (and many more privileges, I'm sure) grant both of us the luxury of barely even perceiving the harm done by a pervasive atmosphere of even low-level prejudice against any given group of people. Women (to return to the people in question), on the other hand, do not have that luxury. In this community they have no option but to be aware of the privileges we males have here. We have very effective cognitive blinders, merely because we have never needed to know what it's like being a woman in this prevalently-male field. The onus is on us to try hard to see, despite those blinders and easy rationalisations, that there is a lot we allow from our fellows which is perpetuating a hostile environment. I'm not making a fuss about one sexist joke, which has already been retracted by its author. I'm making a fuss about allowing and, worse, defending such jokes as a tacitly-accepted norm of our community. And I hope those of us who prefer to think of ourselves as not-sexist will act to clean up our house more. -- \ ?A hundred times every day I remind myself that [?] I must | `\ exert myself in order to give in the same measure as I have | _o__) received and am still receiving? ?Albert Einstein | Ben Finney From tony.pelletier at gmail.com Tue Jan 3 21:50:05 2012 From: tony.pelletier at gmail.com (Tony Pelletier) Date: Tue, 3 Jan 2012 21:50:05 -0500 Subject: Spamming PyPI with stupid packages In-Reply-To: <87pqf0b33c.fsf@benfinney.id.au> References: <87hb0d28j8.fsf@benfinney.id.au> <87aa6522au.fsf@benfinney.id.au> <4f02ba8d$0$29880$c3e8da3$5496439d@news.astraweb.com> <8762gs1mag.fsf@benfinney.id.au> <4f03ad75$0$11122$c3e8da3@news.astraweb.com> <878vloz0zi.fsf@benfinney.id.au> <4f03b3b6$0$11122$c3e8da3@news.astraweb.com> <87pqf0b33c.fsf@benfinney.id.au> Message-ID: Honestly, is this list really what this is all about? I'm bored already... Enough? On Tue, Jan 3, 2012 at 9:42 PM, Ben Finney wrote: > Steven D'Aprano writes: > > > On Wed, 04 Jan 2012 12:54:09 +1100, Ben Finney wrote: > > > It objectifies women. > > > > So you claim. > > I'm sure you have a hundred ready rationalisations for why a joke that > has ?girlfriend? as a fungible object, together with ?car? and ?house? > as things to mechanically import into one's life, is somehow not > objectifying women. > > But, while those rationalisations may satisfy you, I'm not interested in > hearing them. If you don't see that the joke objectifies women, that > tells me quite a lot about how blinkered you are to the problem. > > For what it's worth, I'm very familiar with such rationalisations, > having employed them many times myself. Fortunately there are women who > will speak up against it and encourage men to do the same > . > > > Since you can't or won't persuade me (and anyone else reading) that > > this sort of joke is harmful, does that mean that you will stop > > claiming that it is harmful? > > I have no idea what it would take to persuade you in particular. I do > know that the combined privileges of being white, male, not-poor, and > English-fluent (and many more privileges, I'm sure) grant both of us the > luxury of barely even perceiving the harm done by a pervasive atmosphere > of even low-level prejudice against any given group of people. > > Women (to return to the people in question), on the other hand, do not > have that luxury. In this community they have no option but to be aware > of the privileges we males have here. > > We have very effective cognitive blinders, merely because we have never > needed to know what it's like being a woman in this prevalently-male > field. The onus is on us to try hard to see, despite those blinders and > easy rationalisations, that there is a lot we allow from our fellows > which is perpetuating a hostile environment. > > I'm not making a fuss about one sexist joke, which has already been > retracted by its author. I'm making a fuss about allowing and, worse, > defending such jokes as a tacitly-accepted norm of our community. And I > hope those of us who prefer to think of ourselves as not-sexist will act > to clean up our house more. > > -- > \ ?A hundred times every day I remind myself that [?] I must | > `\ exert myself in order to give in the same measure as I have | > _o__) received and am still receiving? ?Albert Einstein | > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rodrick.brown at gmail.com Tue Jan 3 21:50:24 2012 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Tue, 3 Jan 2012 21:50:24 -0500 Subject: import issue with classes Message-ID: I have a class FooB that derives from FooA i.e. class FooB(FooA): FooA.__init__(self,...) Can someone explain why Import FooA doesn't work and I need to use from FooA import FooA instead? This puzzles me. Thanks. -- [ Rodrick R. Brown ] http://www.linkedin.com/in/rodrickbrown -------------- next part -------------- An HTML attachment was scrubbed... URL: From dan at tombstonezero.net Tue Jan 3 22:06:49 2012 From: dan at tombstonezero.net (Dan Sommers) Date: Wed, 4 Jan 2012 03:06:49 +0000 (UTC) Subject: Spamming PyPI with stupid packages References: <87hb0d28j8.fsf@benfinney.id.au> <87aa6522au.fsf@benfinney.id.au> <4f02ba8d$0$29880$c3e8da3$5496439d@news.astraweb.com> <8762gs1mag.fsf@benfinney.id.au> <4f03ad75$0$11122$c3e8da3@news.astraweb.com> <878vloz0zi.fsf@benfinney.id.au> Message-ID: On Wed, 04 Jan 2012 13:37:24 +1100, Chris Angelico wrote: > And "import pickle" objectifies pickles ... Not quite: "import pickle" merely readies the machinery that objectifies pickles. In order to objectify a pickle, you have to call pickle.loads: >>> import pickle # get ready to objectify a pickle, but don't do it yet >>> x = SomeClass(some_value, some_other_value) >>> s = pickle.dumps(x) # now s contains a pickle >>> y = pickle.loads(s) # this actually objectifies the pickle known as s Sorry. Now back to your regularly scheduled holy war. *sigh* From bahamutzero8825 at gmail.com Tue Jan 3 22:06:55 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Tue, 03 Jan 2012 21:06:55 -0600 Subject: import issue with classes In-Reply-To: References: Message-ID: <4F03C24F.9010703@gmail.com> On 1/3/2012 8:50 PM, Rodrick Brown wrote: > Import FooA doesn't work and I need to use from FooA import FooA > instead? This puzzles me. > Thanks. If you have a module called FooA with a class called FooA, then import FooA imports the /module/. The class would be FooA.FooA, just as the variable x from FooA would be FooA.x. -- CPython 3.2.2 | Windows NT 6.1.7601.17640 From rosuav at gmail.com Tue Jan 3 22:31:51 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Jan 2012 14:31:51 +1100 Subject: Spamming PyPI with stupid packages In-Reply-To: References: <87hb0d28j8.fsf@benfinney.id.au> <87aa6522au.fsf@benfinney.id.au> <4f02ba8d$0$29880$c3e8da3$5496439d@news.astraweb.com> <8762gs1mag.fsf@benfinney.id.au> <4f03ad75$0$11122$c3e8da3@news.astraweb.com> <878vloz0zi.fsf@benfinney.id.au> Message-ID: On Wed, Jan 4, 2012 at 2:06 PM, Dan Sommers wrote: > On Wed, 04 Jan 2012 13:37:24 +1100, Chris Angelico wrote: > >> And "import pickle" objectifies pickles ... > > Not quite: ?"import pickle" merely readies the machinery that objectifies > pickles. ?In order to objectify a pickle, you have to call pickle.loads: Modules are objects too!!! *marches around carrying signs proclaiming Rights for Modules* Does anybody else feel that this holy war is somewhat pointless? Oh wait. Holy war. "Pointless" is redundant. ChrisA From ethan at stoneleaf.us Tue Jan 3 22:34:28 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 03 Jan 2012 19:34:28 -0800 Subject: Spamming PyPI with stupid packages In-Reply-To: <87pqf0b33c.fsf@benfinney.id.au> References: <87hb0d28j8.fsf@benfinney.id.au> <87aa6522au.fsf@benfinney.id.au> <4f02ba8d$0$29880$c3e8da3$5496439d@news.astraweb.com> <8762gs1mag.fsf@benfinney.id.au> <4f03ad75$0$11122$c3e8da3@news.astraweb.com> <878vloz0zi.fsf@benfinney.id.au> <4f03b3b6$0$11122$c3e8da3@news.astraweb.com> <87pqf0b33c.fsf@benfinney.id.au> Message-ID: <4F03C8C4.50805@stoneleaf.us> Ben Finney wrote: > I have no idea what it would take to persuade you in particular. I do > know that the combined privileges of being white, male, not-poor, and > English-fluent (and many more privileges, I'm sure) grant both of us the > luxury of barely even perceiving the harm done by a pervasive atmosphere > of even low-level prejudice against any given group of people. > We have very effective cognitive blinders, merely because we have never > needed to know what it's like being a woman in this prevalently-male > field. The onus is on us to try hard to see, despite those blinders and > easy rationalisations, that there is a lot we allow from our fellows > which is perpetuating a hostile environment. > I'm not making a fuss about one sexist joke, which has already been > retracted by its author. I'm making a fuss about allowing and, worse, > defending such jokes as a tacitly-accepted norm of our community. And I > hope those of us who prefer to think of ourselves as not-sexist will act > to clean up our house more. +1 ~Ethan~ From tjreedy at udel.edu Tue Jan 3 23:13:11 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 03 Jan 2012 23:13:11 -0500 Subject: import issue with classes In-Reply-To: <4F03C24F.9010703@gmail.com> References: <4F03C24F.9010703@gmail.com> Message-ID: On 1/3/2012 10:06 PM, Andrew Berg wrote: > On 1/3/2012 8:50 PM, Rodrick Brown wrote: >> Import FooA doesn't work and I need to use from FooA import FooA >> instead? This puzzles me. >> Thanks. > If you have a module called FooA with a class called FooA, then import > FooA imports the /module/. The class would be FooA.FooA, just as the > variable x from FooA would be FooA.x. This sort of confusion is why it is not recommended to have file/module fooa contain class FooA and why there were some module name changes in Py 3. -- Terry Jan Reedy From waitmeforever at hotmail.com Wed Jan 4 01:10:46 2012 From: waitmeforever at hotmail.com (Yang Chun-Kai) Date: Wed, 4 Jan 2012 14:10:46 +0800 Subject: python2.7 kill thread and find thread id Message-ID: Hello,guys!! I am using python2.7 to write a simple thread program which print the current running thread id and kill it with this id. But I have some questions with this. My code: -----------------------------------------------------from threading import Threadclass t(Thread): def __init__(self): Thread.__init__(self) def run(self): self.tid = Thread.get_ident() print 'thread id is', self.tid def kill(self): *** // how to do this with its own id, for example "exit(self.tid)" ?if __name__ == "__main__" go = t() go.start() go.kill()-----------------------------------------------------First, I can't call get_ident(), seems not supported. Second, how to kill the thread with its own id? I know I can use SystemExit() to shut this down, but I want to kill the certain thread not the whole program. Anyone know how to fix my code to achieve it? Any tips welcomed. Thank you in advance. Kay -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Wed Jan 4 01:12:50 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 4 Jan 2012 01:12:50 -0500 Subject: import issue with classes In-Reply-To: References: Message-ID: On Tue, Jan 3, 2012 at 9:50 PM, Rodrick Brown wrote: > I have a class FooB that derives from FooA > > i.e. > class FooB(FooA): > ? FooA.__init__(self,...) > > Can someone explain why > > Import FooA doesn't work and I need to use from FooA import FooA instead? > This puzzles me. > Thanks. > > > > -- > [ Rodrick R. Brown ] Because you're coming from Java and thinking that Python behaves the same way, which isn't true. In Java, every code file consists of a single public class with the same name as the file. In Python, a module is an object consisting of many other objects, including classes, functions, and variables. There's no need for the class name to be anything related to the file name. By convention, modules (files) have lowercase names. So lets call your file "fooA.py" with a class FooA inside it, just so we can distinguish between them. "import fooA" searches for a file called fooA.py in a set of directories, finds it, compiles it, and binds the now-created module object to the name fooA. The module object fooA has a class "FooA" inside it. They're two separate things. "from fooA import FooA" searches for fooA.py, just like before. But instead of giving you the whole module, it just looks for FooA and binds it to the same name in the current context. From waitmeforever at hotmail.com Wed Jan 4 01:20:58 2012 From: waitmeforever at hotmail.com (Yang Chun-Kai) Date: Wed, 4 Jan 2012 14:20:58 +0800 Subject: python2.7 kill thread and find thread id In-Reply-To: References: Message-ID: Sorry for the misarrangement of my code in list, it happens everytime. I apologized. From: waitmeforever at hotmail.com To: python-list at python.org Subject: python2.7 kill thread and find thread id Date: Wed, 4 Jan 2012 14:10:46 +0800 Hello,guys!! I am using python2.7 to write a simple thread program which print the current running thread id and kill it with this id. But I have some questions with this. < /div>My code: -----------------------------------------------------from threading import Threadclass t(Thread): def __init__(self): Thread.__init__(self) def run(self): self.tid = Thread.get_ident() print 'thread id is', self.tid def kill(self): *** // how to do this with its own id, for example "exit(self.tid)" ?if __name__ == "__main__" go = t() go.start() go.kill()-----------------------------------------------------First, I can't call get_ident(), seems not supported. Second, how to kill the thread with its own id? I know I can use SystemExit() to shut this down, but I want to kill the certain thread not the whole program. Anyone know how to fix my code to achieve it? Any tips welcomed. Thank you in advance. Kay -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Jan 4 01:37:03 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 Jan 2012 01:37:03 -0500 Subject: python philosophical question - strong vs duck typing In-Reply-To: References: Message-ID: On 1/3/2012 8:04 PM, Devin Jeanpierre wrote: >> Can you give an actual example of such a definition of 'strongly typed >> object' that excludes Python objects? > > I'd love to, but I neglected to above because I don't really know > where we share ideas, and I wouldn't want to jump ahead and say > something that seems outlandish. I hope I've done a decent enough job > below. Stop me if I say something you don't agree with. > > Here's a short version: The term often refers to a continuum, where > some languages are "stronger" than others, but there is no objective > definition of "strong" -- it's like asking how big is "big", or how > smart is "smart". Fine so far. cold/hot, good/bad, etc are false dichotomies. Better to use there as comparatives -- better/worse that average, or than the middle 1/2. I don't use 'strong type' unless someone else does, and maybe I should stop being suckered into using it even then ;-). > The actual choice of what continuum strength refers > to varies between people -- some specify it as "reinterpretation of > bits in memory", in which case every dynamic language in the world is > strongly typed (so I'll move on from that), Fine. > or some as "implicit > conversions between types", which is iffy because any function or > overloaded operator can silently convert types (at least in Python), Since Python does not 'silently convert types' as I understand those 3 words, you lose me here. Can you give a code example of what you mean? > meaning the language is as weak as the user (?). But they're both kind > of reasonable and held by a few people, and it's easy to see how maybe > somebody used to significantly more strict rules (OCaml, for example) > might accuse Python of not being all that strong. So you see it isn't > really a change of definition, it's a redrawing of the lines on a > continuum. The OCaml people are reasonable for saying what they say, > because their point of reference is their favorite language, just as > ours is ours. To us, maybe Haskell and OCaml are insanely > strong/"strict", to them, we're insanely weak. I am aware that typed names lead to typed function signatures and that some languages in the ML family even type operators, so that different operators are required for 1+2 and 1.0+2.0 and mixed operations like 1+2.0 are prohibited. But we are talking about the typing of objects here. > Here's another take, more in line with what I really meant: the > continuums expressed above aren't universal either. IME they're chosen > by dynamic typing advocates, which are worried about code readability > and certain styles of immensely common errors that come from > lower-level languages like C. Static typing advocates (at least in the > functional programming language family) are instead concerned about > correctness. For them, type systems are a way to reduce the number of > errors in your code _in general_, not just the specific cases of type > coercion or memory-safety. In this particular sense, Python is not > very far from C I see the object model of Python as being very different from the data model of C. The class of an object is an internal attribute of the object while the type of a block of bits is an external convention enforced by the compiler. I see Python's objects as more similar to the objects of many functional languages, except that Python has mutable objects. ... > Type systems exist which are much "stronger" in what they can protect > you against. As an extreme example, one might take a dependently-typed > language. A statically dependently typed language can protect you > against out-of-bounds array access with a proof at compile time. In I am familiar with the length-parameterized array types of Pascal (which seem in practice to be a nuisance), but I see from https://en.wikipedia.org/wiki/Dependent_type that there is a lot more to the subject. > fact, a statically-dependently-typed language can do things like prove sometimes, though not always, > that two different implementations of the same function are in fact > implementations of the same function -- this is neat for implementing > a non-recursive version of a recursive function, and verifying the > change doesn't influence semantics. Using induction, I can prove, for instance, that these two functions def f_tr(n, val=base): # tail recursive if n: return f_tr(n-1, rec(n, val)) else: return val def f_wi(n, val = base): # while iterative while n: n, val = n-1, rec(n, val) return val are equivalent, assuming enough stack and normal procedural Python semantics. (And assuming no typos ;-). f_tr(0) == base == f_wi(0) f_tr(n+1) == f_tr(n+1, base) == f_tr(n, rec(n+1, base)) == by inductive hypothsis f_wi(n, rec(n+1, base)) == f_wi(n+1, base) == f_wi(n+1) So it is not clear to me what such proofs have to do with types as I understand the term. > It's definitely true that there is something here that Python's types > cannot do, at least not without extremely heavily mangling > (technically __instancecheck__ means that type objects are turing > complete, but I request that we ignore that). These are the sorts of > types that can, in a very real sense, replace unit tests. Just the > fact that your program typechecks is proof that certain properties > hold, and those properties can be very soothing, such as that example > of proving two algorithms return the same output. I can imagine that if one overloads 'type' with enough extra information, the procedural reasoning involved in such proofs might reduce to a more calculational demonstration. The question is whether the months and years of intellectual investment required on the front end pay off in reduced intellectual effort across several applications. I happen to be working on a book on inductive algorithms that will include several such equivalences like that above. I will stick with the sort of proof that I can write and that most can understand. > One last note about static vs dynamic vs strong typing: I do believe > that a strongly typed dynamic+statically typed language is possible Cython with superset features used. > and a good thing. For statically typed code, run-time checks are > disabled (speed), I believe Cython disables the run-times checks that it can tell are unnecessary. For instance, "for i in range(len(array)): array[i]" does not need a runtime check that i is in range(len(array)) and hence can convert array[i] to its unchecked C equivalent. for dynamically typed code they are enabled, and all > the while you can make relatively sophisticated queries about the type > of a thing using an interactive interpreter (somewhat similar to > unifying things in the prolog interpreter, in my view). There is n > So now that we've gotten this far, here's my proposition: It is > reasonable to consider type systems in terms of how many errors they > eliminate in your programs, rather than just readability/memory-safety And interesting and for me, different viewpoint. I tend to be interested in correctness through understanding, or, if you will, logical correctness. Textual correctness, especially with what I do with Python, is a secondary issue. Memory-safety does not directly concern me, since I am not writing or running servers. But it is a major target of malware. To really eliminate errors, we need a multiplicity of types. We need not just floats, but non-negative floats, positive floats, and 'complex' floats that get promoted to complex as necessary. But the checks have to be dynamic, since in general, only constants can be statically checked at compile time. Or you need relative 'x is bigger than y' pair types so that x-y can be determined to be positive. Hmmm. I guess that one could say that such a statement in the course of a proof amounts to a type statement. And the same for loop invariants. > concerns. Also, it is reasonable to have relatively strict standards, > if you're used to a very "strong" type system. Such a person might, > very reasonably, decide that Python is quite weak. Yes, only objects are (strongly ;-) typed. Names are untyped. Function parameters (signatures) are only directly typed as to whether the corresponding arguments are required or not and whether the matching of arguments and parameters is by position, name, or both. The 'type' of Python is something like "object-class based, procedural syntax, certain functional features". Strong/weak has nothing to do with Python itself. > I admit that a lot of what I said here is putting words in other > peoples' mouths, if you object, pretend I said it instead. No objections except as noted. > I am, after all, a fan of ATS at the moment, and thus have some > interest in ridiculously strongly typed languages ;) I see that in the list in the Wikipedia article. > *phew*. That took a lot of time. I hope I haven't lost your attention. No. I might even have learned something. > [ An example of a simple dependently typed program: > http://codepad.org/eLr7lLJd ] Just got it after a minute delay. -- Terry Jan Reedy From tjreedy at udel.edu Wed Jan 4 02:03:19 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 Jan 2012 02:03:19 -0500 Subject: import issue with classes In-Reply-To: References: <4F03C24F.9010703@gmail.com> Message-ID: On 1/3/2012 11:13 PM, Terry Reedy wrote: > On 1/3/2012 10:06 PM, Andrew Berg wrote: >> On 1/3/2012 8:50 PM, Rodrick Brown wrote: >>> Import FooA doesn't work and I need to use from FooA import FooA >>> instead? This puzzles me. >>> Thanks. >> If you have a module called FooA with a class called FooA, then import >> FooA imports the /module/. The class would be FooA.FooA, just as the >> variable x from FooA would be FooA.x. > > This sort of confusion is why it is not recommended to have file/module why it *is* recommended (to have different names) and not recommended to have the same name, including case. > fooa contain class FooA and why there were some module name changes in > Py 3. > -- Terry Jan Reedy From dihedral88888 at googlemail.com Wed Jan 4 03:25:38 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Wed, 4 Jan 2012 00:25:38 -0800 (PST) Subject: .format vs. % In-Reply-To: <1f627dea-fc65-4d64-a594-e4ca9aade96b@e2g2000vbb.googlegroups.com> References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <5059220.15.1325605679953.JavaMail.geo-discussion-forums@prgi2> <1f627dea-fc65-4d64-a594-e4ca9aade96b@e2g2000vbb.googlegroups.com> Message-ID: <33065224.296.1325665538706.JavaMail.geo-discussion-forums@prh19> alex23? 2012?1?4????UTC+8??10?26?35???? > 88888 Dihedral wrote: > > This is a good evolution in Python. It is 2012 now and the text I/O part > > is not as important as 10 years ago. The next move of Python could > > be easy integration of C++ libraries. > > You mean like with Py++? http://pypi.python.org/pypi/pyplusplus/ > > > The auto code generation part for low-paid tedious ? GUI tasks ?is still missing > > in the standard Python. > > Wait, what? How is it the Python community's responsibility to relieve > talentless code-monkeys of their tedium? Why can't they write their > own damn code generators? > I think a code generator to assist the programmer for common tedious boring GUI jobs such as BOA is more important in Python. But Python is not VB. > > Boa and wxpython are still not good enough. > > And what are you contributing to the situation other than > misinformation and markov-generated spam? Do you know what can attract newbies to support python? From alnosa_2011 at yahoo.com Wed Jan 4 04:11:50 2012 From: alnosa_2011 at yahoo.com (alnosa_2011 at yahoo.com) Date: Wed, 4 Jan 2012 01:11:50 -0800 (PST) Subject: The best for your mid year Vacation in Luxor & Aswan 2012 Message-ID: ( the best way to spend your mid year vacation) If you want to spend your mid year vacation in a place will take your mind You should have a nile cruise in Egypt Our trips from 28/1 till 28/2 3 nights included siteseen on 5 stars ship (start from Aswan) 4 nights included siteseen on 5 stars ship (strat from Loxur) Our trips start from 1199 L.E With my best regards Elmasrya travel services +201223094010 +201142832495 +971503641503 http://elmasryatravel.com www.elmasryatravels.com http://www.facebook.com/elmasryia From sivakishore1414 at gmail.com Wed Jan 4 04:45:35 2012 From: sivakishore1414 at gmail.com (siva kishore) Date: Wed, 4 Jan 2012 01:45:35 -0800 (PST) Subject: online jobs Message-ID: online jobs http://gsonlinejobs.yolasite.com/ From jeanpierreda at gmail.com Wed Jan 4 07:22:09 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Wed, 4 Jan 2012 07:22:09 -0500 Subject: python philosophical question - strong vs duck typing In-Reply-To: References: Message-ID: > Since Python does not 'silently convert types' as I understand those 3 > words, you lose me here. Can you give a code example of what you mean? I mean the reasoning behind the arguments like 'X isn't strongly typed because 2 + "3" = 5 but "3" + 2 = "32"'. OCaml considers this a problem and bans all implicit conversions whatsoever. (Or maybe that's more to do with making their type inference better?) I actually stole the classification of continuums from a Python wiki page, and my terminology was influenced by the reading. See: http://wiki.python.org/moin/StrongVsWeakTyping > I am aware that typed names lead to typed function signatures and that some > languages in the ML family even type operators, so that different operators > are required for 1+2 and 1.0+2.0 and mixed operations like 1+2.0 are > prohibited. But we are talking about the typing of objects here. I should state up-front that I'm not sure we can only talk about the typing of objects. There's a bit of a problem in that "dynamically typed" and "statically typed" aren't exactly things that can be compared -- they're almost orthogonal. Almost. Dynamically typed languages like Python keep, by necessity, information about what they are and what they came from (at run-time). (The alternative is to be untyped, which is bad). Statically typed languages do not always have to keep them around. If you do enough at compile-time, you can forget everything at run-time. Run-time and compile-time are completely different, and a language can do any combination of things at both. It's weird that we've decided that there's only two options rather than four, and that we really want to compare these two options. I'm not sure how that fits into what I've said. Maybe I've already contradicted myself. Anyway, in answer, OCaml forbids both at run-time _and_ compile-time the coercion of floats to ints via the + operator, and in doing so enforces its notion of strong typing. You can't add a float to an int. So in this notion, it allows less implicit type conversion -- and run-time object conversion -- than Python, which freely converts floats to ints. This philosophy extends elsewhere in OCaml. > Using induction, I can prove, for instance, that these two functions > > def f_tr(n, val=base): # tail recursive > if n: > return f_tr(n-1, rec(n, val)) > else: > return val > > def f_wi(n, val = base): # while iterative > while n: > n, val = n-1, rec(n, val) > return val > > are equivalent, assuming enough stack and normal procedural Python > semantics. (And assuming no typos ;-). > > f_tr(0) == base == f_wi(0) > f_tr(n+1) == f_tr(n+1, base) == f_tr(n, rec(n+1, base)) > == by inductive hypothsis > f_wi(n, rec(n+1, base)) == f_wi(n+1, base) == f_wi(n+1) > > So it is not clear to me what such proofs have to do with types as I > understand the term. Ah, I messed up and didn't explain that. It doesn't help that I've been too lazy to actually work with ATS proofs directly, so I might say some things that are wrong/vague. In some languages -- particularly dependently-typed languages -- a type can represent a computation. That is, the return type of a function might essentially be the computation that we wish to do, and therefore if the function typechecks then we know it does that computation. (This has all the caveats of formal methods as a whole). Many (all?) of the automated theorem provers are dependently typed languages in this fashion. In particular, if you pick some well-defined decidable computational language, you can try to make your type system powerful enough to encode it. (For example, the primitive recursive functions are a nice subset.) For an example, in ATS the following is a compiler-type which can be used as part of the type declaration for a function: dataprop FIB (int, int) = | FIB0 (0, 0) | FIB1 (1, 1) | {n:nat} {r0,r1:int} FIB2 (n+2, r0+r1) of (FIB (n, r0), FIB (n+1, r1)) The predicate FIB(X, Y) is true when Fibonacci(X) = Y, so this is essentially the same as defining fibonacci recursively: Fibonacci(0) = 0 Fibonacci(1) = 1 Fibonacci(A+2) = Fibonacci(A+1) + Fibonacci(A) It encodes the recursive definition of fibonacci, and if we declare a function as "taking a value m, returning a value n, such that FIB(m, n)", then a successful typecheck is equivalent to a successful proof that the implementation is correct. How does that typecheck work? I don't really know, I haven't at all investigated the proof structure for ATS. Sorry. :( Some cursory reading says that a function can return a proof that is typechecked against dataprop, as well as the value. Maybe that's it. :) > I can imagine that if one overloads 'type' with enough extra information, > the procedural reasoning involved in such proofs might reduce to a more > calculational demonstration. The question is whether the months and years of > intellectual investment required on the front end pay off in reduced > intellectual effort across several applications. Yes. Well, the compiler writers think so. I'm not really sure. Often the incentives are misaligned -- it might not be worth the type in the global economy, but professors need to research _something_. There's also the question of whether it's worth spending all that effort to satisfy a computer: does it really reduce error rates? Even if it does, is it cost-effective at it? Some of the things I've read says that this might not be the right place to apply formal methods (but rather that the best place is when writing the specification), but it's a little bit of an under-researched field. [see http://lambda-the-ultimate.org/node/4425 ] > I happen to be working on a book on inductive algorithms that will include > several such equivalences like that above. I will stick with the sort of > proof that I can write and that most can understand. The way I see it, mathematical english is a pseudocode for a particular kind of declarative programming language. There isn't much point leaving the pseudocode, because it seems to be unambiguous enough. Unless you want an objective observer to verify your work and actually execute the proof/program. I guess if my proof was responsible for decisions made in machinery that could cost lives I'd verify the proof, but if it's just a textbook... :) There is also a relatively common argument against dependently typed languages that, while they're kind of popular in a certain group of people, some think that they are losing the focus of how we should be proving program correctness. I'm not really sure of the merits of this. > I see the object model of Python as being very different from the data model > of C. The class of an object is an internal attribute of the object while > the type of a block of bits is an external convention enforced by the > compiler. I see Python's objects as more similar to the objects of many > functional languages, except that Python has mutable objects. Sorry, yes, the model is very different. I was trying to compare the benefits. I asserted that the primary benefit of Python over C, in terms of errors, is not that the errors no longer exist, it's that they are in a much more manageable form (e.g. tracebacks instead of corrupted data). Whereas in a strongly-statically typed language, the benefit might be that they no longer exist at run-time. That's a massive change. > Cython with superset features used. Yes. One of my pipe dream future projects is to extend Cython to compile to ATS. But that'd require understanding Cython and ATS, and I understand neither. (I was writing some Cython code today and I just keep blowing up the compiler...) > I believe Cython disables the run-times checks that it can tell are > unnecessary. For instance, "for i in range(len(array)): array[i]" does not > need a runtime check that i is in range(len(array)) and hence can convert > array[i] to its unchecked C equivalent. This is exactly the sort of thing! ATS, being a systems language, makes you insert the check yourself :( > To really eliminate errors, we need a multiplicity of types. We need not > just floats, but non-negative floats, positive floats, and 'complex' floats > that get promoted to complex as necessary. But the checks have to be > dynamic, since in general, only constants can be statically checked at > compile time. Or you need relative 'x is bigger than y' pair types so that > x-y can be determined to be positive. > > Hmmm. I guess that one could say that such a statement in the course of a > proof amounts to a type statement. And the same for loop invariants. This excites me. I think you get the appeal of value-dependent types. Although I think I expressed myself poorly, as I haven't brought across that languages like ATS do this at compile time (or maybe your emphasis is on general case?) In ATS, I can define all of these like so[*]: typedef NonNegativeFloat = [a:float | a >= 0.0] float(a) typedef PositiveFloat = [a:float | a > 0.0] float(a) typedef SortedStrictPair = [a,b:float | a > b] @(a, b) And furthermore, it agrees with you on loop invariants: such constraints can form as the type of a function, and all loops are written as tail-recursive functions... :) And of course ATS uses all this type information to prove things. It's absolutely exciting stuff. [*] Actually this isn't true, because the compiler doesn't understand floats. I haven't asked why, but I suspect that it's because float arithmetic works in ways that could confuse the compiler -- e.g. there exists an a > b > 0, such that a - b = a, which violates the mathematical laws that ATS uses to infer things about numbers. I would probably would need to use an infinitely-precise rational type to make it work (quote notation? :D). There's a run-time float type, of course. It might also be possible to define your own compile-time type that only defines <, ==, and >, without dealing with issues like arithmetic. > Yes, only objects are (strongly ;-) typed. Names are untyped. Function > parameters (signatures) are only directly typed as to whether the > corresponding arguments are required or not and whether the matching of > arguments and parameters is by position, name, or both. The 'type' of Python > is something like "object-class based, procedural syntax, certain functional > features". Strong/weak has nothing to do with Python itself. This is a viewpoint I hadn't considered. Yes, you could also object to what is typed and what isn't. I am not really sure how to do it without static typing though. How does one duck-type a name? > Just got it after a minute delay. Hum, perhaps my paste is making the rounds on reddit? ;) Sorry about that. I forgot that this happens with that pastebin. What would be the recommended way of sending such a large and useless file on a mailing list? -- Devin On Wed, Jan 4, 2012 at 1:37 AM, Terry Reedy wrote: > On 1/3/2012 8:04 PM, Devin Jeanpierre wrote: > >>> Can you give an actual example of such a definition of 'strongly typed >>> object' that excludes Python objects? >> >> >> I'd love to, but I neglected to above because I don't really know >> where we share ideas, and I wouldn't want to jump ahead and say >> something that seems outlandish. I hope I've done a decent enough job >> below. Stop me if I say something you don't agree with. >> >> Here's a short version: The term often refers to a continuum, where >> some languages are "stronger" than others, but there is no objective >> definition of "strong" -- it's like asking how big is "big", or how >> smart is "smart". > > > Fine so far. cold/hot, good/bad, etc are false dichotomies. Better to use > there as comparatives -- better/worse that average, or than the middle 1/2. > I don't use 'strong type' unless someone else does, and maybe I should stop > being suckered into using it even then ;-). > > >> The actual choice of what continuum strength refers >> >> to varies between people -- some specify it as "reinterpretation of >> bits in memory", in which case every dynamic language in the world is >> strongly typed (so I'll move on from that), > > > Fine. > > >> or some as "implicit >> conversions between types", which is iffy because any function or >> overloaded operator can silently convert types (at least in Python), > > > Since Python does not 'silently convert types' as I understand those 3 > words, you lose me here. Can you give a code example of what you mean? > > >> meaning the language is as weak as the user (?). But they're both kind >> of reasonable and held by a few people, and it's easy to see how maybe >> somebody used to significantly more strict rules (OCaml, for example) >> might accuse Python of not being all that strong. ?So you see it isn't >> really a change of definition, it's a redrawing of the lines on a >> continuum. The OCaml people are reasonable for saying what they say, >> because their point of reference is their favorite language, just as >> ours is ours. To us, maybe Haskell and OCaml are insanely >> strong/"strict", to them, we're insanely weak. > > > I am aware that typed names lead to typed function signatures and that some > languages in the ML family even type operators, so that different operators > are required for 1+2 and 1.0+2.0 and mixed operations like 1+2.0 are > prohibited. But we are talking about the typing of objects here. > > >> Here's another take, more in line with what I really meant: the >> continuums expressed above aren't universal either. IME they're chosen >> by dynamic typing advocates, which are worried about code readability >> and certain styles of immensely common errors that come from >> lower-level languages like C. Static typing advocates (at least in the >> functional programming language family) are instead concerned about >> correctness. For them, type systems are a way to reduce the number of >> errors in your code _in general_, not just the specific cases of type >> coercion or memory-safety. In this particular sense, Python is not >> very far from C > > > I see the object model of Python as being very different from the data model > of C. The class of an object is an internal attribute of the object while > the type of a block of bits is an external convention enforced by the > compiler. I see Python's objects as more similar to the objects of many > functional languages, except that Python has mutable objects. > > ... > > >> Type systems exist which are much "stronger" in what they can protect >> you against. As an extreme example, one might take a dependently-typed >> language. A statically dependently typed language can protect you >> against out-of-bounds array access with a proof at compile time. In > > > I am familiar with the length-parameterized array types of Pascal (which > seem in practice to be a nuisance), but I see from > https://en.wikipedia.org/wiki/Dependent_type > that there is a lot more to the subject. > > >> fact, a statically-dependently-typed language can do things like prove > > > sometimes, though not always, > > >> that two different implementations of the same function are in fact >> implementations of the same function -- this is neat for implementing >> a non-recursive version of a recursive function, and verifying the >> change doesn't influence semantics. > > > Using induction, I can prove, for instance, that these two functions > > def f_tr(n, val=base): # tail recursive > if n: > return f_tr(n-1, rec(n, val)) > else: > return val > > def f_wi(n, val = base): # while iterative > while n: > n, val = n-1, rec(n, val) > return val > > are equivalent, assuming enough stack and normal procedural Python > semantics. (And assuming no typos ;-). > > f_tr(0) == base == f_wi(0) > f_tr(n+1) == f_tr(n+1, base) == f_tr(n, rec(n+1, base)) > == by inductive hypothsis > f_wi(n, rec(n+1, base)) == f_wi(n+1, base) == f_wi(n+1) > > So it is not clear to me what such proofs have to do with types as I > understand the term. > > >> It's definitely true that there is something here that Python's types >> cannot do, at least not without extremely heavily mangling >> (technically __instancecheck__ means that type objects are turing >> complete, but I request that we ignore that). These are the sorts of >> types that can, in a very real sense, replace unit tests. Just the >> fact that your program typechecks is proof that certain properties >> hold, and those properties can be very soothing, such as that example >> of proving two algorithms return the same output. > > > I can imagine that if one overloads 'type' with enough extra information, > the procedural reasoning involved in such proofs might reduce to a more > calculational demonstration. The question is whether the months and years of > intellectual investment required on the front end pay off in reduced > intellectual effort across several applications. > > I happen to be working on a book on inductive algorithms that will include > several such equivalences like that above. I will stick with the sort of > proof that I can write and that most can understand. > > >> One last note about static vs dynamic vs strong typing: I do believe >> that a strongly typed dynamic+statically typed language is possible > > > Cython with superset features used. > > >> and a good thing. For statically typed code, run-time checks are >> disabled (speed), > > > I believe Cython disables the run-times checks that it can tell are > unnecessary. For instance, "for i in range(len(array)): array[i]" does not > need a runtime check that i is in range(len(array)) and hence can convert > array[i] to its unchecked C equivalent. > > > ?for dynamically typed code they are enabled, and all >> >> the while you can make relatively sophisticated queries about the type >> of a thing using an interactive interpreter (somewhat similar to >> unifying things in the prolog interpreter, in my view). > > > There is n > > >> So now that we've gotten this far, here's my proposition: It is >> reasonable to consider type systems in terms of how many errors they >> eliminate in your programs, rather than just readability/memory-safety > > > And interesting and for me, different viewpoint. I tend to be interested in > correctness through understanding, or, if you will, logical correctness. > Textual correctness, especially with what I do with Python, is a secondary > issue. > > Memory-safety does not directly concern me, since I am not writing or > running servers. But it is a major target of malware. > > To really eliminate errors, we need a multiplicity of types. We need not > just floats, but non-negative floats, positive floats, and 'complex' floats > that get promoted to complex as necessary. But the checks have to be > dynamic, since in general, only constants can be statically checked at > compile time. Or you need relative 'x is bigger than y' pair types so that > x-y can be determined to be positive. > > Hmmm. I guess that one could say that such a statement in the course of a > proof amounts to a type statement. And the same for loop invariants. > > >> concerns. Also, it is reasonable to have relatively strict standards, >> if you're used to a very "strong" type system. Such a person might, >> very reasonably, decide that Python is quite weak. > > > Yes, only objects are (strongly ;-) typed. Names are untyped. Function > parameters (signatures) are only directly typed as to whether the > corresponding arguments are required or not and whether the matching of > arguments and parameters is by position, name, or both. The 'type' of Python > is something like "object-class based, procedural syntax, certain functional > features". Strong/weak has nothing to do with Python itself. > > >> I admit that a lot of what I said here is putting words in other >> peoples' mouths, if you object, pretend I said it instead. > > > No objections except as noted. > > >> I am, after all, a fan of ATS at the moment, and thus have some >> interest in ridiculously strongly typed languages ;) > > I see that in the list in the Wikipedia article. > > >> *phew*. That took a lot of time. I hope I haven't lost your attention. > > > No. I might even have learned something. > > >> [ An example of a simple dependently typed program: >> http://codepad.org/eLr7lLJd ] > > > Just got it after a minute delay. > > > -- > Terry Jan Reedy > > -- > http://mail.python.org/mailman/listinfo/python-list From rami.chowdhury at gmail.com Wed Jan 4 07:49:55 2012 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Wed, 4 Jan 2012 12:49:55 +0000 Subject: Spamming PyPI with stupid packages In-Reply-To: <87pqf0b33c.fsf@benfinney.id.au> References: <87hb0d28j8.fsf@benfinney.id.au> <87aa6522au.fsf@benfinney.id.au> <4f02ba8d$0$29880$c3e8da3$5496439d@news.astraweb.com> <8762gs1mag.fsf@benfinney.id.au> <4f03ad75$0$11122$c3e8da3@news.astraweb.com> <878vloz0zi.fsf@benfinney.id.au> <4f03b3b6$0$11122$c3e8da3@news.astraweb.com> <87pqf0b33c.fsf@benfinney.id.au> Message-ID: On Wed, Jan 4, 2012 at 02:42, Ben Finney wrote: > I'm sure you have a hundred ready rationalisations for why a joke that > has ?girlfriend? as a fungible object, together with ?car? and ?house? > as things to mechanically import into one's life, is somehow not > objectifying women. > > But, while those rationalisations may satisfy you, I'm not interested in > hearing them. If you don't see that the joke objectifies women, that > tells me quite a lot about how blinkered you are to the problem. > > For what it's worth, I'm very familiar with such rationalisations, > having employed them many times myself. Fortunately there are women who > will speak up against it and encourage men to do the same > . > > Steven D'Aprano writes: >> Since you can't or won't persuade me (and anyone else reading) that >> this sort of joke is harmful, does that mean that you will stop >> claiming that it is harmful? > > I have no idea what it would take to persuade you in particular. I do > know that the combined privileges of being white, male, not-poor, and > English-fluent (and many more privileges, I'm sure) grant both of us the > luxury of barely even perceiving the harm done by a pervasive atmosphere > of even low-level prejudice against any given group of people. > > Women (to return to the people in question), on the other hand, do not > have that luxury. In this community they have no option but to be aware > of the privileges we males have here. > > We have very effective cognitive blinders, merely because we have never > needed to know what it's like being a woman in this prevalently-male > field. The onus is on us to try hard to see, despite those blinders and > easy rationalisations, that there is a lot we allow from our fellows > which is perpetuating a hostile environment. > > I'm not making a fuss about one sexist joke, which has already been > retracted by its author. I'm making a fuss about allowing and, worse, > defending such jokes as a tacitly-accepted norm of our community. And I > hope those of us who prefer to think of ourselves as not-sexist will act > to clean up our house more. A hearty +1 to this! -- Rami Chowdhury "A mind all logic is like a knife all blade - it makes the hand bleed that uses it." -- Rabindranath Tagore +44-7581-430-517 / +1-408-597-7068 / +88-0189-245544 From marko at pacujo.net Wed Jan 4 07:51:28 2012 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 04 Jan 2012 14:51:28 +0200 Subject: Locale bug? References: <8739bwop3y.fsf@enterprise.ximalas.info> Message-ID: "=?ISO-8859-1?Q?Trond_Endrest=F8l?=" : > Marko Rauhamaa writes: >> $ python3 >> >>> locale.setlocale(locale.LC_TIME, ('fi_FI', 'UTF-8')) >> >>> time.strftime("%a, %d %b %Y %H:%M:%S %z (%Z)") >> 'ti, 03 tammi\xa0 2012 14:51:57 +0200 (EET)' > > It may be OS-specific. You're right. It's a generic linux problem (in the coreutils rpm of Fedora). An analogous C program demonstrates the same issue. > Your sample code runs fine on FreeBSD/i386 > trond at enterprise:~>python3.2 > >>> locale.setlocale(locale.LC_TIME, ('fi_FI', 'UTF-8')) > >>> time.strftime("%a, %d %b %Y %H:%M:%S %z (%Z)") > 'Ti, 03 Tam 2012 15:03:15 +0100 (CET)' Well, "Ti" and "Tam" probably shouldn't be capitalized... Marko From marko at pacujo.net Wed Jan 4 08:07:15 2012 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 04 Jan 2012 15:07:15 +0200 Subject: Locale bug? References: <8739bwop3y.fsf@enterprise.ximalas.info> Message-ID: Marko Rauhamaa : > "=?ISO-8859-1?Q?Trond_Endrest=F8l?=" : > >> Marko Rauhamaa writes: >>> $ python3 >>> >>> locale.setlocale(locale.LC_TIME, ('fi_FI', 'UTF-8')) >>> >>> time.strftime("%a, %d %b %Y %H:%M:%S %z (%Z)") >>> 'ti, 03 tammi\xa0 2012 14:51:57 +0200 (EET)' >> >> It may be OS-specific. > > You're right. It's a generic linux problem (in the coreutils rpm of > Fedora). An analogous C program demonstrates the same issue. Actually, it's working as designed, no bug at all. It turns out the "garbage" character is the nonbreaking space: >>> print(time.strftime("%a, %d %b %Y %H:%M:%S %z (%Z)")) ke, 04 tammi? 2012 15:03:21 +0200 (EET) The apparent intent is to make all month abbreviations equally long (six characters). Marko From ether.joe at gmail.com Wed Jan 4 09:30:39 2012 From: ether.joe at gmail.com (Sean Wolfe) Date: Wed, 4 Jan 2012 11:30:39 -0300 Subject: python philosophical question - strong vs duck typing In-Reply-To: <87wr98zaiy.fsf@benfinney.id.au> References: <87wr98zaiy.fsf@benfinney.id.au> Message-ID: On Tue, Jan 3, 2012 at 7:28 PM, Ben Finney wrote: > Sean Wolfe writes: > >> Hello everybody, I'm a happy pythonista newly subscribed to the group. > > Welcome! Thanks! and thanks to all, hjaha. > >> I have a theoretical / philosophical question regarding strong vs duck >> typing in Python. Let's say we wanted to type strongly in Python > > There may be an unstated assumption there, and your wording confuses me. > yep, probably. I am throwing around terminology a bit. Here's another attempt --> If I am willing to create some python code, when needed, where when I create a variable, let's say an integer, that it will be for all time an integer, and also that a method that returns say a Sprite custom object, and will for all time return only a Sprite object ... , does this get me significantly closer to being able to compile to C++? I am just thinking in my brain about the differences between cpp and python, and if there is a way to compromise a bit on the python-ness to get closer to cpp, but still be able to keep a lot of the goodness, then put in a translator or converter to cpp and gain performance by using cpp code. Sounds like Rpython, cython, shedskin are doing a lot or all of this, so lots to study up on. > > ?Strongly-typed? is one end of a spectrum whose opposite end is > ?weakly-typed?. Weakly-typed objects are in languages like e.g. PHP, > where an integer object can be added to a string object. Ah ok, I didn't realize this distinction. Now I grok it a bit better. > Python does not have variables in the sense of languages like C; rather, > Python has references bound to objects. A reference (e.g. a name, or a > list index, etc.) never has a type. An object always has a type. yeah I've been learning a lot about this ... at times I have to 're-create' a variable to avoid modifying the original value as well. For example, when I pass a 'screen' object in my game, at times I have to duplicate the screen in the new method, then work on the duplicate, otherwise I will be using the original screen by reference. > You may be thinking of ?static typing? (identifiers have types, and > won't allow themselves to refer to an object of a different type), > versus ?dynamic typing? (identifiers are ignorant of types ? this is > what you have in Python). Yep I think so. Thanks for the info all! From mbadoiu at gmail.com Wed Jan 4 09:35:42 2012 From: mbadoiu at gmail.com (Mihai Badoiu) Date: Wed, 4 Jan 2012 09:35:42 -0500 Subject: pipe into preallocated buffer? Message-ID: is there a way to pipe directly into a preallocated buffer? (subprocessing.pipe.stdout) thanks, --mihai -------------- next part -------------- An HTML attachment was scrubbed... URL: From bthiell at cfa.harvard.edu Wed Jan 4 09:57:56 2012 From: bthiell at cfa.harvard.edu (Benoit Thiell) Date: Wed, 4 Jan 2012 09:57:56 -0500 Subject: Large list in memory slows Python In-Reply-To: References: Message-ID: On Tue, Jan 3, 2012 at 5:59 PM, Peter Otten <__peter__ at web.de> wrote: > Benoit Thiell wrote: > >> I am experiencing a puzzling problem with both Python 2.4 and Python >> 2.6 on CentOS 5. I'm looking for an explanation of the problem and >> possible solutions. Here is what I did: >> >> Python 2.4.3 (#1, Sep 21 2011, 19:55:41) >> IPython 0.8.4 -- An enhanced Interactive Python. >> >> In [1]: def test(): >> ? ?...: ? ? return [(i,) for i in range(10**6)] >> >> In [2]: %time x = test() >> CPU times: user 0.82 s, sys: 0.04 s, total: 0.86 s >> Wall time: 0.86 s >> >> In [4]: big_list = range(50 * 10**6) >> >> In [5]: %time y = test() >> CPU times: user 9.11 s, sys: 0.03 s, total: 9.14 s >> Wall time: 9.15 s >> >> As you can see, after creating a list of 50 million integers, creating >> the same list of 1 million tuples takes about 10 times longer than the >> first time. >> >> I ran these tests on a machine with 144GB of memory and it is not >> swapping. Before creating the big list of integers, IPython used 111MB >> of memory; After the creation, it used 1664MB of memory. > > In older Pythons the heuristic used to decide when to run the cyclic garbage > collection is not well suited for the creation of many objects in a row. > Try switching it off temporarily with > > import gc > gc.disable() > # create many objects that are here to stay > gc.enable() > > You may also encorporate that into your test function: > > def test(): > ? ?gc.disable() > ? ?try: > ? ? ? ?return [...] > ? ?finally: > ? ? ? ?gc.enable() Thanks Peter, this is very helpful. Modifying my test according to your directions produced much more consistent results. Benoit. -- Benoit Thiell The SAO/NASA Astrophysics Data System http://adswww.harvard.edu/ From krissteegmans at gmail.com Wed Jan 4 10:46:19 2012 From: krissteegmans at gmail.com (Kris) Date: Wed, 4 Jan 2012 07:46:19 -0800 (PST) Subject: Program blocked in Queue.Queue.get and Queue.Queue.put Message-ID: <79715c61-4977-4075-bc76-6edadf62a464@dp8g2000vbb.googlegroups.com> I have a program that is blocked and all threads are blocked on a Queue.Queue.get or Queue.Queue.put method (on the same Queue.Queue object). 1 thread shows the below as its last entry in the stack: File: "c:\python27\lib\Queue.py", line 161, in get self.not_empty.acquire() 2 threads show the below as its last entry in the stack: File: "c:\python27\lib\Queue.py", line 118, in put self.not_full.acquire() According to me, this means both the Queue.Queue.not_full and Queue.Queue.not_empty locks are taken, but no other thread seems to have it. Of course, I don't access the locks my self directly. I did send an KeyboardInterrupt to the main thread however. Could it be that it was at that moment doing a Queue.Queue.put and it got interrupted while it has the lock, but before it entered the try block with the finally that releases the lock (so between line 118 and 119 in the Queue.py file)? If this is the case, how do I avoid that? Or is it a bug in the Queue.Queue class? If this is not the case, any clue what else could have happened? Thanks From ether.joe at gmail.com Wed Jan 4 10:56:18 2012 From: ether.joe at gmail.com (Sean Wolfe) Date: Wed, 4 Jan 2012 12:56:18 -0300 Subject: help me get excited about python 3 Message-ID: I am still living in the 2.x world because all the things I want to do right now in python are in 2 (django, pygame). But I want to be excited about the future of the language. I understand the concept of needing to break backwards compatibility. But it's not particularly exciting to think about. What are the cool new bits I should be reading up on? Related reading ... http://lucumr.pocoo.org/2011/12/7/thoughts-on-python3 [Zaphod] Hey, Marvin! We've got a job for you. [Marvin] I won't enjoy it. [Zaphod] Yes, you will. There's a whole new life stretching out in front of you! [Marvin] Oh, not another one! [Zaphod] Shut up and listen! There'll be excitement and adventure and really wild things! [Marvin] Sounds awful. [Zaphod] But, Marvin ... [Marvin] I suppose you want me to help you to get into this spaceship ... [Zaphod] Marvin, will you just listen! [Marvin] ... and open the door for you. [Zaphod] What? Er ... Yeah. [Marvin] Well, I wish you'd just tell me, rather than try to engage my enthusiasm, because I haven't got one. -- A musician must make music, an artist must paint, a poet must write, if he is to be ultimately at peace with himself. - Abraham Maslow From edriscoll at wisc.edu Wed Jan 4 11:15:03 2012 From: edriscoll at wisc.edu (Evan Driscoll) Date: Wed, 04 Jan 2012 10:15:03 -0600 Subject: python philosophical question - strong vs duck typing In-Reply-To: References: Message-ID: <4F047B07.6060907@wisc.edu> On 1/4/2012 12:37 AM, Terry Reedy wrote: > > Using induction, I can prove, for instance, that these two functions > [snip] > are equivalent, assuming enough stack and normal procedural Python > semantics. (And assuming no typos ;-). YOU proved that; your type system didn't. With a powerful enough type system, those two functions would have the same type, while if you had made a typo they wouldn't. The extreme example of a powerful type system is something like Coq or Elf. In a language like that, a mathematical sentence is encoded in a type, and "objects" of a certain type represent a proof that that the sentence can be proved. Evan From someone at someplace.invalid Wed Jan 4 11:43:26 2012 From: someone at someplace.invalid (HoneyMonster) Date: Wed, 4 Jan 2012 16:43:26 +0000 (UTC) Subject: Newbie Help References: Message-ID: On Tue, 03 Jan 2012 17:13:17 -0600, mixolydian wrote: > I want to get into Python progamming for both local database > applications and dynamic web pages. Maybe some Q&D scripts. I am new to Python too, and recently completed my first "real" cross- platform GUI application with local/remote database access. I concur with the other replies. I see no need for an IDE and wholeheartedly recommend PostgreSQL (which integrates with Python very well indeed using Psycopg 2). I have found wxPython best for GUI. There is even a source code generator available for the graphical bits of the application - wxGlade. I was able to get up to speed very easily and quickly indeed (though of course there is a great deal more to learn). These tools are all FOSS. From tim.wintle at teamrubber.com Wed Jan 4 12:01:00 2012 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Wed, 04 Jan 2012 17:01:00 +0000 Subject: python philosophical question - strong vs duck typing In-Reply-To: References: <87wr98zaiy.fsf@benfinney.id.au> Message-ID: <1325696460.11293.21.camel@tim-laptop> On Wed, 2012-01-04 at 11:30 -0300, Sean Wolfe wrote: > On Tue, Jan 3, 2012 at 7:28 PM, Ben Finney wrote: > > Sean Wolfe writes: > > > >> Hello everybody, I'm a happy pythonista newly subscribed to the group. > > > > Welcome! > > Thanks! and thanks to all, hjaha. > > > > >> I have a theoretical / philosophical question regarding strong vs duck > >> typing in Python. Let's say we wanted to type strongly in Python > > > > There may be an unstated assumption there, and your wording confuses me. > > > > yep, probably. I am throwing around terminology a bit. Here's another > attempt --> > > If I am willing to create some python code, when needed, where when I > create a variable, let's say an integer, that it will be for all time > an integer, and also that a method that returns say a Sprite custom > object, and will for all time return only a Sprite object ... , does > this get me significantly closer to being able to compile to C++? I'd really recommend looking at Cython - which has optional static typing and does compile into C / C++ (as a python extension) More generally, a compiler can perform static analysis on code which will re-order AST nodes into single constant assignments. I've forgotten the name but it's something like single static assignment form. When the return type of functions is known it can lead to known types for variables. It's being used heavily in the newest generation of javascript JITs to speed up generated native code. However, when a function has multiple return types (e.g. {}.get returns None if there is no result) then you can't imply the type of the variable even in this form. A JIT (such as pypy) can generate the native code for all seen return types - which is why JITs can in general be more useful to dynamically typed languages such as Python than compilers. Another issue is where types can be modified (e.g. in python you can modify the class of an object at runtime) - dynamic language features such as this make what counts as a "type" fairly flexible. JITs are getting around this using "hidden classes" (there are lots of other names for the same thing) - again it would be very difficult to statically compile this kind of thing to native code. > I am just thinking in my brain about the differences between cpp and > python, and if there is a way to compromise a bit on the python-ness > to get closer to cpp, but still be able to keep a lot of the goodness, > then put in a translator or converter to cpp and gain performance by > using cpp code. Sounds like Rpython, cython, shedskin are doing a lot > or all of this, so lots to study up on. Yup Tim Wintle From ian.g.kelly at gmail.com Wed Jan 4 13:20:18 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 4 Jan 2012 11:20:18 -0700 Subject: help me get excited about python 3 In-Reply-To: References: Message-ID: On Wed, Jan 4, 2012 at 8:56 AM, Sean Wolfe wrote: > I am still living in the 2.x world because all the things I want to do > right now in python are in 2 (django, pygame). But I want to be > excited about the future of the language. I understand the concept of > needing to break backwards compatibility. But it's not particularly > exciting to think about. What are the cool new bits I should be > reading up on? pygame is available for Python 3. I've used it a small amount, and it appears to work just fine. There is also a fork of Django that supports Python 2 and Python 3 in a single codebase: https://bitbucket.org/vinay.sajip/django/ It's still experimental right now, but that doesn't mean you couldn't try it out. The expectation is that it will be merged for the Django 1.5 release. From ian.g.kelly at gmail.com Wed Jan 4 13:39:46 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 4 Jan 2012 11:39:46 -0700 Subject: Spamming PyPI with stupid packages In-Reply-To: References: <87hb0d28j8.fsf@benfinney.id.au> <87aa6522au.fsf@benfinney.id.au> <4f02ba8d$0$29880$c3e8da3$5496439d@news.astraweb.com> <8762gs1mag.fsf@benfinney.id.au> <4f03ad75$0$11122$c3e8da3@news.astraweb.com> <878vloz0zi.fsf@benfinney.id.au> <4f03b3b6$0$11122$c3e8da3@news.astraweb.com> <87pqf0b33c.fsf@benfinney.id.au> Message-ID: On Tue, Jan 3, 2012 at 7:50 PM, Tony Pelletier wrote: > Honestly, is this list really what this is all about? ?I'm bored already... Sorry, this list does not exist for your personal entertainment. Maybe you should try YouTube. And no, it's not really about sexism either, but there is no harm in the occasional educational rant. Kudos to Ben for fighting the good fight! From ian.g.kelly at gmail.com Wed Jan 4 14:28:36 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 4 Jan 2012 12:28:36 -0700 Subject: Spamming PyPI with stupid packages In-Reply-To: References: <87hb0d28j8.fsf@benfinney.id.au> <87aa6522au.fsf@benfinney.id.au> <4f02ba8d$0$29880$c3e8da3$5496439d@news.astraweb.com> <8762gs1mag.fsf@benfinney.id.au> <4f03ad75$0$11122$c3e8da3@news.astraweb.com> <878vloz0zi.fsf@benfinney.id.au> <4f03b3b6$0$11122$c3e8da3@news.astraweb.com> <87pqf0b33c.fsf@benfinney.id.au> Message-ID: On Wed, Jan 4, 2012 at 11:45 AM, Tony Pelletier wrote: > That's a rather ironic comment. ?Idiot. Really? Which part was ironic? >> Sorry, this list does not exist for your personal entertainment. Not this one, that's just a statement of fact. >> Maybe you should try YouTube. Kinda. What I really meant here was "Maybe you should just go away", but that is not really in opposition with what I actually said, so it's not technically irony either, just mild understatement. >> And no, it's not really about sexism either, Literal statement of fact. >> but there is no harm in the occasional educational rant. Literal statement of opinion. >> Kudos to Ben for fighting the good fight! And I meant that 100%. Also not ironic. ... Oh, wait, I get it now. Your post was ironically self-referential. "Clever!" By the way, take a constructive suggestion and stop top-posting. Bottom-posting is the commonly preferred style around these parts. http://en.wikipedia.org/wiki/Posting_style#Top-posting Cheers [irony!], Ian From tony.pelletier at gmail.com Wed Jan 4 14:36:39 2012 From: tony.pelletier at gmail.com (Tony Pelletier) Date: Wed, 4 Jan 2012 14:36:39 -0500 Subject: Spamming PyPI with stupid packages In-Reply-To: References: <87hb0d28j8.fsf@benfinney.id.au> <87aa6522au.fsf@benfinney.id.au> <4f02ba8d$0$29880$c3e8da3$5496439d@news.astraweb.com> <8762gs1mag.fsf@benfinney.id.au> <4f03ad75$0$11122$c3e8da3@news.astraweb.com> <878vloz0zi.fsf@benfinney.id.au> <4f03b3b6$0$11122$c3e8da3@news.astraweb.com> <87pqf0b33c.fsf@benfinney.id.au> Message-ID: I have zero desire to follow the rules of a Python(here's the ironic part. Get it now clever boy?) list when it'd riddled with childish banter that has nothing to do with........ wait for it......................... Python? Do I need to explain it any further? I'm done with you and this list that pollutes my inbox with globs of worthlessness... On Wed, Jan 4, 2012 at 2:28 PM, Ian Kelly wrote: > On Wed, Jan 4, 2012 at 11:45 AM, Tony Pelletier > wrote: > > That's a rather ironic comment. Idiot. > > Really? Which part was ironic? > > >> Sorry, this list does not exist for your personal entertainment. > > Not this one, that's just a statement of fact. > > >> Maybe you should try YouTube. > > Kinda. What I really meant here was "Maybe you should just go away", > but that is not really in opposition with what I actually said, so > it's not technically irony either, just mild understatement. > > >> And no, it's not really about sexism either, > > Literal statement of fact. > > >> but there is no harm in the occasional educational rant. > > Literal statement of opinion. > > >> Kudos to Ben for fighting the good fight! > > And I meant that 100%. Also not ironic. > > ... > > Oh, wait, I get it now. Your post was ironically self-referential. > "Clever!" > > By the way, take a constructive suggestion and stop top-posting. > Bottom-posting is the commonly preferred style around these parts. > http://en.wikipedia.org/wiki/Posting_style#Top-posting > > Cheers [irony!], > Ian > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Wed Jan 4 15:08:02 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 4 Jan 2012 13:08:02 -0700 Subject: Spamming PyPI with stupid packages In-Reply-To: References: <87hb0d28j8.fsf@benfinney.id.au> <87aa6522au.fsf@benfinney.id.au> <4f02ba8d$0$29880$c3e8da3$5496439d@news.astraweb.com> <8762gs1mag.fsf@benfinney.id.au> <4f03ad75$0$11122$c3e8da3@news.astraweb.com> <878vloz0zi.fsf@benfinney.id.au> <4f03b3b6$0$11122$c3e8da3@news.astraweb.com> <87pqf0b33c.fsf@benfinney.id.au> Message-ID: On Wed, Jan 4, 2012 at 12:36 PM, Tony Pelletier wrote: > I have zero desire to follow the rules of a Python(here's the ironic part. > Get it now clever boy?) list when it'd riddled with childish banter that has > nothing to do with........ wait for it......................... Python? Fair enough. If this thread and this exchange were actually representative of the list, I wouldn't want to waste my time with it either. From lucasvickers at gmail.com Wed Jan 4 15:09:51 2012 From: lucasvickers at gmail.com (Lucas Vickers) Date: Wed, 4 Jan 2012 15:09:51 -0500 Subject: Typed python comparison / code analysis questions Message-ID: Hello, I'm relatively new to Python. I come from C/C++ so I love the flexibility but I am slightly irked by the lack of compilation time checking. I've got two questions 1) Are there any tools that do an analysis of code and attempt to catch potential issues such as undefined variables, etc? I use xdebug in php for this purpose and it's a life saver. Currently for Python I use module test cases and simulate situations but this doesn't catch everything and on a larger scale of development becomes difficult. 2) Is there a way to error when comparing variables of different types? I was up late last night coding and caused a few bugs with the below code, which turns out to compare a type to a type. I know good programming I should know what my variable types are, but it would be even better if I could always abide by a rule of using <_ (or something) which would spit an exception when comparing non-equal types/instances. rows = pamss.conn.fetchRows(results) count = rows[0]['cases'] // should be int(rows[0]['cases']) return count < MAX_CONCURRENT_IVR thanks! Lucas -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Jan 4 15:22:03 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 04 Jan 2012 15:22:03 -0500 Subject: python philosophical question - strong vs duck typing In-Reply-To: References: Message-ID: On 1/4/2012 1:37 AM, Terry Reedy wrote: > On 1/3/2012 8:04 PM, Devin Jeanpierre wrote: >> [ An example of a simple dependently typed program: >> http://codepad.org/eLr7lLJd ] > > Just got it after a minute delay. A followup now that I have read it. Removing the 40 line comment, the function itself is fun getitem{n,m:nat}(arr : array(int, n) , length : int(n), index : int m) : int = if index < length then arr[index] else ~1 (* -1, error *) where n,m are compiler variables used to define the dependent (paramaterized) types array(int,n) and int(n)/ The double use of n means that the compiler checks that length n of the array equals the length passed. My response: in Python, there is no need to pass concrete collection sizes because they are packaged with the collection at runtime as an attribute. So: 1) In Python, there is no need for such checking. In addition, the for-loop construct, 'for item in iterable:', removes the possibility of indexing errors. 2) Python classes are, in a sense, or in effect, runtime dependent types. While the formal implementation type of a 'list' is just 'list', the effective computation type is 'mutable sequence of length n'. The type of an iterator is 'read-only sequence of indefinite length'. I find this an interesting way to look at Python. -- Terry Jan Reedy From ben+python at benfinney.id.au Wed Jan 4 15:26:40 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 05 Jan 2012 07:26:40 +1100 Subject: Newbie Help References: <87fwfwz4ly.fsf@benfinney.id.au> Message-ID: <87vcor9ptr.fsf@benfinney.id.au> Ben Finney writes: > * Cross-platform, so that you're not denied the use of any popular > workstation OS. > > For my purposes, either { GNU Screen + Bash + Emacs } or { GNU Screen + > Bash + Vim } are good choices satisfying all the above criteria. There > may be other good combinations. I slightly mis-spoke. Obviously GNU Screen and Bash are only truly available on Unix-like operating systems. But that's pretty much all of the popular workstation OSes except one. GNU Emacs and Vim are truly available on every popular workstation OS. Learn one of them well, and you will be able to take on the diversity of programming tasks much easier. -- \ ?A lot of people are afraid of heights. Not me, I'm afraid of | `\ widths.? ?Steven Wright | _o__) | Ben Finney From ian.g.kelly at gmail.com Wed Jan 4 15:34:23 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 4 Jan 2012 13:34:23 -0700 Subject: Typed python comparison / code analysis questions In-Reply-To: References: Message-ID: On Wed, Jan 4, 2012 at 1:09 PM, Lucas Vickers wrote: > Hello, > > I'm relatively new to Python. ?I come from C/C++ so I love the flexibility > but I am slightly irked by the lack of compilation time checking. > > I've got two questions > 1) Are there any tools that do an analysis of code and attempt to catch > potential issues such as undefined variables, etc? ?I use xdebug in php for > this purpose and it's a life saver. ?Currently for Python I use module test > cases and simulate situations but this doesn't catch everything and on a > larger scale of development becomes difficult. Yes, try pylint, pychecker, or pyflakes. > 2) Is there a way to error when comparing variables of different types? ?I > was up late last night coding and caused a few bugs with the below code, > which turns out to compare a type to a type. ?I know good > programming I should know what my variable types are, but it would be even > better if I could always abide by a rule of using <_ (or something) which > would spit an exception when comparing non-equal types/instances. This is a well-known wart in Python 2. The recommended solution would be to upgrade to Python 3, which no longer allows ordered comparisons between unrelated built-in types. Cheers, Ian From rosuav at gmail.com Wed Jan 4 15:38:03 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Jan 2012 07:38:03 +1100 Subject: Typed python comparison / code analysis questions In-Reply-To: References: Message-ID: On Thu, Jan 5, 2012 at 7:09 AM, Lucas Vickers wrote: > 2) Is there a way to error when comparing variables of different types? Yep. Use Python version 3. >>> 1<"1" Traceback (most recent call last): File "", line 1, in 1<"1" TypeError: unorderable types: int() < str() Chris Angelico From lucasvickers at gmail.com Wed Jan 4 15:42:05 2012 From: lucasvickers at gmail.com (Lucas Vickers) Date: Wed, 4 Jan 2012 15:42:05 -0500 Subject: Typed python comparison / code analysis questions In-Reply-To: References: Message-ID: Thank you! At the moment python3 isn't an option. There's a variety of dependencies I'm working around. Is there any type of 2.x add-on? either way thanks for the info L On Wed, Jan 4, 2012 at 3:34 PM, Ian Kelly wrote: > On Wed, Jan 4, 2012 at 1:09 PM, Lucas Vickers > wrote: > > Hello, > > > > I'm relatively new to Python. I come from C/C++ so I love the > flexibility > > but I am slightly irked by the lack of compilation time checking. > > > > I've got two questions > > 1) Are there any tools that do an analysis of code and attempt to catch > > potential issues such as undefined variables, etc? I use xdebug in php > for > > this purpose and it's a life saver. Currently for Python I use module > test > > cases and simulate situations but this doesn't catch everything and on a > > larger scale of development becomes difficult. > > Yes, try pylint, pychecker, or pyflakes. > > > > > 2) Is there a way to error when comparing variables of different types? > I > > was up late last night coding and caused a few bugs with the below code, > > which turns out to compare a type to a type. I know good > > programming I should know what my variable types are, but it would be > even > > better if I could always abide by a rule of using <_ (or something) which > > would spit an exception when comparing non-equal types/instances. > > This is a well-known wart in Python 2. The recommended solution would > be to upgrade to Python 3, which no longer allows ordered comparisons > between unrelated built-in types. > > Cheers, > Ian > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pils at invalid.ca Wed Jan 4 15:48:36 2012 From: pils at invalid.ca (PiLS) Date: Wed, 4 Jan 2012 20:48:36 +0000 (UTC) Subject: Spamming PyPI with stupid packages References: <4f03ab5b$0$11122$c3e8da3@news.astraweb.com> Message-ID: Le mar, 03 jan 2012 20:28:59, Steven D'Aprano a plopp?: > On Tue, 03 Jan 2012 05:08:47 -0800, Ethan Furman wrote: > > [...] >>> "maybe policing uploads is worse than cluttering PyPI's disk space and >>> RSS feed with dumb 1 KB packages." (Matt Chaput) >>> >>> I'd drop the "maybe". >> >> It's hard enough finding what one wants without having to wade through >> crap. PyPI is not the place for it. > > I agree. But who gets to choose which packages are "serious" enough to > deserve to be on PyPI? Or good enough? > > The cost of allowing anyone the freedom to publish their work is that > some published work will be crap. > > Besides, I find it hard to believe that the search facilities on PyPI are > so bad that there would be any searches that come up with "girlfriend.py" > or "car.py" as false positives. > > Seriously, the over-reaction here is something that has to be seen to be > believed. The original complaint is over a couple of entries in an RSS > feed and showing up on the front page of PyPI, perhaps a dozen words in > total. The reaction has been thousands of words arguing back and forth. > > +1 The "it objectifies wymyn" argument (back and forth) was particularly funny (in a insignificant nonsensical hollier-than-thou nitpicking way). I really was on the verge of pushing the plonk button a couple times (between spurts of uncontrollable laughter). If anything, I see the joke as derogatory to Python programmers; sadly, this very thread proves this view. Also, I find it disturbing that the wymyn-power knights in shiny armour identify a python module with a woman. If I nuke a Karmic Koala, will they rat me out to the WWF, to the UNODA, or to both? -- PiLS From arnodel at gmail.com Wed Jan 4 15:51:26 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 4 Jan 2012 20:51:26 +0000 Subject: Spamming PyPI with stupid packages In-Reply-To: References: <87hb0d28j8.fsf@benfinney.id.au> <87aa6522au.fsf@benfinney.id.au> <4f02ba8d$0$29880$c3e8da3$5496439d@news.astraweb.com> <8762gs1mag.fsf@benfinney.id.au> <4f03ad75$0$11122$c3e8da3@news.astraweb.com> <878vloz0zi.fsf@benfinney.id.au> <4f03b3b6$0$11122$c3e8da3@news.astraweb.com> <87pqf0b33c.fsf@benfinney.id.au> Message-ID: On 4 January 2012 20:08, Ian Kelly wrote: > On Wed, Jan 4, 2012 at 12:36 PM, Tony Pelletier > wrote: >> I have zero desire to follow the rules of a Python(here's the ironic part. >> Get it now clever boy?) list when it'd riddled with childish banter that has >> nothing to do with........ wait for it......................... Python? > > Fair enough. ?If this thread and this exchange were actually > representative of the list, I wouldn't want to waste my time with it > either. Sadly, my feeling is that the amount of vacuous discussions and hair-splitting debates is steadily increasing. Just to see, I had a look at the archives for July 2001 (because that's around the time I took up Python) and the list definitely had a more interesting feel to it. It also made me realise that many of the best contributors have gone or only make rare appearances. Anyway, there was little spam, but already some trolls, e.g. "Is Python Dead?" http://mail.python.org/pipermail/python-list/2001-July/091178.html Not everyone was convinced about PEP 238 (new semantics for "/"): http://mail.python.org/pipermail/python-list/2001-July/090659.html Did you change your mind, Terry? I too used to be against it :) I'll stop now. Cheers, -- Arnaud From rosuav at gmail.com Wed Jan 4 15:55:47 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Jan 2012 07:55:47 +1100 Subject: Spamming PyPI with stupid packages In-Reply-To: References: <4f03ab5b$0$11122$c3e8da3@news.astraweb.com> Message-ID: On Thu, Jan 5, 2012 at 7:48 AM, PiLS wrote: > If I nuke a Karmic Koala, will they rat me out to the WWF, to > the UNODA, or to both? Neither, actually. We'll be so glad you didn't call it a Karmic Koala Bear that we'll send you three American tourists for free. (They're actually quite delicious when properly prepared.) ChrisA From a24061 at ducksburg.com Wed Jan 4 16:15:33 2012 From: a24061 at ducksburg.com (Adam Funk) Date: Wed, 04 Jan 2012 21:15:33 +0000 Subject: UnicodeEncodeError when piping stdout, but not when printing directly to the console Message-ID: (I'm using Python 2.7.2+ on Ubuntu.) When I'm running my program in an xterm, the print command with an argument containing unicode works fine (it correctly detects my UTF-8 environment). But when I run it with a pipe or redirect to a file (| or >), unicode strings fail with the following (for example): UnicodeEncodeError: 'ascii' codec can't encode character u'\u0107' in position 21: ordinal not in range(128) How can I force python (preferably within my python program, rather than having to set something externally) to treat stdout as UTF-8? Thanks, Adam -- Nam Sibbyllam quidem Cumis ego ipse oculis meis vidi in ampulla pendere, et cum illi pueri dicerent: beable beable beable; respondebat illa: doidy doidy doidy. [plorkwort] From __peter__ at web.de Wed Jan 4 16:49:52 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 04 Jan 2012 22:49:52 +0100 Subject: UnicodeEncodeError when piping stdout, but not when printing directly to the console References: Message-ID: Adam Funk wrote: > (I'm using Python 2.7.2+ on Ubuntu.) > > When I'm running my program in an xterm, the print command with an > argument containing unicode works fine (it correctly detects my UTF-8 > environment). But when I run it with a pipe or redirect to a file (| > or >), unicode strings fail with the following (for example): > > UnicodeEncodeError: 'ascii' codec can't encode character u'\u0107' in > position 21: ordinal not in range(128) > > How can I force python (preferably within my python program, rather > than having to set something externally) to treat stdout as UTF-8? $ cat force_utf8.py # -*- coding: utf-8 -*- import sys if sys.stdout.encoding is None: import codecs writer = codecs.getwriter("utf-8") sys.stdout = writer(sys.stdout) print u"?hnlich ?blich n?tig" $ python force_utf8.py ?hnlich ?blich n?tig $ python force_utf8.py | cat ?hnlich ?blich n?tig From someone at someplace.invalid Wed Jan 4 16:54:21 2012 From: someone at someplace.invalid (HoneyMonster) Date: Wed, 4 Jan 2012 21:54:21 +0000 (UTC) Subject: Spamming PyPI with stupid packages References: <4f03ab5b$0$11122$c3e8da3@news.astraweb.com> Message-ID: On Wed, 04 Jan 2012 20:48:36 +0000, PiLS wrote: > If I nuke a Karmic Koala, will they rat me out to the WWF, to the > UNODA, or to both? Personally I'd be cheering for you, provided you also took out all the warthogs, hedgehogs, badgers, drakes, efts, fawns, gibbons, herons, ibexes, jackalopes, lynxes, meerkats, narwhals, ocelots and pangolins. From bahamutzero8825 at gmail.com Wed Jan 4 17:13:58 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 04 Jan 2012 16:13:58 -0600 Subject: help me get excited about python 3 In-Reply-To: References: Message-ID: <4F04CF26.8010906@gmail.com> On 1/4/2012 9:56 AM, Sean Wolfe wrote: > I am still living in the 2.x world because all the things I want to do > right now in python are in 2 (django, pygame). But I want to be > excited about the future of the language. I understand the concept of > needing to break backwards compatibility. But it's not particularly > exciting to think about. What are the cool new bits I should be > reading up on? All the cool new language features, of course. I've only started learning Python, so I haven't watched the "what's new" stuff for older versions (and therefore can't pull anything off the top of my head), but I am pretty excited for 3.3. The new exceptions, the LZMA module, support for cp65001 in Windows... http://docs.python.org/release/3.0.1/whatsnew/3.0.html http://docs.python.org/release/3.1.3/whatsnew/3.1.html http://docs.python.org/py3k/whatsnew/3.2.html http://docs.python.org/dev/whatsnew/3.3.html -- CPython 3.2.2 | Windows NT 6.1.7601.17640 From lperez at winterwyman.com Wed Jan 4 17:32:19 2012 From: lperez at winterwyman.com (Luis Perez) Date: 4 Jan 2012 17:32:19 -0500 Subject: Expert Advice Message-ID: <1289578618.1325716339324.JavaMail.cfservice@sl3app4> Hi Everyone, A number of friends in the community recommended i email this group regarding some obstacles im running into regarding a Python/Django dilemma :). Im currently representing a e-Plushing firm who has built an amazing custom ebook publishing platform in Django and Python. We are now looking for a Python engineer who has dabbled in NoSQL databases. This person will understand programming languages both static and dynamic typing. They offer a great work environment as they have a nice loft in Midtown in addition to challenging/custom work. Below i have included additional details if you know of anyone that might be interested. Ps. We have a great referral program as well. Our ebook publishing platform is built on Django and LAMP (for P in ['Python']) - and the demand is growing! We're looking for a senior software engineer who's passionate about building and shipping products that are great inside and out. As a senior team member, you'll ensure our product enjoys high-availability, scalability, and the other expected non-functional requirements through peer review and leveraging cloud infrastructure. You'll also support our journey towards continuous delivery inclusive of iterative development, automated testing (CI), modern configuration management using chef, and push-button deployments with confidence. About you: You love technology and good engineering as much as shipping great products - and deftly balance these concerns. You're a Python expert and code for fun. You've probably dabbled in NoSQL databases, know multiple programming languages both static and dynamic typing (and pros/cons of each), have tried a variety of web servers and frameworks, understand the power and challenges of different caching strategies, are a go-to for CS fundamentals, and contribute to open source projects. You constructively initiate improvements. You also don't shy away from Linux systems operations where it butts up against development concerns such as redundancy with auto-failover, efficient resource utilization, performance optimization, data management, apache configuration, application monitoring, log file aggregation (e.g., using scribe), security, capacity and scaling concerns - i.e., approaching devops from the development side. You enjoy being a hands-on individual contributor and also have great skills mentoring peers/colleagues - a team player who's well respected due to your technical abilities and willingness to help other team members without the ego. You thrive in a fast-paced yet thoughtful startup environment. Requirements 8+ years in software development in Linux - years of experience are necessary to design robust architectures Python expertise required - (open source) samples will be requested Experience building and maintaining distributed, scale-out, high performant web-based systems on Linux required Have solid CS and OO fundamentals Strong and effective communication skills including with remote team members Have created and consumed RESTful APIs Cloud experience with AWS or comparable required Iterative (agile) development experience required Must have a passion for automated testing Python web framework and MVC pattern usage required; Django a plus; built your own web framework a major plus Push-button deployment experience a plus Experience with Celery and RabbitMQ a plus Knowledge of ePub and HTML5 standards a plus Perks Fun coworkers, great mentors Convenient mid-town Manhattan "loft" Lots of fun with Apple products and ereaders luis perez | principal winter wyman companies - technology staffing tel: 212.616.3582| fax: 212.616.3592 | aim: lpcnn23 I Please consider the environment before printing this email -------------- next part -------------- An HTML attachment was scrubbed... URL: From peter.milliken at gmail.com Wed Jan 4 17:42:52 2012 From: peter.milliken at gmail.com (Peter) Date: Wed, 4 Jan 2012 14:42:52 -0800 (PST) Subject: can a subclass method determine if called by superclass? Message-ID: <13ac20bc-e8b0-4697-8dfd-9fa003af2a48@a17g2000yqj.googlegroups.com> Situation: I am subclassing a class which has methods that call other class methods (and without reading the code of the superclass I am discovering these by trial and error as I build the subclass - this is probably why I may have approached the problem from the wrong viewpoint :-)). Problem: when overriding one of these "indirectly called" superclass methods I would like to take differing actions (in the subclass instance) depending on whether it is the superclass or the subclass instance performing the call. Question: Is there any way to determine in a method whether it is being called by the superclass or by a method of the subclass instance? Now I suspect that what I am doing is actually very muddy thinking :-) and I don't want to attempt to explain why I am approaching the design this way as an explanation would require too much work - I will consider an alternative inheritance approach while waiting an answer, but the answer to the question interested me (even if I do a redesign and come up with a more "elegant" approach to the problem). Thanks Peter From ian.g.kelly at gmail.com Wed Jan 4 18:09:24 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 4 Jan 2012 16:09:24 -0700 Subject: can a subclass method determine if called by superclass? In-Reply-To: <13ac20bc-e8b0-4697-8dfd-9fa003af2a48@a17g2000yqj.googlegroups.com> References: <13ac20bc-e8b0-4697-8dfd-9fa003af2a48@a17g2000yqj.googlegroups.com> Message-ID: On Wed, Jan 4, 2012 at 3:42 PM, Peter wrote: > Situation: I am subclassing a class which has methods that call other > class methods (and without reading the code of the superclass I am > discovering these by trial and error as I build the subclass - this is > probably why I may have approached the problem from the wrong > viewpoint :-)). > > Problem: when overriding one of these "indirectly called" superclass > methods I would like to take differing actions (in the subclass > instance) depending on whether it is the superclass or the subclass > instance performing the call. > > Question: Is there any way to determine in a method whether it is > being called by the superclass or by a method of the subclass > instance? Well, you could get the previous stack level using traceback.extract_stack() and check the filename. But it sounds like what you actually have are two different methods -- one that is used by the superclass, and one that only the subclass knows about and uses. Why not implement it as such? From thudfoo at gmail.com Wed Jan 4 18:13:21 2012 From: thudfoo at gmail.com (xDog Walker) Date: Wed, 4 Jan 2012 15:13:21 -0800 Subject: Spamming PyPI with stupid packages In-Reply-To: <4f03ab5b$0$11122$c3e8da3@news.astraweb.com> References: <4f03ab5b$0$11122$c3e8da3@news.astraweb.com> Message-ID: <201201041513.21570.thudfoo@gmail.com> On Tuesday 2012 January 03 17:28, Steven D'Aprano wrote: > Besides, I find it hard to believe that the search facilities on PyPI are > so bad that there would be any searches that come up with "girlfriend.py" > or "car.py" as false positives. Try an author search for D'Aprano. -- I have seen the future and I am not in it. From soto_andres at yahoo.com Wed Jan 4 18:25:33 2012 From: soto_andres at yahoo.com (Andres Soto) Date: Wed, 4 Jan 2012 15:25:33 -0800 (PST) Subject: a little help Message-ID: <1325719533.2934.YahooMailNeo@web30605.mail.mud.yahoo.com> Hi, I am new using Python, although I have experience using other programming languages like Pascal, FORTRAN, C, Prolog, etc. I am using IDLE Editor for Python in coordination with the command line interface. My situation is the following: I am developing some code. I use the IDLE Editor to write it down. Then, I save it and import it from the command line interface, so it is already available from the prompt. Then I load (read) some data from files using that code. Let suppose that after that I make some changes in the code using again the IDLE Editor, save the program code, and?what else? The updated code is not already available from the command line interface. If I run the module, I lose the data already loaded (and it is a big amount). If I re-import it, the new code is not available Any suggestion? Thanks Andres? -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Jan 4 18:29:21 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Jan 2012 10:29:21 +1100 Subject: a little help In-Reply-To: <1325719533.2934.YahooMailNeo@web30605.mail.mud.yahoo.com> References: <1325719533.2934.YahooMailNeo@web30605.mail.mud.yahoo.com> Message-ID: On Thu, Jan 5, 2012 at 10:25 AM, Andres Soto wrote: > My situation is the following: I am developing some code. I use the IDLE > Editor to write it down. Then, I save it and import it from the command line > interface, so it is already available from the prompt. > Then I load (read) some data from files using that code. Let suppose that > after that I make some changes in the code using again the IDLE Editor, save > the program code, and?what else? The updated code is not already available > from the command line interface. If I run the module, I lose the data > already loaded (and it is a big amount). If I re-import it, the new code is > not available Re-importing modules is a bit messy. The usual way to do this sort of thing would be to run the program directly from the command line, and terminate it when you're done. Is there a particular reason for wanting to import it that way? Chris Angelico From peter.milliken at gmail.com Wed Jan 4 18:37:55 2012 From: peter.milliken at gmail.com (Peter) Date: Wed, 4 Jan 2012 15:37:55 -0800 (PST) Subject: can a subclass method determine if called by superclass? References: <13ac20bc-e8b0-4697-8dfd-9fa003af2a48@a17g2000yqj.googlegroups.com> Message-ID: On Jan 5, 10:09?am, Ian Kelly wrote: > > Well, you could get the previous stack level using > traceback.extract_stack() and check the filename. ?But it sounds like > what you actually have are two different methods -- one that is used > by the superclass, and one that only the subclass knows about and > uses. ?Why not implement it as such? Thanks Ian - that is one possibility. I am trying to create a subclass with slightly different functionality and use it with an existing code base i.e. there is already one or more modules that instantiate the current superclass and I want to just drop in this new class to replace it with no ripples up the line (so to speak). The new class implements some interface changes that can safely be hidden from the rest of the application. From rantingrickjohnson at gmail.com Wed Jan 4 18:40:29 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 4 Jan 2012 15:40:29 -0800 (PST) Subject: help me get excited about python 3 References: Message-ID: <9bf11353-db2d-4e9d-8528-42442d2dad5e@v14g2000yqh.googlegroups.com> On Jan 4, 9:56?am, Sean Wolfe wrote: > I am still living in the 2.x world because all the things I want to do > right now in python are in 2 (django, pygame). But I want to be > excited about the future of the language. Okay. So why not enjoy the best of both worlds (almost) and use version 2.7.2 along with "from __future__ import EVERYTHING". Your best course of action would be to write all code that can be written in Python 3000 IN Python 3000. If you must use Python 2.x because of dependencies, well then, you must. From rosuav at gmail.com Wed Jan 4 19:02:30 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Jan 2012 11:02:30 +1100 Subject: a little help In-Reply-To: <1325721417.64653.YahooMailNeo@web30608.mail.mud.yahoo.com> References: <1325719533.2934.YahooMailNeo@web30605.mail.mud.yahoo.com> <1325721417.64653.YahooMailNeo@web30608.mail.mud.yahoo.com> Message-ID: I think you meant to send that to the list; hope you don't mind my replying on-list. On Thu, Jan 5, 2012 at 10:56 AM, Andres Soto wrote: > the problem is that if I re-run the program, every time I change some > instructions, I have to read (load) again the data and that is what I want > to avoid. Is it possible? That's normal with Python, yes. Usually you'll find that it's more hassle than it's worth to try to modify code "live" like that; even in languages specifically designed with this feature in mind, there's a lot to keep track of. It may be worth writing your program to take a "snapshot" of current state (eg with the pickle module); this might be easier than re-parsing a complicated input data set. But that can be a lot of bother too, and usually in the end it's just not worthwhile. ChrisA From wuwei23 at gmail.com Wed Jan 4 19:23:06 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 4 Jan 2012 16:23:06 -0800 (PST) Subject: .format vs. % References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <5059220.15.1325605679953.JavaMail.geo-discussion-forums@prgi2> <1f627dea-fc65-4d64-a594-e4ca9aade96b@e2g2000vbb.googlegroups.com> <33065224.296.1325665538706.JavaMail.geo-discussion-forums@prh19> Message-ID: <843c22bc-2229-42a5-a1a8-47032a71be3b@d8g2000vbb.googlegroups.com> On Jan 4, 6:25?pm, 88888 Dihedral wrote: > > And what are you contributing to the situation other than > > misinformation and markov-generated spam? > > Do you know what can attract newbies to support python? I'm sure other people doing all the work for them would be a great attractor. Are you volunteering to work on this code generator? From soto_andres at yahoo.com Wed Jan 4 19:29:42 2012 From: soto_andres at yahoo.com (Andres Soto) Date: Wed, 4 Jan 2012 16:29:42 -0800 (PST) Subject: a little help In-Reply-To: References: <1325719533.2934.YahooMailNeo@web30605.mail.mud.yahoo.com> <1325721417.64653.YahooMailNeo@web30608.mail.mud.yahoo.com> Message-ID: <1325723382.2402.YahooMailNeo@web30608.mail.mud.yahoo.com> my mistake is because I have no problem to do that using Prolog which use an interpreter as Python. I thought that the variables in the main global memory space (associated with the command line environment) were kept, although the code that use it could change. As you explain me, Python behave like a compiled language: any time I make a change in the code, I have to "compile" it again, and re-run (and re-load the data). There is nothing to do. Thank you! Regards ? Prof. Dr.?Andr?s Soto DES DACI UNACAR >________________________________ > From: Chris Angelico >To: python-list at python.org >Sent: Wednesday, January 4, 2012 6:02 PM >Subject: Re: a little help > >I think you meant to send that to the list; hope you don't mind my >replying on-list. > >On Thu, Jan 5, 2012 at 10:56 AM, Andres Soto wrote: >> the problem is that if I re-run the program, every time I change some >> instructions, I have to read (load) again the data and that is what I want >> to avoid. Is it possible? > >That's normal with Python, yes. Usually you'll find that it's more >hassle than it's worth to try to modify code "live" like that; even in >languages specifically designed with this feature in mind, there's a >lot to keep track of. > >It may be worth writing your program to take a "snapshot" of current >state (eg with the pickle module); this might be easier than >re-parsing a complicated input data set. But that can be a lot of >bother too, and usually in the end it's just not worthwhile. > >ChrisA >-- >http://mail.python.org/mailman/listinfo/python-list > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Jan 4 19:32:19 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Jan 2012 11:32:19 +1100 Subject: a little help In-Reply-To: <1325723382.2402.YahooMailNeo@web30608.mail.mud.yahoo.com> References: <1325719533.2934.YahooMailNeo@web30605.mail.mud.yahoo.com> <1325721417.64653.YahooMailNeo@web30608.mail.mud.yahoo.com> <1325723382.2402.YahooMailNeo@web30608.mail.mud.yahoo.com> Message-ID: On Thu, Jan 5, 2012 at 11:29 AM, Andres Soto wrote: > my mistake is because I have no problem to do that using Prolog which use an > interpreter as Python. I thought that the variables in the main global > memory space (associated with the command line environment) were kept, > although the code that use it could change. > As you explain me, Python behave like a compiled language: any time I make a > change in the code, I have to "compile" it again, and re-run (and re-load > the data). There is nothing to do. Yeah. There are ways around it (there's a 'reload' function in Python 2, or 'imp.reload' in Python 3), but it's usually simpler and safer to fully restart. ChrisA From wise_jeff at verizon.net Wed Jan 4 20:30:51 2012 From: wise_jeff at verizon.net (Jeffrey Wise) Date: Wed, 4 Jan 2012 20:30:51 -0500 Subject: Trouble getting Python 2.7.2 to recognize Tk in Scientific Linux Release 6 Message-ID: <5384F30B54774506B38AFEDB2C9629F4@WillowLaptop> Hi, I've been a python user for a long time - on Windows, but now I'm working on a Linux system. I'm having trouble getting python to include Tk in it's build. My Tcl/Tk is in a non-standard location (I don't want to interfere with the Python 2.6 installation - that does include Tk until I have 2.7.2 running fully. I've read everything I can find about installing python in Linux, but to no avail. Can someone give me some advice on which file(s) to edit, "configure" arguments to add, etc.? Thanks! ...Jeff -------------- next part -------------- An HTML attachment was scrubbed... URL: From dihedral88888 at googlemail.com Wed Jan 4 20:41:20 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Wed, 4 Jan 2012 17:41:20 -0800 (PST) Subject: .format vs. % In-Reply-To: <843c22bc-2229-42a5-a1a8-47032a71be3b@d8g2000vbb.googlegroups.com> References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <5059220.15.1325605679953.JavaMail.geo-discussion-forums@prgi2> <1f627dea-fc65-4d64-a594-e4ca9aade96b@e2g2000vbb.googlegroups.com> <33065224.296.1325665538706.JavaMail.geo-discussion-forums@prh19> <843c22bc-2229-42a5-a1a8-47032a71be3b@d8g2000vbb.googlegroups.com> Message-ID: <15116626.24.1325727681094.JavaMail.geo-discussion-forums@prix23> alex23? 2012?1?5????UTC+8??8?23?06???? > On Jan 4, 6:25?pm, 88888 Dihedral > wrote: > > > And what are you contributing to the situation other than > > > misinformation and markov-generated spam? > > > > Do you know what can attract newbies to support python? > > I'm sure other people doing all the work for them would be a great > attractor. Are you volunteering to work on this code generator? I am working on the code generation problem in other applications. I could contribute some opinions about this problem. I think the BOA project is in the right direction. From steve+comp.lang.python at pearwood.info Wed Jan 4 21:18:21 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Jan 2012 02:18:21 GMT Subject: can a subclass method determine if called by superclass? References: <13ac20bc-e8b0-4697-8dfd-9fa003af2a48@a17g2000yqj.googlegroups.com> Message-ID: <4f05086c$0$29895$c3e8da3$5496439d@news.astraweb.com> On Wed, 04 Jan 2012 15:37:55 -0800, Peter wrote: > I am trying to create a subclass with slightly different functionality > and use it with an existing code base i.e. there is already one or > more modules that instantiate the current superclass and I want to > just drop in this new class to replace it with no ripples up the line > (so to speak). The new class implements some interface changes that > can safely be hidden from the rest of the application. This is *exactly* the idea behind subclassing. I don't understand your problem, can you explain more? If you want to change behaviour of an object, you subclass it, then override or overload the methods you want to change. You certainly shouldn't be changing the superclass to recognise when it is being called from a subclass! That's completely the wrong approach -- you should put all the new behaviour in the new class. # WRONG! Don't do this. class Parent(object): def method(self, arg): if type(self) is not Parent: # Must be a subclass. print("Called from a subclass. But which one?") print("Doing method stuff.") class Child(Parent): pass # RIGHT! Do this instead. class Parent(object): def method(self, arg): print("Doing method stuff.") class Child(Parent): def method(self, arg): # Overload an existing method. print("Called from Child subclass.") super().method(arg) # Python 3 only # Python 2 use: super(Child, self).method(arg) If method() returns a result, you can capture the result of calling the superclass method and then modify it as needed. Or you can override the method completely, and not call the parent method() at all. Now you can use Child() anywhere that you can use Parent and the caller shouldn't even notice. Or at least that is the idea behind subclassing, although it is possible to break it. You will be okay if the caller uses duck-typing, or isinstance checks, but not if they do exact type checks (which is almost always the wrong thing to do). c = Child() # Duck-typing works: hasattr(c, 'method') # returns True # So do isinstance checks: isinstance(c, Parent) # returns True # but this doesn't and defeats the purpose of having subclasses: type(c) is Parent # returns False, you shouldn't do this! If the caller does do exact type checks, then almost certainly it should be considered a bug in their code and they should be beaten with a clue- bat and told to use isinstance (good) or duck-typing (better still). If I have misunderstood your problem, can you give a concrete (but simple) example of what you are trying to do? -- Steven From edriscoll at wisc.edu Wed Jan 4 23:41:22 2012 From: edriscoll at wisc.edu (Evan Driscoll) Date: Wed, 04 Jan 2012 22:41:22 -0600 Subject: help me get excited about python 3 In-Reply-To: References: Message-ID: <4F0529F2.8070900@wisc.edu> On 1/4/2012 9:56 AM, Sean Wolfe wrote: > I am still living in the 2.x world because all the things I want to do > right now in python are in 2 (django, pygame). But I want to be > excited about the future of the language. I understand the concept of > needing to break backwards compatibility. But it's not particularly > exciting to think about. What are the cool new bits I should be > reading up on? This should be enough to convince you: ~ : python Python 2.7.1 (r271:86832, May 3 2011, 10:31:28) >>> 1 < "1" True ~ : python3 Python 3.2 (r32:88445, May 3 2011, 13:26:55) >>> 1 < "1" Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: int() < str() Maybe with Python 4, '1 < True' will give a TypeError too ;-). Or if that's not enough, ~ : python Python 2.7.1 (r271:86832, May 3 2011, 10:31:28) >>> True, False = False, True >>> "True is " + ("True" if True else "False") 'True is False' ~ : python3 Python 3.2 (r32:88445, May 3 2011, 13:26:55) >>> True, False = False, True File "", line 1 SyntaxError: assignment to keyword Evan From tjreedy at udel.edu Thu Jan 5 01:32:01 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 05 Jan 2012 01:32:01 -0500 Subject: a little help In-Reply-To: <1325723382.2402.YahooMailNeo@web30608.mail.mud.yahoo.com> References: <1325719533.2934.YahooMailNeo@web30605.mail.mud.yahoo.com> <1325721417.64653.YahooMailNeo@web30608.mail.mud.yahoo.com> <1325723382.2402.YahooMailNeo@web30608.mail.mud.yahoo.com> Message-ID: On 1/4/2012 7:29 PM, Andres Soto wrote: > As you explain me, Python behave like a compiled language: any time I > make a change in the code, I have to "compile" it again, and re-run (and > re-load the data). While you are developing a program and expect to make changes, you can try working with a small subset of a large dataset, so reloading is not too painful. -- Terry Jan Reedy From tjreedy at udel.edu Thu Jan 5 01:37:41 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 05 Jan 2012 01:37:41 -0500 Subject: Typed python comparison / code analysis questions In-Reply-To: References: Message-ID: On 1/4/2012 3:42 PM, Lucas Vickers wrote: > At the moment python3 isn't an option. There's a variety of > dependencies I'm working around. Please consider telling the authors of libraries you need that you would like a Python 3 version and say why. One reason given for not upgrading packages is 'lack of demand'. -- Terry Jan Reedy From speeze.pearson at gmail.com Thu Jan 5 02:54:49 2012 From: speeze.pearson at gmail.com (Spencer Pearson) Date: Wed, 4 Jan 2012 23:54:49 -0800 (PST) Subject: Adding an interface to existing classes References: <8f345777-1ef7-46dc-b3fb-a0bea5ebf2c3@r16g2000prr.googlegroups.com> Message-ID: (I'm sorry for my delayed response -- I've been travelling and not had reliable Internet access.) On 2011-12-25, Ian Kelly wrote: > On Thu, Dec 22, 2011 at 1:21 AM, Spencer Pearson > wrote: >> I see a problem with this, though. The intersection of two lines is >> (usually) an object of type Point. Since DrawableLine inherits from >> Line, this means that unless I redefine the "intersect" method in >> DrawableLine, the intersection of two DrawableLines will be a Point >> object, not a DrawablePoint. I don't want to saddle the user with the >> burden of converting every method output into its corresponding >> Drawable subclass, and I don't want to redefine every method to return >> an instance of said subclass. I see no other options if I continue >> down the subclassing path. Am I missing something? > > You could solve this with a factory. Instead of having > Line.intersection() create a Point directly, have it call > self.factory.create_point(). In the drawing module, replace the > factory for the subclasses with one that creates drawable classes > instead. Oh, that's a neat idea. Yes, I think that does exactly what I want! Thanks very much! > This will also work, but inheritance complicates things a > little. ... > ... Probably the easiest way to do this correctly is to follow the > MRO that Python has conveniently already built for you. Something > like: > > def draw(x, *args, **kwargs ): > for class_ in type(x).__mro__: > if class_ in draw_functions: > draw_functions[class_](*args, **kwargs) > break > else: > raise TypeError("don't know how to draw things of type " > "{0}".format(type(x))) You're right, you're right. My implementation was sloppy. I think I'll go with your factory solution, but thanks for the fixed version of draw() -- I've never seen __mro__ before, and it seems to be just the tool for this job! -Spencer From speeze.pearson at gmail.com Thu Jan 5 02:55:20 2012 From: speeze.pearson at gmail.com (Spencer Pearson) Date: Wed, 4 Jan 2012 23:55:20 -0800 (PST) Subject: Adding an interface to existing classes References: <8f345777-1ef7-46dc-b3fb-a0bea5ebf2c3@r16g2000prr.googlegroups.com> <256b9bcf-aa08-4d3e-9928-8fa9d335f1ff@e8g2000prb.googlegroups.com> Message-ID: <93f85e9e-ddb2-47c0-9e58-8234c7efc825@q11g2000vbq.googlegroups.com> On Dec 25 2011, 2:58?pm, Terry Reedy wrote: > On 12/24/2011 6:49 PM,SpencerPearsonwrote: > > > On Dec 23, 9:13 am, Terry Reedy ?wrote: > >> On 12/22/2011 3:21 AM,SpencerPearsonwrote: > > >>> I'm writing a geometry package, with Points and Lines and Circles and > >>> so on, and eventually I want to be able to draw these things on the > >>> screen. I have two options so far for how to accomplish this, but > >>> neither of them sits quite right with me, and I'd like the opinion of > >>> comp.lang.python's wizened elders. > > >>> Option 1. Subclassing. > >>> The most Pythonic way would seem to be writing subclasses for the > >>> things I want to display, adding a ".draw(...)" method to each one, > >>> like this: > > There are people who would advocate a Drawable base class with a virtual > or abstract .draw method and that DrawablePoint, etc, inherit from > Drawable and Point. > > >>> Option 2. A "draw" function, with a function dictionary. > > >> Option 3? Add a draw method to existing classes, rather than subclassing? > > Thanks for the response! Do you mean something like this? > > class Point(GeometricObject): > > ? ? ?def intersect(self, other): > > ? ? ? ? ?... > > I am interpreting this to mean that you have a world coordinate system > for instances that have location and size. > > > ? ? ?def union(self, other): > > ? ? ? ? ?... > > ? ? ?def draw(self, ...): > > ? ? ? ? ?... > > Yes. I would consider that Option 0, the default, unless you have good > reason to choose another. I would certainly include it on a list of options. > > > I'd like to avoid this, because... well, what I want is a geometry > > package, and it seems to me that whistles and bells like GUI support > > ought to be confined to subpackages. I'd look at this and think, "the > > rest of the Point class deals with fundamental geometric reality. > > What's this GUI method doing mixed in with my beautiful mathematical > > purity?" > > By default, all Python objects have a text representation method. I do > not see that giving all concrete geometric objects (with a location and > size) a visual representation is much different. I would use drawing > functions that accept the coordinates and distances of your geometry > world and translate to low-level pixel functions for a particular gui > system. I agree that your geometrical objects should not know about > pixels, screens, windows, and aspect ratios. > > ?> Is this the wrong attitude to take? > > It depends on *your* goal and values. > > > Or did you mean this? > > In file "geometry/gui.py": > > def draw_point(point, ...): > > ? ? ?... > > Point.draw = draw_point > > > I've never modified an existing class before, and I fear the > > unfamiliar. If that's what you meant... it's really an acceptable > > thing to do? > > Yes, in my opinion. The advantage of this is putting all the draw > methods together, and possibly having more than one one set. On the > other hand, one needs to know the data attributes of each class to > understand its draw method. > > > It seems like somebody might see "some_point.draw(...)" > > and be confused by the method's absence in the Point class definition. > > With either suboption, you should put an abstract .draw method in the > GeometricObject base class. > > I would look at various game, graph, geometry, and gui packages handle > drawing for more ideas. > > -- > Terry Jan Reedy (I'm sorry for my delayed response -- I've been travelling and not had reliable Internet access.) On 2011-12-25, Terry Reedy wrote: > There are people who would advocate a Drawable base class with a virtual > or abstract .draw method and that DrawablePoint, etc, inherit from > Drawable and Point. Yes... yes, that makes sense to me. > By default, all Python objects have a text representation method. I do > not see that giving all concrete geometric objects (with a location and > size) a visual representation is much different. I would use drawing > functions that accept the coordinates and distances of your geometry > world and translate to low-level pixel functions for a particular gui > system. I agree that your geometrical objects should not know about > pixels, screens, windows, and aspect ratios. Ha! Oh, I've been being silly. I was going to claim that since there is no standard Python GUI, I ought not chain myself to any one of the candidates. Then I learned that Tkinter comes standard with Python. Oops. All right, now that I know that, the comparison to having a text representation seems very reasonable. I'll definitely reconsider making the draw() method a requirement for all GeometricObjects. >> I've never modified an existing class before, and I fear the >> unfamiliar. If that's what you meant... it's really an acceptable >> thing to do? > > Yes, in my opinion. The advantage of this is putting all the draw > methods together, and possibly having more than one one set. On the > other hand, one needs to know the data attributes of each class to > understand its draw method. > >> It seems like somebody might see "some_point.draw(...)" >> and be confused by the method's absence in the Point class definition. > > With either suboption, you should put an abstract .draw method in the > GeometricObject base class. Sure, sure. I'm comfortable with this way of doing things now. Thanks so much for all your help! -Spencer From speeze.pearson at gmail.com Thu Jan 5 02:56:29 2012 From: speeze.pearson at gmail.com (Spencer Pearson) Date: Wed, 4 Jan 2012 23:56:29 -0800 (PST) Subject: Adding an interface to existing classes References: <8f345777-1ef7-46dc-b3fb-a0bea5ebf2c3@r16g2000prr.googlegroups.com> <22ea371a-f282-4d81-89f6-bc3229e2e8b1@a17g2000yqj.googlegroups.com> <4ef712c0$0$29973$c3e8da3$5496439d@news.astraweb.com> <4ef724d4$0$29973$c3e8da3$5496439d@news.astraweb.com> <4ef72927$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: (I'm sorry for my delayed response -- I've been travelling and not had reliable Internet access.) >> Spencer, i would re-think this entire project from the >> beginning. You are trying to make an object out of everything. You >> don't need to make an object of EVERYTHING. > > Very true. I'm not sure I understand. Surely you're not both saying that I shouldn't write a Point class? Here's an expression I'd like very much to be able to type: sphere1.intersect(sphere2).rotated(angle, axis) If I represented points with something already defined, maybe a tuple or a numpy array, then that would risk that the spheres were tangent, that their intersection was not a Circle (a GeometricObject, with a .rotated method), but a point (a tuple, without one). On 2011-12-25, Steven D'Aprano wrote: > class Line: > intersection_kind = Point > def intersection(self, other): > blah() > return self.intersection_kind(a, b) > > class DrawableLine(Line): > intersection_kind = DrawablePoint If I objected that the intersection of two Lines might, once in a blue moon, be a Line (because they're the same line), this seems like it would edge towards the factory solution that Ian Kelly suggested (i.e. not "return self.intersection_kind(...)", but "return self.factory.create_point(...)" or something similar). Is that so? -Spencer From rurpy at yahoo.com Thu Jan 5 03:05:16 2012 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Thu, 5 Jan 2012 00:05:16 -0800 (PST) Subject: argparse missing optparse capabilities? Message-ID: <84bd6e5a-1849-43dd-a633-7233efee89c4@f11g2000yql.googlegroups.com> I have optparse code that parses a command line containing intermixed positional and optional arguments, where the optional arguments set the context for the following positional arguments. For example, myprogram.py arg1 -c33 arg2 arg3 -c44 arg4 'arg1' is processed in a default context, 'args2' and 'arg3' in context '33', and 'arg4' in context '44'. I am trying to do the same using argparse but it appears to be not doable in a documented way. Here is the working optparse code (which took 30 minutes to write using just the optparse docs): import optparse def append_with_pos (option, opt_str, value, parser): if getattr (parser.values, option.dest, None) is None: setattr (parser.values, option.dest, []) getattr (parser.values, option.dest).append ((value, len (parser.largs))) def opt_parse(): p = optparse.OptionParser() p.add_option ("-c", type=int, action='callback', callback=append_with_pos) opts, args = p.parse_args() return args, opts if __name__ == '__main__': args, opts = opt_parse() print args, opts Output from the command line above: ['arg1', 'arg2', 'arg3', 'arg4'] {'c': [(33, 1), (44, 3)]} The -c values are stored as (value, arglist_position) tuples. Here is an attempt to convert to argparse using the guidelines in the argparse docs: import argparse class AppendWithPos (argparse.Action): def __call__ (self, parser, namespace, values, option_string=None): if getattr (namespace, self.dest, None) is None: setattr (namespace, self.dest, []) getattr (namespace, self.dest).extend ((values, len (parser.largs))) def arg_parse(): p = argparse.ArgumentParser (description='description') p.add_argument ('src', nargs='*') p.add_argument ('-c', type=int, action=AppendWithPos) opts = p.parse_args() return opts if __name__ == '__main__': opts = arg_parse() print opts This fails with, AttributeError: 'ArgumentParser' object has no attribute 'largs' and of course, the argparse.parser is not documented beyond how to instantiate it. Even were that not a problem, argparse complains about "unrecognised arguments" for any positional arguments that occur after an optional one. I've been farting with this code for a day now. Any suggestions on how I can convince argparse to do what optparse does easily will be very welcome. (I tried parse_known_args() but that breaks help and requires me to detect truly unknown arguments.) (Python 2.7.1 if it matters and apologies if Google mangles the formatting of this post.) From rurpy at yahoo.com Thu Jan 5 03:26:56 2012 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Thu, 5 Jan 2012 00:26:56 -0800 (PST) Subject: argparse missing optparse capabilities? References: <84bd6e5a-1849-43dd-a633-7233efee89c4@f11g2000yql.googlegroups.com> Message-ID: On Jan 5, 1:05?am, "ru... at yahoo.com" wrote: > ? class AppendWithPos (argparse.Action): > ? ? def __call__ (self, parser, namespace, values, > option_string=None): > ? ? ? ? if getattr (namespace, self.dest, None) is None: > ? ? ? ? ? ? setattr (namespace, self.dest, []) > ? ? ? ? getattr (namespace, self.dest).extend ((values, len (parser.largs))) I realized right after posting that the above line should be I think, getattr (namespace, self.dest).extend ((values, len (namespace.src))) but that still doesn't help with the "unrecognised arguments" problem. From lie.1296 at gmail.com Thu Jan 5 03:30:37 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 05 Jan 2012 19:30:37 +1100 Subject: a little help In-Reply-To: <1325723382.2402.YahooMailNeo@web30608.mail.mud.yahoo.com> References: <1325719533.2934.YahooMailNeo@web30605.mail.mud.yahoo.com> <1325721417.64653.YahooMailNeo@web30608.mail.mud.yahoo.com> <1325723382.2402.YahooMailNeo@web30608.mail.mud.yahoo.com> Message-ID: On 01/05/2012 11:29 AM, Andres Soto wrote: > my mistake is because I have no problem to do that using Prolog which > use an interpreter as Python. I thought that the variables in the main > global memory space (associated with the command line environment) were > kept, although the code that use it could change. > As you explain me, Python behave like a compiled language: any time I > make a change in the code, I have to "compile" it again, and re-run (and > re-load the data). There is nothing to do. it is usually trivial to redefine state-free functions, you just need to copy and paste the new code into the shell. Redefining a class is a bit more complicated, while you can redefine a class by the same technique (copy pasting the new class definition to the shell), it will not modify the class definition for existing instances of that class. Worst comes to worst, you could end up with a list of instances where half of the items come from the old definition and the other half from the new definition. If your global data are only of native types (e.g. list, dict, int, float), then you usually can safely carry your data between redefinitions; if you have objects in your global data that you want to preserve, you need to be really careful not to confuse instances from old definitions with instances from new definitions. Also, reload() will reload a module with the new definition, but it does not touch existing function definitions in the global namespace; therefore if you want to use reload(), you probably should avoid "from ... import ..." (if you want to import module functions into your global namespace, then you'll need to reimport them after you reload the module). So here's the gotchas to be aware of when reloading modules: 1. import is cached, if you want to reimport a changed module you have to call reload() 2. reload does not modify anything in existing global namespace, if you have imported functions/class definition to your global namespace, you will need to reimport them after reloading. 3. be careful if you mix instances made from old definitions with instances made from new definitions, python does not modify the class definition of existing instances 4. be careful when reloading functions that have function attributes. The same caution applies when reloading class that have class attributes. From dihedral88888 at googlemail.com Thu Jan 5 03:48:33 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Thu, 5 Jan 2012 00:48:33 -0800 (PST) Subject: a little help In-Reply-To: References: <1325719533.2934.YahooMailNeo@web30605.mail.mud.yahoo.com> Message-ID: <12355715.161.1325753313896.JavaMail.geo-discussion-forums@prix23> Chris Angelico? 2012?1?5????UTC+8??7?29?21???? > On Thu, Jan 5, 2012 at 10:25 AM, Andres Soto wrote: > > My situation is the following: I am developing some code. I use the IDLE > > Editor to write it down. Then, I save it and import it from the command line > > interface, so it is already available from the prompt. > > Then I load (read) some data from files using that code. Let suppose that > > after that I make some changes in the code using again the IDLE Editor, save > > the program code, and?what else? The updated code is not already available > > from the command line interface. If I run the module, I lose the data > > already loaded (and it is a big amount). If I re-import it, the new code is > > not available > > Re-importing modules is a bit messy. The usual way to do this sort of > thing would be to run the program directly from the command line, and > terminate it when you're done. Is there a particular reason for > wanting to import it that way? > > Chris Angelico Thus you are developing a module in python. Just use module_name_v??? in those experiments. The version compatible problem is developer's job. From dihedral88888 at googlemail.com Thu Jan 5 03:48:33 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Thu, 5 Jan 2012 00:48:33 -0800 (PST) Subject: a little help In-Reply-To: References: <1325719533.2934.YahooMailNeo@web30605.mail.mud.yahoo.com> Message-ID: <12355715.161.1325753313896.JavaMail.geo-discussion-forums@prix23> Chris Angelico? 2012?1?5????UTC+8??7?29?21???? > On Thu, Jan 5, 2012 at 10:25 AM, Andres Soto wrote: > > My situation is the following: I am developing some code. I use the IDLE > > Editor to write it down. Then, I save it and import it from the command line > > interface, so it is already available from the prompt. > > Then I load (read) some data from files using that code. Let suppose that > > after that I make some changes in the code using again the IDLE Editor, save > > the program code, and?what else? The updated code is not already available > > from the command line interface. If I run the module, I lose the data > > already loaded (and it is a big amount). If I re-import it, the new code is > > not available > > Re-importing modules is a bit messy. The usual way to do this sort of > thing would be to run the program directly from the command line, and > terminate it when you're done. Is there a particular reason for > wanting to import it that way? > > Chris Angelico Thus you are developing a module in python. Just use module_name_v??? in those experiments. The version compatible problem is developer's job. From lie.1296 at gmail.com Thu Jan 5 03:51:28 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 05 Jan 2012 19:51:28 +1100 Subject: help me get excited about python 3 In-Reply-To: <4F0529F2.8070900@wisc.edu> References: <4F0529F2.8070900@wisc.edu> Message-ID: On 01/05/2012 03:41 PM, Evan Driscoll wrote: > On 1/4/2012 9:56 AM, Sean Wolfe wrote: >> I am still living in the 2.x world because all the things I want to do >> right now in python are in 2 (django, pygame). But I want to be >> excited about the future of the language. I understand the concept of >> needing to break backwards compatibility. But it's not particularly >> exciting to think about. What are the cool new bits I should be >> reading up on? > This should be enough to convince you: > > ~ : python > Python 2.7.1 (r271:86832, May 3 2011, 10:31:28) >>>> 1< "1" > True > > ~ : python3 > Python 3.2 (r32:88445, May 3 2011, 13:26:55) >>>> 1< "1" > Traceback (most recent call last): > File "", line 1, in > TypeError: unorderable types: int()< str() > > Maybe with Python 4, '1< True' will give a TypeError too ;-). > > > Or if that's not enough, > > ~ : python > Python 2.7.1 (r271:86832, May 3 2011, 10:31:28) >>>> True, False = False, True >>>> "True is " + ("True" if True else "False") > 'True is False' > > ~ : python3 > Python 3.2 (r32:88445, May 3 2011, 13:26:55) >>>> True, False = False, True > File "", line 1 > SyntaxError: assignment to keyword Somehow I could hear Sean saying something like: "Yeah... and so?" From ulrich.eckhardt at dominolaser.com Thu Jan 5 04:19:22 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 05 Jan 2012 10:19:22 +0100 Subject: argparse missing optparse capabilities? In-Reply-To: <84bd6e5a-1849-43dd-a633-7233efee89c4@f11g2000yql.googlegroups.com> References: <84bd6e5a-1849-43dd-a633-7233efee89c4@f11g2000yql.googlegroups.com> Message-ID: Am 05.01.2012 09:05, schrieb rurpy at yahoo.com: > I have optparse code that parses a command line containing > intermixed positional and optional arguments, where the optional > arguments set the context for the following positional arguments. > For example, > > myprogram.py arg1 -c33 arg2 arg3 -c44 arg4 > > 'arg1' is processed in a default context, 'args2' and 'arg3' in > context '33', and 'arg4' in context '44'. Question: How would you e.g. pass the string "-c33" as first argument, i.e. to be parsed in the default context? The point is that you separate the parameters in a way that makes it possible to parse them in a way that works 100%, not just a way that works in 99% of all cases. For that reason, many commandline tools accept "--" as separator, so that "cp -- -r -x" will copy the file "-r" to the folder "-x". In that light, I would consider restructuring your commandline. > I am trying to do the same using argparse but it appears to be > not doable in a documented way. As already hinted at, I don't think this is possible and that that is so by design. Sorry.. Uli From jeanmichel at sequans.com Thu Jan 5 06:09:41 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 05 Jan 2012 12:09:41 +0100 Subject: can a subclass method determine if called by superclass? In-Reply-To: <13ac20bc-e8b0-4697-8dfd-9fa003af2a48@a17g2000yqj.googlegroups.com> References: <13ac20bc-e8b0-4697-8dfd-9fa003af2a48@a17g2000yqj.googlegroups.com> Message-ID: <4F0584F5.7010704@sequans.com> Peter wrote: > Situation: I am subclassing a class which has methods that call other > class methods (and without reading the code of the superclass I am > discovering these by trial and error as I build the subclass - this is > probably why I may have approached the problem from the wrong > viewpoint :-)). > > Problem: when overriding one of these "indirectly called" superclass > methods I would like to take differing actions (in the subclass > instance) depending on whether it is the superclass or the subclass > instance performing the call. > > Question: Is there any way to determine in a method whether it is > being called by the superclass or by a method of the subclass > instance? > > Now I suspect that what I am doing is actually very muddy thinking :-) > and I don't want to attempt to explain why I am approaching the design > this way as an explanation would require too much work - I will > consider an alternative inheritance approach while waiting an answer, > but the answer to the question interested me (even if I do a redesign > and come up with a more "elegant" approach to the problem). > > Thanks > Peter > As you suspected, this is probably the wrong approach. However since you asked for a solution anyway :o) class Parent(object): def foo(self): # implementation by subclasses is still REQUIRED if self.__class__ is Parent: raise NotImplementedError() # common code for all foo methods print "calling foo" class Child(Parent): def foo(self): # You can still call the virtual method which contains some code Parent.foo(self) # here the custom code p = Parent() c = Child() c.foo() p.foo() Note that this is not the best approach, still acceptable because there is no code specific to a subclass in the base class. JM From jeanmichel at sequans.com Thu Jan 5 06:13:39 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 05 Jan 2012 12:13:39 +0100 Subject: can a subclass method determine if called by superclass? In-Reply-To: <4F0584F5.7010704@sequans.com> References: <13ac20bc-e8b0-4697-8dfd-9fa003af2a48@a17g2000yqj.googlegroups.com> <4F0584F5.7010704@sequans.com> Message-ID: <4F0585E3.5040300@sequans.com> Jean-Michel Pichavant wrote: > Peter wrote: >> Situation: I am subclassing a class which has methods that call other >> class methods (and without reading the code of the superclass I am >> discovering these by trial and error as I build the subclass - this is >> probably why I may have approached the problem from the wrong >> viewpoint :-)). >> >> Problem: when overriding one of these "indirectly called" superclass >> methods I would like to take differing actions (in the subclass >> instance) depending on whether it is the superclass or the subclass >> instance performing the call. >> >> Question: Is there any way to determine in a method whether it is >> being called by the superclass or by a method of the subclass >> instance? >> >> Now I suspect that what I am doing is actually very muddy thinking :-) >> and I don't want to attempt to explain why I am approaching the design >> this way as an explanation would require too much work - I will >> consider an alternative inheritance approach while waiting an answer, >> but the answer to the question interested me (even if I do a redesign >> and come up with a more "elegant" approach to the problem). >> >> Thanks >> Peter >> > As you suspected, this is probably the wrong approach. > > However since you asked for a solution anyway :o) > > class Parent(object): > def foo(self): > # implementation by subclasses is still REQUIRED > if self.__class__ is Parent: > raise NotImplementedError() > # common code for all foo methods > print "calling foo" > > class Child(Parent): > def foo(self): > # You can still call the virtual method which contains some code > Parent.foo(self) > # here the custom code > > > p = Parent() > c = Child() > > > c.foo() > p.foo() > > Note that this is not the best approach, still acceptable because > there is no code specific to a subclass in the base class. > > JM I just realized I didn't addressed the problem you described, sorry, just ignore my mail. JM From andrea.crotti.0 at gmail.com Thu Jan 5 08:24:25 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Thu, 05 Jan 2012 13:24:25 +0000 Subject: argparse and default values Message-ID: <4F05A489.1010604@gmail.com> There's one thing I don't understand about argparse, why doesn't --help show what is the default value?? I mean if I add an option that can be customized it would be good for the user to know what is the current value in my opinion. Is there a way to make it show it? From andrea.crotti.0 at gmail.com Thu Jan 5 08:29:34 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Thu, 05 Jan 2012 13:29:34 +0000 Subject: argparse and default values In-Reply-To: <4F05A489.1010604@gmail.com> References: <4F05A489.1010604@gmail.com> Message-ID: <4F05A5BE.8030802@gmail.com> On 01/05/2012 01:24 PM, Andrea Crotti wrote: > There's one thing I don't understand about argparse, why doesn't > --help show what is the default value?? > I mean if I add an option that can be customized it would be good for > the user > to know what is the current value in my opinion. > > Is there a way to make it show it? Looking at the code I found it already parser = argparse.ArgumentParser(description=description, formatter_class=argparse.ArgumentDefaultsHelpFormatter) the only thing is that it displays also "default: None" which isn't probably very useful, but it would easy to write my own formatter and pass it if I don't like this.. From soto_andres at yahoo.com Thu Jan 5 10:26:57 2012 From: soto_andres at yahoo.com (Andres Soto) Date: Thu, 5 Jan 2012 07:26:57 -0800 (PST) Subject: a little help In-Reply-To: <12355715.161.1325753313896.JavaMail.geo-discussion-forums@prix23> References: <1325719533.2934.YahooMailNeo@web30605.mail.mud.yahoo.com> <12355715.161.1325753313896.JavaMail.geo-discussion-forums@prix23> Message-ID: <1325777217.37534.YahooMailNeo@web30608.mail.mud.yahoo.com> could you be a little bit more explicit. I am a begginer and I don't understand you quite well Thanks Andres Soto >________________________________ > From: 88888 Dihedral >To: python-list at python.org >Cc: python-list at python.org >Sent: Thursday, January 5, 2012 2:48 AM >Subject: Re: a little help > >Chris Angelico? 2012?1?5????UTC+8??7?29?21???? >> On Thu, Jan 5, 2012 at 10:25 AM, Andres Soto wrote: >> > My situation is the following: I am developing some code. I use the IDLE >> > Editor to write it down. Then, I save it and import it from the command line >> > interface, so it is already available from the prompt. >> > Then I load (read) some data from files using that code. Let suppose that >> > after that I make some changes in the code using again the IDLE Editor, save >> > the program code, and?what else? The updated code is not already available >> > from the command line interface. If I run the module, I lose the data >> > already loaded (and it is a big amount). If I re-import it, the new code is >> > not available >> >> Re-importing modules is a bit messy. The usual way to do this sort of >> thing would be to run the program directly from the command line, and >> terminate it when you're done. Is there a particular reason for >> wanting to import it that way? >> >> Chris Angelico > >Thus you are developing a module in python. >Just use module_name_v??? in those experiments. > >The version compatible problem is developer's job. >-- >http://mail.python.org/mailman/listinfo/python-list > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From soto_andres at yahoo.com Thu Jan 5 11:04:11 2012 From: soto_andres at yahoo.com (Andres Soto) Date: Thu, 5 Jan 2012 08:04:11 -0800 (PST) Subject: a little help In-Reply-To: References: <1325719533.2934.YahooMailNeo@web30605.mail.mud.yahoo.com> <1325721417.64653.YahooMailNeo@web30608.mail.mud.yahoo.com> <1325723382.2402.YahooMailNeo@web30608.mail.mud.yahoo.com> Message-ID: <1325779451.13916.YahooMailNeo@web30606.mail.mud.yahoo.com> Please, see my comments between your lines. Thank you very much for your explanation! > > >From: Lie Ryan >To: python-list at python.org >Sent: Thursday, January 5, 2012 2:30 AM >Subject: Re: a little help > >On 01/05/2012 11:29 AM, Andres Soto wrote: >> my mistake is because I have no problem to do that using Prolog which >> use an interpreter as Python. I thought that the variables in the main >> global memory space (associated with the command line environment) were >> kept, although the code that use it could change. >> As you explain me, Python behave like a compiled language: any time I >> make a change in the code, I have to "compile" it again, and re-run (and >> re-load the data). There is nothing to do. > >it is usually trivial to redefine state-free functions, you just need to copy and paste the new code into the shell. > > >&&&yes, I am already using that, but I thought that maybe there were a more elegant way. In Prolog, you just have to reload the code and nothing happens with the global variables > > >?Redefining a class is a bit more complicated, while you can redefine a class by the same technique (copy pasting the new class definition to the shell), it will not modify the class definition for existing instances of that class. Worst comes to worst, you could end up with a list of instances where half of the items come from the old definition and the other half from the new definition. > > >&&&I tried to use classes but I got not good results so I left it for a while > >If your global data are only of native types (e.g. list, dict, int, float), then you usually can safely carry your data between redefinitions;? > > >&&&up to now, I am just using?native types (e.g. list, dict, int, float). How can I carry my data?between redefinitions??copying and pasting the new code into the shell? OK, that I am doing > > >if you have objects in your global data that you want to preserve, you need to be really careful not to confuse instances from old definitions with instances from new definitions. > > >&&&yes, I understand that > >Also, reload() will reload a module with the new definition, but it does not touch existing function definitions in the global namespace; therefore if you want to use reload(), you probably should avoid "from ... import ..." (if you want to import module functions into your global namespace, then you'll need to reimport them after you reload the module). > > >So here's the gotchas to be aware of when reloading modules: > > >1. import is cached, if you want to reimport a changed module you have to call reload() >2. reload does not modify anything in existing global namespace, if you have imported functions/class definition to your global namespace, you will need to reimport them after reloading. >3. be careful if you mix instances made from old definitions with instances made from new definitions, python does not modify the class definition of existing instances >4. be careful when reloading functions that have function attributes. The same caution applies when reloading class that have class attributes. > >-- http://mail.python.org/mailman/listinfo/python-list > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu Jan 5 11:10:41 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 05 Jan 2012 16:10:41 +0000 Subject: Typed python comparison / code analysis questions In-Reply-To: References: Message-ID: <4F05CB81.30505@mrabarnett.plus.com> On 05/01/2012 06:37, Terry Reedy wrote: > On 1/4/2012 3:42 PM, Lucas Vickers wrote: >> At the moment python3 isn't an option. There's a variety of >> dependencies I'm working around. > > Please consider telling the authors of libraries you need that you would > like a Python 3 version and say why. One reason given for not upgrading > packages is 'lack of demand'. > I could also add that if you find a bug in a library, report it. As an example, some months ago I read on StackOverflow an old answer where someone mentioned trying the "regex" module but had found that some Unicode properties were unreliable. That came as a surprise to me because no-one had reported such a problem (and I still don't know what that problem was). Compare that with a recent bug report that it didn't work correctly on Mac OS X. The reporter was very helpful and that bug is now fixed. From rurpy at yahoo.com Thu Jan 5 12:36:48 2012 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Thu, 5 Jan 2012 09:36:48 -0800 (PST) Subject: argparse missing optparse capabilities? References: <84bd6e5a-1849-43dd-a633-7233efee89c4@f11g2000yql.googlegroups.com> Message-ID: On 01/05/2012 02:19 AM, Ulrich Eckhardt wrote: > Am 05.01.2012 09:05, schrieb rurpy at yahoo.com: >> I have optparse code that parses a command line containing >> intermixed positional and optional arguments, where the optional >> arguments set the context for the following positional arguments. >> For example, >> >> myprogram.py arg1 -c33 arg2 arg3 -c44 arg4 >> >> 'arg1' is processed in a default context, 'args2' and 'arg3' in >> context '33', and 'arg4' in context '44'. > > Question: How would you e.g. pass the string "-c33" as first argument, > i.e. to be parsed in the default context? There will not be a need for that. > The point is that you separate the parameters in a way that makes it > possible to parse them in a way that works 100%, not just a way that > works in 99% of all cases. I agree that one should strive for a syntax that "works 100%" but in this case, the simplicity and intuitiveness of the existing command syntax outweigh by far the need for having it work in very improbable corner cases. (And I'm sure I've seen this syntax used in other unix command line tools in the past though I don't have time to look for examples now.) If argparse does not handle this syntax for some such purity reason (as opposed to, for example. it is hard to do in argparse's current design) then argparse is mistakenly putting purity before practicality. > For that reason, many commandline tools > accept "--" as separator, so that "cp -- -r -x" will copy the file "-r" > to the folder "-x". In that light, I would consider restructuring your > commandline. In my case that's not possible since I am replacing an existing tool with a Python application and changing the command line syntax is not an option. >> I am trying to do the same using argparse but it appears to be >> not doable in a documented way. > > As already hinted at, I don't think this is possible and that that is so > by design. Thanks for the confirmation. I guess that shows that optparse has a reason to exist beyond backwards compatibility. From santosh.ssit at gmail.com Thu Jan 5 13:03:32 2012 From: santosh.ssit at gmail.com (hisan) Date: Thu, 5 Jan 2012 10:03:32 -0800 (PST) Subject: Unable to install xmldiff package on WIndows7 References: Message-ID: Can some one help me out here Its High Priority On Jan 4, 12:47?am, hisan wrote: > Hi All > > i have downloaded "xmldiff-0.6.10" from their official site (http://www.logilab.org/859). > I have tried installing the same on my 32 bit Windows 7 OS using the > command "setup.py install" but below exceptions are thrown in the > console. > please help me out in installing this package on Windows > > Exceptions thrown while installing > > C:\Users\santosh\Downloads\xmldiff-0.6.10>setup.py build > running build > running build_py > package init file '.\test\__init__.py' not found (or not a regular > file) > package init file '.\test\__init__.py' not found (or not a regular > file) > running build_ext > building 'xmldiff.maplookup' extension > gcc -mno-cygwin -mdll -O -Wall -ID:\Python26\include -ID:\Python26\PC - > c extensions/maplookup.c -o b > uild\temp.win32-2.6\Release\extensions\maplookup.o > error: command 'gcc' failed: No such file or directory From rodperson at rodperson.com Thu Jan 5 13:10:16 2012 From: rodperson at rodperson.com (Rod Person) Date: Thu, 5 Jan 2012 13:10:16 -0500 Subject: Unable to install xmldiff package on WIndows7 In-Reply-To: References: Message-ID: <20120105131016.000023e6@unknown> On Thu, 5 Jan 2012 10:03:32 -0800 (PST) hisan wrote: > Can some one help me out here Its High Priority > > > > On Jan 4, 12:47?am, hisan wrote: > > Hi All > > > > i have downloaded "xmldiff-0.6.10" from their official site > > (http://www.logilab.org/859). I have tried installing the same on > > my 32 bit Windows 7 OS using the command "setup.py install" but > > below exceptions are thrown in the console. > > please help me out in installing this package on Windows > > > > Exceptions thrown while installing > > > > C:\Users\santosh\Downloads\xmldiff-0.6.10>setup.py build > > running build > > running build_py > > package init file '.\test\__init__.py' not found (or not a regular > > file) > > package init file '.\test\__init__.py' not found (or not a regular > > file) > > running build_ext > > building 'xmldiff.maplookup' extension > > gcc -mno-cygwin -mdll -O -Wall -ID:\Python26\include > > -ID:\Python26\PC - c extensions/maplookup.c -o b > > uild\temp.win32-2.6\Release\extensions\maplookup.o > > error: command 'gcc' failed: No such file or directory > It trying to compile this extension using GNU gcc. You'd need that to compile this one windows. Don't know if there is a windows version but check http://gcc.gnu.org -- Rod Person http://www.rodperson.com rodperson at rodperson.com 'Silence is a fence around wisdom' From ian.g.kelly at gmail.com Thu Jan 5 13:14:33 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 5 Jan 2012 11:14:33 -0700 Subject: argparse missing optparse capabilities? In-Reply-To: <84bd6e5a-1849-43dd-a633-7233efee89c4@f11g2000yql.googlegroups.com> References: <84bd6e5a-1849-43dd-a633-7233efee89c4@f11g2000yql.googlegroups.com> Message-ID: On Thu, Jan 5, 2012 at 1:05 AM, rurpy at yahoo.com wrote: > I have optparse code that parses a command line containing > intermixed positional and optional arguments, where the optional > arguments set the context for the following positional arguments. > For example, > > ?myprogram.py arg1 -c33 arg2 arg3 -c44 arg4 > > 'arg1' is processed in a default context, 'args2' and 'arg3' in > context '33', and 'arg4' in context '44'. > > I am trying to do the same using argparse but it appears to be > not doable in a documented way. > > Here is the working optparse code (which took 30 minutes to write > using just the optparse docs): > > ?import optparse > ?def append_with_pos (option, opt_str, value, parser): > ? ? ? ?if getattr (parser.values, option.dest, None) is None: > ? ? ? ? ? ?setattr (parser.values, option.dest, []) > ? ? ? ?getattr (parser.values, option.dest).append ((value, len > (parser.largs))) > ?def opt_parse(): > ? ? ? ?p = optparse.OptionParser() > ? ? ? ?p.add_option ("-c", type=int, > ? ? ? ? ? ?action='callback', callback=append_with_pos) > ? ? ? ?opts, args = p.parse_args() > ? ? ? ?return args, opts > ?if __name__ == '__main__': > ? ? ? ?args, opts = opt_parse() > ? ? ? ?print args, opts > > Output from the command line above: > ?['arg1', 'arg2', 'arg3', 'arg4'] {'c': [(33, 1), (44, 3)]} > The -c values are stored as (value, arglist_position) tuples. > > Here is an attempt to convert to argparse using the guidelines > in the argparse docs: > > ?import argparse > ?class AppendWithPos (argparse.Action): > ? ?def __call__ (self, parser, namespace, values, > option_string=None): > ? ? ? ?if getattr (namespace, self.dest, None) is None: > ? ? ? ? ? ?setattr (namespace, self.dest, []) > ? ? ? ?getattr (namespace, self.dest).extend ((values, len > (parser.largs))) > ?def arg_parse(): > ? ? ? ?p = argparse.ArgumentParser (description='description') > ? ? ? ?p.add_argument ('src', nargs='*') > ? ? ? ?p.add_argument ('-c', type=int, action=AppendWithPos) > ? ? ? ?opts = p.parse_args() > ? ? ? ?return opts > ?if __name__ == '__main__': > ? ? ? ?opts = arg_parse() > ? ? ? ?print opts > > This fails with, > ?AttributeError: 'ArgumentParser' object has no attribute 'largs' > and of course, the argparse.parser is not documented beyond how > to instantiate it. ?Even were that not a problem, argparse complains > about "unrecognised arguments" for any positional arguments that > occur after an optional one. ?I've been farting with this code for > a day now. > > Any suggestions on how I can convince argparse to do what optparse > does easily will be very welcome. ?(I tried parse_known_args() but > that breaks help and requires me to detect truly unknown arguments.) > > (Python 2.7.1 if it matters and apologies if Google mangles > the formatting of this post.) You have the namespace object in your custom action. Instead of "len(parser.largs)", couldn't you just do "len(namespace.src)"? Cheers, Ian From ian.g.kelly at gmail.com Thu Jan 5 13:46:02 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 5 Jan 2012 11:46:02 -0700 Subject: argparse missing optparse capabilities? In-Reply-To: References: <84bd6e5a-1849-43dd-a633-7233efee89c4@f11g2000yql.googlegroups.com> Message-ID: On Thu, Jan 5, 2012 at 11:14 AM, Ian Kelly wrote: > On Thu, Jan 5, 2012 at 1:05 AM, rurpy at yahoo.com wrote: >> I have optparse code that parses a command line containing >> intermixed positional and optional arguments, where the optional >> arguments set the context for the following positional arguments. >> For example, >> >> ?myprogram.py arg1 -c33 arg2 arg3 -c44 arg4 >> >> 'arg1' is processed in a default context, 'args2' and 'arg3' in >> context '33', and 'arg4' in context '44'. >> >> I am trying to do the same using argparse but it appears to be >> not doable in a documented way. >> >> Here is the working optparse code (which took 30 minutes to write >> using just the optparse docs): >> >> ?import optparse >> ?def append_with_pos (option, opt_str, value, parser): >> ? ? ? ?if getattr (parser.values, option.dest, None) is None: >> ? ? ? ? ? ?setattr (parser.values, option.dest, []) >> ? ? ? ?getattr (parser.values, option.dest).append ((value, len >> (parser.largs))) >> ?def opt_parse(): >> ? ? ? ?p = optparse.OptionParser() >> ? ? ? ?p.add_option ("-c", type=int, >> ? ? ? ? ? ?action='callback', callback=append_with_pos) >> ? ? ? ?opts, args = p.parse_args() >> ? ? ? ?return args, opts >> ?if __name__ == '__main__': >> ? ? ? ?args, opts = opt_parse() >> ? ? ? ?print args, opts >> >> Output from the command line above: >> ?['arg1', 'arg2', 'arg3', 'arg4'] {'c': [(33, 1), (44, 3)]} >> The -c values are stored as (value, arglist_position) tuples. >> >> Here is an attempt to convert to argparse using the guidelines >> in the argparse docs: >> >> ?import argparse >> ?class AppendWithPos (argparse.Action): >> ? ?def __call__ (self, parser, namespace, values, >> option_string=None): >> ? ? ? ?if getattr (namespace, self.dest, None) is None: >> ? ? ? ? ? ?setattr (namespace, self.dest, []) >> ? ? ? ?getattr (namespace, self.dest).extend ((values, len >> (parser.largs))) >> ?def arg_parse(): >> ? ? ? ?p = argparse.ArgumentParser (description='description') >> ? ? ? ?p.add_argument ('src', nargs='*') >> ? ? ? ?p.add_argument ('-c', type=int, action=AppendWithPos) >> ? ? ? ?opts = p.parse_args() >> ? ? ? ?return opts >> ?if __name__ == '__main__': >> ? ? ? ?opts = arg_parse() >> ? ? ? ?print opts >> >> This fails with, >> ?AttributeError: 'ArgumentParser' object has no attribute 'largs' >> and of course, the argparse.parser is not documented beyond how >> to instantiate it. ?Even were that not a problem, argparse complains >> about "unrecognised arguments" for any positional arguments that >> occur after an optional one. ?I've been farting with this code for >> a day now. >> >> Any suggestions on how I can convince argparse to do what optparse >> does easily will be very welcome. ?(I tried parse_known_args() but >> that breaks help and requires me to detect truly unknown arguments.) >> >> (Python 2.7.1 if it matters and apologies if Google mangles >> the formatting of this post.) > > You have the namespace object in your custom action. ?Instead of > "len(parser.largs)", couldn't you just do "len(namespace.src)"? Sorry, I missed the second part of that. You seem to be right, as far as I can tell from tinkering with it, all the positional arguments have to be in a single group. If you have some positional arguments followed by an option followed by more positional arguments, and any of the arguments have a loose nargs quantifier ('?' or '*' or '+'), then you get an error. From peter.milliken at gmail.com Thu Jan 5 13:59:48 2012 From: peter.milliken at gmail.com (Peter) Date: Thu, 5 Jan 2012 10:59:48 -0800 (PST) Subject: can a subclass method determine if called by superclass? References: <13ac20bc-e8b0-4697-8dfd-9fa003af2a48@a17g2000yqj.googlegroups.com> <4F0584F5.7010704@sequans.com> Message-ID: <0d85f158-250d-429f-b8c2-e3c53c9d7ca8@d9g2000yqg.googlegroups.com> Thanks for the help guys - it appears there is no better way than Ian suggested. I have restructured my class hierarchy so the problem has now "gone away". It would have been nice to discover some previously unknown (to me at least!) Python trick, but such is life :-) Regards Peter From alec.taylor6 at gmail.com Thu Jan 5 14:01:46 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Fri, 6 Jan 2012 06:01:46 +1100 Subject: virtualenv wrecked my Django+modules install Message-ID: Good morning, On my system (Windows 8 Developer Preview x64 with Python 2.7.2 x64) I painstakingly installed all the dependencies for Django, Satchmo and a few other large scale projects. (about 10% couldn't be installed with pip, which is why I use the word 'painstakingly') Recently though I needed Pinax for something, so following there guide (http://pinax.readthedocs.org/en/latest/gettingstarted.html) I setup a virtualenv for it. Not only could I not get Pinax running, but when I went back to work on my Satchmo-based project, and ran "manage.py runserver" I got the following error: Traceback (most recent call last): File "P:\Prototype\Django\store\manage.py", line 18, in from django.core.management import execute_manager ImportError: No module named django.core.management Typing in `import django` from the interpreter gives me: Traceback (most recent call last): File "", line 1, in ImportError: No module named django Does this mean I need to install everything required by my project all over again? - If so, should I take a virtualenv approach (and what would the advantages be of doing so)? Thanks for all suggestions, Alec Taylor From gordon at panix.com Thu Jan 5 14:34:37 2012 From: gordon at panix.com (John Gordon) Date: Thu, 5 Jan 2012 19:34:37 +0000 (UTC) Subject: Unable to install xmldiff package on WIndows7 References: Message-ID: In hisan writes: > Can some one help me out here Its High Priority GCC is failing with a "No such file or directory" error. I assume this means either that gcc is not installed on your computer, or that it couldn't find one of the files you passed on the command line. The first case seems less likely, as I would expect a "Command not found" error instead of "No such file or directory". The second case seems more likely, especially since one of the directories GCC is trying to use contains embedded spaces in the name: -ID:\Python26\PC - c extensions/maplookup.c Can you rename that directory to something that does not contain spaces and try it again? -- 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 lie.1296 at gmail.com Thu Jan 5 14:53:34 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Fri, 06 Jan 2012 06:53:34 +1100 Subject: a little help In-Reply-To: <1325779451.13916.YahooMailNeo@web30606.mail.mud.yahoo.com> References: <1325719533.2934.YahooMailNeo@web30605.mail.mud.yahoo.com> <1325721417.64653.YahooMailNeo@web30608.mail.mud.yahoo.com> <1325723382.2402.YahooMailNeo@web30608.mail.mud.yahoo.com> <1325779451.13916.YahooMailNeo@web30606.mail.mud.yahoo.com> Message-ID: On 01/06/2012 03:04 AM, Andres Soto wrote: > Please, see my comments between your lines. Thank you very much for > your explanation! > * > * > *From:* Lie Ryan > *To:* python-list at python.org > *Sent:* Thursday, January 5, 2012 2:30 AM > *Subject:* Re: a little help > > On 01/05/2012 11:29 AM, Andres Soto wrote: > > my mistake is because I have no problem to do that using Prolog which > > use an interpreter as Python. I thought that the variables in the > main > > global memory space (associated with the command line > environment) were > > kept, although the code that use it could change. > > As you explain me, Python behave like a compiled language: any time I > > make a change in the code, I have to "compile" it again, and > re-run (and > > re-load the data). There is nothing to do. > > it is usually trivial to redefine state-free functions, you just > need to copy and paste the new code into the shell. > > &&&yes, I am already using that, but I thought that maybe there were > a more elegant way. In Prolog, you just have to reload the code and > nothing happens with the global variables Alternative to copy pasting is to reload the module; but that comes with the caution that the old function/class definition may still be lying around in the global namespace if you imported them into your global namespace, so you had to either restrict yourself to using class/function using the module namespace or you had to remember to reimport them into your global namespace. You also need to be careful if you passes a module function as callbacks, as the callback will not be automatically replaced with the new definition. From python at mrabarnett.plus.com Thu Jan 5 15:11:39 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 05 Jan 2012 20:11:39 +0000 Subject: Unable to install xmldiff package on WIndows7 In-Reply-To: References: Message-ID: <4F0603FB.8050300@mrabarnett.plus.com> On 05/01/2012 19:34, John Gordon wrote: > In hisan writes: > >> Can some one help me out here Its High Priority > > GCC is failing with a "No such file or directory" error. > > I assume this means either that gcc is not installed on your computer, > or that it couldn't find one of the files you passed on the command line. > > The first case seems less likely, as I would expect a "Command not found" > error instead of "No such file or directory". > > The second case seems more likely, especially since one of the directories > GCC is trying to use contains embedded spaces in the name: > > -ID:\Python26\PC - c extensions/maplookup.c > > Can you rename that directory to something that does not contain spaces > and try it again? > Alternatively, enclose it in quotes. From rich at noir.com Thu Jan 5 16:34:30 2012 From: rich at noir.com (K Richard Pixley) Date: Thu, 05 Jan 2012 13:34:30 -0800 Subject: help me get excited about python 3 In-Reply-To: References: Message-ID: You get some of the good stuff by importing future, unicode literals which essentially means you're working in unicode by default most of the time, and print function, (a small fix but long overdue). I try to write python3 whenever I can. It's rare that dependencies keep me back. More often it's debugger problems or lack of distributions, (python3 doesn't entirely build on MacOsX Lion and the distributed binaries can't download third party code that requires compilation). If you do anything with raw data, the bytes/unicode upgrades are a god send. The old way was workable, (although I still don't understand string quoting). The new way is much better, more rational, easier to understand, more consistent, better documented, closer to intuitive expectations, and expressively clearer. Trying to find idioms that work for both is horrendous, though. Unicode rocks. This change alone is leading me to use python in many places where, in the past, I would have used /bin/sh for portability. Utf-8 file names, file names with spaces and other "special characters", and user entered data fields with diacriticals are all difficult to handle in /bin/sh, awkward in python2, but near trivial in python3. Classic classes are finally dead. Range now works like xrange used to. This is great, although a bit clumsy when trying to write for both 2 and 3 concurrently. In practice, most of the library changes are 1:1 renames, which are both worthwhile and easy enough to work with. Most of the other interesting features, (imo), have been backported to 2.7. Context managers, "with", str.format(), etc. I'm currently writing in both more or less concurrently most of the time, (can't afford to live without the debugger), and I'm really, REALLY looking forward to the day when I can drop the python2 idioms. I really hate adding crap to python3 clean code in order to backport support for python2. Really, the biggest win to 3, aside from the unicode/bytes change, is the fact that a lot of outdated stuff is finally getting flushed. IMO, it's not so much about the new features, (context managers are big, but have been backported), as it is about the lack of pollution from ancient ones. Many of the new changes are ramifications of these removals. --rich From dihedral88888 at googlemail.com Thu Jan 5 17:16:35 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Thu, 5 Jan 2012 14:16:35 -0800 (PST) Subject: virtualenv wrecked my Django+modules install In-Reply-To: References: Message-ID: <32395968.380.1325801795538.JavaMail.geo-discussion-forums@prar8> Use co-linux or VMware to do some experiment first. This is better than those old days of workstations or the mainframes from 5 to 10 vendors 20 years ago. From dihedral88888 at googlemail.com Thu Jan 5 17:16:35 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Thu, 5 Jan 2012 14:16:35 -0800 (PST) Subject: virtualenv wrecked my Django+modules install In-Reply-To: References: Message-ID: <32395968.380.1325801795538.JavaMail.geo-discussion-forums@prar8> Use co-linux or VMware to do some experiment first. This is better than those old days of workstations or the mainframes from 5 to 10 vendors 20 years ago. From rich at noir.com Thu Jan 5 17:43:02 2012 From: rich at noir.com (K Richard Pixley) Date: Thu, 05 Jan 2012 14:43:02 -0800 Subject: socketserver question Message-ID: Once I've instantiated my server class, along with a handler class, called server.serve_forever(), handler.handle() has been called, I've done my work, and I'm ready to shut the whole thing down... How do I do that? The doc says server.shutdown(), but if I call self.server.shutdown() from within handler.handle(), I seem to get a deadlock, which is exactly what I'd expect in a single threaded system with no way to "signal" the server.server_forever() loop which is several frames up the stack. I've also tried sys.exit() but it seems that the server object is catching that as an exception. How is this expected to work? How do I terminate the server.serve_forever() loop? --rich From pywin32 at gmail.com Thu Jan 5 17:44:05 2012 From: pywin32 at gmail.com (random joe) Date: Thu, 5 Jan 2012 14:44:05 -0800 (PST) Subject: Help with python-list archives Message-ID: <78484055-dd01-4237-9217-9eb038fc744f@p16g2000yqd.googlegroups.com> Hi. I am new to python and wanted to search the python-list archives for answers to my many questions but i can't seem to get the archive files to uncompressed? What gives? From what i understand they are gzip files so i assumed the gzip module would work, but no! The best i could do was to get a ton of chinese chars using gzip and zlib.uncompress(). I would like to be courteous and search for my answers before asking so as not to waste anyones time. Does anyone know how to uncompress these files into a readable text form? From miki.tebeka at gmail.com Thu Jan 5 18:39:36 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Thu, 5 Jan 2012 15:39:36 -0800 (PST) Subject: Help with python-list archives In-Reply-To: <78484055-dd01-4237-9217-9eb038fc744f@p16g2000yqd.googlegroups.com> References: <78484055-dd01-4237-9217-9eb038fc744f@p16g2000yqd.googlegroups.com> Message-ID: <14749754.624.1325806776674.JavaMail.geo-discussion-forums@vbgw2> Is there Google groups search not good enough? (groups.google.com/group/comp.lang.python) Also, can you give an example of the code and an input file? From pywin32 at gmail.com Thu Jan 5 18:52:14 2012 From: pywin32 at gmail.com (random joe) Date: Thu, 5 Jan 2012 15:52:14 -0800 (PST) Subject: Help with python-list archives References: <78484055-dd01-4237-9217-9eb038fc744f@p16g2000yqd.googlegroups.com> <14749754.624.1325806776674.JavaMail.geo-discussion-forums@vbgw2> Message-ID: <8f3b98e1-3b21-4f06-8456-0a555a7ee523@u32g2000yqe.googlegroups.com> On Jan 5, 5:39?pm, Miki Tebeka wrote: > Is the Google groups search not good enough? That works but i would like to do some regexes and set up some defaults. > Also, can you give an example of the code and an input file? Sure. Take the most recent file as example. "2012 - January.txt.gz". If you use the python doc example this is the result. If i use "r" or "rb" the result is the same. >>> import gzip >>> f1 = gzip.open('C:\\2012-January.txt.gz', 'rb') >>> data = f1.read() >>> data[:100] '\x1f\x8b\x08\x08x\n\x05O\x02\xff/srv/mailman/archives/private/python- list/2012-January.txt\x00\xec\xbdy\x7f\xdb\xc6\xb50\xfcw\xf0)\xa6z|+ \xaa!!l\xdc\x14[\x8b-;V\xe2-\x92\x12' >>> f2 = gzip.open('C:\\2012-January.txt.gz', 'r') >>> data = f2.read() >>> data[:100] '\x1f\x8b\x08\x08x\n\x05O\x02\xff/srv/mailman/archives/private/python- list/2012-January.txt\x00\xec\xbdy\x7f\xdb\xc6\xb50\xfcw\xf0)\xa6z|+ \xaa!!l\xdc\x14[\x8b-;V\xe2-\x92\x12' The docs and google provide no clear answer. I even tried 7zip and ended up with nothing but gibberish characters. There must be levels of compression or something. Why could they not simply use the tar format? Is there anywhere else one can download the archives? From ian.g.kelly at gmail.com Thu Jan 5 19:02:53 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 5 Jan 2012 17:02:53 -0700 Subject: Help with python-list archives In-Reply-To: <14749754.624.1325806776674.JavaMail.geo-discussion-forums@vbgw2> References: <78484055-dd01-4237-9217-9eb038fc744f@p16g2000yqd.googlegroups.com> <14749754.624.1325806776674.JavaMail.geo-discussion-forums@vbgw2> Message-ID: On Thu, Jan 5, 2012 at 4:39 PM, Miki Tebeka wrote: > Is there Google groups search not good enough? (groups.google.com/group/comp.lang.python) My experience with the Google groups search (and Google groups in general) in the past has been terrible. If you're looking for a specific thread, it can actually be quite hard to find. From ian.g.kelly at gmail.com Thu Jan 5 19:10:07 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 5 Jan 2012 17:10:07 -0700 Subject: Help with python-list archives In-Reply-To: <8f3b98e1-3b21-4f06-8456-0a555a7ee523@u32g2000yqe.googlegroups.com> References: <78484055-dd01-4237-9217-9eb038fc744f@p16g2000yqd.googlegroups.com> <14749754.624.1325806776674.JavaMail.geo-discussion-forums@vbgw2> <8f3b98e1-3b21-4f06-8456-0a555a7ee523@u32g2000yqe.googlegroups.com> Message-ID: On Thu, Jan 5, 2012 at 4:52 PM, random joe wrote: > Sure. Take the most recent file as example. "2012 - January.txt.gz". > If you use the python doc example this is the result. If i use "r" or > "rb" the result is the same. > >>>> import gzip >>>> f1 = gzip.open('C:\\2012-January.txt.gz', 'rb') >>>> data = f1.read() >>>> data[:100] > '\x1f\x8b\x08\x08x\n\x05O\x02\xff/srv/mailman/archives/private/python- > list/2012-January.txt\x00\xec\xbdy\x7f\xdb\xc6\xb50\xfcw\xf0)\xa6z|+ > \xaa!!l\xdc\x14[\x8b-;V\xe2-\x92\x12' >>>> f2 = gzip.open('C:\\2012-January.txt.gz', 'r') >>>> data = f2.read() >>>> data[:100] > '\x1f\x8b\x08\x08x\n\x05O\x02\xff/srv/mailman/archives/private/python- > list/2012-January.txt\x00\xec\xbdy\x7f\xdb\xc6\xb50\xfcw\xf0)\xa6z|+ > \xaa!!l\xdc\x14[\x8b-;V\xe2-\x92\x12' > > The docs and google provide no clear answer. I even tried 7zip and > ended up with nothing but gibberish characters. There must be levels > of compression or something. Why could they not simply use the tar > format? Is there anywhere else one can download the archives? Interesting. I tried this on a Linux system using both gunzip and your code, and both worked fine to extract that file. I also tried your code on a Windows system, and I get the same result that you do. This appears to be a bug in the gzip module under Windows. I think there may be something peculiar about the archive files that the module is not handling correctly. If I gunzip the file locally and then gzip it again before trying to open it in Python, then everything seems to be fine. From rurpy at yahoo.com Thu Jan 5 19:30:29 2012 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Thu, 5 Jan 2012 16:30:29 -0800 (PST) Subject: argparse missing optparse capabilities? References: <84bd6e5a-1849-43dd-a633-7233efee89c4@f11g2000yql.googlegroups.com> Message-ID: On 01/05/2012 11:46 AM, Ian Kelly wrote: > On Thu, Jan 5, 2012 at 11:14 AM, Ian Kelly wrote: >> On Thu, Jan 5, 2012 at 1:05 AM, rurpy at yahoo.com wrote: >>> I have optparse code that parses a command line containing >>> intermixed positional and optional arguments, where the optional >>> arguments set the context for the following positional arguments. >>> For example, >>> >>> myprogram.py arg1 -c33 arg2 arg3 -c44 arg4 >>> >>> 'arg1' is processed in a default context, 'args2' and 'arg3' in >>> context '33', and 'arg4' in context '44'. >>> >>> I am trying to do the same using argparse but it appears to be >>> not doable in a documented way. >[...] > > Sorry, I missed the second part of that. You seem to be right, as far > as I can tell from tinkering with it, all the positional arguments > have to be in a single group. If you have some positional arguments > followed by an option followed by more positional arguments, and any > of the arguments have a loose nargs quantifier ('?' or '*' or '+'), > then you get an error. OK, thanks for the second confirmation. I was hoping there was something I missed or some undocumented option to allow intermixed optional and positional arguments with Argparse but it appears not. I notice that Optparse seems to intentionally provide this capability since it offers a "disable_interspersed_args()" method. It is unfortunate that Argparse chose to not to provide backward compatibility for this thus forcing some users to continue using a deprecated module. From pywin32 at gmail.com Thu Jan 5 19:45:30 2012 From: pywin32 at gmail.com (random joe) Date: Thu, 5 Jan 2012 16:45:30 -0800 (PST) Subject: Help with python-list archives References: <78484055-dd01-4237-9217-9eb038fc744f@p16g2000yqd.googlegroups.com> <14749754.624.1325806776674.JavaMail.geo-discussion-forums@vbgw2> <8f3b98e1-3b21-4f06-8456-0a555a7ee523@u32g2000yqe.googlegroups.com> Message-ID: <0cbcc2ce-5dff-4cd9-89f5-833956dc8e37@q7g2000yqn.googlegroups.com> On Jan 5, 6:10?pm, Ian Kelly wrote: > Interesting. ?I tried this on a Linux system using both gunzip and > your code, and both worked fine to extract that file. ?I also tried > your code on a Windows system, and I get the same result that you do. > This appears to be a bug in the gzip module under Windows. > > I think there may be something peculiar about the archive files that > the module is not handling correctly. ?If I gunzip the file locally > and then gzip it again before trying to open it in Python, then > everything seems to be fine. That is interesting. I wonder if anyone else has had the same issue? Just to be thorough I tried to uncompress using both python 2.x and 3.x and the results are unreadable text files in both cases. I have no idea what the problem could be. Especially without some way to compare my files to the gunzip'ed files on a linux machine. From python at mrabarnett.plus.com Thu Jan 5 20:27:00 2012 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 06 Jan 2012 01:27:00 +0000 Subject: Help with python-list archives In-Reply-To: References: <78484055-dd01-4237-9217-9eb038fc744f@p16g2000yqd.googlegroups.com> <14749754.624.1325806776674.JavaMail.geo-discussion-forums@vbgw2> <8f3b98e1-3b21-4f06-8456-0a555a7ee523@u32g2000yqe.googlegroups.com> Message-ID: <4F064DE4.3060403@mrabarnett.plus.com> On 06/01/2012 00:10, Ian Kelly wrote: > On Thu, Jan 5, 2012 at 4:52 PM, random joe wrote: >> Sure. Take the most recent file as example. "2012 - January.txt.gz". >> If you use the python doc example this is the result. If i use "r" or >> "rb" the result is the same. >> >>>>> import gzip >>>>> f1 = gzip.open('C:\\2012-January.txt.gz', 'rb') >>>>> data = f1.read() >>>>> data[:100] >> '\x1f\x8b\x08\x08x\n\x05O\x02\xff/srv/mailman/archives/private/python- >> list/2012-January.txt\x00\xec\xbdy\x7f\xdb\xc6\xb50\xfcw\xf0)\xa6z|+ >> \xaa!!l\xdc\x14[\x8b-;V\xe2-\x92\x12' >>>>> f2 = gzip.open('C:\\2012-January.txt.gz', 'r') >>>>> data = f2.read() >>>>> data[:100] >> '\x1f\x8b\x08\x08x\n\x05O\x02\xff/srv/mailman/archives/private/python- >> list/2012-January.txt\x00\xec\xbdy\x7f\xdb\xc6\xb50\xfcw\xf0)\xa6z|+ >> \xaa!!l\xdc\x14[\x8b-;V\xe2-\x92\x12' >> >> The docs and google provide no clear answer. I even tried 7zip and >> ended up with nothing but gibberish characters. There must be levels >> of compression or something. Why could they not simply use the tar >> format? Is there anywhere else one can download the archives? > > Interesting. I tried this on a Linux system using both gunzip and > your code, and both worked fine to extract that file. I also tried > your code on a Windows system, and I get the same result that you do. > This appears to be a bug in the gzip module under Windows. > > I think there may be something peculiar about the archive files that > the module is not handling correctly. If I gunzip the file locally > and then gzip it again before trying to open it in Python, then > everything seems to be fine. I've found that if I gunzip it twice (gunzip it and then gunzip the result) using the gzip module I get the text file. From pywin32 at gmail.com Thu Jan 5 21:14:25 2012 From: pywin32 at gmail.com (random joe) Date: Thu, 5 Jan 2012 18:14:25 -0800 (PST) Subject: Help with python-list archives References: <78484055-dd01-4237-9217-9eb038fc744f@p16g2000yqd.googlegroups.com> <14749754.624.1325806776674.JavaMail.geo-discussion-forums@vbgw2> <8f3b98e1-3b21-4f06-8456-0a555a7ee523@u32g2000yqe.googlegroups.com> Message-ID: On Jan 5, 7:27?pm, MRAB wrote: > I've found that if I gunzip it twice (gunzip it and then gunzip the > result) using the gzip module I get the text file. On a windows machine? If so, can you post a code snippet please? Thanks From 1248283536 at qq.com Thu Jan 5 21:24:12 2012 From: 1248283536 at qq.com (=?gbk?B?y66+ssH3ye4=?=) Date: Fri, 6 Jan 2012 10:24:12 +0800 Subject: problem to install Flask Message-ID: ~$ sudo easy_install Flask Searching for Flask Reading http://pypi.python.org/simple/Flask/ Reading http://github.com/mitsuhiko/flask/ Best match: Flask 0.8 Downloading http://pypi.python.org/packages/source/F/Flask/Flask-0.8.tar.gz#md5=a5169306cfe49b3b369086f2a63816ab Processing Flask-0.8.tar.gz Running Flask-0.8/setup.py -q bdist_egg --dist-dir /tmp/easy_install-tnoyjj/Flask-0.8/egg-dist-tmp-pq04_a Traceback (most recent call last): File "/usr/local/bin/easy_install", line 9, in load_entry_point('distribute==0.6.24', 'console_scripts', 'easy_install')() File "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", line 1883, in main with_ei_usage(lambda: File "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", line 1864, in with_ei_usage return f() File "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", line 1887, in distclass=DistributionWithoutHelpCommands, **kw File "/usr/local/lib/python3.2/distutils/core.py", line 148, in setup dist.run_commands() File "/usr/local/lib/python3.2/distutils/dist.py", line 917, in run_commands self.run_command(cmd) File "/usr/local/lib/python3.2/distutils/dist.py", line 936, in run_command cmd_obj.run() File "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", line 349, in run self.easy_install(spec, not self.no_deps) File "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", line 589, in easy_install return self.install_item(spec, dist.location, tmpdir, deps) File "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", line 619, in install_item dists = self.install_eggs(spec, download, tmpdir) File "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", line 809, in install_eggs return self.build_and_install(setup_script, setup_base) File "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", line 1086, in build_and_install self.run_setup(setup_script, setup_base, args) File "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", line 1075, in run_setup run_setup(setup_script, args) File "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/sandbox.py", line 31, in run_setup lambda: exec(compile(open( File "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/sandbox.py", line 73, in run return func() File "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/sandbox.py", line 33, in ).read(), "setup.py", 'exec'), File "setup.py", line 62 print "Audit requires PyFlakes installed in your system.""" ^ SyntaxError: invalid syntax what is the matter? -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Thu Jan 5 21:48:18 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 5 Jan 2012 18:48:18 -0800 (PST) Subject: virtualenv wrecked my Django+modules install References: Message-ID: <60f10857-6a3d-4f3d-9d69-39487e4885f8@e2g2000vbb.googlegroups.com> On Jan 6, 5:01?am, Alec Taylor wrote: > Does this mean I need to install everything required by my project all > over again? - If so, should I take a virtualenv approach (and what > would the advantages be of doing so)? Virtualenv should _never_ clobber any non-virtualenv installs, that's the whole purpose of it. > Not only could I not get Pinax running, but when I went back to work > on my Satchmo-based project[...] Did you de-activate the Pinax virtualenv before trying to work on your other project? That's the only guess I have as to why you couldn't see your original installation. From python at mrabarnett.plus.com Thu Jan 5 22:00:56 2012 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 06 Jan 2012 03:00:56 +0000 Subject: Help with python-list archives In-Reply-To: References: <78484055-dd01-4237-9217-9eb038fc744f@p16g2000yqd.googlegroups.com> <14749754.624.1325806776674.JavaMail.geo-discussion-forums@vbgw2> <8f3b98e1-3b21-4f06-8456-0a555a7ee523@u32g2000yqe.googlegroups.com> Message-ID: <4F0663E8.4090302@mrabarnett.plus.com> On 06/01/2012 02:14, random joe wrote: > On Jan 5, 7:27 pm, MRAB wrote: > >> I've found that if I gunzip it twice (gunzip it and then gunzip the >> result) using the gzip module I get the text file. > > On a windows machine? If so, can you post a code snippet please? > Thanks import gzip in_file = gzip.open(r"C:\2012-January.txt.gz") out_file = open(r"C:\2012-January.txt.tmp", "wb") out_file.write(in_file.read()) in_file.close() out_file.close() in_file = gzip.open(r"C:\2012-January.txt.tmp") out_file = open(r"C:\2012-January.txt", "wb") out_file.write(in_file.read()) in_file.close() out_file.close() From python at mrabarnett.plus.com Thu Jan 5 22:05:03 2012 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 06 Jan 2012 03:05:03 +0000 Subject: problem to install Flask In-Reply-To: References: Message-ID: <4F0664DF.5020804@mrabarnett.plus.com> On 06/01/2012 02:24, ???? wrote: > ~$ sudo easy_install Flask > Searching for Flask > Reading http://pypi.python.org/simple/Flask/ > Reading http://github.com/mitsuhiko/flask/ > Best match: Flask 0.8 > Downloading > http://pypi.python.org/packages/source/F/Flask/Flask-0.8.tar.gz#md5=a5169306cfe49b3b369086f2a63816ab > Processing Flask-0.8.tar.gz > Running Flask-0.8/setup.py -q bdist_egg --dist-dir > /tmp/easy_install-tnoyjj/Flask-0.8/egg-dist-tmp-pq04_a > Traceback (most recent call last): > File "/usr/local/bin/easy_install", line 9, in > load_entry_point('distribute==0.6.24', 'console_scripts', 'easy_install')() > File > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > line 1883, in main > with_ei_usage(lambda: > File > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > line 1864, in with_ei_usage > return f() > File > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > line 1887, in > distclass=DistributionWithoutHelpCommands, **kw > File "/usr/local/lib/python3.2/distutils/core.py", line 148, in setup > dist.run_commands() > File "/usr/local/lib/python3.2/distutils/dist.py", line 917, in run_commands > self.run_command(cmd) > File "/usr/local/lib/python3.2/distutils/dist.py", line 936, in run_command > cmd_obj.run() > File > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > line 349, in run > self.easy_install(spec, not self.no_deps) > File > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > line 589, in easy_install > return self.install_item(spec, dist.location, tmpdir, deps) > File > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > line 619, in install_item > dists = self.install_eggs(spec, download, tmpdir) > File > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > line 809, in install_eggs > return self.build_and_install(setup_script, setup_base) > File > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > line 1086, in build_and_install > self.run_setup(setup_script, setup_base, args) > File > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > line 1075, in run_setup > run_setup(setup_script, args) > File > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/sandbox.py", > line 31, in run_setup > lambda: exec(compile(open( > File > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/sandbox.py", > line 73, in run > return func() > File > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/sandbox.py", > line 33, in > ).read(), "setup.py", 'exec'), > File "setup.py", line 62 > print "Audit requires PyFlakes installed in your system.""" > ^ > SyntaxError: invalid syntax > > > what is the matter? > The syntax of this line: print "Audit requires PyFlakes installed in your system." tells me that it's written for Python 2, but this: /usr/local/lib/python3.2 tells me that you're using Python 3. In Python 2, "print" is a statement; in Python 3 it's a function. From 1248283536 at qq.com Thu Jan 5 22:08:29 2012 From: 1248283536 at qq.com (=?gbk?B?y66+ssH3ye4=?=) Date: Fri, 6 Jan 2012 11:08:29 +0800 Subject: =?gbk?B?u9i4tKO6IHByb2JsZW0gdG8gaW5zdGFsbCAgRmxh?= =?gbk?B?c2s=?= Message-ID: yes i run python3,how to install flask in python3? ------------------ ???? ------------------ ???: "MRAB"; ????: 2012?1?6?(???) ??11:05 ???: "python-list"; ??: Re: problem to install Flask On 06/01/2012 02:24, ???? wrote: > ~$ sudo easy_install Flask > Searching for Flask > Reading http://pypi.python.org/simple/Flask/ > Reading http://github.com/mitsuhiko/flask/ > Best match: Flask 0.8 > Downloading > http://pypi.python.org/packages/source/F/Flask/Flask-0.8.tar.gz#md5=a5169306cfe49b3b369086f2a63816ab > Processing Flask-0.8.tar.gz > Running Flask-0.8/setup.py -q bdist_egg --dist-dir > /tmp/easy_install-tnoyjj/Flask-0.8/egg-dist-tmp-pq04_a > Traceback (most recent call last): > File "/usr/local/bin/easy_install", line 9, in > load_entry_point('distribute==0.6.24', 'console_scripts', 'easy_install')() > File > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > line 1883, in main > with_ei_usage(lambda: > File > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > line 1864, in with_ei_usage > return f() > File > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > line 1887, in > distclass=DistributionWithoutHelpCommands, **kw > File "/usr/local/lib/python3.2/distutils/core.py", line 148, in setup > dist.run_commands() > File "/usr/local/lib/python3.2/distutils/dist.py", line 917, in run_commands > self.run_command(cmd) > File "/usr/local/lib/python3.2/distutils/dist.py", line 936, in run_command > cmd_obj.run() > File > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > line 349, in run > self.easy_install(spec, not self.no_deps) > File > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > line 589, in easy_install > return self.install_item(spec, dist.location, tmpdir, deps) > File > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > line 619, in install_item > dists = self.install_eggs(spec, download, tmpdir) > File > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > line 809, in install_eggs > return self.build_and_install(setup_script, setup_base) > File > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > line 1086, in build_and_install > self.run_setup(setup_script, setup_base, args) > File > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > line 1075, in run_setup > run_setup(setup_script, args) > File > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/sandbox.py", > line 31, in run_setup > lambda: exec(compile(open( > File > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/sandbox.py", > line 73, in run > return func() > File > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/sandbox.py", > line 33, in > ).read(), "setup.py", 'exec'), > File "setup.py", line 62 > print "Audit requires PyFlakes installed in your system.""" > ^ > SyntaxError: invalid syntax > > > what is the matter? > The syntax of this line: print "Audit requires PyFlakes installed in your system." tells me that it's written for Python 2, but this: /usr/local/lib/python3.2 tells me that you're using Python 3. In Python 2, "print" is a statement; in Python 3 it's a function. -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From pywin32 at gmail.com Thu Jan 5 23:01:25 2012 From: pywin32 at gmail.com (random joe) Date: Thu, 5 Jan 2012 20:01:25 -0800 (PST) Subject: Help with python-list archives References: <78484055-dd01-4237-9217-9eb038fc744f@p16g2000yqd.googlegroups.com> <14749754.624.1325806776674.JavaMail.geo-discussion-forums@vbgw2> <8f3b98e1-3b21-4f06-8456-0a555a7ee523@u32g2000yqe.googlegroups.com> Message-ID: On Jan 5, 9:00?pm, MRAB wrote: > On 06/01/2012 02:14, random joe wrote: > > > On Jan 5, 7:27 pm, MRAB ?wrote: > > >> ?I've found that if I gunzip it twice (gunzip it and then gunzip the > >> ?result) using the gzip module I get the text file. > > > On a windows machine? If so, can you post a code snippet please? > > Thanks > > import gzip > > in_file = gzip.open(r"C:\2012-January.txt.gz") > out_file = open(r"C:\2012-January.txt.tmp", "wb") > out_file.write(in_file.read()) > in_file.close() > out_file.close() > > in_file = gzip.open(r"C:\2012-January.txt.tmp") > out_file = open(r"C:\2012-January.txt", "wb") > out_file.write(in_file.read()) > in_file.close() > out_file.close() EXCELLENT! Thanks. THis works however there is one more tiny hiccup. The text has lost all significant indention and newlines. Was this intended or is this a result of another bug? From pywin32 at gmail.com Thu Jan 5 23:08:30 2012 From: pywin32 at gmail.com (random joe) Date: Thu, 5 Jan 2012 20:08:30 -0800 (PST) Subject: Help with python-list archives References: <78484055-dd01-4237-9217-9eb038fc744f@p16g2000yqd.googlegroups.com> <14749754.624.1325806776674.JavaMail.geo-discussion-forums@vbgw2> <8f3b98e1-3b21-4f06-8456-0a555a7ee523@u32g2000yqe.googlegroups.com> Message-ID: On Jan 5, 10:01?pm, random joe wrote: > On Jan 5, 9:00?pm, MRAB wrote: > > import gzip > > > in_file = gzip.open(r"C:\2012-January.txt.gz") > > out_file = open(r"C:\2012-January.txt.tmp", "wb") > > out_file.write(in_file.read()) > > in_file.close() > > out_file.close() > > > in_file = gzip.open(r"C:\2012-January.txt.tmp") > > out_file = open(r"C:\2012-January.txt", "wb") > > out_file.write(in_file.read()) > > in_file.close() > > out_file.close() > > EXCELLENT! Thanks. > > THis works however there is one more tiny hiccup. The text has lost > all significant indention and newlines. Was this intended or is this a > result of another bug? Nevermind. Notepad was the problem. After using a real editor the text is displayed correctly! Thanks for help everyone! PS: I wonder why no one has added a note to the Python-list archives to advise people about the bug? From rosuav at gmail.com Thu Jan 5 23:11:31 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Jan 2012 15:11:31 +1100 Subject: Help with python-list archives In-Reply-To: References: <78484055-dd01-4237-9217-9eb038fc744f@p16g2000yqd.googlegroups.com> <14749754.624.1325806776674.JavaMail.geo-discussion-forums@vbgw2> <8f3b98e1-3b21-4f06-8456-0a555a7ee523@u32g2000yqe.googlegroups.com> Message-ID: On Fri, Jan 6, 2012 at 3:01 PM, random joe wrote: > THis works however there is one more tiny hiccup. The text has lost > all significant indention and newlines. Was this intended or is this a > result of another bug? I'm seeing it as plain text, with proper newlines. There's no indentation as it just runs straight through, top-to-bottom; but you should be able to see line breaks. Check your mail reader in case something's getting botched there. ChrisA From rosuav at gmail.com Thu Jan 5 23:12:04 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Jan 2012 15:12:04 +1100 Subject: Help with python-list archives In-Reply-To: References: <78484055-dd01-4237-9217-9eb038fc744f@p16g2000yqd.googlegroups.com> <14749754.624.1325806776674.JavaMail.geo-discussion-forums@vbgw2> <8f3b98e1-3b21-4f06-8456-0a555a7ee523@u32g2000yqe.googlegroups.com> Message-ID: On Fri, Jan 6, 2012 at 3:08 PM, random joe wrote: > Nevermind. Notepad was the problem. After using a real editor the text > is displayed correctly! Thanks for help everyone! ... or that could be your problem :) ChrisA From rantingrickjohnson at gmail.com Fri Jan 6 00:22:46 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 5 Jan 2012 21:22:46 -0800 (PST) Subject: Spamming PyPI with stupid packages References: <87hb0d28j8.fsf@benfinney.id.au> <87aa6522au.fsf@benfinney.id.au> <4f02ba8d$0$29880$c3e8da3$5496439d@news.astraweb.com> <8762gs1mag.fsf@benfinney.id.au> <4f03ad75$0$11122$c3e8da3@news.astraweb.com> <878vloz0zi.fsf@benfinney.id.au> Message-ID: On Jan 3, 8:37?pm, Chris Angelico wrote: > On Wed, Jan 4, 2012 at 12:54 PM, Ben Finney wrote: > > It objectifies women. If you can't see how that's harmful to women, I > > haven't the stamina to educate you. > > And "import pickle" objectifies pickles. It's deplorable how few > gherkins become programmers, and I think it's because of these > immature jokes about pickles that have become entrenched in the Python > community. No, no, "import pickle" is not about objectifying pickles, it's a sub- conscience Freudian phallic symbol! import pickle pickle.LONG4 # Only the blind would miss that one! pickle.load pickle.dump pickle.EMPTY_DICT # Using GvR's pronunciation But don't worry, *some group* is sure to be offended. From rantingrickjohnson at gmail.com Fri Jan 6 00:26:31 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 5 Jan 2012 21:26:31 -0800 (PST) Subject: Spamming PyPI with stupid packages References: <87hb0d28j8.fsf@benfinney.id.au> <87aa6522au.fsf@benfinney.id.au> <4f02ba8d$0$29880$c3e8da3$5496439d@news.astraweb.com> <8762gs1mag.fsf@benfinney.id.au> <4f03ad75$0$11122$c3e8da3@news.astraweb.com> <878vloz0zi.fsf@benfinney.id.au> <4f03b3b6$0$11122$c3e8da3@news.astraweb.com> <87pqf0b33c.fsf@benfinney.id.au> Message-ID: <71acb4bd-217d-4fb5-a5a8-f5c782398d42@u32g2000yqe.googlegroups.com> On Jan 3, 8:42?pm, Ben Finney wrote: > Steven D'Aprano writes: > > On Wed, 04 Jan 2012 12:54:09 +1100, Ben Finney wrote: > > > It objectifies women. > > > So you claim. > > I'm sure you have a hundred ready rationalisations for why a joke that > has ?girlfriend? as a fungible object, together with ?car? and ?house? > as things to mechanically import into one's life, is somehow not > objectifying women. > > But, while those rationalisations may satisfy you, I'm not interested in > hearing them. If you don't see that the joke objectifies women, that > tells me quite a lot about how blinkered you are to the problem. > > For what it's worth, I'm very familiar with such rationalisations, > having employed them many times myself. Fortunately there are women who > will speak up against it and encourage men to do the same > . > > > Since you can't or won't persuade me (and anyone else reading) that > > this sort of joke is harmful, does that mean that you will stop > > claiming that it is harmful? > > I have no idea what it would take to persuade you in particular. I do > know that the combined privileges of being white, male, not-poor, and > English-fluent (and many more privileges, I'm sure) grant both of us the > luxury of barely even perceiving the harm done by a pervasive atmosphere > of even low-level prejudice against any given group of people. > > Women (to return to the people in question), on the other hand, do not > have that luxury. In this community they have no option but to be aware > of the privileges we males have here. > > We have very effective cognitive blinders, merely because we have never > needed to know what it's like being a woman in this prevalently-male > field. The onus is on us to try hard to see, despite those blinders and > easy rationalisations, that there is a lot we allow from our fellows > which is perpetuating a hostile environment. > > I'm not making a fuss about one sexist joke, which has already been > retracted by its author. I'm making a fuss about allowing and, worse, > defending such jokes as a tacitly-accepted norm of our community. And I > hope those of us who prefer to think of ourselves as not-sexist will act > to clean up our house more. Your points are all valid, except, not valid in this particular argument. import girlfriend is not sexist, no more than import car is selfish, and import house is greedy. I think the joke is on the poor guy who needs this module. He is a poor soul with nothing, who needs to import everything. From rantingrickjohnson at gmail.com Fri Jan 6 00:58:08 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 5 Jan 2012 21:58:08 -0800 (PST) Subject: Spamming PyPI with stupid packages References: Message-ID: <8b7226d5-d37b-4b9c-ba73-0b0ee6fe6640@f33g2000yqh.googlegroups.com> On Jan 1, 5:24?pm, Alexander Kapps wrote: > Uh oh, should I really send this? ... Yes. Yes, I should! Sorry, I > cannot resists. > > >>> allow everyone to do "import girlfriend" > > I'm betting on a joke, like antigravity only significantly less > > funny and more sexist. > > Absolutely not funny. I hope that someday people will understand > that sexism is just another form of racism. I want everyone to realize that just because you are offended by someones statements, actions, or behavior, DOES NOT mean those statements, actions or behaviors are wrong. Example: I have a right to buy the flag of your country and burn it. To you the flag is a symbol to be worshiped. SO WHAT! To me your flag is a worthless piece of cloth! And since i bought and own this worthless piece of cloth, i can burn it, stomp on it, poke it with a stick, and even wipe my kulo with it! Sure, doing all these things may make me look like a complete idiot, but it is my god given right to act like an idiot! Now, you could get all upset and call in the gestapo, or you could just have a giggle and go about your day. Choice is yours. Anecdote: A while back i read a story about some kids gesturing their middle fingers to on-duty policemen. As you might have guessed the kids were arrested, handled roughly, and charged with disorderly conduct. Soon after the kids sued the police department and received a nice amount of money for their false arrest. Just like the police, all the people getting upset over this light- hearted joke are over-reacting and trying to abuse power. They believe they have the power to stop other people from offending them. No, the police DO NOT have that power, and YOU don't not have that power. However, you DO have the power to ignore. And that is what the gestapo *should* have done. Now, if someone were making jokes about handicapped or mentally challenged people (or anyone who does not have the capacity to defend themselves) THEN you would be justified to make an argument. This case warrants no such justification. Heck, there is not even a specific victim to protect -- well, except for the poor guy who has to import everything. Nobody cares about him :'-( From wuwei23 at gmail.com Fri Jan 6 01:23:56 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 5 Jan 2012 22:23:56 -0800 (PST) Subject: =?GB2312?B?UmU6ILvYuLSjuiBwcm9ibGVtIHRvIGluc3RhbGwgRmxhc2s=?= References: Message-ID: On Jan 6, 1:08 pm, "????" <1248283... at qq.com> wrote: > yes i run python3,how to install flask in python3? You can't: http://flask.pocoo.org/docs/foreword/#the-status-of-python-3 From ian.g.kelly at gmail.com Fri Jan 6 02:41:01 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 Jan 2012 00:41:01 -0700 Subject: Help with python-list archives In-Reply-To: <4F0663E8.4090302@mrabarnett.plus.com> References: <78484055-dd01-4237-9217-9eb038fc744f@p16g2000yqd.googlegroups.com> <14749754.624.1325806776674.JavaMail.geo-discussion-forums@vbgw2> <8f3b98e1-3b21-4f06-8456-0a555a7ee523@u32g2000yqe.googlegroups.com> <4F0663E8.4090302@mrabarnett.plus.com> Message-ID: On Thu, Jan 5, 2012 at 8:00 PM, MRAB wrote: > import gzip > > in_file = gzip.open(r"C:\2012-January.txt.gz") > out_file = open(r"C:\2012-January.txt.tmp", "wb") > out_file.write(in_file.read()) > in_file.close() > out_file.close() > > in_file = gzip.open(r"C:\2012-January.txt.tmp") > out_file = open(r"C:\2012-January.txt", "wb") > out_file.write(in_file.read()) > in_file.close() > out_file.close() One could also avoid creating the intermediate file by using a StringIO to keep it in memory instead: import gzip from cStringIO import StringIO in_file = gzip.open('2012-January.txt.gz') tmp_file = StringIO(in_file.read()) in_file.close() in_file = gzip.GzipFile(fileobj=tmp_file) out_file = open('2012-January.txt', 'wb') out_file.write(in_file.read()) in_file.close() out_file.close() Sadly, GzipFile won't read directly from another GzipFile instance (ValueError: Seek from end not supported), so some sort of intermediate is necessary. From ian.g.kelly at gmail.com Fri Jan 6 02:45:25 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 Jan 2012 00:45:25 -0700 Subject: Help with python-list archives In-Reply-To: References: <78484055-dd01-4237-9217-9eb038fc744f@p16g2000yqd.googlegroups.com> <14749754.624.1325806776674.JavaMail.geo-discussion-forums@vbgw2> <8f3b98e1-3b21-4f06-8456-0a555a7ee523@u32g2000yqe.googlegroups.com> Message-ID: On Thu, Jan 5, 2012 at 9:08 PM, random joe wrote: > PS: I wonder why no one has added a note to the Python-list archives > to advise people about the bug? Probably nobody has noticed it until now. It seems to be a quirk of the archive files that they are double-gzipped, and most people probably just use gunzip or gzcat (or a higher-level tool that invokes those) to extract them, which seems to be smart enough to handle it. From dihedral88888 at googlemail.com Fri Jan 6 03:01:03 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 6 Jan 2012 00:01:03 -0800 (PST) Subject: problem to install Flask In-Reply-To: References: Message-ID: <21175980.655.1325836864075.JavaMail.geo-discussion-forums@preg25> MRAB? 2012?1?6????UTC+8??11?05?03???? > On 06/01/2012 02:24, ???? wrote: > > ~$ sudo easy_install Flask > > Searching for Flask > > Reading http://pypi.python.org/simple/Flask/ > > Reading http://github.com/mitsuhiko/flask/ > > Best match: Flask 0.8 > > Downloading > > http://pypi.python.org/packages/source/F/Flask/Flask-0.8.tar.gz#md5=a5169306cfe49b3b369086f2a63816ab > > Processing Flask-0.8.tar.gz > > Running Flask-0.8/setup.py -q bdist_egg --dist-dir > > /tmp/easy_install-tnoyjj/Flask-0.8/egg-dist-tmp-pq04_a > > Traceback (most recent call last): > > File "/usr/local/bin/easy_install", line 9, in > > load_entry_point('distribute==0.6.24', 'console_scripts', 'easy_install')() > > File > > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > > line 1883, in main > > with_ei_usage(lambda: > > File > > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > > line 1864, in with_ei_usage > > return f() > > File > > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > > line 1887, in > > distclass=DistributionWithoutHelpCommands, **kw > > File "/usr/local/lib/python3.2/distutils/core.py", line 148, in setup > > dist.run_commands() > > File "/usr/local/lib/python3.2/distutils/dist.py", line 917, in run_commands > > self.run_command(cmd) > > File "/usr/local/lib/python3.2/distutils/dist.py", line 936, in run_command > > cmd_obj.run() > > File > > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > > line 349, in run > > self.easy_install(spec, not self.no_deps) > > File > > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > > line 589, in easy_install > > return self.install_item(spec, dist.location, tmpdir, deps) > > File > > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > > line 619, in install_item > > dists = self.install_eggs(spec, download, tmpdir) > > File > > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > > line 809, in install_eggs > > return self.build_and_install(setup_script, setup_base) > > File > > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > > line 1086, in build_and_install > > self.run_setup(setup_script, setup_base, args) > > File > > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > > line 1075, in run_setup > > run_setup(setup_script, args) > > File > > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/sandbox.py", > > line 31, in run_setup > > lambda: exec(compile(open( > > File > > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/sandbox.py", > > line 73, in run > > return func() > > File > > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/sandbox.py", > > line 33, in > > ).read(), "setup.py", 'exec'), > > File "setup.py", line 62 > > print "Audit requires PyFlakes installed in your system.""" > > ^ > > SyntaxError: invalid syntax > > > > > > what is the matter? > > > The syntax of this line: > > print "Audit requires PyFlakes installed in your system." > > tells me that it's written for Python 2, but this: > > /usr/local/lib/python3.2 > > tells me that you're using Python 3. > > In Python 2, "print" is a statement; in Python 3 it's a function. http://docs.python.org/library/2to3.html I am studying the Python 2 to 3 module for code generation techniques under my debugged environments by various operating systems such as the linux, Windows or Apples. Python is an excellent programming language that really support cross platform SW developments. From dihedral88888 at googlemail.com Fri Jan 6 03:01:03 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 6 Jan 2012 00:01:03 -0800 (PST) Subject: problem to install Flask In-Reply-To: References: Message-ID: <21175980.655.1325836864075.JavaMail.geo-discussion-forums@preg25> MRAB? 2012?1?6????UTC+8??11?05?03???? > On 06/01/2012 02:24, ???? wrote: > > ~$ sudo easy_install Flask > > Searching for Flask > > Reading http://pypi.python.org/simple/Flask/ > > Reading http://github.com/mitsuhiko/flask/ > > Best match: Flask 0.8 > > Downloading > > http://pypi.python.org/packages/source/F/Flask/Flask-0.8.tar.gz#md5=a5169306cfe49b3b369086f2a63816ab > > Processing Flask-0.8.tar.gz > > Running Flask-0.8/setup.py -q bdist_egg --dist-dir > > /tmp/easy_install-tnoyjj/Flask-0.8/egg-dist-tmp-pq04_a > > Traceback (most recent call last): > > File "/usr/local/bin/easy_install", line 9, in > > load_entry_point('distribute==0.6.24', 'console_scripts', 'easy_install')() > > File > > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > > line 1883, in main > > with_ei_usage(lambda: > > File > > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > > line 1864, in with_ei_usage > > return f() > > File > > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > > line 1887, in > > distclass=DistributionWithoutHelpCommands, **kw > > File "/usr/local/lib/python3.2/distutils/core.py", line 148, in setup > > dist.run_commands() > > File "/usr/local/lib/python3.2/distutils/dist.py", line 917, in run_commands > > self.run_command(cmd) > > File "/usr/local/lib/python3.2/distutils/dist.py", line 936, in run_command > > cmd_obj.run() > > File > > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > > line 349, in run > > self.easy_install(spec, not self.no_deps) > > File > > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > > line 589, in easy_install > > return self.install_item(spec, dist.location, tmpdir, deps) > > File > > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > > line 619, in install_item > > dists = self.install_eggs(spec, download, tmpdir) > > File > > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > > line 809, in install_eggs > > return self.build_and_install(setup_script, setup_base) > > File > > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > > line 1086, in build_and_install > > self.run_setup(setup_script, setup_base, args) > > File > > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/command/easy_install.py", > > line 1075, in run_setup > > run_setup(setup_script, args) > > File > > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/sandbox.py", > > line 31, in run_setup > > lambda: exec(compile(open( > > File > > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/sandbox.py", > > line 73, in run > > return func() > > File > > "/usr/local/lib/python3.2/site-packages/distribute-0.6.24-py3.2.egg/setuptools/sandbox.py", > > line 33, in > > ).read(), "setup.py", 'exec'), > > File "setup.py", line 62 > > print "Audit requires PyFlakes installed in your system.""" > > ^ > > SyntaxError: invalid syntax > > > > > > what is the matter? > > > The syntax of this line: > > print "Audit requires PyFlakes installed in your system." > > tells me that it's written for Python 2, but this: > > /usr/local/lib/python3.2 > > tells me that you're using Python 3. > > In Python 2, "print" is a statement; in Python 3 it's a function. http://docs.python.org/library/2to3.html I am studying the Python 2 to 3 module for code generation techniques under my debugged environments by various operating systems such as the linux, Windows or Apples. Python is an excellent programming language that really support cross platform SW developments. From peter.mosley at talk21.com Fri Jan 6 04:02:01 2012 From: peter.mosley at talk21.com (peter) Date: Fri, 6 Jan 2012 01:02:01 -0800 (PST) Subject: help me get excited about python 3 References: Message-ID: I'm sure Python 3 is wonderful, but I make heavy use of the Python Imaging Library, which as I understand it has not been adapted to Python 3. There may be alternatives, but as I have a large amount of working code using PIL I am reluctant to drop it just yet. Peter From a24061 at ducksburg.com Fri Jan 6 04:12:22 2012 From: a24061 at ducksburg.com (Adam Funk) Date: Fri, 06 Jan 2012 09:12:22 +0000 Subject: UnicodeEncodeError when piping stdout, but not when printing directly to the console References: Message-ID: On 2012-01-04, Peter Otten wrote: > Adam Funk wrote: >> How can I force python (preferably within my python program, rather >> than having to set something externally) to treat stdout as UTF-8? > > > $ cat force_utf8.py > # -*- coding: utf-8 -*- > import sys > > if sys.stdout.encoding is None: > import codecs > writer = codecs.getwriter("utf-8") > sys.stdout = writer(sys.stdout) > > print u"?hnlich ?blich n?tig" That's great, thanks! I guess issues like this will magically go away when I eventually move to Python 3? -- Physics is like sex. Sure, it may give some practical results, but that's not why we do it. [Richard Feynman] From __peter__ at web.de Fri Jan 6 04:34:10 2012 From: __peter__ at web.de (Peter Otten) Date: Fri, 06 Jan 2012 10:34:10 +0100 Subject: UnicodeEncodeError when piping stdout, but not when printing directly to the console References: Message-ID: Adam Funk wrote: > On 2012-01-04, Peter Otten wrote: > >> Adam Funk wrote: > >>> How can I force python (preferably within my python program, rather >>> than having to set something externally) to treat stdout as UTF-8? >> >> >> $ cat force_utf8.py >> # -*- coding: utf-8 -*- >> import sys >> >> if sys.stdout.encoding is None: >> import codecs >> writer = codecs.getwriter("utf-8") >> sys.stdout = writer(sys.stdout) >> >> print u"?hnlich ?blich n?tig" > > That's great, thanks! > > I guess issues like this will magically go away when I eventually move > to Python 3? Not "magically", but UTF-8 has become the default encoding... From ulrich.eckhardt at dominolaser.com Fri Jan 6 04:48:00 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Fri, 06 Jan 2012 10:48:00 +0100 Subject: replacing __dict__ with an OrderedDict Message-ID: Hi! The topic explains pretty much what I'm trying to do under Python 2.7[1]. The reason for this is that I want dir(SomeType) to show the attributes in the order of their declaration. This in turn should hopefully make unittest execute my tests in the order of their declaration[2], so that the output becomes more readable and structured, just as my test code (hopefully) is. I've been toying around with metaclasses, trying to replace __dict__ directly, or using type() to construct the class, but either I hit read-only attributes or the changes seem to be ignored. As additional thought (but I'm not there yet), I guess that if I want dir(some_object) to be ordered similarly, I will also have to perform some steps on instance creation, not only on class creation, right? Thanks for any suggestions! Uli [1] I'm stuck with 2.x for now, from what I found it would be easier using 3.x. [2] No, don't tell me that the tests should run in any order. It's not the case that my tests depend on each other, but if one basic test for the presence of an API fails, the elaborate tests using that API will obviously fail, too, and I just want to take the first test that fails and analyse that instead of guessing the point to start debugging from the N failed tests. From ivan at llaisdy.com Fri Jan 6 05:03:17 2012 From: ivan at llaisdy.com (Ivan) Date: Fri, 06 Jan 2012 10:03:17 +0000 Subject: How to support a non-standard encoding? Message-ID: Dear All I'm developing a python application for which I need to support a non-standard character encoding (specifically ISO 6937/2-1983, Addendum 1-1989). Here are some of the properties of the encoding and its use in the application: - I need to read and write data to/from files. The file format includes two sections in different character encodings (so I shan't be able to use codecs.open()). - iso-6937 sections include non-printing control characters - iso-6937 is a variable width encoding, e.g. "A" = [41], "?" = [0xC8, 0x41]; all non-spacing diacritical marks are in the range 0xC0-0xCF. By any chance is there anyone out there working on iso-6937? Otherwise, I think I need to write a new codec to support reading and writing this data. Does anyone know of any tutorials or blog posts on implementing a codec for a non-standard characeter encoding? Would anyone be interested in reading one? With thanks and best wishes Ivan -- ============================================================ Ivan A. Uemlianin Llaisdy Speech Technology Research and Development ivan at llaisdy.com www.llaisdy.com llaisdy.wordpress.com github.com/llaisdy www.linkedin.com/in/ivanuemlianin "Froh, froh! Wie seine Sonnen, seine Sonnen fliegen" (Schiller, Beethoven) ============================================================ From sheng.peisi.luo at gmail.com Fri Jan 6 05:03:56 2012 From: sheng.peisi.luo at gmail.com (=?UTF-8?B?572X5pmf?=) Date: Fri, 6 Jan 2012 02:03:56 -0800 (PST) Subject: share a apache pattern log parser Message-ID: <11ee2f62-329f-4372-8b2b-fd3c13d71060@y12g2000yqc.googlegroups.com> Hi, folks. Recently my work involved lots of parsing and statics of apache server log. Yes, we have pylogsparser and apachelog, but none of them is for human IMHO :( Inspired by kennethreitz, who is the author of the fabulous requests module, and his concept of "python for human", I extract a little apache pattern server log parser "apache_log_parser" to share with you at https://github.com/happy15/apache_log_parser Hope you like it. From lie.1296 at gmail.com Fri Jan 6 06:43:00 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Fri, 06 Jan 2012 22:43:00 +1100 Subject: replacing __dict__ with an OrderedDict In-Reply-To: References: Message-ID: On 01/06/2012 08:48 PM, Ulrich Eckhardt wrote: > Hi! > > The topic explains pretty much what I'm trying to do under Python > 2.7[1]. The reason for this is that I want dir(SomeType) to show the > attributes in the order of their declaration. This in turn should > hopefully make unittest execute my tests in the order of their > declaration[2], so that the output becomes more readable and structured, > just as my test code (hopefully) is. IMO that's a futile effort, first, because as you already know, the test should not rely on the order. If you want the result to be printed in a certain order, that's a display issue, not testing order issue. I guess you would have better luck doing what you want by customizing the TestResult or TestRunner. From __peter__ at web.de Fri Jan 6 06:44:21 2012 From: __peter__ at web.de (Peter Otten) Date: Fri, 06 Jan 2012 12:44:21 +0100 Subject: replacing __dict__ with an OrderedDict References: Message-ID: Ulrich Eckhardt wrote: > The topic explains pretty much what I'm trying to do under Python > 2.7[1]. The reason for this is that I want dir(SomeType) to show the > attributes in the order of their declaration. This in turn should > hopefully make unittest execute my tests in the order of their > declaration[2], so that the output becomes more readable and structured, > just as my test code (hopefully) is. > > I've been toying around with metaclasses, trying to replace __dict__ > directly, or using type() to construct the class, but either I hit > read-only attributes or the changes seem to be ignored. Alternatively you can write your own test loader: $ cat ordered_unittest2.py import unittest class Test(unittest.TestCase): def test_gamma(self): pass def test_beta(self): pass def test_alpha(self): pass class Loader(unittest.TestLoader): def getTestCaseNames(self, testCaseClass): """Return a sequence of method names found within testCaseClass sorted by co_firstlineno. """ def first_lineno(name): method = getattr(testCaseClass, name) return method.im_func.__code__.co_firstlineno function_names = super(Loader, self).getTestCaseNames(testCaseClass) function_names.sort(key=first_lineno) return function_names if __name__ == "__main__": unittest.main(testLoader=Loader()) $ python2.7 ordered_unittest2.py -v test_gamma (__main__.Test) ... ok test_beta (__main__.Test) ... ok test_alpha (__main__.Test) ... ok ---------------------------------------------------------------------- Ran 3 tests in 0.001s OK $ From ulrich.eckhardt at dominolaser.com Fri Jan 6 08:36:25 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Fri, 06 Jan 2012 14:36:25 +0100 Subject: replacing __dict__ with an OrderedDict In-Reply-To: References: Message-ID: Am 06.01.2012 12:43, schrieb Lie Ryan: > On 01/06/2012 08:48 PM, Ulrich Eckhardt wrote: >> Hi! >> >> The topic explains pretty much what I'm trying to do under Python >> 2.7[1]. The reason for this is that I want dir(SomeType) to show the >> attributes in the order of their declaration. This in turn should >> hopefully make unittest execute my tests in the order of their >> declaration[2], so that the output becomes more readable and structured, >> just as my test code (hopefully) is. > > IMO that's a futile effort, first, because as you already know, the test > should not rely on the order. If you want the result to be printed in a > certain order, that's a display issue, not testing order issue. I'm not sure if you just -ahem- enjoy Usenet discussions, but please read the footnote that explains that I don't want to discuss this part and why you are actually wrong with your partial understanding of the issue. ;^) > I guess you would have better luck doing what you want by customizing > the TestResult or TestRunner. True, perhaps, but doing it this way would be more fun and easier reusable in other cases where the default order is not desirable. I can also go and name the test functions test_000 to test_009 to get results quickly, if that was the only goal. Cheers! Uli From ulrich.eckhardt at dominolaser.com Fri Jan 6 08:40:26 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Fri, 06 Jan 2012 14:40:26 +0100 Subject: replacing __dict__ with an OrderedDict In-Reply-To: References: Message-ID: Am 06.01.2012 12:44, schrieb Peter Otten: > Alternatively you can write your own test loader: [...CODE...] Well, actually you just did that for me and it works! ;) Nonetheless, I'm still wondering if I could somehow replace the dict with an OrderedDict. Thank you! Uli From tim.wintle at teamrubber.com Fri Jan 6 08:47:26 2012 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Fri, 06 Jan 2012 13:47:26 +0000 Subject: How to support a non-standard encoding? In-Reply-To: References: Message-ID: <1325857646.7790.4.camel@tim-laptop> On Fri, 2012-01-06 at 10:03 +0000, Ivan wrote: > Dear All > > I'm developing a python application for which I need to support a > non-standard character encoding (specifically ISO 6937/2-1983, Addendum > 1-1989). If your system version of iconv contains that encoding (mine does) then you could use a wrapped iconv library to avoid re-inventing the wheel. I've got a forked version of the "iconv" package from pypi available here: .. it should work on python2.5-2.7 Tim From ralf at systemexit.de Fri Jan 6 08:59:14 2012 From: ralf at systemexit.de (Ralf Schmitt) Date: Fri, 06 Jan 2012 14:59:14 +0100 Subject: [ANNOUNCE] greenlet 0.3.3 Message-ID: <874nw9gcel.fsf@winserver.brainbot.com> Hi, I have uploaded greenlet 0.3.3 to PyPI: http://pypi.python.org/pypi/greenlet What is it? ----------- The greenlet module provides coroutines for python. coroutines allow suspending and resuming execution at certain locations. concurrence[1], eventlet[2] and gevent[3] use the greenlet module in order to implement concurrent network applications. Documentation can be found here: http://greenlet.readthedocs.org The code is hosted on github: https://github.com/python-greenlet/greenlet Changes in version 0.3.3 ------------------------ The NEWS file lists these changes for release 0.3.3: * Use sphinx to build documentation and publish it on greenlet.rtfd.org * Prevent segfaults on openbsd 4/i386 * Workaround gcc-4.0 not allowing to clobber rbx * Enhance test infrastructure * Fix possible compilation problems when including greenlet.h in C++ mode * Make the greenlet module work on x64 windows * Add a test for greenlet C++ exceptions * Fix compilation on Solaris with SunStudio [1] http://opensource.hyves.org/concurrence/ [2] http://eventlet.net/ [3] http://www.gevent.org/ -- Cheers Ralf Schmitt From ivan at llaisdy.com Fri Jan 6 09:03:56 2012 From: ivan at llaisdy.com (Ivan Uemlianin) Date: Fri, 06 Jan 2012 14:03:56 +0000 Subject: How to support a non-standard encoding? In-Reply-To: <1325857646.7790.4.camel@tim-laptop> References: <1325857646.7790.4.camel@tim-laptop> Message-ID: <4F06FF4C.3030500@llaisdy.com> Dear Tim Thanks for your help. > If your system version of iconv contains that encoding, ... Alas, it doesn't: $ iconv -l |grep 6937 $ Also, I'd like to package the app so other people could use it, so I wouldn't want to depend too much on the local OS. Best wishes Ivan On 06/01/2012 13:47, Tim Wintle wrote: > On Fri, 2012-01-06 at 10:03 +0000, Ivan wrote: >> Dear All >> >> I'm developing a python application for which I need to support a >> non-standard character encoding (specifically ISO 6937/2-1983, Addendum >> 1-1989). > > If your system version of iconv contains that encoding (mine does) then > you could use a wrapped iconv library to avoid re-inventing the wheel. > > I've got a forked version of the "iconv" package from pypi available > here: > > > > .. it should work on python2.5-2.7 > > Tim > -- ============================================================ Ivan A. Uemlianin Llaisdy Speech Technology Research and Development ivan at llaisdy.com www.llaisdy.com llaisdy.wordpress.com github.com/llaisdy www.linkedin.com/in/ivanuemlianin "Froh, froh! Wie seine Sonnen, seine Sonnen fliegen" (Schiller, Beethoven) ============================================================ From ethan at stoneleaf.us Fri Jan 6 09:13:43 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 06 Jan 2012 06:13:43 -0800 Subject: replacing __dict__ with an OrderedDict In-Reply-To: References: Message-ID: <4F070197.7000809@stoneleaf.us> Ulrich Eckhardt wrote: > Hi! > > The topic explains pretty much what I'm trying to do under Python > 2.7[1]. The reason for this is that I want dir(SomeType) to show the > attributes in the order of their declaration. This in turn should > hopefully make unittest execute my tests in the order of their > declaration[2], so that the output becomes more readable and structured, > just as my test code (hopefully) is. I believe unittest executes tests in alphabetical order, but it does not display them in the same order when it prints error/fail results. ~Ethan~ From a24061 at ducksburg.com Fri Jan 6 09:22:17 2012 From: a24061 at ducksburg.com (Adam Funk) Date: Fri, 06 Jan 2012 14:22:17 +0000 Subject: UnicodeEncodeError when piping stdout, but not when printing directly to the console References: Message-ID: On 2012-01-06, Peter Otten wrote: > Adam Funk wrote: > >> On 2012-01-04, Peter Otten wrote: >> >>> Adam Funk wrote: >> >>>> How can I force python (preferably within my python program, rather >>>> than having to set something externally) to treat stdout as UTF-8? >>> >>> >>> $ cat force_utf8.py >>> # -*- coding: utf-8 -*- >>> import sys >>> >>> if sys.stdout.encoding is None: >>> import codecs >>> writer = codecs.getwriter("utf-8") >>> sys.stdout = writer(sys.stdout) >>> >>> print u"?hnlich ?blich n?tig" >> >> That's great, thanks! >> >> I guess issues like this will magically go away when I eventually move >> to Python 3? > > Not "magically", but UTF-8 has become the default encoding... Close enough! -- When Elaine turned 11, her mother sent her to train under Donald Knuth in his mountain hideaway. [XKCD 342] From tundra at tundraware.com Fri Jan 6 10:18:22 2012 From: tundra at tundraware.com (Tim Daneliuk) Date: Fri, 06 Jan 2012 09:18:22 -0600 Subject: [ANN]: 'tsshbatch', Batch ssh Tool, Version 1.134 Released Message-ID: 'tsshbatch' Version 1.134 is now released and available for download at: http://www.tundraware.com/Software/tsshbatch This is the first public release. --------------------------------------------------------------------- What Is 'tsshbatch'? ------------------ 'tsshbatch' is a tool to enable you to issue a command to many servers without having to log into each one separately. When writing scripts, this overcomes the 'ssh' limitation of not being able to specify the password on the command line. 'tsshbatch' also understands basic 'sudo' syntax and can be used to access a server, 'sudo' a command, and then exit. 'tsshbatch' thus allows you to write complex, hands-off scripts that issue commands to many servers without the tedium of manual login and 'sudo' promotion. System administrators, especially, will find this helpful when working in large server farms. 'tsshbatch' is written in Python and requires the 'paramiko library. It has been tested on various Linux and FreeBSD variants as well as cygwin on MS-Windows. --------------------------------------------------------------------- Complete details of all fixes, changes, and new features can be found in the WHATSNEW.txt and documentation files included in the distribution. A FreeBSD port has been submitted as well. From ian.g.kelly at gmail.com Fri Jan 6 11:06:02 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 Jan 2012 09:06:02 -0700 Subject: replacing __dict__ with an OrderedDict In-Reply-To: References: Message-ID: On Fri, Jan 6, 2012 at 6:40 AM, Ulrich Eckhardt wrote: > Nonetheless, I'm still wondering if I could somehow replace the dict with an > OrderedDict. In Python 3, yes. This is pretty much the entire use case for the new __prepare__ method of metaclasses. See the "OrderedClass" example at: http://docs.python.org/py3k/reference/datamodel.html#special-method-names Cheers, Ian From ian.g.kelly at gmail.com Fri Jan 6 11:07:24 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 Jan 2012 09:07:24 -0700 Subject: replacing __dict__ with an OrderedDict In-Reply-To: References: Message-ID: On Fri, Jan 6, 2012 at 9:06 AM, Ian Kelly wrote: > On Fri, Jan 6, 2012 at 6:40 AM, Ulrich Eckhardt > wrote: >> Nonetheless, I'm still wondering if I could somehow replace the dict with an >> OrderedDict. > > In Python 3, yes. ?This is pretty much the entire use case for the new > __prepare__ method of metaclasses. ?See the "OrderedClass" example at: > http://docs.python.org/py3k/reference/datamodel.html#special-method-names That link should be: http://docs.python.org/py3k/reference/datamodel.html#customizing-class-creation From lie.1296 at gmail.com Fri Jan 6 12:01:44 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 07 Jan 2012 04:01:44 +1100 Subject: replacing __dict__ with an OrderedDict In-Reply-To: References: Message-ID: On 01/07/2012 12:36 AM, Ulrich Eckhardt wrote: > Am 06.01.2012 12:43, schrieb Lie Ryan: >> On 01/06/2012 08:48 PM, Ulrich Eckhardt wrote: >>> Hi! >>> >>> The topic explains pretty much what I'm trying to do under Python >>> 2.7[1]. The reason for this is that I want dir(SomeType) to show the >>> attributes in the order of their declaration. This in turn should >>> hopefully make unittest execute my tests in the order of their >>> declaration[2], so that the output becomes more readable and structured, >>> just as my test code (hopefully) is. >> >> IMO that's a futile effort, first, because as you already know, the test >> should not rely on the order. If you want the result to be printed in a >> certain order, that's a display issue, not testing order issue. > > I'm not sure if you just -ahem- enjoy Usenet discussions, but please > read the footnote that explains that I don't want to discuss this part > and why you are actually wrong with your partial understanding of the > issue. ;^) I fully understand your issue, and I stand by my opinion. I believe you're misunderstanding the nature of your problem, your issue is not that you want a customized test order execution, but you want a customized view of the test result. That unittest executes its tests in alphabetical order is implementation detail for a very good reason, and good unittest practice dictates that execution order should never be defined (some even argued that the execution order should be randomized). If the test runner turns out to execute tests concurrently, that should not cause problems for a well-designed test. Displaying the test results in a more convenient order for viewing is what you really wanted in 99.99% of the cases. > > I guess you would have better luck doing what you want by customizing > > the TestResult or TestRunner. > > True, perhaps, but doing it this way would be more fun and easier > reusable in other cases where the default order is not desirable. I can > also go and name the test functions test_000 to test_009 to get results > quickly, if that was the only goal. Fun and easier, perhaps. Except that it solves the wrong problem. From ian.g.kelly at gmail.com Fri Jan 6 12:20:28 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 Jan 2012 10:20:28 -0700 Subject: replacing __dict__ with an OrderedDict In-Reply-To: References: Message-ID: On Fri, Jan 6, 2012 at 10:01 AM, Lie Ryan wrote: > That unittest executes its tests in alphabetical order is implementation > detail for a very good reason, and good unittest practice dictates that > execution order should never be defined (some even argued that the execution > order should be randomized). If the test runner turns out to execute tests > concurrently, that should not cause problems for a well-designed test. > Displaying the test results in a more convenient order for viewing is what > you really wanted in 99.99% of the cases. Randomizing the order is not a bad idea, but you also need to be able to run the tests in a consistent order, from a specific random seed. In the real world, test conflicts and dependencies do happen, and if we observe a failure, make a change, rerun the tests and observe success, we need to be able to be sure that we actually fixed the bug, and that it didn't pass only because it was run in a different order. Concurrent testing is a bad idea for this reason -- it's not repeatable (testing concurrency, OTOH, is a perfectly fine thing to be thinking about). Cheers, Ian From lie.1296 at gmail.com Fri Jan 6 12:42:53 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 07 Jan 2012 04:42:53 +1100 Subject: replacing __dict__ with an OrderedDict In-Reply-To: References: Message-ID: On 01/07/2012 04:20 AM, Ian Kelly wrote: > On Fri, Jan 6, 2012 at 10:01 AM, Lie Ryan wrote: >> That unittest executes its tests in alphabetical order is implementation >> detail for a very good reason, and good unittest practice dictates that >> execution order should never be defined (some even argued that the execution >> order should be randomized). If the test runner turns out to execute tests >> concurrently, that should not cause problems for a well-designed test. >> Displaying the test results in a more convenient order for viewing is what >> you really wanted in 99.99% of the cases. > > Randomizing the order is not a bad idea, but you also need to be able > to run the tests in a consistent order, from a specific random seed. > In the real world, test conflicts and dependencies do happen, and if > we observe a failure, make a change, rerun the tests and observe > success, we need to be able to be sure that we actually fixed the bug, > and that it didn't pass only because it was run in a different order. > > Concurrent testing is a bad idea for this reason -- it's not > repeatable (testing concurrency, OTOH, is a perfectly fine thing to be > thinking about). Concurrent testing is perfectly fine strategy in the case where you have thousands of tests and running them synchronously will just take too long. Certainly it makes it harder to repeat the test if there is any sort of dependency in the tests, but when you have the large number of tests, the benefit may exceeds the drawbacks. From dmitrey15 at gmail.com Fri Jan 6 13:02:28 2012 From: dmitrey15 at gmail.com (dmitrey) Date: Fri, 6 Jan 2012 10:02:28 -0800 (PST) Subject: how to get id(function) for each function in stack? Message-ID: <1002d4cd-6cfe-4b79-917f-361a06ffd215@a11g2000vbz.googlegroups.com> hi all, how to get id(func) for each func in stack? (I mean memory address, to compare it with id(some known funcs)) Thank you in advance, D. From ian.g.kelly at gmail.com Fri Jan 6 13:28:21 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 Jan 2012 11:28:21 -0700 Subject: how to get id(function) for each function in stack? In-Reply-To: <1002d4cd-6cfe-4b79-917f-361a06ffd215@a11g2000vbz.googlegroups.com> References: <1002d4cd-6cfe-4b79-917f-361a06ffd215@a11g2000vbz.googlegroups.com> Message-ID: On Fri, Jan 6, 2012 at 11:02 AM, dmitrey wrote: > hi all, > how to get id(func) for each func in stack? (I mean memory address, to > compare it with id(some known funcs)) > Thank you in advance, D. The answer hasn't changed since your last thread about this. The stack contains code objects, not functions. You can get the code objects using inspect.stack(), and compare them to the func_code attributes of the functions you're interested in. Also, there's no need to use id() for this. Just use the "is" operator to check identity. for frame_tuple in inspect.stack(): frame = frame_tuple[0] if frame.f_code is some_function.func_code: print("Found it!") Cheers, Ian From dmitrey15 at gmail.com Fri Jan 6 14:29:16 2012 From: dmitrey15 at gmail.com (dmitrey) Date: Fri, 6 Jan 2012 11:29:16 -0800 (PST) Subject: how to get id(function) for each function in stack? References: <1002d4cd-6cfe-4b79-917f-361a06ffd215@a11g2000vbz.googlegroups.com> Message-ID: <9f8a8fd4-3541-4f9b-a887-3d10524de8f1@t30g2000vbx.googlegroups.com> On Jan 6, 8:28?pm, Ian Kelly wrote: > On Fri, Jan 6, 2012 at 11:02 AM, dmitrey wrote: > > hi all, > > how to get id(func) for each func in stack? (I mean memory address, to > > compare it with id(some known funcs)) > > Thank you in advance, D. > > The answer hasn't changed since your last thread about this. ?The > stack contains code objects, not functions. ?You can get the code > objects using inspect.stack(), and compare them to the func_code > attributes of the functions you're interested in. > > Also, there's no need to use id() for this. ?Just use the "is" > operator to check identity. > > for frame_tuple in inspect.stack(): > ? ? frame = frame_tuple[0] > ? ? if frame.f_code is some_function.func_code: > ? ? ? ? print("Found it!") > > Cheers, > Ian Python build-in function sum() has no attribute func_code, what should I do in the case? D. From ian.g.kelly at gmail.com Fri Jan 6 14:50:43 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 Jan 2012 12:50:43 -0700 Subject: how to get id(function) for each function in stack? In-Reply-To: <9f8a8fd4-3541-4f9b-a887-3d10524de8f1@t30g2000vbx.googlegroups.com> References: <1002d4cd-6cfe-4b79-917f-361a06ffd215@a11g2000vbz.googlegroups.com> <9f8a8fd4-3541-4f9b-a887-3d10524de8f1@t30g2000vbx.googlegroups.com> Message-ID: On Fri, Jan 6, 2012 at 12:29 PM, dmitrey wrote: > Python build-in function sum() has no attribute func_code, what should > I do in the case? Built-in functions and C extension functions have no code objects, and for that reason they also do not exist in the stack. There is no way to find sum() in the Python stack, because it isn't there. From d at davea.name Fri Jan 6 14:56:26 2012 From: d at davea.name (Dave Angel) Date: Fri, 06 Jan 2012 14:56:26 -0500 Subject: how to get id(function) for each function in stack? In-Reply-To: <9f8a8fd4-3541-4f9b-a887-3d10524de8f1@t30g2000vbx.googlegroups.com> References: <1002d4cd-6cfe-4b79-917f-361a06ffd215@a11g2000vbz.googlegroups.com> <9f8a8fd4-3541-4f9b-a887-3d10524de8f1@t30g2000vbx.googlegroups.com> Message-ID: <4F0751EA.3020507@davea.name> On 01/06/2012 02:29 PM, dmitrey wrote: > On Jan 6, 8:28 pm, Ian Kelly wrote: >> On Fri, Jan 6, 2012 at 11:02 AM, dmitrey wrote: >>> hi all, >>> how to get id(func) for each func in stack? (I mean memory address, to >>> compare it with id(some known funcs)) >>> Thank you in advance, D. >> The answer hasn't changed since your last thread about this. The >> stack contains code objects, not functions. You can get the code >> objects using inspect.stack(), and compare them to the func_code >> attributes of the functions you're interested in. >> >> Also, there's no need to use id() for this. Just use the "is" >> operator to check identity. >> >> for frame_tuple in inspect.stack(): >> frame = frame_tuple[0] >> if frame.f_code is some_function.func_code: >> print("Found it!") >> >> Cheers, >> Ian > Python build-in function sum() has no attribute func_code, what should > I do in the case? > D. flag = False for frame_tuple in inspect.stack(): frame = frame_tuple[0] if frame.f_code is some_function.func_code: flag = True if !flag: print "FuncDesigner.sum() not used. Change." -- DaveA From wxjmfauth at gmail.com Fri Jan 6 15:00:00 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Fri, 6 Jan 2012 12:00:00 -0800 (PST) Subject: How to support a non-standard encoding? References: Message-ID: <1480875f-d133-40a1-8fd1-dd31a2dd430b@d10g2000vbh.googlegroups.com> On 6 jan, 11:03, Ivan wrote: > Dear All > > I'm developing a python application for which I need to support a > non-standard character encoding (specifically ISO 6937/2-1983, Addendum > 1-1989). ?Here are some of the properties of the encoding and its use in > the application: > > ? ?- I need to read and write data to/from files. ?The file format > ? ? ?includes two sections in different character encodings (so I > ? ? ?shan't be able to use codecs.open()). > > ? ?- iso-6937 sections include non-printing control characters > > ? ?- iso-6937 is a variable width encoding, e.g. "A" = [41], > ? ? ?"?" = [0xC8, 0x41]; all non-spacing diacritical marks are in the > ? ? ?range 0xC0-0xCF. > > By any chance is there anyone out there working on iso-6937? > > Otherwise, I think I need to write a new codec to support reading and > writing this data. ?Does anyone know of any tutorials or blog posts on > implementing a codec for a non-standard characeter encoding? ?Would > anyone be interested in reading one? > Take a look at the files, Python modules, in the ...\Lib\encodings. This is the place where all codecs are centralized. Python is magically using these a long there are present in that dir. I remember, long time ago, for the fun, I created such a codec quite easily. I picked up one of the file as template and I modified its "table". It was a byte <-> byte table. For multibytes coding scheme, it may be a litte bit more complicated; you may take a look, eg, at the mbcs.py codec. The distibution of such a codec may be a problem. ---- Another simple approach, os independent. You probably do not write your code in iso-6937, but you only need to encode/decode some bytes sequence "on the fly". In that case, work with bytes, create a couple of coding / decoding functions with a created [*] as helper. It's not so complicate. Use Py2 or Py3 (the recommended way ;-) ) as pivot encoding. [*] I also created once a such a dict from # http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WindowsBestFit/bestfit1252.txt I never checked if it does correpond to the "official" cp1252 codec. jmf From ian.g.kelly at gmail.com Fri Jan 6 15:37:51 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 Jan 2012 13:37:51 -0700 Subject: how to get id(function) for each function in stack? In-Reply-To: <4F0751EA.3020507@davea.name> References: <1002d4cd-6cfe-4b79-917f-361a06ffd215@a11g2000vbz.googlegroups.com> <9f8a8fd4-3541-4f9b-a887-3d10524de8f1@t30g2000vbx.googlegroups.com> <4F0751EA.3020507@davea.name> Message-ID: On Fri, Jan 6, 2012 at 12:56 PM, Dave Angel wrote: > On 01/06/2012 02:29 PM, dmitrey wrote: >> >> On Jan 6, 8:28 pm, Ian Kelly ?wrote: >>> >>> On Fri, Jan 6, 2012 at 11:02 AM, dmitrey ?wrote: >>>> >>>> hi all, >>>> how to get id(func) for each func in stack? (I mean memory address, to >>>> compare it with id(some known funcs)) >>>> Thank you in advance, D. >>> >>> The answer hasn't changed since your last thread about this. ?The >>> stack contains code objects, not functions. ?You can get the code >>> objects using inspect.stack(), and compare them to the func_code >>> attributes of the functions you're interested in. >>> >>> Also, there's no need to use id() for this. ?Just use the "is" >>> operator to check identity. >>> >>> for frame_tuple in inspect.stack(): >>> ? ? frame = frame_tuple[0] >>> ? ? if frame.f_code is some_function.func_code: >>> ? ? ? ? print("Found it!") >>> >>> Cheers, >>> Ian >> >> Python build-in function sum() has no attribute func_code, what should >> I do in the case? >> D. > > flag = False > > > for frame_tuple in inspect.stack(): > ? ?frame = frame_tuple[0] > ? ?if frame.f_code is some_function.func_code: > ? ? ? ?flag = True > > if !flag: > ? ?print "FuncDesigner.sum() not used. ?Change." That would also print when no sum function is used at all, e.g. a simple "a + b". I don't think that's what the OP wants. From tim.wintle at teamrubber.com Fri Jan 6 15:42:33 2012 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Fri, 06 Jan 2012 20:42:33 +0000 Subject: How to support a non-standard encoding? In-Reply-To: <1480875f-d133-40a1-8fd1-dd31a2dd430b@d10g2000vbh.googlegroups.com> References: <1480875f-d133-40a1-8fd1-dd31a2dd430b@d10g2000vbh.googlegroups.com> Message-ID: <1325882553.17884.0.camel@tim-laptop> On Fri, 2012-01-06 at 12:00 -0800, jmfauth wrote: > The distibution of such a codec may be a problem. There is a register_codec method (or similar) in the codecs module. Tim From arnodel at gmail.com Fri Jan 6 16:32:31 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 6 Jan 2012 21:32:31 +0000 Subject: replacing __dict__ with an OrderedDict In-Reply-To: References: Message-ID: On 6 January 2012 11:44, Peter Otten <__peter__ at web.de> wrote: > class Loader(unittest.TestLoader): > ? ?def getTestCaseNames(self, testCaseClass): > ? ? ? ?"""Return a sequence of method names found within testCaseClass > ? ? ? ?sorted by co_firstlineno. > ? ? ? ?""" That's a clever trick! -- Arnaud From arnodel at gmail.com Fri Jan 6 16:38:32 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 6 Jan 2012 21:38:32 +0000 Subject: replacing __dict__ with an OrderedDict In-Reply-To: References: Message-ID: On 6 January 2012 13:40, Ulrich Eckhardt wrote: > Am 06.01.2012 12:44, schrieb Peter Otten: > >> Alternatively you can write your own test loader: > > [...CODE...] > > Well, actually you just did that for me and it works! ;) > > > Nonetheless, I'm still wondering if I could somehow replace the dict with an > OrderedDict. No, you can't. -- Arnaud From zyzhu2000 at gmail.com Fri Jan 6 16:46:16 2012 From: zyzhu2000 at gmail.com (GZ) Date: Fri, 6 Jan 2012 13:46:16 -0800 (PST) Subject: Nested Function Question Message-ID: <14889cd9-f02b-4a81-9ccb-8fb8492e1091@n39g2000yqh.googlegroups.com> Hi, I am reading the documentation of functools.partial (http:// docs.python.org/library/functools.html#functools.partial) and found the following 'reference implementation' of functools.partial. def partial(func, *args, **keywords): def newfunc(*fargs, **fkeywords): newkeywords = keywords.copy() newkeywords.update(fkeywords) return func(*(args + fargs), **newkeywords) newfunc.func = func newfunc.args = args newfunc.keywords = keywords return newfunc I don't understand why the below 3 lines are needed: newfunc.func = func newfunc.args = args newfunc.keywords = keywords It is as if they are trying to prevent garbage collection, but I don't get why it is needed. As long as something holds reference to newfunc, because it in turn references keywords and args, nothing will be freed. If nothing is referencing newfunc, then everything should be freed. Thanks, GZ From ian.g.kelly at gmail.com Fri Jan 6 17:04:20 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 Jan 2012 15:04:20 -0700 Subject: Nested Function Question In-Reply-To: <14889cd9-f02b-4a81-9ccb-8fb8492e1091@n39g2000yqh.googlegroups.com> References: <14889cd9-f02b-4a81-9ccb-8fb8492e1091@n39g2000yqh.googlegroups.com> Message-ID: On Fri, Jan 6, 2012 at 2:46 PM, GZ wrote: > Hi, > > I am reading the documentation of functools.partial (http:// > docs.python.org/library/functools.html#functools.partial) and found > the following 'reference implementation' of functools.partial. > > def partial(func, *args, **keywords): > ? ?def newfunc(*fargs, **fkeywords): > ? ? ? ?newkeywords = keywords.copy() > ? ? ? ?newkeywords.update(fkeywords) > ? ? ? ?return func(*(args + fargs), **newkeywords) > ? ?newfunc.func = func > ? ?newfunc.args = args > ? ?newfunc.keywords = keywords > ? ?return newfunc > > I don't understand why the below 3 lines are needed: > > ? ?newfunc.func = func > ? ?newfunc.args = args > ? ?newfunc.keywords = keywords > > > It is as if they are trying to prevent garbage collection, but I don't > get why it is needed. As long as something holds reference to newfunc, > because it in turn references keywords and args, nothing will be > freed. If nothing is referencing newfunc, then everything should be > freed. They exist for introspection. The partial object has to store the function and arguments it was passed so that it can call it later, so as long as they're being stored anyway, why not make them visible? From lie.1296 at gmail.com Fri Jan 6 19:17:38 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 07 Jan 2012 11:17:38 +1100 Subject: how to get id(function) for each function in stack? In-Reply-To: References: <1002d4cd-6cfe-4b79-917f-361a06ffd215@a11g2000vbz.googlegroups.com> <9f8a8fd4-3541-4f9b-a887-3d10524de8f1@t30g2000vbx.googlegroups.com> Message-ID: On 01/07/2012 06:50 AM, Ian Kelly wrote: > On Fri, Jan 6, 2012 at 12:29 PM, dmitrey wrote: >> Python build-in function sum() has no attribute func_code, what should >> I do in the case? > > Built-in functions and C extension functions have no code objects, and > for that reason they also do not exist in the stack. There is no way > to find sum() in the Python stack, because it isn't there. a practical solution to this issue is to wrap the C functions in Python functions. You lose some speed but that might be an acceptable tradeoff in some situations (especially if you're only wrapping when debugging). From steve+comp.lang.python at pearwood.info Fri Jan 6 19:45:31 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Jan 2012 00:45:31 GMT Subject: replacing __dict__ with an OrderedDict References: Message-ID: <4f0795ab$0$29966$c3e8da3$5496439d@news.astraweb.com> On Sat, 07 Jan 2012 04:01:44 +1100, Lie Ryan wrote: > On 01/07/2012 12:36 AM, Ulrich Eckhardt wrote: >> True, perhaps, but doing it this way would be more fun and easier >> reusable in other cases where the default order is not desirable. I can >> also go and name the test functions test_000 to test_009 to get results >> quickly, if that was the only goal. > > Fun and easier, perhaps. Except that it solves the wrong problem. Fun and easier, and a terrible thing to do. Contrast: "test_binsearch_tuple is failing. What does that mean?" "Oh, that tests that binsearch works on a tuple. You need to look at the BinSearch.search_tuple method and see what it's doing." with "test_047 is failing. What does that mean?" "How the hell should I know?" Debugging is hard enough without obfuscating the test names. You wouldn't write a function called "func_009", why write one called "test_009"? -- Steven From steve+comp.lang.python at pearwood.info Fri Jan 6 19:49:21 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Jan 2012 00:49:21 GMT Subject: replacing __dict__ with an OrderedDict References: Message-ID: <4f079690$0$29966$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 Jan 2012 10:20:28 -0700, Ian Kelly wrote: > On Fri, Jan 6, 2012 at 10:01 AM, Lie Ryan wrote: >> That unittest executes its tests in alphabetical order is >> implementation detail for a very good reason, and good unittest >> practice dictates that execution order should never be defined (some >> even argued that the execution order should be randomized). If the test >> runner turns out to execute tests concurrently, that should not cause >> problems for a well-designed test. Displaying the test results in a >> more convenient order for viewing is what you really wanted in 99.99% >> of the cases. > > Randomizing the order is not a bad idea, but you also need to be able to > run the tests in a consistent order, from a specific random seed. In the > real world, test conflicts and dependencies do happen, In the real world, test conflicts and dependencies are bugs in your test suite that should be fixed, like any other bug in code. The fact that it is test code that is failing is irrelevant. Also in the real world, sometimes it is too hard to fix a bug and you just live with it. > and if we observe > a failure, make a change, rerun the tests and observe success, we need > to be able to be sure that we actually fixed the bug, and that it didn't > pass only because it was run in a different order. Every test should stand alone. You should be able to isolate each and every test and run it without the others. If you can't, your test suite is buggy. (Chances are good that most test suites are buggy. After all, who writes tests for their tests? That's just the start of an infinite regress with rapidly diminishing benefit.) You may not be able to run tests *simultaneously*, due to clashes involving external resources, but you should be able to run them in random order. -- Steven From steve+comp.lang.python at pearwood.info Fri Jan 6 19:54:43 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Jan 2012 00:54:43 GMT Subject: how to get id(function) for each function in stack? References: <1002d4cd-6cfe-4b79-917f-361a06ffd215@a11g2000vbz.googlegroups.com> Message-ID: <4f0797d3$0$29966$c3e8da3$5496439d@news.astraweb.com> On Fri, 06 Jan 2012 10:02:28 -0800, dmitrey wrote: > hi all, > how to get id(func) for each func in stack? (I mean memory address, to > compare it with id(some known funcs)) Thank you in advance, D. id() does not return a memory address, except perhaps by accident. It returns a ID number. In Jython, and I think IronPython, id() returns a sequential number for each object created. The first object created by the Jython virtual machine gets ID 1, the second gets ID 2, and so on. -- Steven From pywin32 at gmail.com Fri Jan 6 19:55:32 2012 From: pywin32 at gmail.com (random joe) Date: Fri, 6 Jan 2012 16:55:32 -0800 (PST) Subject: Help with python-list archives References: <78484055-dd01-4237-9217-9eb038fc744f@p16g2000yqd.googlegroups.com> <14749754.624.1325806776674.JavaMail.geo-discussion-forums@vbgw2> <8f3b98e1-3b21-4f06-8456-0a555a7ee523@u32g2000yqe.googlegroups.com> <4F0663E8.4090302@mrabarnett.plus.com> Message-ID: <0616bd58-bb3d-4e75-b142-fc3979b20aac@cf6g2000vbb.googlegroups.com> On Jan 6, 1:41?am, Ian Kelly wrote: > One could also avoid creating the intermediate file by using a > StringIO to keep it in memory instead: Yes StringIO is perfect for this. Many thanks to all who replied. From lie.1296 at gmail.com Fri Jan 6 20:21:48 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 07 Jan 2012 12:21:48 +1100 Subject: replacing __dict__ with an OrderedDict In-Reply-To: <4f079690$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <4f079690$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01/07/2012 11:49 AM, Steven D'Aprano wrote: > You may not be able to run tests*simultaneously*, due to clashes > involving external resources, but you should be able to run them in > random order. tests that involves external resources should be mocked, although there are always a few external resources that cannot be mocked, those are the exceptions not the rule; a concurrent test runner might have mechanisms to mark them to be run synchronously. From ian.g.kelly at gmail.com Fri Jan 6 20:24:23 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 Jan 2012 18:24:23 -0700 Subject: replacing __dict__ with an OrderedDict In-Reply-To: <4f079690$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <4f079690$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Jan 6, 2012 at 5:49 PM, Steven D'Aprano wrote: > In the real world, test conflicts and dependencies are bugs in your test > suite that should be fixed, like any other bug in code. The fact that it > is test code that is failing is irrelevant. I agree 100%, but none of that changes my point, which is that when that this sort of problem arises, you need to be able to test consistently to know that the bug is actually fixed. > Every test should stand alone. You should be able to isolate each and > every test and run it without the others. Ideally, yes. I'm talking about *unintentional* conflicts and dependencies. From jeanpierreda at gmail.com Fri Jan 6 20:54:24 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Fri, 6 Jan 2012 20:54:24 -0500 Subject: python philosophical question - strong vs duck typing In-Reply-To: References: Message-ID: > where n,m are compiler variables used to define the dependent > (paramaterized) types array(int,n) and int(n)/ The double use of n means > that the compiler checks that length n of the array equals the length > passed. > > My response: in Python, there is no need to pass concrete collection sizes > because they are packaged with the collection at runtime as an attribute. > So: > > 1) In Python, there is no need for such checking. In addition, the for-loop > construct, 'for item in iterable:', removes the possibility of indexing > errors. Correct. This is a systems language, designed so that you do the least work possible and store the least amount possible in memory. For that reason it's one of the fastest languages on the language shootout, with the least memory usage overall. ( http://shootout.alioth.debian.org/ ) That is, you can also simply do "A[k] = 3", and if the compiler can prove that k is always less than the length of the list, then this goes ahead without any extra work like a runtime check. This is similar to what Cython does above, but Python always does the check -- and ATS makes this optimization a core feature of the language, and predictable: you can force the compiler to try to do this, and if it can't, you can try to provide more information so that it can. The easiest way to prove it was provided above, by doing a runtime check -- but there are other ways (e.g. the inference Cython did; convenient constants; etc.) This is probably less appealing to Python programmers, who (rightly) don't really care about speed unless it becomes an issue. For them, ATS also has more advanced features like proofs of adherence to specification and so on (e.g. FIB above). On the other hand, ATS's main focus is, as far as I can tell, being something that's "as fast as C, and safer than Haskell". I don't think it's meant for Pythonistas. :) (I've seen it compared to Ada, as well) I should also note that while Python stores the length information at runtime, you can do that in ATS too (it has exceptions). In fact, ATS has two array types: array0 keeps the size information at runtime, and array does not. With array0, out-of-bounds index access results in a runtime exception, with no compile-time checks performed. I don't really want to undestate how awesome Python is, though. I have long been of the opinion that C's attitude was unacceptable[**] -- if you forget to check, things go drastically wrong in undefined and unpredictable ways (that depend on your libc/compiler/etc.). Python offers a way out: all errors are checked for by Python itself. This makes your job easier and makes mistakes obvious. ATS is nowhere near as easy in general. :) Also, you make a good point about for loops. They are a wonderful thing. :) (ATS doesn't have them; it could get them in theory...) [*] With the idea being that in Python you can get unexpected errors at runtime, whereas in ATS you can try to prove they can't exist, at compile time. E.g. take "AttributeError: None has no attribute 'split'" versus non-nullable types [**] Unfortunately, C is still irreplaceable. ATS is never going to win this one. I do think that dependent typing will eventually enter the mainstream, though. It's a powerful concept we rely on implicitly all the time, and I seem to be seeing more of it lately. > 2) Python classes are, in a sense, or in effect, runtime dependent types. > While the formal implementation type of a 'list' is just 'list', the > effective computation type is 'mutable sequence of length n'. The type of an > iterator is 'read-only sequence of indefinite length'. I find this an > interesting way to look at Python. I think that's reasonable. I don't think it would be outrageous to promote this concept to how we do isinstance checks, but nobody but me seems to like things like "except IOError(errno.EBADF): ...". (Usually the if-statements aren't really more complicated, but IOError is an exception (which is being rectified a different way)). But yes, even without it being part of the language we can model it that way. And it's something we do all the time. I think another good example of that is the "k-tuple". k-tuples seem very different to n-tuples, for n != k. -- Devin On Wed, Jan 4, 2012 at 3:22 PM, Terry Reedy wrote: > On 1/4/2012 1:37 AM, Terry Reedy wrote: >> >> On 1/3/2012 8:04 PM, Devin Jeanpierre wrote: > > >>> [ An example of a simple dependently typed program: >>> http://codepad.org/eLr7lLJd ] >> >> >> Just got it after a minute delay. > > > A followup now that I have read it. Removing the 40 line comment, the > function itself is > > fun getitem{n,m:nat}(arr : array(int, n) , > ?length : int(n), index : int m) : int = > ? ?if index < length then > ? ? ? ?arr[index] > ? ?else > ? ? ? ?~1 (* -1, error *) > > where n,m are compiler variables used to define the dependent > (paramaterized) types array(int,n) and int(n)/ The double use of n means > that the compiler checks that length n of the array equals the length > passed. > > My response: in Python, there is no need to pass concrete collection sizes > because they are packaged with the collection at runtime as an attribute. > So: > > 1) In Python, there is no need for such checking. In addition, the for-loop > construct, 'for item in iterable:', removes the possibility of indexing > errors. > > 2) Python classes are, in a sense, or in effect, runtime dependent types. > While the formal implementation type of a 'list' is just 'list', the > effective computation type is 'mutable sequence of length n'. The type of an > iterator is 'read-only sequence of indefinite length'. I find this an > interesting way to look at Python. > > > -- > Terry Jan Reedy > > -- > http://mail.python.org/mailman/listinfo/python-list From alec.taylor6 at gmail.com Fri Jan 6 22:38:47 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sat, 7 Jan 2012 14:38:47 +1100 Subject: virtualenv wrecked my Django+modules install In-Reply-To: <60f10857-6a3d-4f3d-9d69-39487e4885f8@e2g2000vbb.googlegroups.com> References: <60f10857-6a3d-4f3d-9d69-39487e4885f8@e2g2000vbb.googlegroups.com> Message-ID: I ran Pinax-env\Scripts\deactivate.bat but it didn't change anything. I'm skeptical if satchmo will work in a virtualenv, since many of its dependencies (such as PIL) I had to install with a setup from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pil How would I get around this issue in a virtualenv? P:\Prototype>where python C:\Python27\python.exe P:\Prototype>Pinax-env\Scripts\activate.bat (Pinax-env) P:\Prototype>where python P:\Prototype\Pinax-env\Scripts\python.exe C:\Python27\python.exe From abdullahzuberi at gmail.com Sat Jan 7 03:07:38 2012 From: abdullahzuberi at gmail.com (abdullah zuberi) Date: Sat, 7 Jan 2012 13:07:38 +0500 Subject: No subject Message-ID: hello ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From vickyjackson606 at gmail.com Sat Jan 7 05:24:51 2012 From: vickyjackson606 at gmail.com (vicky jackson) Date: Sat, 7 Jan 2012 02:24:51 -0800 (PST) Subject: ====== Laptop Sale And Service ======= Message-ID: <79ff1def-13fa-4103-88b0-0a47a7f16ae8@k8g2000yqk.googlegroups.com> Laptop Sale And Service ============================= http://bit.ly/zqEA6Q ============================= Laptop, printer, scanner sales and services From robert.kern at gmail.com Sat Jan 7 05:39:28 2012 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 07 Jan 2012 10:39:28 +0000 Subject: how to get id(function) for each function in stack? In-Reply-To: References: <1002d4cd-6cfe-4b79-917f-361a06ffd215@a11g2000vbz.googlegroups.com> <9f8a8fd4-3541-4f9b-a887-3d10524de8f1@t30g2000vbx.googlegroups.com> Message-ID: On 1/7/12 12:17 AM, Lie Ryan wrote: > On 01/07/2012 06:50 AM, Ian Kelly wrote: >> On Fri, Jan 6, 2012 at 12:29 PM, dmitrey wrote: >>> Python build-in function sum() has no attribute func_code, what should >>> I do in the case? >> >> Built-in functions and C extension functions have no code objects, and >> for that reason they also do not exist in the stack. There is no way >> to find sum() in the Python stack, because it isn't there. > > a practical solution to this issue is to wrap the C functions in Python > functions. You lose some speed but that might be an acceptable tradeoff in some > situations (especially if you're only wrapping when debugging). His problem is that he wants to find out when someone is using the builtin sum() on his objects (which apparently don't react well to it) and give an informative warning. __builtin__.sum() is not under his control, fortunately. -- 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 sophie.sperner at gmail.com Sat Jan 7 05:59:21 2012 From: sophie.sperner at gmail.com (Sophie Sperner) Date: Sat, 7 Jan 2012 02:59:21 -0800 (PST) Subject: Getting involved Message-ID: Dear community, Let me ask here please. I'm a first-year PhD student in Ireland. My background is in mathematics, though I'm going to stream my career into programming with Python, Java and C++ languages. I have some good experience with C++ what allowed me to have a presentation in Europe quite recently - I participated in an open-source cloud computing project. I used Python a little bit in that project, though mainly it was in C++. I was reading a beautiful "Thinking in Java" book this summer while looking for a PhD. I have no experience in Java. I learned some Python while writing a website based on Django. I know some other auxiliary tools like Git, SVN, SQL, XML and javascript. Now... I really want to find a job, but there is no interesting job on the market or my skills are not enough to get one. So I really want to learn Python and Java in parallel by reading books (have already chosen proper ones), searching google (got used to it) and most important writing code and thus I think to participate in an open- source project again. Could you please list me 2 or 3 projects in Python and/or Java which are currently active (vivid) and useful? Thank you. From rosuav at gmail.com Sat Jan 7 06:13:40 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Jan 2012 22:13:40 +1100 Subject: Getting involved In-Reply-To: References: Message-ID: On Sat, Jan 7, 2012 at 9:59 PM, Sophie Sperner wrote: > Could you please list me 2 or 3 projects in Python and/or Java which > are currently active (vivid) and useful? Easiest way to find a project to join would be to go to SourceForge, Google Code, GitHub, BitBucket, or any other large hosting facility, and browse the project list. Soon as you find one that makes you go "That is SO COOL!", start reading their bugtracker. There's always something to play with! ChrisA From bahamutzero8825 at gmail.com Sat Jan 7 06:16:22 2012 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sat, 07 Jan 2012 05:16:22 -0600 Subject: Getting involved In-Reply-To: References: Message-ID: <4F082986.6010106@gmail.com> On 1/7/2012 4:59 AM, Sophie Sperner wrote: > Could you please list me 2 or 3 projects in Python and/or Java which > are currently active (vivid) and useful? If you really want to mix Python and Java, you could help the Jython project update to 3.x. One thing the Python community as a whole could really use is help transitioning to 3.x. If helping the alternate implementations (Jython, IronPython, PyPy) get to 3.x isn't quite what you're looking to do, look for a major project that needs to be ported to 3.x. I can't think of any off the top of my head since I haven't paid much attention to projects that don't support 3.x, but I'm sure there are many. -- CPython 3.2.2 | Windows NT 6.1.7601.17640 From sophie.sperner at gmail.com Sat Jan 7 06:17:13 2012 From: sophie.sperner at gmail.com (Sophie Sperner) Date: Sat, 7 Jan 2012 03:17:13 -0800 (PST) Subject: Getting involved References: Message-ID: On Jan 7, 11:13?am, Chris Angelico wrote: > On Sat, Jan 7, 2012 at 9:59 PM, Sophie Sperner wrote: > > Could you please list me 2 or 3 projects in Python and/or Java which > > are currently active (vivid) and useful? > > Easiest way to find a project to join would be to go to SourceForge, > Google Code, GitHub, BitBucket, or any other large hosting facility, > and browse the project list. Soon as you find one that makes you go > "That is SO COOL!", start reading their bugtracker. There's always > something to play with! > > ChrisA I tried github, but the description of the every project is so small that I can't understand it.. I browsed several pages of github and closed my browser - I have not found anything. I hope someone with a project in mind can write me here. Thanks. From sophie.sperner at gmail.com Sat Jan 7 06:36:58 2012 From: sophie.sperner at gmail.com (Sophie Sperner) Date: Sat, 7 Jan 2012 03:36:58 -0800 (PST) Subject: Getting involved References: Message-ID: <0106f4dc-41ad-46f1-8eca-e3ba50a7e382@f11g2000yql.googlegroups.com> Jython, don't want to migrate something. Then Django is very boring project. From stefan_ml at behnel.de Sat Jan 7 06:53:52 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 07 Jan 2012 12:53:52 +0100 Subject: Getting involved In-Reply-To: <4F082986.6010106@gmail.com> References: <4F082986.6010106@gmail.com> Message-ID: Andrew Berg, 07.01.2012 12:16: > On 1/7/2012 4:59 AM, Sophie Sperner wrote: >> Could you please list me 2 or 3 projects in Python and/or Java which >> are currently active (vivid) and useful? > > If you really want to mix Python and Java, you could help the Jython > project [...] A big issue that I have with Jython is that its ElementTree XML parser support is so increadibly slow. It could seriously benefit from a better integration between the Java XML support it uses and the Python ElementTree module that it inherits from CPython. Considering that XML is a requirement in many real world applications, especially in the Java world, you (Sophie) might be interested in adding all three of Python, Java and XML to your toolbox at the same time, while also learning how to benchmark and optimise Java and Python code. I think that would pretty quickly get you up to speed with real world software development. Stefan From sophie.sperner at gmail.com Sat Jan 7 07:01:12 2012 From: sophie.sperner at gmail.com (Sophie Sperner) Date: Sat, 7 Jan 2012 04:01:12 -0800 (PST) Subject: Getting involved References: <4F082986.6010106@gmail.com> Message-ID: On Jan 7, 11:53?am, Stefan Behnel wrote: > Andrew Berg, 07.01.2012 12:16: > > > On 1/7/2012 4:59 AM, Sophie Sperner wrote: > >> Could you please list me 2 or 3 projects in Python and/or Java which > >> are currently active (vivid) and useful? > > > If you really want to mix Python and Java, you could help the Jython > > project [...] > > A big issue that I have with Jython is that its ElementTree XML parser > support is so increadibly slow. It could seriously benefit from a better > integration between the Java XML support it uses and the Python ElementTree > module that it inherits from CPython. Considering that XML is a requirement > in many real world applications, especially in the Java world, you (Sophie) > might be interested in adding all three of Python, Java and XML to your > toolbox at the same time, while also learning how to benchmark and optimise > Java and Python code. I think that would pretty quickly get you up to speed > with real world software development. > > Stefan Sounds interesting. Are you a developer or user of Jython? Can you tell me more about this particular issue? Or it is easier to check jython.org? From patrick at bierans.de Sat Jan 7 07:10:20 2012 From: patrick at bierans.de (patrick at bierans.de) Date: Sat, 7 Jan 2012 13:10:20 +0100 (CET) Subject: your feedback to my first project please Message-ID: <1067747504.957862.1325938220403.JavaMail.open-xchange@email.1und1.de An HTML attachment was scrubbed... URL: From __peter__ at web.de Sat Jan 7 07:59:46 2012 From: __peter__ at web.de (Peter Otten) Date: Sat, 07 Jan 2012 13:59:46 +0100 Subject: your feedback to my first project please References: <499.26273427463$1325938350@news.gmane.org> Message-ID: patrick at bierans.de wrote: > It's my first script in python and I'd like to know if my way > of coding
A warm welcome and a grumpy "please post in plain-text" ;) > I am settled - so you can go full on. ;) You seem to be sure you won't regret that ;) > - What about my coding style in general? Looks good. >   Is my naming of variables, classes and methods/functions stupid? > def __init__(self, dim_, default_=0): No. Except for the trailing underscore. I think "dim" is a keyword in Basic... > - Do my test cases cover enough? Are they unelegant? Don't use assert, use the appropriate method, like self.assertEquals(...). Generally your test cases test the wrong stuff. An attribute's leading underscore is a good hint that you shouldn't inspect its value in your tests. For example, to get some confidence that the internal variables are initialised correctly you could do class TestAverageStack(unittest.TestCase): def test(self): a = AverageStack(10) self.assertEquals(a.inout(100), 10) That way you remain free to completely rewrite the AverageTest implementation without changing the test suite. > Can I write some variables in the assertion messages? I found > some code in the internet using % and ` but it is not working here. You must be doing it wrong. >>> assert False, "who's afraid of %s, %s, and %s?" % ("red", "yellow", "blue") Traceback (most recent call last): File "", line 1, in AssertionError: who's afraid of red, yellow, and blue? > - Do you have some performance improvements for my class? It will have > to run at highest performance. Rewrite it in C ;) Seriously, have a look at collections.deque; if you need to support only integers you can also safely store the sum and add new values and remove outdated ones without risking that errors accumulate. > for i in range(self._dim): > _sum += self._data[i] > _count += 1 > return _sum / _count You need "from __future__ import division": >>> 1/2 0 >>> from __future__ import division >>> 1/2 0.5 Also: >>> d = {1:10, 2:20, 3:30} >>> sum(d.itervalues()) 60 That's all folks... From darcy at druid.net Sat Jan 7 08:04:02 2012 From: darcy at druid.net (D'Arcy Cain) Date: Sat, 07 Jan 2012 08:04:02 -0500 Subject: your feedback to my first project please In-Reply-To: <1067747504.957862.1325938220403.JavaMail.open-xchange@email.1und1.de References: <1067747504.957862.1325938220403.JavaMail.open-xchange@email.1und1.de Message-ID: <4F0842C2.3060002@druid.net> On 12-01-07 07:10 AM, patrick at bierans.de wrote: > It's my first script in python and I'd like to know if my way of coding > so far is right and if YOU have some little tips for me > or if you can point my nose on some things I've missed so far. Looks pretty good overall. I have a little armchair quarterbacking for you. The main thing I wonder is why a dict to store values. You index by a contiguous range of ints so why not use a list. __init__ becomes this. Note I also lose those superfluous underscores. def __init__(self, dim, default=0): self.data = [default] * dim self.pos = 0 self.dim = dim Here is how I would write avg() (not _avg) def _avg(self): """Calculates the average of all values currently in stock. This also includes the default values not yet overwritten.""" return sum(self.data)/self.dim You could drop your inout method with this change to avg(): def _avg(self, value = None): """Calculates the average of all values currently in stock. This also includes the default values not yet overwritten. Optionally adds a new value.""" if value is not None: self.in(value) return sum(self.data)/self.dim I am not sure how you get a float out of this though. You may want to set self.dim to float(dim) in __init__. > I've read a lot of the official documentation - even some of the weired > but cool stuff. And I also read some PEPs like the PEP 8. And I'd love to > go for TDD. But feedback would help me on my way. I don't know why TDD seems to be more popular with Python programmers than others but I do recommend as much of that as possible. > - How is my code formatting? Good. > I know the TestCases are ugly, I still have no feeling for it. :( Test cases don't have to be pretty, just extensive. What I can't tell is whether you wrote the tests first or not. The sequence should be; 1. Write the test 2. Run the test to prove it fails 3. Write code until test passes 4. Stop Steps 2 and 4 are particularly important. Step 2 assures that you have a real test. A test that can't fail is useless. Step 4 assures that you never add code without a test. However, don't be afraid to add extra tests at any time. > - What about my coding style in general? > Is my naming of variables, classes and methods/functions stupid? I would just ease up on the underscores. Looks like you are on the right track though. -- 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 __peter__ at web.de Sat Jan 7 08:12:28 2012 From: __peter__ at web.de (Peter Otten) Date: Sat, 07 Jan 2012 14:12:28 +0100 Subject: your feedback to my first project please References: <499.26273427463$1325938350@news.gmane.org> Message-ID: patrick at bierans.de wrote: > I know the TestCases are ugly, I still have no feeling for it. I forgot to mention: instead of testing each and every thing in one big method put each test into a short dedicated TestCase.test_... method. That reduces the risk of undetected side effects and often allows you to learn what went wrong from the -- thoroughly chosen ;) -- name of the test method alone. coverage.py is a good tool to give you an idea of what portion of your module code is covered by your tests. From stefan_ml at behnel.de Sat Jan 7 09:40:42 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 07 Jan 2012 15:40:42 +0100 Subject: Getting involved - Jython ElementTree performance In-Reply-To: References: <4F082986.6010106@gmail.com> Message-ID: Sophie Sperner, 07.01.2012 13:01: > On Jan 7, 11:53 am, Stefan Behnel wrote: >> A big issue that I have with Jython is that its ElementTree XML parser >> support is so increadibly slow. It could seriously benefit from a better >> integration between the Java XML support it uses and the Python ElementTree >> module that it inherits from CPython. Considering that XML is a requirement >> in many real world applications, especially in the Java world, you (Sophie) >> might be interested in adding all three of Python, Java and XML to your >> toolbox at the same time, while also learning how to benchmark and optimise >> Java and Python code. I think that would pretty quickly get you up to speed >> with real world software development. > > Sounds interesting. Are you a developer or user of Jython? More of a user. I'm actually developing lxml, a fast XML library for CPython that reimplements ElementTree. When working with Java, I try to keep using ElementTree in Jython because it gives me a simple to use XML interface, but it's sometimes hard to defend its use because the parser part is so slow - several times slower than lxml would run here. > Can you tell me more about this particular issue? Or it is easier to > check jython.org? Here's a bit of a discussion: http://sourceforge.net/mailarchive/message.php?msg_id=24946690 The current integration is more at a "make it work" than a "make it fast" level. Specifically, the "expat" replacement module has several problems, also at an algorithmic level, that make it slow. I did some benchmarking, actually not on Jython, but at least comparing CPython and PyPy: http://blog.behnel.de/index.php?p=210 I posted the benchmarking code here: http://mail.python.org/pipermail/python-dev/2011-December/115111.html You can use the attached script to see for yourself. It should also run on Jython, so you can use it to compare the performance of ElementTree in CPython and Jython on your own machine. That being said, yes, I'd suggest discussing this on a Jython related list. I cross-posted it to the jython-devel mailing list, please discuss anything related to Jython development over there. Stefan From y.turgut at gmail.com Sat Jan 7 10:00:57 2012 From: y.turgut at gmail.com (Yigit Turgut) Date: Sat, 7 Jan 2012 07:00:57 -0800 (PST) Subject: Calling a variable inside a function of another class Message-ID: <5a91e124-b6e9-4e2f-88d6-50a33eb496db@k29g2000vbl.googlegroups.com> class test(test1): def __init__(self, device): . . . def _something(self, x=1) self.dt = data if __name__ == "__main__": test.something.dt ??? I am trying to call a variable located in a function of a class from main but couldn't succeed.Any ideas? From drobinow at gmail.com Sat Jan 7 10:18:15 2012 From: drobinow at gmail.com (David Robinow) Date: Sat, 7 Jan 2012 10:18:15 -0500 Subject: Nested Function Question In-Reply-To: References: <14889cd9-f02b-4a81-9ccb-8fb8492e1091@n39g2000yqh.googlegroups.com> Message-ID: On Fri, Jan 6, 2012 at 5:04 PM, Ian Kelly wrote: > On Fri, Jan 6, 2012 at 2:46 PM, GZ wrote: >> Hi, >> >> I am reading the documentation of functools.partial (http:// >> docs.python.org/library/functools.html#functools.partial) and found >> the following 'reference implementation' of functools.partial. >> >> def partial(func, *args, **keywords): >> ? ?def newfunc(*fargs, **fkeywords): >> ? ? ? ?newkeywords = keywords.copy() >> ? ? ? ?newkeywords.update(fkeywords) >> ? ? ? ?return func(*(args + fargs), **newkeywords) >> ? ?newfunc.func = func >> ? ?newfunc.args = args >> ? ?newfunc.keywords = keywords >> ? ?return newfunc >> >> I don't understand why the below 3 lines are needed: >> >> ? ?newfunc.func = func >> ? ?newfunc.args = args >> ? ?newfunc.keywords = keywords >> >> >> It is as if they are trying to prevent garbage collection, but I don't >> get why it is needed. As long as something holds reference to newfunc, >> because it in turn references keywords and args, nothing will be >> freed. If nothing is referencing newfunc, then everything should be >> freed. > > They exist for introspection. ?The partial object has to store the > function and arguments it was passed so that it can call it later, so > as long as they're being stored anyway, why not make them visible? I tend toward the minimalist end of the spectrum when it comes to code commenting, but it seems to me this would be a good place for a few words of explanation. From dihedral88888 at googlemail.com Sat Jan 7 10:43:56 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sat, 7 Jan 2012 07:43:56 -0800 (PST) Subject: python philosophical question - strong vs duck typing In-Reply-To: References: Message-ID: <24489559.1078.1325951036106.JavaMail.geo-discussion-forums@prmw6> Terry Reedy? 2012?1?5????UTC+8??4?22?03???? > On 1/4/2012 1:37 AM, Terry Reedy wrote: > > On 1/3/2012 8:04 PM, Devin Jeanpierre wrote: > > >> [ An example of a simple dependently typed program: > >> http://codepad.org/eLr7lLJd ] > > > > Just got it after a minute delay. > > A followup now that I have read it. Removing the 40 line comment, the > function itself is > > fun getitem{n,m:nat}(arr : array(int, n) , > length : int(n), index : int m) : int = > if index < length then > arr[index] > else > ~1 (* -1, error *) > > where n,m are compiler variables used to define the dependent > (paramaterized) types array(int,n) and int(n)/ The double use of n means > that the compiler checks that length n of the array equals the length > passed. > > My response: in Python, there is no need to pass concrete collection > sizes because they are packaged with the collection at runtime as an > attribute. So: > > 1) In Python, there is no need for such checking. In addition, the > for-loop construct, 'for item in iterable:', removes the possibility of > indexing errors. > > 2) Python classes are, in a sense, or in effect, runtime dependent > types. While the formal implementation type of a 'list' is just 'list', > the effective computation type is 'mutable sequence of length n'. The > type of an iterator is 'read-only sequence of indefinite length'. I find > this an interesting way to look at Python. Also it is easy to turn an indexed object to be an iterator by a function decorator that returns a generator in the object level without declaring a new class from a class written by others. Thus this can lead to a decoupled design of software among many contributors in an elegant way. I prefer a factorized decoupled blocks of modules to be completed by several programmers to build a package. > > -- > Terry Jan Reed From dihedral88888 at googlemail.com Sat Jan 7 10:43:56 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sat, 7 Jan 2012 07:43:56 -0800 (PST) Subject: python philosophical question - strong vs duck typing In-Reply-To: References: Message-ID: <24489559.1078.1325951036106.JavaMail.geo-discussion-forums@prmw6> Terry Reedy? 2012?1?5????UTC+8??4?22?03???? > On 1/4/2012 1:37 AM, Terry Reedy wrote: > > On 1/3/2012 8:04 PM, Devin Jeanpierre wrote: > > >> [ An example of a simple dependently typed program: > >> http://codepad.org/eLr7lLJd ] > > > > Just got it after a minute delay. > > A followup now that I have read it. Removing the 40 line comment, the > function itself is > > fun getitem{n,m:nat}(arr : array(int, n) , > length : int(n), index : int m) : int = > if index < length then > arr[index] > else > ~1 (* -1, error *) > > where n,m are compiler variables used to define the dependent > (paramaterized) types array(int,n) and int(n)/ The double use of n means > that the compiler checks that length n of the array equals the length > passed. > > My response: in Python, there is no need to pass concrete collection > sizes because they are packaged with the collection at runtime as an > attribute. So: > > 1) In Python, there is no need for such checking. In addition, the > for-loop construct, 'for item in iterable:', removes the possibility of > indexing errors. > > 2) Python classes are, in a sense, or in effect, runtime dependent > types. While the formal implementation type of a 'list' is just 'list', > the effective computation type is 'mutable sequence of length n'. The > type of an iterator is 'read-only sequence of indefinite length'. I find > this an interesting way to look at Python. Also it is easy to turn an indexed object to be an iterator by a function decorator that returns a generator in the object level without declaring a new class from a class written by others. Thus this can lead to a decoupled design of software among many contributors in an elegant way. I prefer a factorized decoupled blocks of modules to be completed by several programmers to build a package. > > -- > Terry Jan Reed From steve+comp.lang.python at pearwood.info Sat Jan 7 11:01:22 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Jan 2012 16:01:22 GMT Subject: Calling a variable inside a function of another class References: <5a91e124-b6e9-4e2f-88d6-50a33eb496db@k29g2000vbl.googlegroups.com> Message-ID: <4f086c52$0$29966$c3e8da3$5496439d@news.astraweb.com> On Sat, 07 Jan 2012 07:00:57 -0800, Yigit Turgut wrote: > I am trying to call a variable located in a function of a class from > main but couldn't succeed.Any ideas? You cannot access local variables from outside their function. That's why they are called *local* variables. You probably want to access *attributes* of the class or the instance. You have to define them first -- you can't access something that doesn't exist. class Test: shared = 42 # Shared, class attribute def __init__(self): self.dt = 23 # Instance attribute, not shared. print(Test.shared) # prints 42 However, print(Test.dt) fails because no instance has been created yet, and so there is no dt attribute. You have to create an instance first, then __init__ will run and create the attribute: instance = Test() print(instance.dt) # prints 23 -- Steven From y.turgut at gmail.com Sat Jan 7 11:18:10 2012 From: y.turgut at gmail.com (Yigit Turgut) Date: Sat, 7 Jan 2012 08:18:10 -0800 (PST) Subject: Calling a variable inside a function of another class References: <5a91e124-b6e9-4e2f-88d6-50a33eb496db@k29g2000vbl.googlegroups.com> <4f086c52$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Jan 7, 6:01?pm, Steven D'Aprano wrote: > On Sat, 07 Jan 2012 07:00:57 -0800, Yigit Turgut wrote: > > I am trying to call a variable located in a function of a class from > > main but couldn't succeed.Any ideas? > > You cannot access local variables from outside their function. That's why > they are called *local* variables. > > You probably want to access *attributes* of the class or the instance. > You have to define them first -- you can't access something that doesn't > exist. > > class Test: > ? ? shared = 42 ?# Shared, class attribute > ? ? def __init__(self): > ? ? ? ? self.dt = 23 ?# Instance attribute, not shared. > > print(Test.shared) ?# prints 42 > > However, print(Test.dt) fails because no instance has been created yet, > and so there is no dt attribute. You have to create an instance first, > then __init__ will run and create the attribute: > > instance = Test() > print(instance.dt) ?# prints 23 > > -- > Steven How about assigning the variable as global, wouldn't it be more effective? From oktakaweb at gmail.com Sat Jan 7 13:32:18 2012 From: oktakaweb at gmail.com (Oktaka Com) Date: Sat, 7 Jan 2012 10:32:18 -0800 (PST) Subject: Installing a script and use it via python -m Message-ID: <35d4f491-85e3-48ee-81e8-b9a627dcb19c@i26g2000vbt.googlegroups.com> Hi all, Is there a way to do below: 1) install via setup.py some script: xxx.py 2) python -m xxx.py In fact, this question opens to: Is there a platform independent way to copy xxx.py to somewhere that the system will search for? Thanks, From solipsis at pitrou.net Sat Jan 7 15:39:09 2012 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sat, 7 Jan 2012 20:39:09 +0000 (UTC) Subject: Getting involved References: Message-ID: Hello, Sophie Sperner gmail.com> writes: > > Let me ask here please. I'm a first-year PhD student in Ireland. My > background is in mathematics, though I'm going to stream my career > into programming with Python, Java and C++ languages. I have some good > experience with C++ what allowed me to have a presentation in Europe > quite recently - I participated in an open-source cloud computing > project. I used Python a little bit in that project, though mainly it > was in C++. > > [...] > > Could you please list me 2 or 3 projects in Python and/or Java which > are currently active (vivid) and useful? CPython itself - the reference and most used implementation - is written partly in Python (most of the stdlib is) and partly in C. It is easy to find things to do even without touching C. You could take a look: http://docs.python.org/devguide/ Regards Antoine. From cs at zip.com.au Sat Jan 7 16:31:48 2012 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 8 Jan 2012 08:31:48 +1100 Subject: Installing a script and use it via python -m In-Reply-To: <35d4f491-85e3-48ee-81e8-b9a627dcb19c@i26g2000vbt.googlegroups.com> References: <35d4f491-85e3-48ee-81e8-b9a627dcb19c@i26g2000vbt.googlegroups.com> Message-ID: <20120107213148.GA18689@cskk.homeip.net> On 07Jan2012 10:32, Oktaka Com wrote: | Is there a way to do below: | | 1) install via setup.py some script: xxx.py | 2) python -m xxx.py | | In fact, this question opens to: Is there a platform independent way | to copy xxx.py to somewhere that the system will search for? Depends what's in your $PYTHONPATH I think, but setup.py has an "install for user" option. Use that, then plain old python -m xxx (note: no .py here - it is the module name, not the file pathname). Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ I will not do it as a hack I will not do it for my friends I will not do it on a Mac I will not write for Uncle Sam I will not do it on weekends I won't do ADA, Sam-I-Am - Gregory Bond From ericsnowcurrently at gmail.com Sat Jan 7 16:48:56 2012 From: ericsnowcurrently at gmail.com (Eric Snow) Date: Sat, 7 Jan 2012 14:48:56 -0700 Subject: Getting involved In-Reply-To: References: Message-ID: On Sat, Jan 7, 2012 at 1:39 PM, Antoine Pitrou wrote: > > Hello, > > Sophie Sperner gmail.com> writes: >> >> Let me ask here please. I'm a first-year PhD student in Ireland. My >> background is in mathematics, though I'm going to stream my career >> into programming with Python, Java and C++ languages. I have some good >> experience with C++ what allowed me to have a presentation in Europe >> quite recently - I participated in an open-source cloud computing >> project. I used Python a little bit in that project, though mainly it >> was in C++. >> >> [...] >> >> Could you please list me 2 or 3 projects in Python and/or Java which >> are currently active (vivid) and useful? > > CPython itself - the reference and most used implementation - is written partly > in Python (most of the stdlib is) and partly in C. It is easy to find things to > do even without touching C. You could take a look: > http://docs.python.org/devguide/ +1 > > Regards > > Antoine. > > > -- > http://mail.python.org/mailman/listinfo/python-list From lars at rational-it.com Sat Jan 7 20:16:22 2012 From: lars at rational-it.com (lars van gemerden) Date: Sat, 7 Jan 2012 17:16:22 -0800 (PST) Subject: multiple inheritance from list and other class Message-ID: Hello, I have an error message i do not understand: My code is in essence: class A(object): #no __new__ or __init__ def meth1(self, args): #some code def meth2(self, args): #some code class B(list, A) pass b = B([1,2,3,4]) error: Traceback (most recent call last): File "D:\Documents\Code\Eclipse\workspace\FlowTools\iteraids.py", line 431, in testolist() File "D:\Documents\Code\Eclipse\workspace\FlowTools\iteraids.py", line 381, in testolist b = B([0,1,2,3,4]) TypeError: B() takes exactly 2 arguments (1 given) (adapted the error to the example classes) Can anyone help/explain? Cheers, Lars From rosuav at gmail.com Sat Jan 7 20:27:06 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Jan 2012 12:27:06 +1100 Subject: multiple inheritance from list and other class In-Reply-To: References: Message-ID: On Sun, Jan 8, 2012 at 12:16 PM, lars van gemerden wrote: > Hello, > > I have an error message i do not understand: > > My code is in essence: > > b = B([1,2,3,4]) > > error: > ? ?b = B([0,1,2,3,4]) > TypeError: B() takes exactly 2 arguments (1 given) Your code doesn't quite match your error message, and the code as posted (with 'pass' in the method bodies to make it compile) works fine. Can you derive a minimal test-case that actually produces the error in question, and then post the actual code and error? Also - what version of Python are you using? Chris Angelico From monaghand.david at gmail.com Sat Jan 7 21:30:56 2012 From: monaghand.david at gmail.com (David Monaghan) Date: Sun, 08 Jan 2012 02:30:56 +0000 Subject: MOST COMMON QUESTIONS ASKED BY NON-MUSLIMS ????????? References: <6c0983b6-8786-4b04-b393-a6518f65ebbb@n6g2000vbz.googlegroups.com> Message-ID: On Tue, 3 Jan 2012 09:57:50 -0800 (PST), John Ladasky wrote: >On Jan 3, 7:40?am, BV wrote: >> MOST COMMON QUESTIONS ASKED BY NON-MUSLIMS > >Q0. Why do thousand-line religious posts appear in comp.lang.python? You know, I would never have seen this post if you hadn't "authenticated" it by starting a thread around it. DaveM From dihedral88888 at googlemail.com Sat Jan 7 23:43:48 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sat, 7 Jan 2012 20:43:48 -0800 (PST) Subject: Nested Function Question In-Reply-To: <14889cd9-f02b-4a81-9ccb-8fb8492e1091@n39g2000yqh.googlegroups.com> References: <14889cd9-f02b-4a81-9ccb-8fb8492e1091@n39g2000yqh.googlegroups.com> Message-ID: <33260053.1203.1325997828352.JavaMail.geo-discussion-forums@prak33> GZ? 2012?1?7????UTC+8??5?46?16???? > Hi, > > I am reading the documentation of functools.partial (http:// > docs.python.org/library/functools.html#functools.partial) and found > the following 'reference implementation' of functools.partial. > > def partial(func, *args, **keywords): > def newfunc(*fargs, **fkeywords): > newkeywords = keywords.copy() > newkeywords.update(fkeywords) > return func(*(args + fargs), **newkeywords) > newfunc.func = func > newfunc.args = args > newfunc.keywords = keywords > return newfunc > > I don't understand why the below 3 lines are needed: > > newfunc.func = func > newfunc.args = args > newfunc.keywords = keywords > > > It is as if they are trying to prevent garbage collection, but I don't > get why it is needed. As long as something holds reference to newfunc, > because it in turn references keywords and args, nothing will be > freed. If nothing is referencing newfunc, then everything should be > freed. > > Thanks, > GZ This is used to produce a new function with some default parameters fixed of an old function that requires many parameters in the caller part. From lie.1296 at gmail.com Sun Jan 8 00:43:38 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 08 Jan 2012 16:43:38 +1100 Subject: MOST COMMON QUESTIONS ASKED BY NON-MUSLIMS ????????? In-Reply-To: <201201031324.13090.gheskett@wdtv.com> References: <6c0983b6-8786-4b04-b393-a6518f65ebbb@n6g2000vbz.googlegroups.com> <201201031324.13090.gheskett@wdtv.com> Message-ID: On 01/04/2012 05:24 AM, gene heskett wrote: > On Tuesday, January 03, 2012 01:13:08 PM John Ladasky did opine: > >> On Jan 3, 7:40 am, BV wrote: >>> MOST COMMON QUESTIONS ASKED BY NON-MUSLIMS >> >> Q0. Why do thousand-line religious posts appear in comp.lang.python? > > Already discussed, at considerable length& I got told off. > > The solution is to chop the link between google.groups and this list. But > that subject has been declared verboten. Too much inconvenience to ask the > googlers to subscribe to the real list I guess. Because my spamassassin > has been trained on so much google (& yahoo too) originated spam, one > poster here, Jerome, has his messages always caught. He comes in thru the > groups coupling and I have considered moving his messages to the ham > folder, but realized all that would do is poison my bayes. > > Since TPTB of this list don't care, neither do I, so his messages continue > to be automatically fed to SA as spam, daily. Shrug. Did you try gmane newsgroup gateway? I set my python-list subscription through gmane, and there is almost no spam even though I never set any filtering. From dihedral88888 at googlemail.com Sun Jan 8 01:08:22 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sat, 7 Jan 2012 22:08:22 -0800 (PST) Subject: multiple inheritance from list and other class In-Reply-To: References: Message-ID: <2328.1302.1326002902374.JavaMail.geo-discussion-forums@prnp7> A list is a container. Chris Angelico? 2012?1?8????UTC+8??9?27?06???? > On Sun, Jan 8, 2012 at 12:16 PM, lars van gemerden wrote: > > Hello, > > > > I have an error message i do not understand: > > > > My code is in essence: > > > > b = B([1,2,3,4]) > > > > error: > > ? ?b = B([0,1,2,3,4]) > > TypeError: B() takes exactly 2 arguments (1 given) > > Your code doesn't quite match your error message, and the code as > posted (with 'pass' in the method bodies to make it compile) works > fine. Can you derive a minimal test-case that actually produces the > error in question, and then post the actual code and error? Also - > what version of Python are you using? > > Chris Angelico The class is defined in a silly way. In python declaring a class with only trivial properties added is not very python at all. Just let an object obtain new properties to save the troubles of deriving a lot classes not different too much. From dihedral88888 at googlemail.com Sun Jan 8 01:08:22 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sat, 7 Jan 2012 22:08:22 -0800 (PST) Subject: multiple inheritance from list and other class In-Reply-To: References: Message-ID: <2328.1302.1326002902374.JavaMail.geo-discussion-forums@prnp7> A list is a container. Chris Angelico? 2012?1?8????UTC+8??9?27?06???? > On Sun, Jan 8, 2012 at 12:16 PM, lars van gemerden wrote: > > Hello, > > > > I have an error message i do not understand: > > > > My code is in essence: > > > > b = B([1,2,3,4]) > > > > error: > > ? ?b = B([0,1,2,3,4]) > > TypeError: B() takes exactly 2 arguments (1 given) > > Your code doesn't quite match your error message, and the code as > posted (with 'pass' in the method bodies to make it compile) works > fine. Can you derive a minimal test-case that actually produces the > error in question, and then post the actual code and error? Also - > what version of Python are you using? > > Chris Angelico The class is defined in a silly way. In python declaring a class with only trivial properties added is not very python at all. Just let an object obtain new properties to save the troubles of deriving a lot classes not different too much. From steve+comp.lang.python at pearwood.info Sun Jan 8 01:41:14 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Jan 2012 06:41:14 GMT Subject: multiple inheritance from list and other class References: <2328.1302.1326002902374.JavaMail.geo-discussion-forums@prnp7> Message-ID: <4f093a8a$0$29966$c3e8da3$5496439d@news.astraweb.com> On Sat, 07 Jan 2012 22:08:22 -0800, 88888 Dihedral wrote: [...] > The class is defined in a silly way. > In python declaring a class with only trivial properties added is not > very python at all. The example given looks like a Mixin class, which is perfectly acceptable in Python. -- Steven From steve+comp.lang.python at pearwood.info Sun Jan 8 01:42:01 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Jan 2012 06:42:01 GMT Subject: multiple inheritance from list and other class References: Message-ID: <4f093ab9$0$29966$c3e8da3$5496439d@news.astraweb.com> On Sat, 07 Jan 2012 17:16:22 -0800, lars van gemerden wrote: > Hello, > > I have an error message i do not understand: > > My code is in essence: The code you give works fine. It does not show the error you say it does. Please test your code before posting and ensure it actually fails the way you expect. It is perfectly fine to use multiple inheritance in the way you show. Here is an even simpler example: py> class Spam(object): ... pass ... py> class Ham(list, Spam): ... pass ... py> py> h = Ham([1, 2, 3]) py> And no exception is raised. -- Steven From ivan at llaisdy.com Sun Jan 8 03:50:07 2012 From: ivan at llaisdy.com (Ivan) Date: Sun, 08 Jan 2012 08:50:07 +0000 Subject: How to support a non-standard encoding? In-Reply-To: References: <1480875f-d133-40a1-8fd1-dd31a2dd430b@d10g2000vbh.googlegroups.com> Message-ID: Dear jmf, Tim Thanks for these pointers. They look v useful. I'll have a go and report back (with success I hope). Best wishes Ivan On 06/01/2012 20:42, Tim Wintle wrote: > On Fri, 2012-01-06 at 12:00 -0800, jmfauth wrote: >> The distibution of such a codec may be a problem. > > There is a register_codec method (or similar) in the codecs module. > > Tim > > -- ============================================================ Ivan A. Uemlianin Llaisdy Speech Technology Research and Development ivan at llaisdy.com www.llaisdy.com llaisdy.wordpress.com github.com/llaisdy www.linkedin.com/in/ivanuemlianin "Froh, froh! Wie seine Sonnen, seine Sonnen fliegen" (Schiller, Beethoven) ============================================================ From lars at rational-it.com Sun Jan 8 05:48:47 2012 From: lars at rational-it.com (lars van gemerden) Date: Sun, 8 Jan 2012 02:48:47 -0800 (PST) Subject: multiple inheritance from list and other class References: <4f093ab9$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Jan 8, 7:42?am, Steven D'Aprano wrote: > On Sat, 07 Jan 2012 17:16:22 -0800, lars van gemerden wrote: > > Hello, > > > I have an error message i do not understand: > > > My code is in essence: > > The code you give works fine. It does not show the error you say it does. > Please test your code before posting and ensure it actually fails the way > you expect. > > It is perfectly fine to use multiple inheritance in the way you show. > Here is an even simpler example: > > py> class Spam(object): > ... ? ? pass > ... > py> class Ham(list, Spam): > ... ? ? pass > ... > py> > py> h = Ham([1, 2, 3]) > py> > > And no exception is raised. > > -- > Steven Sorry for wasting you time, I found the error (had "def" instead of "class" before B in the example), sorry about not testing, shouldn't post at 2:00 AM. Thanks all the same, Lars From bryanjugglercryptographer at yahoo.com Sun Jan 8 06:11:14 2012 From: bryanjugglercryptographer at yahoo.com (Bryan) Date: Sun, 8 Jan 2012 03:11:14 -0800 (PST) Subject: socketserver question References: Message-ID: <3af969f6-4cbf-46e9-9cf0-0bb231c241a1@n39g2000yqh.googlegroups.com> K Richard Pixley wrote: [...] > The doc says server.shutdown(), but if I call self.server.shutdown() > from within handler.handle(), I seem to get a deadlock, which is exactly > what I'd expect in a single threaded system with no way to "signal" the > server.server_forever() loop which is several frames up the stack. Well, it's documented behavior, but not what I would have expected. Seems to go out of its way to deadlock. Stopping the main loop from inside a request is perfectly reasonable thing to want to do, and single-threaded GUI's do it all the time. It's not an up-the-stack problem. shutdown() sets a flag that will cause the loop not to repeat, but then calls wait() for an event that won't be signaled until the loop exits, breaking the single-threaded case. It's bad design. Given the library class is as it is, one solution (untested) is to relax being single-threader for just a bit. import thread thread.start_new_thread(server.shutdown, ()) -- --Bryan From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Sun Jan 8 06:16:25 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Sun, 08 Jan 2012 12:16:25 +0100 Subject: How to support a non-standard encoding? In-Reply-To: <1480875f-d133-40a1-8fd1-dd31a2dd430b@d10g2000vbh.googlegroups.com> References: <1480875f-d133-40a1-8fd1-dd31a2dd430b@d10g2000vbh.googlegroups.com> Message-ID: Am 06.01.2012 21:00 schrieb jmfauth: > Another simple approach, os independent. > > You probably do not write your code in iso-6937, but > you only need to encode/decode some bytes sequence > "on the fly". In that case, work with bytes, create > a couple of coding / decoding functions with a > created [*] as helper. It's not so complicate. > Use Py2 or Py3 (the recommended > way ;-) ) as pivot encoding. These coding/decoding functions are exactly the way to create a codec. I. e., it is not much more. Thomas From y.turgut at gmail.com Sun Jan 8 08:23:43 2012 From: y.turgut at gmail.com (Yigit Turgut) Date: Sun, 8 Jan 2012 05:23:43 -0800 (PST) Subject: Parallel Processing Message-ID: <25422fc4-b2ba-41aa-b12a-5e2fdc989bab@j9g2000vby.googlegroups.com> Hi all, I am trying to run two functions at the same time with Parallel Processing (pp) as following ; import pygame import sys import time import math import pp screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) timer = pygame.time.Clock() white = True start = time.time() end = time.time() - start def test1(): global end while(end<5): end = time.time() - start timer.tick(4) #FPS screen.fill((255,255,255) if white else (0, 0, 0)) white = not white pygame.display.update() def test2(): global end while(end2<5): end2 = time.time() - start print end ppservers = () if len(sys.argv) > 1: ncpus = int(sys.argv[1]) # Creates jobserver with ncpus workers job_server = pp.Server(ncpus, ppservers=ppservers) else: # Creates jobserver with automatically detected number of workers job_server = pp.Server(ppservers=ppservers) print "Starting PP with", job_server.get_ncpus(), "workers" job1 = job_server.submit(test1,test2) result = job1() And the output is ; Starting PP with 2 workers Traceback (most recent call last): File "fl.py", line 46, in job1 = job_server.submit(test1,test2) File "/usr/lib/python2.6/site-packages/pp.py", line 402, in submit raise TypeError("args argument must be a tuple") TypeError: args argument must be a tuple When I change job1 to just to see if it will run one function only; job1 = job_server.submit(test1) I get an output of; NameError: global name 'end' is not defined end variable is defined as global but I get a NameError. Anyone has an idea what's going on ? From d at davea.name Sun Jan 8 09:34:53 2012 From: d at davea.name (Dave Angel) Date: Sun, 08 Jan 2012 09:34:53 -0500 Subject: Parallel Processing In-Reply-To: <25422fc4-b2ba-41aa-b12a-5e2fdc989bab@j9g2000vby.googlegroups.com> References: <25422fc4-b2ba-41aa-b12a-5e2fdc989bab@j9g2000vby.googlegroups.com> Message-ID: <4F09A98D.4070800@davea.name> On 01/08/2012 08:23 AM, Yigit Turgut wrote: > Hi all, > > I am trying to run two functions at the same time with Parallel > Processing (pp) as following ; > > import pygame > import sys > import time > import math > import pp > > screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) > timer = pygame.time.Clock() > white = True > start = time.time() > end = time.time() - start > > def test1(): > global end > while(end<5): > end = time.time() - start > timer.tick(4) #FPS > screen.fill((255,255,255) if white else (0, 0, 0)) > white = not white > pygame.display.update() > > def test2(): > global end > while(end2<5): > end2 = time.time() - start > print end > > ppservers = () > > if len(sys.argv)> 1: > ncpus = int(sys.argv[1]) > # Creates jobserver with ncpus workers > job_server = pp.Server(ncpus, ppservers=ppservers) > else: > # Creates jobserver with automatically detected number of workers > job_server = pp.Server(ppservers=ppservers) > print "Starting PP with", job_server.get_ncpus(), "workers" > > job1 = job_server.submit(test1,test2) > result = job1() > > And the output is ; > > Starting PP with 2 workers > Traceback (most recent call last): > File "fl.py", line 46, in > job1 = job_server.submit(test1,test2) > File "/usr/lib/python2.6/site-packages/pp.py", line 402, in submit > raise TypeError("args argument must be a tuple") > TypeError: args argument must be a tuple > > > When I change job1 to just to see if it will run one function only; > job1 = job_server.submit(test1) > > I get an output of; > > NameError: global name 'end' is not defined > > end variable is defined as global but I get a NameError. Anyone has an > idea what's going on ? First, please tell us about any external dependencies (eg. imports). Pygame may not matter, since there are many people here using it, but each of us has to hunt down something that does parallel processing with an interface similar to what you're using. For the next person, the most likely candidate out of the dozens available is: http://www.parallelpython.com/ Your problem, as stated in the raise statement, is that the submit method is expecting a tuple for its "args argument". Now I had to go to the website to find an example, but it appears that your second argument should have been a tuple of the arguments for your function. See * submit*(self, func, args=(), depfuncs=(), modules=(), callback=None, callbackargs=(), group='default', globals=None) on page: http://www.parallelpython.com/content/view/15/30/#API So you're passing it two function objects, and the second one is in the place where it's expecting a tuple of arguments. Apparently you should be calling submit multiple times, once for each function. As for the error you get when you do that, please post the full traceback. I suspect that the message you did post has a typo in it, or that the error occurred when your source code was not as you show it here. You have two variables end and end2, and only the first one is ever declared global. func2() should get a different error when you run it; since it tries to use a local end2 before defining it. I recommend always testing your code with a single thread before trying to launch more complex multithread stuff. Just call func() and func2(), and see if they complete, and get reasonable answers. -- DaveA From y.turgut at gmail.com Sun Jan 8 10:45:01 2012 From: y.turgut at gmail.com (Yigit Turgut) Date: Sun, 8 Jan 2012 07:45:01 -0800 (PST) Subject: Parallel Processing References: <25422fc4-b2ba-41aa-b12a-5e2fdc989bab@j9g2000vby.googlegroups.com> Message-ID: <402bb451-9986-4a26-b606-6a1c3429f98e@s18g2000vby.googlegroups.com> On Jan 8, 4:34?pm, Dave Angel wrote: > On 01/08/2012 08:23 AM, Yigit Turgut wrote: > > > > > > > > > Hi all, > > > I am trying to run two functions at the same time with Parallel > > Processing (pp) as following ; > > > import pygame > > import sys > > import time > > import math > > import pp > > > screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) > > timer = pygame.time.Clock() > > white = True > > start = time.time() > > end = time.time() - start > > > def test1(): > > ? ?global end > > ? ?while(end<5): > > ? ? ?end = time.time() - start > > ? ? ?timer.tick(4) #FPS > > ? ? ?screen.fill((255,255,255) if white else (0, 0, 0)) > > ? ? ?white = not white > > ? ? ?pygame.display.update() > > > def test2(): > > ? ?global end > > ? ?while(end2<5): > > ? ? ?end2 = time.time() - start > > ? ? ?print end > > > ppservers = () > > > if len(sys.argv)> ?1: > > ? ? ?ncpus = int(sys.argv[1]) > > ? ? ?# Creates jobserver with ncpus workers > > ? ? ?job_server = pp.Server(ncpus, ppservers=ppservers) > > else: > > ? ? ?# Creates jobserver with automatically detected number of workers > > ? ? ?job_server = pp.Server(ppservers=ppservers) > > print "Starting PP with", job_server.get_ncpus(), "workers" > > > job1 = job_server.submit(test1,test2) > > result = job1() > > > And the output is ; > > > Starting PP with 2 workers > > Traceback (most recent call last): > > ? ?File "fl.py", line 46, in > > ? ? ?job1 = job_server.submit(test1,test2) > > ? ?File "/usr/lib/python2.6/site-packages/pp.py", line 402, in submit > > ? ? ?raise TypeError("args argument must be a tuple") > > TypeError: args argument must be a tuple > > > When I change job1 to just to see if it will run one function only; > > job1 = job_server.submit(test1) > > > I get an output of; > > > NameError: global name 'end' is not defined > > > end variable is defined as global but I get a NameError. Anyone has an > > idea what's going on ? > > First, please tell us about any external dependencies (eg. imports). > Pygame may not matter, since there are many people here using it, but > each of us has to hunt down something that does parallel processing with > an interface similar to what you're using. ?For the next person, the > most likely candidate out of the dozens available is:http://www.parallelpython.com/ > > Your problem, as stated in the raise statement, is that the submit > method is expecting a tuple for its "args argument". ?Now I had to go to > the website to find an example, but it appears that your second argument > should have been a tuple of the arguments for your function. ?See > * ? ? ?submit*(self, func, args=(), depfuncs=(), modules=(), > callback=None, callbackargs=(), group='default', globals=None) > > on page:http://www.parallelpython.com/content/view/15/30/#API > > So you're passing it two function objects, and the second one is in the > place where it's expecting a tuple of arguments. ?Apparently you should > be calling submit multiple times, once for each function. > > As for the error you get when you do that, please post the full > traceback. I suspect that the message you did post has a typo in it, or > that the error occurred when your source code was not as you show it > here. ?You have two variables end and end2, and only the first one is > ever declared global. ?func2() should get a different error when you run > it; since it tries to use a local end2 before defining it. > > I recommend always testing your code with a single thread before trying > to launch more complex multithread stuff. ?Just call func() and func2(), > and see if they complete, and get reasonable answers. > > -- > > DaveA There are no imports other than defined on the script, which are; import pygame import sys import time import math import pp You are correct about trying to pass two functions and second one is in place where a tuple of arguments supposed to be. But what if these functions don't have any arguments ? I tested functions test1() and test2() seperately ; they work. Once I figure out how to run these functions simultaneously, I will add an argument to test2 and try then on. My main goal is to simultaneously run two functions, one of them has one argument the other doesn't. To get familiar with parallel processing I am experimenting now without arguments and then I will embed the code to my application. I am experimenting with the following ; import pygame import sys import time import math import pp screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) timer = pygame.time.Clock() white = True start = time.time() end = time.time() - start def test1(): global end global white while(end<5): end = time.time() - start timer.tick(4) #FPS screen.fill((255,255,255) if white else (0, 0, 0)) white = not white pygame.display.update() def test2(): global end while(end<5): end = time.time() - start print end ppservers = () job_server = pp.Server(ppservers=ppservers) print "Starting pp with", job_server.get_ncpus(), "workers" job1 = job_server.submit(test1()) job2 = job_server.submit(test2()) result = job1() result2 = job2() print "Counting...", result2 job_server.print_stats() test1() works as expected (job1) but test2() doesn't work and I get the following traceback ; Traceback (most recent call last): File "fl.py", line 33, in job1 = job_server.submit(test1()) File "/usr/lib/python2.6/site-packages/pp.py", line 458, in submit sfunc = self.__dumpsfunc((func, ) + depfuncs, modules) File "/usr/lib/python2.6/site-packages/pp.py", line 629, in __dumpsfunc sources = [self.__get_source(func) for func in funcs] File "/usr/lib/python2.6/site-packages/pp.py", line 696, in __get_source sourcelines = inspect.getsourcelines(func)[0] File "/usr/lib/python2.6/inspect.py", line 678, in getsourcelines lines, lnum = findsource(object) File "/usr/lib/python2.6/inspect.py", line 519, in findsource file = getsourcefile(object) or getfile(object) File "/usr/lib/python2.6/inspect.py", line 441, in getsourcefile filename = getfile(object) File "/usr/lib/python2.6/inspect.py", line 418, in getfile raise TypeError('arg is not a module, class, method, ' TypeError: arg is not a module, class, method, function, traceback, frame, or code object Error is related to test1 not having an argument. When I leave it empty as following ; job1 = job_server.submit(test1,()) test1 doesn't run. When I do ; job1 = job_server.submit(test1()) Display works but I get; TypeError: arg is not a module, class, method, function, traceback, frame, or code object (complete traceback same as above). And test2 doesn't work also. But when I do; job1 = job_server.submit(test1,()) job2 = job_server.submit(test2()) I get test2 working but test1 not working. Obviously related to argument arrangement in submit. From rosuav at gmail.com Sun Jan 8 11:00:59 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Jan 2012 03:00:59 +1100 Subject: Parallel Processing In-Reply-To: <402bb451-9986-4a26-b606-6a1c3429f98e@s18g2000vby.googlegroups.com> References: <25422fc4-b2ba-41aa-b12a-5e2fdc989bab@j9g2000vby.googlegroups.com> <402bb451-9986-4a26-b606-6a1c3429f98e@s18g2000vby.googlegroups.com> Message-ID: On Mon, Jan 9, 2012 at 2:45 AM, Yigit Turgut wrote: > job1 = job_server.submit(test1,()) > job2 = job_server.submit(test2()) The first of these passes test1 and an empty tuple as arguments to submit(). The second calls test2 with no arguments, then passes its return value to submit(), which is not what you want to do. Chris Angelico From ether.joe at gmail.com Sun Jan 8 11:37:11 2012 From: ether.joe at gmail.com (Sean Wolfe) Date: Sun, 8 Jan 2012 13:37:11 -0300 Subject: No subject In-Reply-To: References: Message-ID: is anybody out there? On Sat, Jan 7, 2012 at 5:07 AM, abdullah zuberi wrote: > hello ? > -- > http://mail.python.org/mailman/listinfo/python-list > -- A musician must make music, an artist must paint, a poet must write, if he is to be ultimately at peace with himself. - Abraham Maslow From y.turgut at gmail.com Sun Jan 8 11:39:50 2012 From: y.turgut at gmail.com (Yigit Turgut) Date: Sun, 8 Jan 2012 08:39:50 -0800 (PST) Subject: Parallel Processing References: <25422fc4-b2ba-41aa-b12a-5e2fdc989bab@j9g2000vby.googlegroups.com> <402bb451-9986-4a26-b606-6a1c3429f98e@s18g2000vby.googlegroups.com> Message-ID: <3161f7ec-feb6-41ef-b73d-bb22e3e7704e@n6g2000vbg.googlegroups.com> On Jan 8, 6:00?pm, Chris Angelico wrote: > On Mon, Jan 9, 2012 at 2:45 AM, Yigit Turgut wrote: > > job1 = job_server.submit(test1,()) > > job2 = job_server.submit(test2()) > > The first of these passes test1 and an empty tuple as arguments to > submit(). The second calls test2 with no arguments, then passes its > return value to submit(), which is not what you want to do. > > Chris Angelico Yes that's correct but (test1,()) doesn't do any good since it doesn't execute the loop. screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) timer = pygame.time.Clock() white = True start = time.time() end = time.time() - start end2= time.time() - start def test1(): global end global white while(end<5): end = time.time() - start timer.tick(4) #FPS screen.fill((255,255,255) if white else (0, 0, 0)) white = not white pygame.display.update() def test2(): global end2 while(end2<5): end2 = time.time() - start print end2 ppservers = () job_server = pp.Server(ppservers=ppservers) job1 = job_server.submit(test1, (), globals=globals()) job2 = job_server.submit(test2, (), globals=globals()) result = job1() result2 = job2() print result2 job_server.print_stats() This *supposed to* print values of 'end' and simultaneously execute test1. Eventhough I set globals parameter and nothing seems to be wrong this code generates the following traceback ; Starting pp with 2 workers An error has occured during the function execution Traceback (most recent call last): File "/usr/lib/python2.6/site-packages/ppworker.py", line 90, in run __result = __f(*__args) File "", line 4, in test1 NameError: global name 'end' is not defined An error has occured during the function execution Traceback (most recent call last): File "/usr/lib/python2.6/site-packages/ppworker.py", line 90, in run __result = __f(*__args) File "", line 3, in test2 NameError: global name 'end2' is not defined How can this be, what am I missing ? From rantingrickjohnson at gmail.com Sun Jan 8 12:47:53 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 8 Jan 2012 09:47:53 -0800 (PST) Subject: No subject References: Message-ID: <6ac7f794-9916-4019-89e2-eefb7818067e@k10g2000yqk.googlegroups.com> On Jan 8, 10:37?am, Sean Wolfe wrote: > is anybody out there? Oh yes, in fact there are many of us who are "out there". http://www.youtube.com/watch?v=bHNa_f28Q-s From some-friend at web.de Sun Jan 8 14:32:59 2012 From: some-friend at web.de (Some Friend) Date: Sun, 08 Jan 2012 20:32:59 +0100 Subject: idle mac os x international keyboard umlaut input Message-ID: Dear Friends, with an international keyboard on mac os 10.6 an umlaut is inserted according to the chosen keyboard layout with alt + u followed by a, o or u for ?, ? or ?, or with cmd + " followed by a, o or u for ?, ? or ?. Neither way works in the IDLE console or file window of IDLE. Both ways work on the python console in a terminal window. IDLE version 3.2.2, Phyton version 3.2.2 and Tk version 8.5 according to IDLE -> "About IDLE". Names of the keyboard layouts: "US" and "US International - PC" Thank y'll for any Help From patrick at bierans.de Sun Jan 8 14:46:49 2012 From: patrick at bierans.de (patrick at bierans.de) Date: Sun, 8 Jan 2012 20:46:49 +0100 (CET) Subject: your feedback to my first project please Message-ID: <2123007772.204183.1326052009748.JavaMail.open-xchange@email.1und1.de Thanks for the feedback! I took the time reading and understanding it and to let it getting into my bones. And I also lost time on reading more of this freaky and interesting documentation and was testing a lot of different stuff with my enviroment. My current code can be seen here if you are interested: http://pastebin.com/3fz6qm9z? #AverageStack.py http://pastebin.com/tUSGs3gb? #TestAverageStack.py Here are my replies to your time consuming and informative replies ;) > D'Arcy wrote: [code examples] Python has some really interesting tricks I have not seen in php. For example: self._data = [default] * dim? - That's nice. :) And allowing the getter to also set a value was a nice idea. I meant: def avg(self, value=None) Thanks for that! :) But I will keep some of my underscores for "private" attributes and methods. And I googled: "dim" was basic. I know too many languages and start mixing the keywords - shame on me. ;) > D'Arcy and Peter wrote: [about writing testcases] Good Eye: I wrote the tests after coding - I know that this is the wrong way. I just wanted to start coding and after some time I decided that I shoud have some test cases. This is no real TDD - true. ;) I'll do that right next time. > Peter wrote: You must be doing it [writing test cases] wrong. After thinking about it: Yupp. You are right. Having written tests to check "private" attributes really hurts one's pride. ;) > Peter wrote: You need "from __future__ import division" Thanks for pointing me to it. I really would have fallen for it! > Peter wrote: assert False, " %s, %s ?" % ("red", "yellow") Can you do that with a.avg() instead of a string like "red"? TIA, Patrick PS: > gene wrote: [plain text emails] Thanks for pointing me to that. But it was the mistake of my webmailer. I am well aware of the etiquette of mailing lists. (As you can see my mail was wordwrapped accordingly.) But I will not blame you for full quoting my html email... *cough* ;-P ? I hope I can get my webmailer to go for plain text email. The option is set but does not seam to apply. ?( From dgeorge at daviddgeorge.com Sun Jan 8 16:37:45 2012 From: dgeorge at daviddgeorge.com (David George) Date: Sun, 08 Jan 2012 16:37:45 -0500 Subject: Error Importing MySQLdb Message-ID: Hello there, I have been trying for awhile now to get MySQLdb working. I am currently getting this error when trying to import it: >>> import MySQLdb Traceback (most recent call last): File "", line 1, in File "build/bdist.macosx-10.7-intel/egg/MySQLdb/init.py", line 19, in File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 7, in File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 6, in bootstrap ImportError: dlopen(/Users/username/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so, 2): Library not loaded: /usr/local/lib/libmysqlclient.18.dylib Referenced from: /Users/username/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so Reason: image not found Anyone know what I need to do in order to correct these errors. Thanks From d at davea.name Sun Jan 8 17:02:21 2012 From: d at davea.name (Dave Angel) Date: Sun, 08 Jan 2012 17:02:21 -0500 Subject: Parallel Processing In-Reply-To: <3161f7ec-feb6-41ef-b73d-bb22e3e7704e@n6g2000vbg.googlegroups.com> References: <25422fc4-b2ba-41aa-b12a-5e2fdc989bab@j9g2000vby.googlegroups.com> <402bb451-9986-4a26-b606-6a1c3429f98e@s18g2000vby.googlegroups.com> <3161f7ec-feb6-41ef-b73d-bb22e3e7704e@n6g2000vbg.googlegroups.com> Message-ID: <4F0A126D.4030702@davea.name> On 01/08/2012 11:39 AM, Yigit Turgut wrote: > > screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) > timer = pygame.time.Clock() > white = True > start = time.time() > end = time.time() - start > end2= time.time() - start > > def test1(): > global end > global white > while(end<5): > end = time.time() - start > timer.tick(4) #FPS > screen.fill((255,255,255) if white else (0, 0, 0)) > white = not white > pygame.display.update() > > def test2(): > global end2 > while(end2<5): > end2 = time.time() - start > print end2 > > ppservers = () > job_server = pp.Server(ppservers=ppservers) > > job1 = job_server.submit(test1, (), globals=globals()) > job2 = job_server.submit(test2, (), globals=globals()) > result = job1() > result2 = job2() > > print result2 > > job_server.print_stats() > > This *supposed to* print values of 'end' and simultaneously execute > test1. Eventhough I set globals parameter and nothing seems to be > wrong this code generates the following traceback ; > > Starting pp with 2 workers > An error has occured during the function execution > Traceback (most recent call last): > File "/usr/lib/python2.6/site-packages/ppworker.py", line 90, in run > __result = __f(*__args) > File "", line 4, in test1 > NameError: global name 'end' is not defined > An error has occured during the function execution > Traceback (most recent call last): > File "/usr/lib/python2.6/site-packages/ppworker.py", line 90, in run > __result = __f(*__args) > File "", line 3, in test2 > NameError: global name 'end2' is not defined > > How can this be, what am I missing ? I don't see anything on the http://www.parallelpython.com website that indicates how it handles globals. Remember this is creating a separate process, so it can't literally share the globals you have. i would have expected it to pickle them when you say globals=globals(), but I dunno. In any case, I can't see any value in making end global with the "global" statement. I'd move the end= line inside the function, and forget about making it global. The other thing you don't supply is a list of functions that might be called by your function. See the depfuncs argument. It probably handles all the system libraries, but I can't see how it'd be expected to handle pygame. With the limited information supplied by the website, I'd experiment first with simpler things. Make two functions that are self-contained, and try them first. No global statements, and no calls to pygame. After that much worked, then I'd try adding arguments, and then return values. Then i'd try calling separate functions (declaring them in depfuncs). And finally I'd try some 3rd party library. -- DaveA From hoogendoorn.eelco at gmail.com Sun Jan 8 17:03:20 2012 From: hoogendoorn.eelco at gmail.com (Eelco) Date: Sun, 8 Jan 2012 14:03:20 -0800 (PST) Subject: replacing __dict__ with an OrderedDict References: <4f079690$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <10504296-daa3-4c3d-b45a-883af99e6804@z19g2000vbe.googlegroups.com> i havnt read every post in great detail, but it doesnt seem like your actual question has been answered, so ill give it a try. AFAIK, changing __dict__ to be an ordereddict is fundamentally impossible in python 2. __dict__ is a builtin language construct hardcoded into the C API. There is no way to mess with it. Apparently this is different in python 3, but I dont know much about that. From benjamin.kaplan at case.edu Sun Jan 8 17:12:50 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 8 Jan 2012 17:12:50 -0500 Subject: idle mac os x international keyboard umlaut input In-Reply-To: References: Message-ID: On Sun, Jan 8, 2012 at 2:32 PM, Some Friend wrote: > Dear Friends, > with an international keyboard on mac os 10.6 > an umlaut is inserted according to the chosen > keyboard layout with alt + u followed by a, > o or u for ?, ? or ?, or with cmd + " followed > by a, o or u for ?, ? or ?. ?Neither way works > in the IDLE console or file window of IDLE. > Both ways work on the python console in a terminal > window. > > IDLE version 3.2.2, Phyton version 3.2.2 and > Tk version 8.5 according to IDLE -> "About IDLE". > > Names of the keyboard layouts: > "US" and "US International - PC" > > Thank y'll for any Help > -- This issue came up a few weeks ago too. The conclusion was that it's a bug in the Cocoa version of Tcl/Tk so there's unfortunately not much that can be done from the Python side. https://groups.google.com/group/comp.lang.python/browse_thread/thread/c7f22b059c68452a/85d11aa8f4b8b3c1 From benjamin.kaplan at case.edu Sun Jan 8 17:17:15 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 8 Jan 2012 17:17:15 -0500 Subject: Error Importing MySQLdb In-Reply-To: References: Message-ID: On Sun, Jan 8, 2012 at 4:37 PM, David George wrote: > Hello there, > I have been trying for awhile now to get MySQLdb working. I am currently > getting this error when trying to import it: > >>>> import MySQLdb > > Traceback (most recent call last): File "", line 1, in File > "build/bdist.macosx-10.7-intel/egg/MySQLdb/init.py", line 19, in File > "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 7, in File > "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 6, in bootstrap > ImportError: > dlopen(/Users/username/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so, > 2): Library not loaded: /usr/local/lib/libmysqlclient.18.dylib Referenced > from: > /Users/username/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so > Reason: image not found > > Anyone know what I need to do in order to correct these errors. > > Thanks MySQLdb is having trouble loading the MySQL client library. Since I assume MySQL is installed, my best guess is that you have an architecture problem. Your Python is probably running in 64-bit mode. Do you have a 64-bit MySQL install? The "file" command will tell you which architectures are in a binary if you're unsure. From dgeorge29ca at gmail.com Sun Jan 8 17:37:04 2012 From: dgeorge29ca at gmail.com (davidfx) Date: Sun, 8 Jan 2012 14:37:04 -0800 (PST) Subject: Error Importing MySQLdb In-Reply-To: References: Message-ID: <18369429.1936.1326062224503.JavaMail.geo-discussion-forums@vbdz6> I am not sure what file you mean. Where should I look for the file you are talking about? By the way MySQL works fine within MAMP. Thanks for your suggestions. From dgeorge29ca at gmail.com Sun Jan 8 17:37:04 2012 From: dgeorge29ca at gmail.com (davidfx) Date: Sun, 8 Jan 2012 14:37:04 -0800 (PST) Subject: Error Importing MySQLdb In-Reply-To: References: Message-ID: <18369429.1936.1326062224503.JavaMail.geo-discussion-forums@vbdz6> I am not sure what file you mean. Where should I look for the file you are talking about? By the way MySQL works fine within MAMP. Thanks for your suggestions. From d at davea.name Sun Jan 8 18:08:23 2012 From: d at davea.name (Dave Angel) Date: Sun, 08 Jan 2012 18:08:23 -0500 Subject: Error Importing MySQLdb In-Reply-To: <18369429.1936.1326062224503.JavaMail.geo-discussion-forums@vbdz6> References: <18369429.1936.1326062224503.JavaMail.geo-discussion-forums@vbdz6> Message-ID: <4F0A21E7.2000504@davea.name> On 01/08/2012 05:37 PM, davidfx wrote: > I am not sure what file you mean. Where should I look for the file you are talking about? By the way MySQL works fine within MAMP. > > Thanks for your suggestions. In most Linux/Unix systems, there is a file utility on the system PATH. To find the type of a particular file, you run it as file unknowndata and it'll use its heuristics to guess what kind of data you have, written by what software, or what type of executable you have, and whether it's 32 bit or 64, etc. -- DaveA From sebastian_rooks at lavabit.c_o_m Sun Jan 8 18:44:56 2012 From: sebastian_rooks at lavabit.c_o_m (Sebastian Rooks) Date: Mon, 09 Jan 2012 00:44:56 +0100 Subject: An "alternative" to Learning Perl Message-ID: Hello everyone, I was wondering if you could help me. I'm looking for a python introductory book, kind of like Learning Python only smaller (?!) The thing is, I travel to and from work each day for about 1,5h in each direction, and do most of my reading on the train :\ (seriously) And I can't find one (just one) python book shorter than 500 pages that is worth its weight in salt. Anyone know of any, any at all? All suggestions welcomed! -- Sebastian From dhoese at gmail.com Sun Jan 8 19:02:55 2012 From: dhoese at gmail.com (David Hoese) Date: Sun, 08 Jan 2012 18:02:55 -0600 Subject: Parallel Processing In-Reply-To: References: Message-ID: <4F0A2EAF.8090704@gmail.com> On 1/8/12 1:45 PM, Yigit Turgut wrote: > There are no imports other than defined on the script, which are; > > import pygame > import sys > import time > import math > import pp > > You are correct about trying to pass two functions and second one is > in place where a tuple of arguments supposed to be. But what if these > functions don't have any arguments ? I tested functions test1() and > test2() seperately ; they work. Once I figure out how to run these > functions simultaneously, I will add an argument to test2 and try then > on. My main goal is to simultaneously run two functions, one of them > has one argument the other doesn't. To get familiar with parallel > processing I am experimenting now without arguments and then I will > embed the code to my application. I am experimenting with the > following ; > > import pygame > import sys > import time > import math > import pp > > screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) > timer = pygame.time.Clock() > white = True > start = time.time() > end = time.time() - start > > def test1(): > global end > global white > while(end<5): > end = time.time() - start > timer.tick(4) #FPS > screen.fill((255,255,255) if white else (0, 0, 0)) > white = not white > pygame.display.update() > > def test2(): > global end > while(end<5): > end = time.time() - start > print end > > ppservers = () > job_server = pp.Server(ppservers=ppservers) > print "Starting pp with", job_server.get_ncpus(), "workers" > > job1 = job_server.submit(test1()) > job2 = job_server.submit(test2()) > result = job1() > result2 = job2() > > print "Counting...", result2 > > job_server.print_stats() > > test1() works as expected (job1) but test2() doesn't work and I get > the following traceback ; > > Traceback (most recent call last): > File "fl.py", line 33, in > job1 = job_server.submit(test1()) > File "/usr/lib/python2.6/site-packages/pp.py", line 458, in submit > sfunc = self.__dumpsfunc((func, ) + depfuncs, modules) > File "/usr/lib/python2.6/site-packages/pp.py", line 629, in > __dumpsfunc > sources = [self.__get_source(func) for func in funcs] > File "/usr/lib/python2.6/site-packages/pp.py", line 696, in > __get_source > sourcelines = inspect.getsourcelines(func)[0] > File "/usr/lib/python2.6/inspect.py", line 678, in getsourcelines > lines, lnum = findsource(object) > File "/usr/lib/python2.6/inspect.py", line 519, in findsource > file = getsourcefile(object) or getfile(object) > File "/usr/lib/python2.6/inspect.py", line 441, in getsourcefile > filename = getfile(object) > File "/usr/lib/python2.6/inspect.py", line 418, in getfile > raise TypeError('arg is not a module, class, method, ' > TypeError: arg is not a module, class, method, function, traceback, > frame, or code object > > Error is related to test1 not having an argument. When I leave it > empty as following ; > > job1 = job_server.submit(test1,()) > > test1 doesn't run. When I do ; > > job1 = job_server.submit(test1()) > > Display works but I get; > > TypeError: arg is not a module, class, method, function, traceback, > frame, or code object (complete traceback same as above). > > And test2 doesn't work also. But when I do; > > job1 = job_server.submit(test1,()) > job2 = job_server.submit(test2()) > > I get test2 working but test1 not working. Obviously related to > argument arrangement in submit. Hi, I've never used pygame or Parallel Python, but I played around with the code you provided and did one of my favorite debugging techniques...I printed things out and read the output. So one thing I did was printed the globals before the function definitions and inside test1(). Which the first print shows what I expect from calling "print globals()", then inside test1() I only get functions, modules, and a few other things. So I checked the pp documentation and found this about the globals keyword: globals - dictionary from which all modules, functions and classes It also handles imports funny because I tried doing "from pprint import pprint" and it couldn't find it properly even though that's a function (it couldn't find a class that that function uses). So I think you'll have to pass things in as arguments or a dependency functions as others have suggested. There is also a 'modules' keyword that you can provide names of modules to import, which might help. And is there a reason you need to use Parallel Python and can't use something more simple like python's "multiprocessing" or the classic "os.fork()"? I understand that Parallel Python can run on remote servers in parallel...but how complicated is your program going to be? I got the following to work (not sure if its what you want): ### import pp def test1(): start = time.time() end = time.time() - start screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) timer = pygame.time.Clock() white = True while(end<5): end = time.time() - start timer.tick(4) #FPS screen.fill((255,255,255) if white else (0, 0, 0)) white = not white pygame.display.update() def test2(): start = time.time() end2= time.time() - start while(end2<5): end2 = time.time() - start print end2 ppservers = () job_server = pp.Server(ppservers=ppservers) job1 = job_server.submit(test1, modules=("pygame","time")) job2 = job_server.submit(test2, modules=("time",)) result = job1() result2 = job2() print result2 job_server.print_stats() ### However, I don't know if this will always work the way you want it to, depending on how you setup your Parallel Python servers. By that I mean, if you run this on any machine that isn't local, I think it will try to connect to that remote display when getting the pygame "screen". But again, I've never used pygame. And this was also a quick throw together, so you could probably pass in "start" and stuff like that so that it doesn't have to be calculated both times. Summary: Parallel Python doesn't handle global variables in a normal way (it doesn't like things that aren't functions, modules, or classes) so...don't use globals. Let me know if any of that didn't make sense. -Dave P.S. If anyone has any other results I would be curious to hear. From wuwei23 at gmail.com Sun Jan 8 20:02:01 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 8 Jan 2012 17:02:01 -0800 (PST) Subject: No subject References: Message-ID: On Jan 9, 2:37?am, Sean Wolfe wrote: > is anybody out there? > > On Sat, Jan 7, 2012 at 5:07 AM, abdullah zuberi > > wrote: > > hello ? Just nod if you can hear me! From benjamin.kaplan at case.edu Sun Jan 8 20:23:09 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sun, 8 Jan 2012 20:23:09 -0500 Subject: Error Importing MySQLdb In-Reply-To: <18369429.1936.1326062224503.JavaMail.geo-discussion-forums@vbdz6> References: <18369429.1936.1326062224503.JavaMail.geo-discussion-forums@vbdz6> Message-ID: On Sun, Jan 8, 2012 at 5:37 PM, davidfx wrote: > I am not sure what file you mean. ?Where should I look for the file you are talking about? ?By the way MySQL works fine within MAMP. > > Thanks for your suggestions. Like I said, it's likely an architecture issue. If you have a 32-bit MySQL install and are using a 64-bit Python, it won't be able to load the client libraries. The Python install included in Lion is universal (a single file containing both 32-bit and 64-bit executables) so if it's loaded by a 32-bit program, it will load in 32-bit mode. "file" is a command that uses heuristics to determine the type of a file. You run it from a terminal. $ file /usr/bin/python /usr/bin/python: Mach-O universal binary with 2 architectures /usr/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64 /usr/bin/python (for architecture i386): Mach-O executable i386 Try running "file /usr/local/lib/libmysqlclient.18.dylib". According to the traceback you posted, that's the library that failed to load. If you need to force Python to run in 32-bit mode, you can use the arch command "arch -i386 python" From y.turgut at gmail.com Sun Jan 8 20:46:39 2012 From: y.turgut at gmail.com (Yigit Turgut) Date: Sun, 8 Jan 2012 17:46:39 -0800 (PST) Subject: Parallel Processing References: Message-ID: On Jan 9, 12:02 am, Dave Angel wrote: > On 01/08/2012 11:39 AM, Yigit Turgut wrote: > > > > > > > > > > > screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) > > timer = pygame.time.Clock() > > white = True > > start = time.time() > > end = time.time() - start > > end2= time.time() - start > > > def test1(): > > global end > > global white > > while(end<5): > > end = time.time() - start > > timer.tick(4) #FPS > > screen.fill((255,255,255) if white else (0, 0, 0)) > > white = not white > > pygame.display.update() > > > def test2(): > > global end2 > > while(end2<5): > > end2 = time.time() - start > > print end2 > > > ppservers = () > > job_server = pp.Server(ppservers=ppservers) > > > job1 = job_server.submit(test1, (), globals=globals()) > > job2 = job_server.submit(test2, (), globals=globals()) > > result = job1() > > result2 = job2() > > > print result2 > > > job_server.print_stats() > > > This *supposed to* print values of 'end' and simultaneously execute > > test1. Eventhough I set globals parameter and nothing seems to be > > wrong this code generates the following traceback ; > > > Starting pp with 2 workers > > An error has occured during the function execution > > Traceback (most recent call last): > > File "/usr/lib/python2.6/site-packages/ppworker.py", line 90, in run > > __result = __f(*__args) > > File "", line 4, in test1 > > NameError: global name 'end' is not defined > > An error has occured during the function execution > > Traceback (most recent call last): > > File "/usr/lib/python2.6/site-packages/ppworker.py", line 90, in run > > __result = __f(*__args) > > File "", line 3, in test2 > > NameError: global name 'end2' is not defined > > > How can this be, what am I missing ? > > I don't see anything on thehttp://www.parallelpython.com > website that indicates how it handles > globals. Remember this is creating a separate process, so it can't > literally share the globals you have. i would have expected it to > pickle them when you say globals=globals(), but I dunno. In any case, I > can't see any value in making end global with the "global" statement. > I'd move the end= line inside the function, and forget about making it > global. globals=globals() works but not for each variable (lol). Some of them gets recognized and some don't for some reason I couldn't figure out yet. But that's the main scheme. > > The other thing you don't supply is a list of functions that might be > called by your function. See the depfuncs argument. It probably > handles all the system libraries, but I can't see how it'd be expected > to handle pygame. depfuncs passes the dependent functions that will/might be used at the execution phase of the called function. PP doesn't require to set modules for basic I/O,sys etc. Only 3rd party ones like numpy, scipy and so on. > > With the limited information supplied by the website, I'd experiment > first with simpler things. Make two functions that are self-contained, > and try them first. No global statements, and no calls to pygame. > After that much worked, then I'd try adding arguments, and then return > values. > That's what I did. After investigating similar approaches to achieve the task, I unconsciously developed an idea that 'this is not going to be easy' and approached with that perception. Now I realize that it's much more simple than I thought. The work it does is complex but it requires very little effort to operate functionally. > Then i'd try calling separate functions (declaring them in depfuncs). > And finally I'd try some 3rd party library. Don't think will try another package for the same task. I am now moving on to PP + PyCUDA to harness GPU available CPU cores. Thank you for the guidance. On Jan 9, 2:02?am, David Hoese wrote: > On 1/8/12 1:45 PM, Yigit Turgut wrote: > > > There are no imports other than defined on the script, which are; > > > import pygame > > import sys > > import time > > import math > > import pp > > > You are correct about ?trying to pass two functions and second one is > > in place where a tuple of arguments supposed to be. But what if these > > functions don't have any arguments ? I tested functions test1() and > > test2() seperately ; they work. Once I figure out how to run these > > functions simultaneously, I will add an argument to test2 and try then > > on. My main goal is to simultaneously run two functions, one of them > > has one argument the other doesn't. To get familiar with parallel > > processing I am experimenting now without arguments and then I will > > embed the code to my application. I am experimenting with the > > following ; > > > import pygame > > import sys > > import time > > import math > > import pp > > > screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) > > timer = pygame.time.Clock() > > white = True > > start = time.time() > > end = time.time() - start > > > def test1(): > > ? ?global end > > ? ?global white > > ? ?while(end<5): > > ? ? ?end = time.time() - start > > ? ? ?timer.tick(4) #FPS > > ? ? ?screen.fill((255,255,255) if white else (0, 0, 0)) > > ? ? ?white = not white > > ? ? ?pygame.display.update() > > > def test2(): > > ? ?global end > > ? ?while(end<5): > > ? ? ?end = time.time() - start > > ? ? ?print end > > > ppservers = () > > job_server = pp.Server(ppservers=ppservers) > > print "Starting pp with", job_server.get_ncpus(), "workers" > > > job1 = job_server.submit(test1()) > > job2 = job_server.submit(test2()) > > result = job1() > > result2 = job2() > > > print "Counting...", result2 > > > job_server.print_stats() > > > test1() works as expected (job1) but test2() doesn't work and I get > > the following traceback ; > > > Traceback (most recent call last): > > ? ?File "fl.py", line 33, in > > ? ? ?job1 = job_server.submit(test1()) > > ? ?File "/usr/lib/python2.6/site-packages/pp.py", line 458, in submit > > ? ? ?sfunc = self.__dumpsfunc((func, ) + depfuncs, modules) > > ? ?File "/usr/lib/python2.6/site-packages/pp.py", line 629, in > > __dumpsfunc > > ? ? ?sources = [self.__get_source(func) for func in funcs] > > ? ?File "/usr/lib/python2.6/site-packages/pp.py", line 696, in > > __get_source > > ? ? ?sourcelines = inspect.getsourcelines(func)[0] > > ? ?File "/usr/lib/python2.6/inspect.py", line 678, in getsourcelines > > ? ? ?lines, lnum = findsource(object) > > ? ?File "/usr/lib/python2.6/inspect.py", line 519, in findsource > > ? ? ?file = getsourcefile(object) or getfile(object) > > ? ?File "/usr/lib/python2.6/inspect.py", line 441, in getsourcefile > > ? ? ?filename = getfile(object) > > ? ?File "/usr/lib/python2.6/inspect.py", line 418, in getfile > > ? ? ?raise TypeError('arg is not a module, class, method, ' > > TypeError: arg is not a module, class, method, function, traceback, > > frame, or code object > > > Error is related to test1 not having an argument. ?When I leave it > > empty as following ; > > > job1 = job_server.submit(test1,()) > > > test1 doesn't run. When I do ; > > > job1 = job_server.submit(test1()) > > > Display works but I get; > > > TypeError: arg is not a module, class, method, function, traceback, > > frame, or code object (complete traceback same as above). > > > And test2 doesn't work also. But when I do; > > > job1 = job_server.submit(test1,()) > > job2 = job_server.submit(test2()) > > > I get test2 working but test1 not working. Obviously related to > > argument arrangement in submit. > > Hi, > > I've never used pygame or Parallel Python, but I played around with the > code you provided and did one of my favorite debugging techniques...I > printed things out and read the output. > > So one thing I did was printed the globals before the function > definitions and inside test1(). ?Which the first print shows what I > expect from calling "print globals()", then inside test1() I only get > functions, modules, and a few other things. ?So I checked the pp > documentation and found this about the globals keyword: > > ? ? ?globals - dictionary from which all modules, functions and classes > > It also handles imports funny because I tried doing "from pprint import > pprint" and it couldn't find it properly even though that's a function > (it couldn't find a class that that function uses). ?So I think you'll > have to pass things in as arguments or a dependency functions as others > have suggested. ?There is also a 'modules' keyword that you can provide > names of modules to import, which might help. ?And is there a reason you > need to use Parallel Python and can't use something more simple like > python's "multiprocessing" or the classic "os.fork()"? ?I understand > that Parallel Python can run on remote servers in parallel...but how > complicated is your program going to be? > > I got the following to work (not sure if its what you want): > ### > import pp > > def test1(): > ? ? ?start = time.time() > ? ? ?end = time.time() - start > ? ? ?screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) > ? ? ?timer = pygame.time.Clock() > ? ? ?white = True > ? ? ?while(end<5): > ? ? ? ? ?end = time.time() - start > ? ? ?timer.tick(4) #FPS > ? ? ?screen.fill((255,255,255) if white else (0, 0, 0)) > ? ? ?white = not white > ? ? ?pygame.display.update() > > def test2(): > ? ? ?start = time.time() > ? ? ?end2= time.time() - start > ? ? ?while(end2<5): > ? ? ? ? ?end2 = time.time() - start > ? ? ?print end2 > > ppservers = () > job_server = pp.Server(ppservers=ppservers) > > job1 = job_server.submit(test1, modules=("pygame","time")) > job2 = job_server.submit(test2, modules=("time",)) > result = job1() > result2 = job2() > > print ?result2 > > job_server.print_stats() > ### > > However, I don't know if this will always work the way you want it to, > depending on how you setup your Parallel Python servers. ?By that I > mean, if you run this on any machine that isn't local, I think it will > try to connect to that remote display when getting the pygame "screen". > But again, I've never used pygame. ?And this was also a quick throw > together, so you could probably pass in "start" and stuff like that so > that it doesn't have to be calculated both times. > > Summary: Parallel Python doesn't handle global variables in a normal way > (it doesn't like things that aren't functions, modules, or classes) > so...don't use globals. ?Let me know if any of that didn't make sense. > > -Dave > > P.S. If anyone has any other results I would be curious to hear. Hi, That's correct, parallel python has an unusual way of handling functions but it's actually very simple compared to the work it's doing. It also *may* be some buggy because it doesn't get globals() frequently thus one should do globals().update at necessary lines.Also weirdly, it doesn't require to point to pygame. Following works as expected ; ppservers = () job_server = pp.Server(ppservers=ppservers) job1 = job_server.submit(test1, args=(), globals=globals()) job2 = job_server.submit(test2, args=(), globals=globals()) result = job1() result2 = job2() Thank you for the productive reply. From steve+comp.lang.python at pearwood.info Sun Jan 8 21:21:30 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Jan 2012 02:21:30 GMT Subject: Using an OrderedDict for __dict__ in Python 3 using __prepare__ Message-ID: <4f0a4f2a$0$11120$c3e8da3@news.astraweb.com> I'm using Python 3.1 and trying to create a class using an OrderedDict as its __dict__, but it isn't working as I expect. See http://www.python.org/dev/peps/pep-3115/ for further details. Here is my code: from collections import OrderedDict # The metaclass class OrderedClass(type): # The prepare function @classmethod def __prepare__(metacls, name, bases): # No keywords in this case print('calling metaclass __prepare__') return OrderedDict() # The metaclass invocation def __new__(cls, name, bases, classdict): print('calling metaclass __new__') for x in cls, name, bases, classdict, type(classdict): print(' ', x) return type.__new__(cls, name, bases, classdict) class MyClass(metaclass=OrderedClass): spam = 'Cardinal Biggles' ham = 'Ethel the Aardvark' def method1(self): pass def method2(self): pass list(MyClass.__dict__.keys()) and the results I get: calling metaclass __prepare__ calling metaclass __new__ MyClass () OrderedDict([('__module__', '__main__'), ('spam', 'Cardinal Biggles'), ('ham', 'Ethel the Aardvark'), ('method1', ), ('method2', )]) ['__module__', 'method2', 'ham', 'spam', 'method1', '__dict__', '__weakref__', '__doc__'] I expected that the output of MyClass.__dict__.keys would match the input OrderedDict (ignoring the entries added later, like __module__ and __doc__). And I'm completely flummoxed by the existence of MyClass.__dict__['__dict__']. What am I doing wrong? -- Steven From dgeorge at daviddgeorge.com Sun Jan 8 21:38:21 2012 From: dgeorge at daviddgeorge.com (David George) Date: Sun, 08 Jan 2012 21:38:21 -0500 Subject: No subject In-Reply-To: References: Message-ID: Sean Wolfe wrote: > is anybody out there? > > On Sat, Jan 7, 2012 at 5:07 AM, abdullah zuberi > wrote: >> hello ? >> Hello there Sean, How are you doing? From d at davea.name Sun Jan 8 21:46:05 2012 From: d at davea.name (Dave Angel) Date: Sun, 08 Jan 2012 21:46:05 -0500 Subject: Parallel Processing In-Reply-To: References: Message-ID: <4F0A54ED.8060506@davea.name> On 01/08/2012 08:46 PM, Yigit Turgut wrote: > On Jan 9, 12:02 am, Dave Angel wrote: >> >> Then i'd try calling separate functions (declaring them in depfuncs). >> And finally I'd try some 3rd party library. > Don't think will try another package for the same task. I am now > moving on to PP + PyCUDA to harness GPU available CPU cores. > > Thank you for the guidance. > Actually, I wasn't suggesting an alternative to pp, but rather introducing refs to libraries like numpy. I don't know what pp's methodology is, but I can guess which parts are trivial, and which parts tend to be trickier. Once things are in a separate process, it's best not to assume any shared state between the processes. Thus I'd expect globals() to be copied, not shared. And the error messages had very low line numbers, which I could take to mean they didn't add your imports and other stuff. Point is, when i start having trouble with code that's inadequately documented, I try the simplest things, and work up to the complex ones. -- DaveA From lists at cheimes.de Sun Jan 8 21:46:17 2012 From: lists at cheimes.de (Christian Heimes) Date: Mon, 09 Jan 2012 03:46:17 +0100 Subject: Using an OrderedDict for __dict__ in Python 3 using __prepare__ In-Reply-To: <4f0a4f2a$0$11120$c3e8da3@news.astraweb.com> References: <4f0a4f2a$0$11120$c3e8da3@news.astraweb.com> Message-ID: Am 09.01.2012 03:21, schrieb Steven D'Aprano: > What am I doing wrong? You aren't doing anything wrong. It's just not possible to have something different than a dict as a type's __dict__. It's a deliberate limitation and required optimization. The __prepare__ hook allows to you have a dict subclass as intermediate dict, but in the end it always comes down to a dict. The code in Objects/typeobject.c:type_new() copies the dict: /* Initialize tp_dict from passed-in dict */ type->tp_dict = dict = PyDict_Copy(dict); PyDict_Copy() takes an instance of a PyDict_Type subclass and always returns a PyDictObject. However you can use the __prepare__ hook to *remember* the order of insertion, see http://docs.python.org/py3k/reference/datamodel.html#customizing-class-creation Christian From ether.joe at gmail.com Sun Jan 8 22:50:16 2012 From: ether.joe at gmail.com (Sean Wolfe) Date: Mon, 9 Jan 2012 00:50:16 -0300 Subject: No subject In-Reply-To: References: Message-ID: On Sun, Jan 8, 2012 at 11:38 PM, David George wrote: > > Sean Wolfe wrote: >> >> is anybody out there? >> >> On Sat, Jan 7, 2012 at 5:07 AM, abdullah zuberi >> ?wrote: >>> >>> hello ? >>> > > Hello there Sean, How are you doing? > -- > http://mail.python.org/mailman/listinfo/python-list I'm freakin awesome. This reply all feature is a little high tech for me though, took me a few times to figure it out. That's done though so on to self sustaining nuclear fusion ... brb From ether.joe at gmail.com Sun Jan 8 22:55:22 2012 From: ether.joe at gmail.com (Sean Wolfe) Date: Mon, 9 Jan 2012 00:55:22 -0300 Subject: An "alternative" to Learning Perl In-Reply-To: References: Message-ID: On Sun, Jan 8, 2012 at 8:44 PM, Sebastian Rooks wrote: > Hello everyone, > > I was wondering if you could help me. I'm looking for a python > introductory book, kind of like Learning Python only smaller (?!) > The thing is, I travel to and from work each day for about 1,5h in each > direction, and do most of my reading on the train :\ > > (seriously) > > And I can't find one (just one) python book shorter than 500 pages that > is worth its weight in salt. > > Anyone know of any, any at all? > > All suggestions welcomed! > > -- Sebastian > -- kindle? ipad? tablet? also there is python programming for the absolute beginner, which is agreat book but it's pretty beginner. But well written. At least Iliked it.http://www.amazon.com/Python-Programming-Absolute-Beginner-3rd/dp/1435455002 Also byte of python ... I think there's a hardcover version you can buyhttp://www.swaroopch.com/buybook/ From wuwei23 at gmail.com Sun Jan 8 23:58:25 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 8 Jan 2012 20:58:25 -0800 (PST) Subject: replacing __dict__ with an OrderedDict References: Message-ID: <4a6cfeeb-1db6-47e9-b11f-2b49eb5b8b71@n6g2000vbg.googlegroups.com> On Jan 7, 2:06?am, Ian Kelly wrote: > wrote: > > Nonetheless, I'm still wondering if I could somehow replace the dict with an > > OrderedDict. > > In Python 3, yes. ?This is pretty much the entire use case for the new > __prepare__ method of metaclasses. ?See the "OrderedClass" example[...] This isn't accurate. The OrderedClass example uses an OrderedDict to remember the method creation order: def __new__(cls, name, bases, classdict): result = type.__new__(cls, name, bases, dict(classdict)) result.members = tuple(classdict) return result The instantiated objects __dict__ will still be a regularly dictionary, while the assignment order is stored in the class attribute .members. From nagle at animats.com Mon Jan 9 00:35:44 2012 From: nagle at animats.com (John Nagle) Date: Sun, 08 Jan 2012 21:35:44 -0800 Subject: python philosophical question - strong vs duck typing In-Reply-To: <59305aab-7ddf-4c61-b8ba-025a2ce10b48@d10g2000vbh.googlegroups.com> References: <59305aab-7ddf-4c61-b8ba-025a2ce10b48@d10g2000vbh.googlegroups.com> Message-ID: <4f0a7ca9$0$1727$742ec2ed@news.sonic.net> On 1/3/2012 6:15 PM, alex23 wrote: > On Jan 4, 6:38 am, Terry Reedy wrote: >> Shredskin compiles a subset of >> Python, or a subset of usages, to C, with similar benefits. > > That is, of course, 'Shedskin' and 'C++' :) > > +1 for either Cython or Shedskin as your next step for more performant > Python. I've tried Shed Skin, and it's an excellent idea that's not ready for prime time. One guy did it all, and it needs a greater level of effort than that. It does do well on numeric code. There's a reason for that. If you can figure out at compile time which variables can be represented as "int", "bool", "char" (or "wchar_t") and "double", performance on numeric work improves enormously. CPython boxes everything, including integers, in a "CObject" object, so there's dispatching overhead just to add two numbers. A type-inferring compiler has to analyze the whole program at once, because the type of a function's arguments is determined by its callers. This is slow. The alternative is to guess what the type of something is likely to be, compile code at run time, and be prepared to back out a bad guess. This requires a very complex system, but that's how PyPy does it. Performance does not seem to reach Shed Skin levels. Python has some serious problems that preclude optimization. Basically, the language is designed to be run by a naive (non-optimizing) interpreter, and allows things that are easy for such an implementation but very tough to optimize. An example is the ability to store into the variables of a module from outside it, and even from another thread. Every attempt to get rid of the Global Interpreter Lock has hit that problem. John Nagle From nagle at animats.com Mon Jan 9 00:47:07 2012 From: nagle at animats.com (John Nagle) Date: Sun, 08 Jan 2012 21:47:07 -0800 Subject: Error Importing MySQLdb In-Reply-To: References: <18369429.1936.1326062224503.JavaMail.geo-discussion-forums@vbdz6> Message-ID: <4f0a7f54$0$1659$742ec2ed@news.sonic.net> On 1/8/2012 5:23 PM, Benjamin Kaplan wrote: > On Sun, Jan 8, 2012 at 5:37 PM, davidfx wrote: >> I am not sure what file you mean. Where should I look for the file you are talking about? By the way MySQL works fine within MAMP. >> >> Thanks for your suggestions. > > > Like I said, it's likely an architecture issue. If you have a 32-bit > MySQL install and are using a 64-bit Python, it won't be able to load > the client libraries. The Python install included in Lion is universal > (a single file containing both 32-bit and 64-bit executables) so if > it's loaded by a 32-bit program, it will load in 32-bit mode. Actually, the issue is only whether you have 64-bit MySQL client libraries for C to which MySQLdb can link. Those are called "MySQL Connector/C", and here are the download pages for them. http://dev.mysql.com/downloads/connector/c/ The actual database can (and usually should be) the 64-bit executable, while the libraries can be 32 or 64 bit. They communicate over a socket, and don't even need to be on the same machine. Unfortunately, the whole MySQLdb/Python/Connector/C versioning setup is a mess. See: http://chaos.weblogs.us/archives/327 John Nagle From some-friend at web.de Mon Jan 9 00:58:14 2012 From: some-friend at web.de (Some Friend) Date: Mon, 09 Jan 2012 06:58:14 +0100 Subject: idle mac os x international keyboard umlaut input In-Reply-To: References: Message-ID: Am 08.01.12 23:12, schrieb Benjamin Kaplan: > On Sun, Jan 8, 2012 at 2:32 PM, Some Friend wrote: >> Dear Friends, >> with an international keyboard on mac os 10.6 >> an umlaut is inserted according to the chosen >> keyboard layout with alt + u followed by a, >> o or u for ?, ? or ?, or with cmd + " followed >> by a, o or u for ?, ? or ?. Neither way works >> in the IDLE console or file window of IDLE. >> Both ways work on the python console in a terminal >> window. >> >> IDLE version 3.2.2, Phyton version 3.2.2 and >> Tk version 8.5 according to IDLE -> "About IDLE". >> >> Names of the keyboard layouts: >> "US" and "US International - PC" >> >> Thank y'll for any Help >> -- > > This issue came up a few weeks ago too. The conclusion was that it's a > bug in the Cocoa version of Tcl/Tk so there's unfortunately not much > that can be done from the Python side. > > https://groups.google.com/group/comp.lang.python/browse_thread/thread/c7f22b059c68452a/85d11aa8f4b8b3c1 ... so it's paste and copy then :-(. Thanks for your Help. From bugcy013 at gmail.com Mon Jan 9 04:11:21 2012 From: bugcy013 at gmail.com (Ganesh Kumar) Date: Mon, 9 Jan 2012 14:41:21 +0530 Subject: re module help Message-ID: Hi Guys, I have created regular expression with os modules, I have created file sdptool to match the regular expression pattern, will print the result. I want without creating file how to get required output, I tried but i didn't get output correctly, over stream. #! /usr/bin/python import os,re def scan(): cmd = "sdptool -i hci0 search OPUSH > sdptool" fp = os.popen(cmd) results = [] l = open("sdptool").read() pattern = r"^Searching for OPUSH on (\w\w(:\w\w)+).*?Channel: (\d+)" r = re.compile(pattern, flags=re.MULTILINE|re.DOTALL) while True: for match in r.finditer(l): g = match.groups() results.append((g[0],'phone',g[2])) return results ## output [('00:15:83:3D:0A:57', 'phone', '1')] http://dpaste.com/684335/ please guide me. with out file creating, to archive required output. Did I learn something today? If not, I wasted it. -------------- next part -------------- An HTML attachment was scrubbed... URL: From noufal at nibrahim.net.in Mon Jan 9 04:15:33 2012 From: noufal at nibrahim.net.in (Noufal Ibrahim) Date: Mon, 09 Jan 2012 14:45:33 +0530 Subject: [BangPypers] re module help In-Reply-To: (Ganesh Kumar's message of "Mon, 9 Jan 2012 14:41:21 +0530") References: Message-ID: <87vcolme2y.fsf@sanitarium.localdomain> Ganesh Kumar writes: > Hi Guys, > > I have created regular expression with os modules, I have created file > sdptool to match the regular expression pattern, will print the result. > I want without creating file how to get required output, I tried but i > didn't get output correctly, over stream. You should use the subprocess module to deal with external commands. >>> import subprocess >>> s = subprocess.Popen(["head", "/etc/hosts"], stdout = subprocess.PIPE) >>> hosts_head = s.stdout.read() >>> print hosts_head 127.0.0.1 localhost [...] Use that get your output and then parse it with the regexp. -- ~noufal http://nibrahim.net.in The best cure for insomnia is to get a lot of sleep. -W. C. Fields From 1248283536 at qq.com Mon Jan 9 04:18:07 2012 From: 1248283536 at qq.com (=?gbk?B?y66+ssH3ye4=?=) Date: Mon, 9 Jan 2012 17:18:07 +0800 Subject: how to install lxml in window xp? Message-ID: in my xp ,python26,easy_install installed. i want to install lxml in window xp 1.c:\python26\scripts\easy_install lxml what i get is: Reading http://codespeak.net/lxml Best match: lxml 2.3.3 Downloading http://lxml.de/files/lxml-2.3.3.tgz Processing lxml-2.3.3.tgz Running lxml-2.3.3\setup.py -q bdist_egg --dist-dir c:\windows\temp\easy_install -58e4ap\lxml-2.3.3\egg-dist-tmp-hyg1bg Building lxml version 2.3.3. Building with Cython 0.15.1. ERROR: 'xslt-config' is not recognized as an internal or external command, operable program or batch file. ** make sure the development packages of libxml2 and libxslt are installed ** Using build configuration of libxslt warning: no files found matching 'lxml.etree.c' under directory 'src\lxml' warning: no files found matching 'lxml.objectify.c' under directory 'src\lxml' warning: no files found matching 'lxml.etree.h' under directory 'src\lxml' warning: no files found matching 'lxml.etree_api.h' under directory 'src\lxml' warning: no files found matching 'etree_defs.h' under directory 'src\lxml' Reading http://codespeak.net/lxml Best match: lxml 2.3.3 Downloading http://lxml.de/files/lxml-2.3.3.tgz Processing lxml-2.3.3.tgz Running lxml-2.3.3\setup.py -q bdist_egg --dist-dir c:\windows\temp\easy_install -58e4ap\lxml-2.3.3\egg-dist-tmp-hyg1bg Building lxml version 2.3.3. Building with Cython 0.15.1. ERROR: 'xslt-config' is not recognized as an internal or external command, operable program or batch file. ** make sure the development packages of libxml2 and libxslt are installed ** Using build configuration of libxslt warning: no files found matching 'lxml.etree.c' under directory 'src\lxml' warning: no files found matching 'lxml.objectify.c' under directory 'src\lxml' warning: no files found matching 'lxml.etree.h' under directory 'src\lxml' warning: no files found matching 'lxml.etree_api.h' under directory 'src\lxml' warning: no files found matching 'etree_defs.h' under directory 'src\lxml' warning: no files found matching 'pubkey.asc' under directory 'doc' warning: no files found matching 'tagpython*.png' under directory 'doc' warning: no files found matching 'Makefile' under directory 'doc' error: Setup script exited with error: None how can i install the lxml in my xp?? -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Mon Jan 9 05:19:53 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 09 Jan 2012 11:19:53 +0100 Subject: how to install lxml in window xp? In-Reply-To: References: Message-ID: ????, 09.01.2012 10:18: > in my xp ,python26,easy_install installed. > i want to install lxml in window xp > 1.c:\python26\scripts\easy_install lxml > > what i get is: > > Reading http://codespeak.net/lxml > Best match: lxml 2.3.3 > Downloading http://lxml.de/files/lxml-2.3.3.tgz > Processing lxml-2.3.3.tgz > Running lxml-2.3.3\setup.py -q bdist_egg --dist-dir c:\windows\temp\easy_install > -58e4ap\lxml-2.3.3\egg-dist-tmp-hyg1bg > Building lxml version 2.3.3. > Building with Cython 0.15.1. > ERROR: 'xslt-config' is not recognized as an internal or external command, > operable program or batch file. > > ** make sure the development packages of libxml2 and libxslt are installed ** Well? > how can i install the lxml in my xp?? You should read the docs: http://lxml.de/FAQ.html#where-are-the-binary-builds http://lxml.de/installation.html#installation Note that lxml currently lacks binary Windows builds for its latest releases. There are eggs for the original 2.3 release, though. Stefan From robert.kern at gmail.com Mon Jan 9 05:45:00 2012 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 09 Jan 2012 10:45:00 +0000 Subject: python philosophical question - strong vs duck typing In-Reply-To: <4f0a7ca9$0$1727$742ec2ed@news.sonic.net> References: <59305aab-7ddf-4c61-b8ba-025a2ce10b48@d10g2000vbh.googlegroups.com> <4f0a7ca9$0$1727$742ec2ed@news.sonic.net> Message-ID: On 1/9/12 5:35 AM, John Nagle wrote: > Python has some serious problems that preclude optimization. > Basically, the language is designed to be run by a naive (non-optimizing) > interpreter, and allows things that are easy > for such an implementation but very tough to optimize. An > example is the ability to store into the variables of a module > from outside it, and even from another thread. Every attempt > to get rid of the Global Interpreter Lock has hit that problem. You keep repeating this falsehood about the GIL. You have been repeatedly shown that this is false[1][2], though I have yet to see you acknowledge it. The GIL exists to protect Python's internal data structures, mostly the reference counts on objects. The reason that the attempts to remove the GIL from CPython have not been accepted is because they cause unacceptable performance losses in the common unthreaded case. In implementations of Python that do not use reference counting, there is no GIL. Neither Jython nor IronPython have a GIL, but they both have the standard Python semantics that let you store variables into modules from the outside, even from other threads. [1] http://mail.python.org/pipermail/python-list/2011-February/1265760.html [2] http://mail.python.org/pipermail/python-list/2011-April/1269056.html -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From bv5bv5bv5 at yahoo.com Mon Jan 9 06:05:01 2012 From: bv5bv5bv5 at yahoo.com (BV) Date: Mon, 9 Jan 2012 03:05:01 -0800 (PST) Subject: THE EXPANSION OF THE UNIVERSE IN THE QURAN !!!!!!!!!!!!!! Message-ID: THE EXPANSION OF THE UNIVERSE IN THE QURAN What you are about to read might sound unusual but it could be very enlightened In 1929, in the California Mount Wilson observatory, an American astronomer by the name of Edwin Hubble made one of the greatest discoveries in the history of astronomy. While he observed the stars with a giant telescope, he found out that the light from them was shifted to the red end of the spectrum and that this shift was more pronounced the further a star was from the earth. This discovery had an electrifying effect in the world of science, because according to the recognized rules of physics, the spectra of light beams traveling towards the point of observation tend towards violet while the spectra of the light beams moving away from the point of observation tend towards red. During Hubble?s observations, the light from stars was discovered to tend towards red. This meant that they were constantly moving away from us. Long before, Hubble made another very important discovery: Stars and galaxies moved away not only from us, but also from one another. The only conclusion that could be derived from a universe where everything moves away from everything else is that the universe constantly ?expands?. To better understand, the universe can be thought of as the surface of a balloon being blown up. Just as the points on the surface of a balloon move apart from each other as the balloon is inflated, so do the objects in space move apart from each other as the universe keeps expanding. In fact, this had been theoretically discovered even earlier. Albert Einstein, who is considered the greatest scientist of the century, had concluded after the calculations he made in theoretical physics that the universe could not be static. However, he had laid his discovery to rest simply not to conflict with the widely recognized static universe model of his time. Later on, Einstein was to identify his act as ?the greatest mistake of his career?. Subsequently, it became definite by Hubble?s observations that the universe expands. What importance, then, did the fact that the universe expands have on the existence of the universe? The expansion of the universe implied that if it could travel backwards in time, the universe would prove to have originated from a single point. The calculations showed that this ?single point? that harbored all the matter of the universe should have ?zero volume? and ?infinite density?. The universe had come about by the explosion of this single point with zero volume. This great explosion that marked the beginning of the universe was named the ?Big Bang? and the theory started to be so called. It has to be stated that ?zero volume? is a theoretical expression used for de******ive purposes. Science can define the concept of ?nothingness?, which is beyond the limits of human comprehension, only by expressing it as a point with zero volume?. In truth, ?a point with no volume? means ?nothingness?. The universe has come into being from nothingness. In other words, it was created. The Big Bang theory showed that in the beginning all the objects in the universe were of one piece and then were parted. This fact, which was revealed by the Big Bang theory was stated in the Quran 14 centuries ago, when people had a very limited knowledge about the universe; Allaah says (what means): "Have those who disbelieved not considered that the heavens and the earth were a joined entity, and We separated them and made from water every living thing? Then will they not believe?" [Quran 21:30] As stated in the verse, everything, even the ?heavens and the earth? that were not yet created, were created with a Big Bang out of a single point, and shaped the present universe by being parted from each other. When we compare the statements in the verse with the Big Bang theory, we see that they fully agree with each other. However, the Big Bang was introduced as a scientific theory only in the 20th century. The expansion of the universe is one of the most important pieces of evidence that the universe was created out of nothing. Although this fact was not discovered by science until the 20th century, Allaah has informed us of this reality in the Quran (revealed 1,400 years ago) saying (what means): " And the heaven We constructed with strength, and indeed, We are [its expander."[Quran 51: 47] 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.USC.EDU/DEPT/MSA/QURAN HTTP://WWW.QURANFORALL.ORG HTTP://WWW.QURANEXPLORER.COM/QURAN HTTP://WWW.PROPHETMUHAMMED.ORG HTTP://WWW.CHATISLAMONLINE.ORG/AR HTTP://WWW.DAR-US-SALAM.COM HTTP://YOUTUBEISLAM.COM From lie.1296 at gmail.com Mon Jan 9 07:10:14 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 09 Jan 2012 23:10:14 +1100 Subject: replacing __dict__ with an OrderedDict In-Reply-To: <10504296-daa3-4c3d-b45a-883af99e6804@z19g2000vbe.googlegroups.com> References: <4f079690$0$29966$c3e8da3$5496439d@news.astraweb.com> <10504296-daa3-4c3d-b45a-883af99e6804@z19g2000vbe.googlegroups.com> Message-ID: On 01/09/2012 09:03 AM, Eelco wrote: > i havnt read every post in great detail, but it doesnt seem like your > actual question has been answered, so ill give it a try. > > AFAIK, changing __dict__ to be an ordereddict is fundamentally > impossible in python 2. __dict__ is a builtin language construct > hardcoded into the C API. There is no way to mess with it. > > Apparently this is different in python 3, but I dont know much about > that. Actually the primary question has been answered by Ian Kelly which suggested __prepare__ for Python 3, and Peter Otten posted a code for a custom TestLoader that will essentially do what the OP wanted. I was just suggesting that what the OP thinks he wants is quite likely not what he actually wants. From ulrich.eckhardt at dominolaser.com Mon Jan 9 08:16:22 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 09 Jan 2012 14:16:22 +0100 Subject: replacing __dict__ with an OrderedDict In-Reply-To: References: <4f079690$0$29966$c3e8da3$5496439d@news.astraweb.com> <10504296-daa3-4c3d-b45a-883af99e6804@z19g2000vbe.googlegroups.com> Message-ID: <6u5rt8-971.ln1@satorlaser.homedns.org> Am 09.01.2012 13:10, schrieb Lie Ryan: > I was just suggesting that what the OP thinks he wants is quite > likely not what he actually wants. Rest assured that the OP has a rather good idea of what he wants and why, the latter being something you don't know, because he never bothered to explain it and you never asked. Please don't think he's an idiot just because he wants something that doesn't make sense to you. *le sigh* Uli From roy at panix.com Mon Jan 9 09:35:10 2012 From: roy at panix.com (Roy Smith) Date: Mon, 09 Jan 2012 09:35:10 -0500 Subject: replacing __dict__ with an OrderedDict References: Message-ID: In article , Ian Kelly wrote: > Randomizing the order is not a bad idea, but you also need to be able > to run the tests in a consistent order, from a specific random seed. > In the real world, test conflicts and dependencies do happen, and if > we observe a failure, make a change, rerun the tests and observe > success, we need to be able to be sure that we actually fixed the bug, > and that it didn't pass only because it was run in a different order. I've seen this argument play out multiple times on this group. Executive summary: OP: "I want to do X" Peanut Gallery: "You're not supposed to do that" Here's my commentary on that. The classic unittest philosophy says that tests should be independent of each other, which means they should be able to be run in arbitrary order. Some people advocate that the test framework should intentionally randomize the order, to flush out inter-test dependencies that the author didn't realize existed (or intend). Test independence is a good thing. Many people don't understand this when writing tests, and inadvertently write tests that depend on each other. I've worked with those systems. They're a bear to debug. You've got some test suite that runs for 15 minutes and dies at case 37 of 43. If you try to run case 37 by itself, it won't run, and you can't figure out what state cases 1-36 were supposed to leave the system in to make 37 work. You could sink days or weeks into debugging this kind of crap. BTDT. That being said, the unittest module, while designed to support the "all tests must be independent" philosophy, is a useful piece of software for lots of things. It provides an easy to use framework for writing tests, lots of convenient assertions, reporting, test discovery, etc, etc. If somebody (i.e. the classic "consenting adult" of the Python world) wants to take advantage of that to write a test suite where the tests *do* depend on each other, and have to be run in a certain order, there's nothing wrong with that. As long as they understand the consequences of their actions, don't try to preach unittest religion to them. They're in the best position to know if what they're trying to do is the best thing for their particular situation. From neilc at norwich.edu Mon Jan 9 09:52:39 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 9 Jan 2012 14:52:39 GMT Subject: replacing __dict__ with an OrderedDict References: Message-ID: <9n0d9nFrheU1@mid.individual.net> On 2012-01-09, Roy Smith wrote: > If somebody (i.e. the classic "consenting adult" of the Python > world) wants to take advantage of that to write a test suite > where the tests *do* depend on each other, and have to be run > in a certain order, there's nothing wrong with that. As long > as they understand the consequences of their actions, don't try > to preach unittest religion to them. They're in the best > position to know if what they're trying to do is the best thing > for their particular situation. If a question springs from an idea that is usually a bad practice, then it should be challenged. The possible broken-nose of a questioner is a small price to pay for the education of the peanut gallery. If a questioner does not wish to defend what they are doing, he or she has that right, of course. -- Neil Cerutti From ulrich.eckhardt at dominolaser.com Mon Jan 9 11:59:45 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Mon, 09 Jan 2012 17:59:45 +0100 Subject: replacing __dict__ with an OrderedDict In-Reply-To: References: Message-ID: <11jrt8-l32.ln1@satorlaser.homedns.org> Am 09.01.2012 15:35, schrieb Roy Smith: > The classic unittest philosophy says that tests should be independent of > each other, which means they should be able to be run in arbitrary > order. Some people advocate that the test framework should > intentionally randomize the order, to flush out inter-test dependencies > that the author didn't realize existed (or intend). While I agree with the idea, I'd like to add that independence is an illusion. You already have possible dependencies if you run tests in the same process/OS-installation/computer/parallel universe. If you now happen to influence one test with another and the next run randomizes the tests differently, you will never see the fault again. Without this reproducability, you don't gain anything but the bad stomach feeling that something is wrong. > Test independence is a good thing. Many people don't understand this > when writing tests, and inadvertently write tests that depend on each > other. I've worked with those systems. They're a bear to debug. > You've got some test suite that runs for 15 minutes and dies at case 37 > of 43. If you try to run case 37 by itself, it won't run, and you can't > figure out what state cases 1-36 were supposed to leave the system in to > make 37 work. You could sink days or weeks into debugging this kind of > crap. BTDT. I'm sorry to hear that, debugging other peoples' feces is never a task to wish for. That said, there are two kinds of dependencies and in at least this discussion there hasn't been any mentioning of the differences yet, but those differences are important. Your unfortunate case is where test X creates persistent state that must be present in order for test X+1 to produce meaningful results. This kind of dependency obviously blows, as it means you can't debug test X+1 separately. I'd call this operational dependency. This kind of dependency is IMHO a bug in the tests themselves. The unit testing framework could help you find those bugs by allowing random order of execution for the test cases. There is another dependency and that I'd call a logical dependency. This occurs when e.g. test X tests for an API presence and test Y tests the API behaviour. In other words, Y has no chance to succeed if X already failed. Unfortunately, there is no way to express this relation, there is no "@unittest.depends(test_X)" to decorate test_Y with (Not yet!). Each test would be the root of a tree of tests that it depends on. If a dependency fails already, you can either skip the tree or at least mark the following test failures as implicit failures, so that you can easily distinguish them from the root cause. This kind of dependency is quite normal although not directly supported by the unittest module. As a workaround, being able to define an order allows you to move the dependencies further to the top, so they are tested first. To sum it up, in order to catch operational dependencies, you need a random order while in order to clearly express logical dependencies in the output, you want a fixed order. Neither is the one true way, though my gut feeling is that the fixed order is overall more useful. > As long as they understand the consequences of their actions, don't > try to preach unittest religion to them. They're in the best > position to know if what they're trying to do is the best thing for > their particular situation. Amen! Uli From ian.g.kelly at gmail.com Mon Jan 9 12:30:19 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 9 Jan 2012 10:30:19 -0700 Subject: replacing __dict__ with an OrderedDict In-Reply-To: <11jrt8-l32.ln1@satorlaser.homedns.org> References: <11jrt8-l32.ln1@satorlaser.homedns.org> Message-ID: On Mon, Jan 9, 2012 at 9:59 AM, Ulrich Eckhardt wrote: > There is another dependency and that I'd call a logical dependency. This > occurs when e.g. test X tests for an API presence and test Y tests the API > behaviour. In other words, Y has no chance to succeed if X already failed. > Unfortunately, there is no way to express this relation, there is no > "@unittest.depends(test_X)" to decorate test_Y with (Not yet!). Each test > would be the root of a tree of tests that it depends on. If a dependency > fails already, you can either skip the tree or at least mark the following > test failures as implicit failures, so that you can easily distinguish them > from the root cause. I can see where that could be useful. On the other hand, if such a decorator were included in unittest, I can already envision people abusing it to explicitly enshrine their operational dependencies, maybe even taking it as encouragement to write their tests in that fashion. From nikos.kouras at gmail.com Mon Jan 9 17:19:04 2012 From: nikos.kouras at gmail.com (=?UTF-8?B?zp3Ouc66z4zOu86xzr/PgiDOms6/z43Pgc6xz4I=?=) Date: Mon, 9 Jan 2012 14:19:04 -0800 (PST) Subject: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error References: <24123dfe-b2fc-4f4c-8dfe-23bfef19b205@m10g2000vbc.googlegroups.com> Message-ID: Can you please explain me what the [0] in host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] does at the end? Why not just host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] ) instead? what is the need of [0] ? From dbinks at codeaurora.org Mon Jan 9 17:35:42 2012 From: dbinks at codeaurora.org (Dominic Binks) Date: Mon, 09 Jan 2012 14:35:42 -0800 Subject: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error In-Reply-To: References: <24123dfe-b2fc-4f4c-8dfe-23bfef19b205@m10g2000vbc.googlegroups.com> Message-ID: <4F0B6BBE.5090501@codeaurora.org> On 1/9/2012 2:19 PM, ???????? ?????? wrote: > Can you please explain me what the [0] in host = > socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] does at the end? > > Why not just host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] ) > instead? what is the need of [0] ? The address database can have multiple names for the same IP address so gethostbyaddr returns a list - [0] being the first item in the list (and usually considered the canonical name) -- Dominic Binks: dbinks at codeaurora.org Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum From david.garvey at gmail.com Mon Jan 9 17:51:24 2012 From: david.garvey at gmail.com (david.garvey at gmail.com) Date: Mon, 9 Jan 2012 14:51:24 -0800 Subject: classes and __iter__ Message-ID: Hello, I have a class and i return both a key list and dictionary from the class. Is it good form to do this? The print helo.__dict__ shows both the list and dictionary. >>> class Parse_Nagios_Header: ... def __init__(self): ... self.keylist = [] ... self.d = {} ... f = open("common.h") ... lines = f.readlines() ... lines = filter(lambda x: not x.isspace(), lines) ... f.close() ... for line in lines: ... if re.search("CMD", line): ... line = line.lstrip('#define ') ... line = line.strip() ... line.replace('\t', ' ') ... line = line.split() ... if len(line) > 2: ... pass ... elif len(line) == 2: ... line[1] = int(line[1]) ... self.d[line[1]] = line[0] ... self.keylist = sorted(self.d.iterkeys()) ... def __iter__(self): ... return iter(self.keylist, self.d) ... >>> helo = Parse_Nagios_Header() >>> print helo <__main__.Parse_Nagios_Header instance at 0x7fbf5b09b488> >>> for key in helo.keylist: ... print "Key:%s Value:%s" %(key,helo.d[key]) ... Key:0 Value:CMD_NONE Key:1 Value:CMD_ADD_HOST_COMMENT Key:2 Value:CMD_DEL_HOST_COMMENT Key:3 Value:CMD_ADD_SVC_COMMENT Key:4 Value:CMD_DEL_SVC_COMMENT Key:5 Value:CMD_ENABLE_SVC_CHECK -- David Garvey -------------- next part -------------- An HTML attachment was scrubbed... URL: From nikos.kouras at gmail.com Mon Jan 9 18:04:12 2012 From: nikos.kouras at gmail.com (=?UTF-8?B?zp3Ouc66z4zOu86xzr/PgiDOms6/z43Pgc6xz4I=?=) Date: Mon, 9 Jan 2012 15:04:12 -0800 (PST) Subject: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error References: <24123dfe-b2fc-4f4c-8dfe-23bfef19b205@m10g2000vbc.googlegroups.com> Message-ID: <1e0e10e9-263f-4fde-8cdd-ece561c2c5fd@w4g2000vbc.googlegroups.com> On 10 ???, 00:35, Dominic Binks wrote: > On 1/9/2012 2:19 PM, ???????? ?????? wrote: > > > Can you please explain me what the [0] in host = > > socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] does at the end? > > > Why not just host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] ) > > instead? what is the need of [0] ? > > The address database can have multiple names for the same IP address so > gethostbyaddr returns a list - [0] being the first item in the list (and > usually considered the canonical name) Thank you! From rosuav at gmail.com Mon Jan 9 18:14:25 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Jan 2012 10:14:25 +1100 Subject: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error In-Reply-To: <4F0B6BBE.5090501@codeaurora.org> References: <24123dfe-b2fc-4f4c-8dfe-23bfef19b205@m10g2000vbc.googlegroups.com> <4F0B6BBE.5090501@codeaurora.org> Message-ID: On Tue, Jan 10, 2012 at 9:35 AM, Dominic Binks wrote: > The address database can have multiple names for the same IP address so > gethostbyaddr returns a list - [0] being the first item in the list (and > usually considered the canonical name) Point to note: The inverse operation, getting IP addresses from names, quite frequently returns multiple results - and in that case, there's no "canonical name". You'll still usually want to take the zeroth (first) item in the list, but often the list will change in order. Try, for instance: $ dig +short www.google.com which uses DNS rotation as a form of load-balancing. In any case, you normally just take the first entry. ChrisA From clp2 at rebertia.com Mon Jan 9 18:17:48 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 9 Jan 2012 15:17:48 -0800 Subject: classes and __iter__ In-Reply-To: References: Message-ID: On Mon, Jan 9, 2012 at 2:51 PM, david.garvey at gmail.com wrote: >>>> class Parse_Nagios_Header: > ...???? def __init__(self): > ...???????? self.keylist = [] > ...???????? self.d = {} > ...???? def __iter__(self): > ...???????? return iter(self.keylist, self.d) No idea what you're expecting this __iter__() to do, but it doesn't work at all. Relevant docs: http://docs.python.org/library/functions.html#iter http://docs.python.org/reference/datamodel.html#object.__iter__ Cheers, Chris From ian.g.kelly at gmail.com Mon Jan 9 18:20:32 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 9 Jan 2012 16:20:32 -0700 Subject: classes and __iter__ In-Reply-To: References: Message-ID: On Mon, Jan 9, 2012 at 3:51 PM, david.garvey at gmail.com wrote: > ...???? def __iter__(self): > ...???????? return iter(self.keylist, self.d) This method is incorrect. The 2-argument form of iter() is very different from the 1-argument form. Whereas the 1-argument form takes an iterable, the 2-argument form takes a callable and a sentinel value. In that case, iter() attempts to call the callable until the sentinel is returned. In your code, it would attempt to call the keylist (which would fail with a TypeError) until it returned the dictionary as a result. This would be more in line with what you're trying to do: def __iter__(self): for key in self.keylist: yield key, self.d[key] >>>> for key in helo.keylist: > ...???? print "Key:%s Value:%s" %(key,helo.d[key]) Note that this works because you're not actually using the class's __iter__ method here. You're iterating over the keylist directly, not over the containing class instance. From nikos.kouras at gmail.com Mon Jan 9 18:23:22 2012 From: nikos.kouras at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Mon, 9 Jan 2012 15:23:22 -0800 (PST) Subject: Explanation about for Message-ID: ================================ dataset = cursor.fetchall() for row in dataset: print ( "" ) for item in row: print ( " %s " % item ) ================================ and this: ================================ dataset = cursor.fetchall() for host, hits, agent, date in dataset: print ( "" ) for item in host, hits, agent, date: print ( " %s " % item ) ================================ Can you please explain me how the for structure works here? a) In the 1st example we have 'for row in dataset' what is the value of 'row' at that time? What part of 'dataset' is 'row'? b) In the 2nd example we have for 'host, hits, agent, date in dataset'. How does these 4 variables take their values out of dataset? How dataset is being splitted? Please explain to me if you like as simple as you can Thank you. From david.garvey at gmail.com Mon Jan 9 18:30:24 2012 From: david.garvey at gmail.com (david.garvey at gmail.com) Date: Mon, 9 Jan 2012 15:30:24 -0800 Subject: classes and __iter__ In-Reply-To: References: Message-ID: Chris, Both a list and dict are both iterable. I get a python dictionary object of both iterables.;) It is nice... but I don't know if this is good form? Should I be asking the duck question here? >>> print helo.__dict__ {'keylist': [0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 999], 'd': {0: 'CMD_NONE', 1: 'CMD_ADD_HOST_COMMENT', 2: 'CMD_DEL_HOST_COMMENT', 3: 'CMD_ADD_SVC_COMMENT', 4: 'CMD_DEL_SVC_COMMENT', 5: 'CMD_ENABLE_SVC_CHECK', 6: 'CMD_DISABLE_SVC_CHECK', 7: 'CMD_SCHEDULE_SVC_CHECK', 9: 'CMD_DELAY_SVC_NOTIFICATION', 10: 'CMD_DELAY_HOST_NOTIFICATION', 11: 'CMD_DISABLE_NOTIFICATIONS', 12: 'CMD_ENABLE_NOTIFICATIONS', 13: 'CMD_RESTART_PROCESS', 14: 'CMD_SHUTDOWN_PROCESS', 15: 'CMD_ENABLE_HOST_SVC_CHECKS', 16: 'CMD_DISABLE_HOST_SVC_CHECKS', 17: 'CMD_SCHEDULE_HOST_SVC_CHECKS', 20: 'CMD_DEL_ALL_HOST_COMMENTS', 21: 'CMD_DEL_ALL_SVC_COMMENTS', 22: 'CMD_ENABLE_SVC_NOTIFICATIONS', 23: 'CMD_DISABLE_SVC_NOTIFICATIONS', 24: 'CMD_ENABLE_HOST_NOTIFICATIONS', 25: 'CMD_DISABLE_HOST_NOTIFICATIONS', 26: 'CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST', 27: 'CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST', 28: 'CMD_ENABLE_HOST_SVC_NOTIFICATIONS', 29: 'CMD_DISABLE_HOST_SVC_NOTIFICATIONS', 30: 'CMD_PROCESS_SERVICE_CHECK_RESULT', 31: 'CMD_SAVE_STATE_INFORMATION', 32: 'CMD_READ_STATE_INFORMATION', 33: 'CMD_ACKNOWLEDGE_HOST_PROBLEM', 34: 'CMD_ACKNOWLEDGE_SVC_PROBLEM', 35: 'CMD_START_EXECUTING_SVC_CHECKS', 36: 'CMD_STOP_EXECUTING_SVC_CHECKS', 37: 'CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS', 38: 'CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS', 39: 'CMD_ENABLE_PASSIVE_SVC_CHECKS', 40: 'CMD_DISABLE_PASSIVE_SVC_CHECKS', 41: 'CMD_ENABLE_EVENT_HANDLERS', 42: 'CMD_DISABLE_EVENT_HANDLERS', 43: 'CMD_ENABLE_HOST_EVENT_HANDLER', 44: 'CMD_DISABLE_HOST_EVENT_HANDLER', 45: 'CMD_ENABLE_SVC_EVENT_HANDLER', 46: 'CMD_DISABLE_SVC_EVENT_HANDLER', 47: 'CMD_ENABLE_HOST_CHECK', 48: 'CMD_DISABLE_HOST_CHECK', 49: 'CMD_START_OBSESSING_OVER_SVC_CHECKS', 50: 'CMD_STOP_OBSESSING_OVER_SVC_CHECKS', 51: 'CMD_REMOVE_HOST_ACKNOWLEDGEMENT', 52: 'CMD_REMOVE_SVC_ACKNOWLEDGEMENT', 53: 'CMD_SCHEDULE_FORCED_HOST_SVC_CHECKS', 54: 'CMD_SCHEDULE_FORCED_SVC_CHECK', 55: 'CMD_SCHEDULE_HOST_DOWNTIME', 56: 'CMD_SCHEDULE_SVC_DOWNTIME', 57: 'CMD_ENABLE_HOST_FLAP_DETECTION', 58: 'CMD_DISABLE_HOST_FLAP_DETECTION', 59: 'CMD_ENABLE_SVC_FLAP_DETECTION', 60: 'CMD_DISABLE_SVC_FLAP_DETECTION', 61: 'CMD_ENABLE_FLAP_DETECTION', 62: 'CMD_DISABLE_FLAP_DETECTION', 63: 'CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS', 64: 'CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS', 65: 'CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS', 66: 'CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS', 67: 'CMD_ENABLE_HOSTGROUP_SVC_CHECKS', 68: 'CMD_DISABLE_HOSTGROUP_SVC_CHECKS', 77: 'CMD_FLUSH_PENDING_COMMANDS', 78: 'CMD_DEL_HOST_DOWNTIME', 79: 'CMD_DEL_SVC_DOWNTIME', 80: 'CMD_ENABLE_FAILURE_PREDICTION', 81: 'CMD_DISABLE_FAILURE_PREDICTION', 82: 'CMD_ENABLE_PERFORMANCE_DATA', 83: 'CMD_DISABLE_PERFORMANCE_DATA', 84: 'CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME', 85: 'CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME', 86: 'CMD_SCHEDULE_HOST_SVC_DOWNTIME', 87: 'CMD_PROCESS_HOST_CHECK_RESULT', 88: 'CMD_START_EXECUTING_HOST_CHECKS', 89: 'CMD_STOP_EXECUTING_HOST_CHECKS', 90: 'CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS', 91: 'CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS', 92: 'CMD_ENABLE_PASSIVE_HOST_CHECKS', 93: 'CMD_DISABLE_PASSIVE_HOST_CHECKS', 94: 'CMD_START_OBSESSING_OVER_HOST_CHECKS', 95: 'CMD_STOP_OBSESSING_OVER_HOST_CHECKS', 96: 'CMD_SCHEDULE_HOST_CHECK', 98: 'CMD_SCHEDULE_FORCED_HOST_CHECK', 99: 'CMD_START_OBSESSING_OVER_SVC', 100: 'CMD_STOP_OBSESSING_OVER_SVC', 101: 'CMD_START_OBSESSING_OVER_HOST', 102: 'CMD_STOP_OBSESSING_OVER_HOST', 103: 'CMD_ENABLE_HOSTGROUP_HOST_CHECKS', 104: 'CMD_DISABLE_HOSTGROUP_HOST_CHECKS', 105: 'CMD_ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS', 106: 'CMD_DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS', 107: 'CMD_ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS', 108: 'CMD_DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS', 109: 'CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS', 110: 'CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS', 111: 'CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS', 112: 'CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS', 113: 'CMD_ENABLE_SERVICEGROUP_SVC_CHECKS', 114: 'CMD_DISABLE_SERVICEGROUP_SVC_CHECKS', 115: 'CMD_ENABLE_SERVICEGROUP_HOST_CHECKS', 116: 'CMD_DISABLE_SERVICEGROUP_HOST_CHECKS', 117: 'CMD_ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS', 118: 'CMD_DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS', 119: 'CMD_ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS', 120: 'CMD_DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS', 121: 'CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME', 122: 'CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME', 123: 'CMD_CHANGE_GLOBAL_HOST_EVENT_HANDLER', 124: 'CMD_CHANGE_GLOBAL_SVC_EVENT_HANDLER', 125: 'CMD_CHANGE_HOST_EVENT_HANDLER', 126: 'CMD_CHANGE_SVC_EVENT_HANDLER', 127: 'CMD_CHANGE_HOST_CHECK_COMMAND', 128: 'CMD_CHANGE_SVC_CHECK_COMMAND', 129: 'CMD_CHANGE_NORMAL_HOST_CHECK_INTERVAL', 130: 'CMD_CHANGE_NORMAL_SVC_CHECK_INTERVAL', 131: 'CMD_CHANGE_RETRY_SVC_CHECK_INTERVAL', 132: 'CMD_CHANGE_MAX_HOST_CHECK_ATTEMPTS', 133: 'CMD_CHANGE_MAX_SVC_CHECK_ATTEMPTS', 134: 'CMD_SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME', 135: 'CMD_ENABLE_HOST_AND_CHILD_NOTIFICATIONS', 136: 'CMD_DISABLE_HOST_AND_CHILD_NOTIFICATIONS', 137: 'CMD_SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME', 138: 'CMD_ENABLE_SERVICE_FRESHNESS_CHECKS', 139: 'CMD_DISABLE_SERVICE_FRESHNESS_CHECKS', 140: 'CMD_ENABLE_HOST_FRESHNESS_CHECKS', 141: 'CMD_DISABLE_HOST_FRESHNESS_CHECKS', 142: 'CMD_SET_HOST_NOTIFICATION_NUMBER', 143: 'CMD_SET_SVC_NOTIFICATION_NUMBER', 144: 'CMD_CHANGE_HOST_CHECK_TIMEPERIOD', 145: 'CMD_CHANGE_SVC_CHECK_TIMEPERIOD', 146: 'CMD_PROCESS_FILE', 147: 'CMD_CHANGE_CUSTOM_HOST_VAR', 148: 'CMD_CHANGE_CUSTOM_SVC_VAR', 149: 'CMD_CHANGE_CUSTOM_CONTACT_VAR', 150: 'CMD_ENABLE_CONTACT_HOST_NOTIFICATIONS', 151: 'CMD_DISABLE_CONTACT_HOST_NOTIFICATIONS', 152: 'CMD_ENABLE_CONTACT_SVC_NOTIFICATIONS', 153: 'CMD_DISABLE_CONTACT_SVC_NOTIFICATIONS', 154: 'CMD_ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS', 155: 'CMD_DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS', 156: 'CMD_ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS', 157: 'CMD_DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS', 158: 'CMD_CHANGE_RETRY_HOST_CHECK_INTERVAL', 159: 'CMD_SEND_CUSTOM_HOST_NOTIFICATION', 160: 'CMD_SEND_CUSTOM_SVC_NOTIFICATION', 161: 'CMD_CHANGE_HOST_NOTIFICATION_TIMEPERIOD', 162: 'CMD_CHANGE_SVC_NOTIFICATION_TIMEPERIOD', 163: 'CMD_CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD', 164: 'CMD_CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD', 165: 'CMD_CHANGE_HOST_MODATTR', 166: 'CMD_CHANGE_SVC_MODATTR', 167: 'CMD_CHANGE_CONTACT_MODATTR', 168: 'CMD_CHANGE_CONTACT_MODHATTR', 169: 'CMD_CHANGE_CONTACT_MODSATTR', 170: 'CMD_DEL_DOWNTIME_BY_HOST_NAME', 171: 'CMD_DEL_DOWNTIME_BY_HOSTGROUP_NAME', 172: 'CMD_DEL_DOWNTIME_BY_START_TIME_COMMENT', 999: 'CMD_CUSTOM_COMMAND'}} On Mon, Jan 9, 2012 at 3:17 PM, Chris Rebert wrote: > On Mon, Jan 9, 2012 at 2:51 PM, david.garvey at gmail.com > wrote: > > >>>> class Parse_Nagios_Header: > > ... def __init__(self): > > ... self.keylist = [] > > ... self.d = {} > > > ... def __iter__(self): > > ... return iter(self.keylist, self.d) > > No idea what you're expecting this __iter__() to do, but it doesn't work > at all. > Relevant docs: > http://docs.python.org/library/functions.html#iter > http://docs.python.org/reference/datamodel.html#object.__iter__ > > Cheers, > Chris > -- David Garvey -------------- next part -------------- An HTML attachment was scrubbed... URL: From nicholas.dokos at hp.com Mon Jan 9 18:32:44 2012 From: nicholas.dokos at hp.com (Nick Dokos) Date: Mon, 09 Jan 2012 18:32:44 -0500 Subject: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error In-Reply-To: References: <24123dfe-b2fc-4f4c-8dfe-23bfef19b205@m10g2000vbc.googlegroups.com> <4F0B6BBE.5090501@codeaurora.org> Message-ID: <31290.1326151964@lefou.usa.hp.com> Chris Angelico wrote: > On Tue, Jan 10, 2012 at 9:35 AM, Dominic Binks wrote: > > The address database can have multiple names for the same IP address so > > gethostbyaddr returns a list - [0] being the first item in the list (and > > usually considered the canonical name) > > Point to note: The inverse operation, getting IP addresses from names, > quite frequently returns multiple results - and in that case, there's > no "canonical name". You'll still usually want to take the zeroth > (first) item in the list, but often the list will change in order. > Try, for instance: > > $ dig +short www.google.com > > which uses DNS rotation as a form of load-balancing. > > In any case, you normally just take the first entry. > On both 2.6.6 and 2.7.1, the doc says: ,---- | >>> help(socket.gethostbyaddr) | Help on built-in function gethostbyaddr in module _socket: | | gethostbyaddr(...) | gethostbyaddr(host) -> (name, aliaslist, addresslist) | | Return the true host name, a list of aliases, and a list of IP addresses, | for a host. The host argument is a string giving a host name or IP number. `---- so socket.gethostbyaddr(os.environ['REMOTE_ADDR'])[0] is the 0th element of the tuple, i.e. the *name* that is returned. So (unless I'm confused which is always a distinct possibility) this has nothing to do with load-balancing or multiple addresses: it's the equivalent of dig +short -x Nick From ian.g.kelly at gmail.com Mon Jan 9 18:42:22 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 9 Jan 2012 16:42:22 -0700 Subject: Explanation about for In-Reply-To: References: Message-ID: 2012/1/9 ???????? ?????? : > ================================ > dataset = cursor.fetchall() > > for row in dataset: > ? ?print ( "" ) > > ? ?for item in row: > ? ? ? ?print ( " %s " % item ) > ================================ > > and this: > > ================================ > dataset = cursor.fetchall() > > for host, hits, agent, date in dataset: > ? ?print ( "" ) > > ? ?for item in host, hits, agent, date: > ? ? ? ?print ( " %s " % item ) > ================================ > > > Can you please explain me how the for structure works here? You should probably read through the Python tutorial or a Python book for the basics of Python for loops. > a) In the 1st example we have 'for row in dataset' what is the value > of 'row' at that time? What part of 'dataset' is 'row'? dataset is an iterable object, which means that Python can ask it for an iterator and then use that iterator to "loop" through the dataset in some fashion. In this case, 'dataset' is a database cursor, and the values returned by the iterator are the rows that were selected by the query that executed, represented as tuples. 'row' takes on the value of each of those tuples, one at a time. > b) In the 2nd example we have for 'host, hits, agent, date in > dataset'. How does these 4 variables take their values out of dataset? > How dataset is being splitted? The second example works the same way as the first, except that instead of storing each row tuple in a single variable called row, it unpacks each tuple into four different variables named 'host', 'hits', 'agent', and 'date'. These represent the values of the selected columns from the query, for each selected row. HTH, Ian From ian.g.kelly at gmail.com Mon Jan 9 18:55:38 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 9 Jan 2012 16:55:38 -0700 Subject: classes and __iter__ In-Reply-To: References: Message-ID: On Mon, Jan 9, 2012 at 4:30 PM, david.garvey at gmail.com wrote: > Chris, > > Both a list and dict are both iterable.? I get a python dictionary object of > both iterables.;) It is nice... but I don't know if this is good form? > Should I be asking the duck question here? >>>> print helo.__dict__ [SNIP] I think you're confused, which is probably why your question is so confusing. helo.__dict__ has nothing to do with iterables or the __iter__ method of your class. This is just the instance dictionary of the "helo" object, which contains all the attributes stored on that object. I'm still not sure exactly what it is that you're asking whether it is "good form"? I also don't know what the "duck question" is -- I presume you're referring to duck typing ("Does it quack like a duck?"), but I don't see how that is relevant to the code you posted. Cheers, Ian From clp2 at rebertia.com Mon Jan 9 18:58:41 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 9 Jan 2012 15:58:41 -0800 Subject: Explanation about for In-Reply-To: References: Message-ID: On Mon, Jan 9, 2012 at 3:23 PM, ???????? ?????? wrote: > ================================ > dataset = cursor.fetchall() > > for row in dataset: > ? ?print ( "" ) > > ? ?for item in row: > ? ? ? ?print ( " %s " % item ) > ================================ > > and this: > Your second snippet makes use of Python's iterable/sequence/tuple-unpacking feature. Here's the relevant part of the Language Reference: http://docs.python.org/reference/simple_stmts.html#assignment-statements By way of example, given: seq = [1,2,3,4] Then: w, x, y, z = seq Results in: w = 1 x = 2 y = 3 z = 4 `seq` has been "unpacked", and its elements have been assigned to variables (namely: `w`, `x`, `y`, and `z`). If the number of variables doesn't match the number of elements, Python will raise an exception. > ================================ > dataset = cursor.fetchall() > > for host, hits, agent, date in dataset: for-loops perform repeated assignments to the loop variable(s), and, like with the simple assignment statement example I gave, also permit the use of unpacking in such assignments. To make the unpacking more explicit, the loop can be equivalently rewritten as: for _row in dataset: host, hits, agent, date = _row # rest same as before... > ? ?print ( "" ) > > ? ?for item in host, hits, agent, date: Python's syntax for tuples is based solely on commas and does not require parentheses, though a tuple's repr() always includes the parentheses and programmers often/typically do too. (See http://docs.python.org/tutorial/datastructures.html#tuples-and-sequences .) For example: x = 1, 2 And: x = (1, 2) Both do exactly the same thing: set `x` to a tuple of length 2 containing the elements 1 and 2. The loop thus might be more clearly written as: for item in (host, hits, agent, date): So, what's happening is that Python is iterating over the elements of an anonymous literal tuple; `item` will thus take on the values of `host`, `hits`, `agent`, and `date`, in turn. > ? ? ? ?print ( " %s " % item ) > ================================ Cheers, Chris -- http://rebertia.com From clp2 at rebertia.com Mon Jan 9 19:15:17 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 9 Jan 2012 16:15:17 -0800 Subject: classes and __iter__ In-Reply-To: References: Message-ID: On Mon, Jan 9, 2012 at 3:30 PM, david.garvey at gmail.com wrote: > Chris, > > Both a list and dict are both iterable.? I get a python dictionary object of > both iterables.;) No, you get a Python object with both iterables as instance variables. Instance variables happen to be stored using a dict (which is accessible as .__dict__), but that's to some extent an implementation detail whose relevance here I fail to see. My point was that, as Ian explained, your __iter__() method, as written, is horribly broken. > It is nice... but I don't know if this is good form? I'm confused as to why you wrote a class (particularly when its name is an *action* rather than a noun; big red flag right there!) for your task in the first place. I think you'd be best served by moving your parsing code into a function and using a http://pypi.python.org/pypi/sorteddict , which provides the sorted-keys property you seemed to be trying to accomplish. Also, please avoid top-posting in the future. (See http://en.wikipedia.org/wiki/Posting_style ) Cheers, Chris -- http://rebertia.com From phihag at phihag.de Mon Jan 9 19:41:04 2012 From: phihag at phihag.de (Philipp Hagemeister) Date: Tue, 10 Jan 2012 01:41:04 +0100 Subject: codecs in a chroot / without fs access Message-ID: <4F0B8920.1090400@phihag.de> I want to forbid my application to access the filesystem. The easiest way seems to be chrooting and droping privileges. However, surprisingly, python loads the codecs from the filesystem on-demand, which makes my program crash: >>> import os >>> os.getuid() 0 >>> os.chroot('/tmp') >>> ''.decode('raw-unicode-escape') Traceback (most recent call last): File "", line 1, in (Interestingly, Python goes looking for the literal file "" in sys.path. Wonder what happens if I touch /usr/lib/python2.7/dist-packages/). Is there a neat way to solve this problem, i.e. have access to all codecs in a chroot? If not, I'd love to have a function codecs.preload_all() that does what my workaround does: import codecs,glob,os.path encs = [os.path.splitext(os.path.basename(f))[0] for f in glob.glob('/usr/lib/python*/encodings/*.py')] for e in encs: try: codecs.lookup(e) except LookupError: pass # __init__.py or something enumerate /usr/lib/python.*/encodings/*.py and call codecs.lookup for every os.path.splitext(os.path.basename(filename))[0] Dou you see any problem with this design? - Philipp -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: OpenPGP digital signature URL: From nikos.kouras at gmail.com Mon Jan 9 19:51:07 2012 From: nikos.kouras at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Tue, 10 Jan 2012 02:51:07 +0200 Subject: Explanation about for In-Reply-To: References: Message-ID: ???? 10 ?????????? 2012 1:42 ?.?., ? ??????? Ian Kelly < ian.g.kelly at gmail.com> ??????: > > > b) In the 2nd example we have for 'host, hits, agent, date in > > dataset'. How does these 4 variables take their values out of dataset? > > How dataset is being splitted? > > The second example works the same way as the first, except that > instead of storing each row tuple in a single variable called row, it > unpacks each tuple into four different variables named 'host', 'hits', > 'agent', and 'date'. These represent the values of the selected > columns from the query, for each selected row. > > if the MySQL query was: cursor.execute( '''SELECT host, hits, agent, date FROM visitors WHERE pin = %s ORDER BY date DESC''', pin ) can you help me imagine how the mysql database cursor that holds the query results would look like? I must somehow visualize it in order to understand it! Also what happend if the query was: cursor.execute( '''SELECT host FROM visitors") ? the result would have to be something likelike? ----------------- |somehost1| ----------------- |somehost2| ----------------- |somehost3| ----------------- ..................... ..................... |somehost n| ----------------- So what values host, hits, agent, date would have in 'for host, hits, agent, date in dataset' ? Every row has one string how can that be split in 4? Excuse my english. -------------- next part -------------- An HTML attachment was scrubbed... URL: From david.garvey at gmail.com Mon Jan 9 19:57:03 2012 From: david.garvey at gmail.com (david.garvey at gmail.com) Date: Mon, 9 Jan 2012 16:57:03 -0800 Subject: classes and __iter__ In-Reply-To: References: Message-ID: Thanks Ian & Chris for the conversation... On Mon, Jan 9, 2012 at 4:15 PM, Chris Rebert wrote: > On Mon, Jan 9, 2012 at 3:30 PM, david.garvey at gmail.com > wrote: > > Chris, > > > > Both a list and dict are both iterable. I get a python dictionary > object of > > both iterables.;) > > No, you get a Python object with both iterables as instance variables. > Instance variables happen to be stored using a dict (which is > accessible as .__dict__), but that's to some extent an implementation > detail whose relevance here I fail to see. My point was that, as Ian > explained, your __iter__() method, as written, is horribly broken. > > > It is nice... but I don't know if this is good form? > > I'm confused as to why you wrote a class (particularly when its name > is an *action* rather than a noun; big red flag right there!) for your > task in the first place. I think you'd be best served by moving your > parsing code into a function and using a > http://pypi.python.org/pypi/sorteddict , which provides the > sorted-keys property you seemed to be trying to accomplish. > > Also, please avoid top-posting in the future. (See > http://en.wikipedia.org/wiki/Posting_style ) > > Cheers, > Chris > -- > http://rebertia.com > -- David Garvey -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Mon Jan 9 20:05:50 2012 From: roy at panix.com (Roy Smith) Date: Mon, 09 Jan 2012 20:05:50 -0500 Subject: replacing __dict__ with an OrderedDict References: <11jrt8-l32.ln1@satorlaser.homedns.org> Message-ID: In article <11jrt8-l32.ln1 at satorlaser.homedns.org>, Ulrich Eckhardt wrote: > > Some people advocate that the test framework should > > intentionally randomize the order, to flush out inter-test dependencies > > that the author didn't realize existed (or intend). > > If you now > happen to influence one test with another and the next run randomizes > the tests differently, you will never see the fault again. Without this > reproducability, you don't gain anything but the bad stomach feeling > that something is wrong. The standard solution to that is to print out the PRNG initialization state and provide a way in your test harness to re-initialize it to that state. I've done things like that in test scenarios where it is difficult or impossible to cover the problem space deterministically. > Your unfortunate case is where test X creates persistent state that must > be present in order for test X+1 to produce meaningful results. This > kind of dependency obviously blows, as it means you can't debug test X+1 > separately. I'd call this operational dependency. > > This kind of dependency is IMHO a bug in the tests themselves. For the most part, I'm inclined to agree. However, there are scenarios where having each test build the required state from scratch is prohibitively expensive. Imagine if you worked at NASA wanted to run test_booster_ignition(), test_booster_cutoff(), test_second_stage_ignition(), and test_self_destruct(). I suppose you could run them in random order, but you'd use up a lot of rockets that way. Somewhat more seriously, let's say you wanted to do test queries against a database with 100 million records in it. You could rebuild the database from scratch for each test, but doing so might take hours per test. Sometimes, real life is just *so* inconvenient. > There is another dependency and that I'd call a logical dependency. This > occurs when e.g. test X tests for an API presence and test Y tests the > API behaviour. In other words, Y has no chance to succeed if X already > failed. Sure. I run into that all the time. A trivial example would be the project I'm working on now. I've come to realize that a long unbroken string of E's means, "Dummy, you forgot to bring the application server up before you ran the tests". It would be nicer if the test suite could have run a single test which proved it could create a TCP connection and when that failed, just stop. From python at mrabarnett.plus.com Mon Jan 9 20:08:03 2012 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 10 Jan 2012 01:08:03 +0000 Subject: classes and __iter__ In-Reply-To: References: Message-ID: <4F0B8F73.4090108@mrabarnett.plus.com> On 09/01/2012 22:51, david.garvey at gmail.com wrote: > Hello, > > I have a class and i return both a key list and dictionary from the > class. Is it good form to do this? The print helo.__dict__ shows both > the list and dictionary. > > > > >>> class Parse_Nagios_Header: > ... def __init__(self): > ... self.keylist = [] > ... self.d = {} > ... f = open("common.h") > ... lines = f.readlines() > ... lines = filter(lambda x: not x.isspace(), lines) > ... f.close() > ... for line in lines: > ... if re.search("CMD", line): You don't need to use a regex for this. It's better to do this instead: if "CMD" in line: > ... line = line.lstrip('#define ') The .lstrip, .rstrip and .strip methods treat the argument as a _set_ of characters, so that line will strip the characters '#', 'd', 'e', 'f, 'i', 'n' and ' ' from the left end of the line however many times they occur. > ... line = line.strip() > ... line.replace('\t', ' ') > ... line = line.split() The .split method, when called without an argument (or an argument of None), will split on a sequence of whitespace characters, but ignore leading and trailing whitespace. Therefore, there is no need to use the .strip method or the .replace (which will have no effect anyway because it _returns_ its result, which is then discarded) before the split. > ... if len(line) > 2: > ... pass The preceding two lines are pointless. Just turn the next line into an 'if'; it'll have the same effect. > ... elif len(line) == 2: > ... line[1] = int(line[1]) > ... self.d[line[1]] = line[0] > ... self.keylist = sorted(self.d.iterkeys()) > ... def __iter__(self): > ... return iter(self.keylist, self.d) > ... [snip] From ian.g.kelly at gmail.com Mon Jan 9 20:11:32 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 9 Jan 2012 18:11:32 -0700 Subject: Explanation about for In-Reply-To: References: Message-ID: 2012/1/9 ???????? ?????? : > if the MySQL query was: > > cursor.execute( '''SELECT host, hits, agent, date FROM visitors WHERE pin = > %s ORDER BY date DESC''', pin ) > > can you help me imagine how the mysql database cursor that holds the query > results would look like? I must somehow visualize it in order to understand > it! You can think of it as a pointer, traversing over one row of the result set at a time. Hopefully this will come out legibly: ----------------------------------------------- | HOST | HITS | AGENT | DATE | ----------------------------------------------- ------------- | foo | 7 | IE6 | 1/1/11 | <---- | cursor | ----------------------------------------------- ------------- | bar | 42 | Firefox | 2/2/10 | ----------------------------------------------- | baz | 4 | Chrome | 3/3/09 | ------------------------------------------------ > Also what happend if the query was: > cursor.execute( '''SELECT host FROM visitors") ? > > the result would have to be something likelike? > > ----------------- > |somehost1| > ----------------- > |somehost2| > ----------------- > |somehost3| > ----------------- > ..................... > ..................... > |somehost n| > ----------------- > > So what values?host, hits, agent, date would have in 'for?host, hits, agent, > date in > ?dataset' ? Every row has one string how can that be split in 4? Why don't you try it and see what happens? But to spare you the suspense, you would get: ValueError: need more than 1 value to unpack Because you can't unpack a 1-length tuple into four variables. The code assumes that the query is selecting exactly 4 columns. From david.garvey at gmail.com Mon Jan 9 20:22:05 2012 From: david.garvey at gmail.com (david.garvey at gmail.com) Date: Mon, 9 Jan 2012 17:22:05 -0800 Subject: classes and __iter__ In-Reply-To: References: Message-ID: I see your meaning for __iter__ method.;) On Mon, Jan 9, 2012 at 4:57 PM, david.garvey at gmail.com < david.garvey at gmail.com> wrote: > Thanks Ian & Chris for the conversation... > > > > > On Mon, Jan 9, 2012 at 4:15 PM, Chris Rebert wrote: > >> On Mon, Jan 9, 2012 at 3:30 PM, david.garvey at gmail.com >> wrote: >> > Chris, >> > >> > Both a list and dict are both iterable. I get a python dictionary >> object of >> > both iterables.;) >> >> No, you get a Python object with both iterables as instance variables. >> Instance variables happen to be stored using a dict (which is >> accessible as .__dict__), but that's to some extent an implementation >> detail whose relevance here I fail to see. My point was that, as Ian >> explained, your __iter__() method, as written, is horribly broken. >> >> > It is nice... but I don't know if this is good form? >> >> I'm confused as to why you wrote a class (particularly when its name >> is an *action* rather than a noun; big red flag right there!) for your >> task in the first place. I think you'd be best served by moving your >> parsing code into a function and using a >> http://pypi.python.org/pypi/sorteddict , which provides the >> sorted-keys property you seemed to be trying to accomplish. >> >> Also, please avoid top-posting in the future. (See >> http://en.wikipedia.org/wiki/Posting_style ) >> >> Cheers, >> Chris >> -- >> http://rebertia.com >> > > > > -- > David Garvey > -- David Garvey -------------- next part -------------- An HTML attachment was scrubbed... URL: From david.garvey at gmail.com Mon Jan 9 21:06:54 2012 From: david.garvey at gmail.com (david.garvey at gmail.com) Date: Mon, 9 Jan 2012 18:06:54 -0800 Subject: classes and __iter__ In-Reply-To: References: Message-ID: *Here is a good tutorial: http://shutupandship.com/articles/iterators/index.html * On Mon, Jan 9, 2012 at 5:22 PM, david.garvey at gmail.com < david.garvey at gmail.com> wrote: > I see your meaning for __iter__ method.;) > > > On Mon, Jan 9, 2012 at 4:57 PM, david.garvey at gmail.com < > david.garvey at gmail.com> wrote: > >> Thanks Ian & Chris for the conversation... >> >> >> >> >> On Mon, Jan 9, 2012 at 4:15 PM, Chris Rebert wrote: >> >>> On Mon, Jan 9, 2012 at 3:30 PM, david.garvey at gmail.com >>> wrote: >>> > Chris, >>> > >>> > Both a list and dict are both iterable. I get a python dictionary >>> object of >>> > both iterables.;) >>> >>> No, you get a Python object with both iterables as instance variables. >>> Instance variables happen to be stored using a dict (which is >>> accessible as .__dict__), but that's to some extent an implementation >>> detail whose relevance here I fail to see. My point was that, as Ian >>> explained, your __iter__() method, as written, is horribly broken. >>> >>> > It is nice... but I don't know if this is good form? >>> >>> I'm confused as to why you wrote a class (particularly when its name >>> is an *action* rather than a noun; big red flag right there!) for your >>> task in the first place. I think you'd be best served by moving your >>> parsing code into a function and using a >>> http://pypi.python.org/pypi/sorteddict , which provides the >>> sorted-keys property you seemed to be trying to accomplish. >>> >>> Also, please avoid top-posting in the future. (See >>> http://en.wikipedia.org/wiki/Posting_style ) >>> >>> Cheers, >>> Chris >>> -- >>> http://rebertia.com >>> >> >> >> >> -- >> David Garvey >> > > > > -- > David Garvey > -- David Garvey -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Jan 9 21:08:35 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Jan 2012 13:08:35 +1100 Subject: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error In-Reply-To: <31290.1326151964@lefou.usa.hp.com> References: <24123dfe-b2fc-4f4c-8dfe-23bfef19b205@m10g2000vbc.googlegroups.com> <4F0B6BBE.5090501@codeaurora.org> <31290.1326151964@lefou.usa.hp.com> Message-ID: On Tue, Jan 10, 2012 at 10:32 AM, Nick Dokos wrote: > Chris Angelico wrote: >> Point to note: The inverse operation, getting IP addresses from names, > > so socket.gethostbyaddr(os.environ['REMOTE_ADDR'])[0] is the 0th element > of the tuple, i.e. the *name* that is returned. Correct, I was drawing a noteworthy parallel with the inverse - gethostbyname. ChrisA From david.garvey at gmail.com Mon Jan 9 21:30:17 2012 From: david.garvey at gmail.com (david.garvey at gmail.com) Date: Mon, 9 Jan 2012 18:30:17 -0800 Subject: classes and __iter__ In-Reply-To: <4F0B8F73.4090108@mrabarnett.plus.com> References: <4F0B8F73.4090108@mrabarnett.plus.com> Message-ID: Many thanks mrabarnett for the code critic... On Mon, Jan 9, 2012 at 5:08 PM, MRAB wrote: > On 09/01/2012 22:51, david.garvey at gmail.com wrote: > >> Hello, >> >> I have a class and i return both a key list and dictionary from the >> class. Is it good form to do this? The print helo.__dict__ shows both >> the list and dictionary. >> >> >> >> >>> class Parse_Nagios_Header: >> ... def __init__(self): >> ... self.keylist = [] >> ... self.d = {} >> ... f = open("common.h") >> ... lines = f.readlines() >> ... lines = filter(lambda x: not x.isspace(), lines) >> ... f.close() >> ... for line in lines: >> ... if re.search("CMD", line): >> > > You don't need to use a regex for this. It's better to do this instead: > > if "CMD" in line: > > > ... line = line.lstrip('#define ') >> > > The .lstrip, .rstrip and .strip methods treat the argument as a _set_ > of characters, so that line will strip the characters '#', 'd', 'e', > 'f, 'i', 'n' and ' ' from the left end of the line however many times > they occur. > > > ... line = line.strip() >> ... line.replace('\t', ' ') >> ... line = line.split() >> > > The .split method, when called without an argument (or an argument of > None), will split on a sequence of whitespace characters, but ignore > leading and trailing whitespace. > > Therefore, there is no need to use the .strip method or the .replace > (which will have no effect anyway because it _returns_ its result, > which is then discarded) before the split. > > > ... if len(line) > 2: >> ... pass >> > > The preceding two lines are pointless. Just turn the next line into an > 'if'; it'll have the same effect. > > > ... elif len(line) == 2: >> ... line[1] = int(line[1]) >> ... self.d[line[1]] = line[0] >> ... self.keylist = sorted(self.d.iterkeys()) >> ... def __iter__(self): >> ... return iter(self.keylist, self.d) >> ... >> > [snip] > -- > http://mail.python.org/**mailman/listinfo/python-list > -- David Garvey -------------- next part -------------- An HTML attachment was scrubbed... URL: From contropinion at gmail.com Mon Jan 9 22:35:41 2012 From: contropinion at gmail.com (contro opinion) Date: Tue, 10 Jan 2012 11:35:41 +0800 Subject: function problem Message-ID: code1: def FirstDeco(func): print 'haha' y=func() return y print y @FirstDeco def test(): print 'asdf' return 7 result : haha asdf code2: def FirstDeco(func): print 'haha' y=func() #return y print y @FirstDeco def test(): print 'asdf' return 7 result : haha asdf 7 why the result of code1 and code2 is different? -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Mon Jan 9 22:44:31 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 9 Jan 2012 19:44:31 -0800 Subject: function problem In-Reply-To: References: Message-ID: On Mon, Jan 9, 2012 at 7:35 PM, contro opinion wrote: > code1: > > def FirstDeco(func): > ?? print 'haha' > ?? y=func() > ?? return y > ?? print? y Since there's a `return` right before it, the latter `print` here will *never* be executed. Cheers, Chris From contropinion at gmail.com Mon Jan 9 22:59:49 2012 From: contropinion at gmail.com (contro opinion) Date: Tue, 10 Jan 2012 11:59:49 +0800 Subject: decorator problem1: Message-ID: test1.py def deco(func): print 'i am in deco' return func @deco def test(): print 'i am in test' when you run it ,you get : test2.py def tsfunc(func): def wrappedFunc(): print '[%s] %s() called' % (ctime(), func.__name__) print 'i am in deco' return func() return wrappedFunc @tsfunc def test(): print "i am in test" when you run test2.py,you can get nothing ,why can't i get :?? i am in deco -------------- next part -------------- An HTML attachment was scrubbed... URL: From contropinion at gmail.com Mon Jan 9 23:14:10 2012 From: contropinion at gmail.com (contro opinion) Date: Tue, 10 Jan 2012 12:14:10 +0800 Subject: decorator problem Message-ID: test1.py def deco(func): print 'i am in deco' @deco def test(): print 'i am in test' when you run it ,you get : i am in deco test2.py def tsfunc(func): def wrappedFunc(): print 'i am in deco' return func() return wrappedFunc @tsfunc def test(): print "i am in test" when you run test2.py,you can get nothing ,why can't i get :?? i am in deco -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Mon Jan 9 23:21:21 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 09 Jan 2012 23:21:21 -0500 Subject: replacing __dict__ with an OrderedDict In-Reply-To: References: <11jrt8-l32.ln1@satorlaser.homedns.org> Message-ID: On 1/9/2012 8:05 PM, Roy Smith wrote: > In article<11jrt8-l32.ln1 at satorlaser.homedns.org>, > Ulrich Eckhardt wrote: > >>> Some people advocate that the test framework should >>> intentionally randomize the order, to flush out inter-test dependencies >>> that the author didn't realize existed (or intend). >> >> If you now >> happen to influence one test with another and the next run randomizes >> the tests differently, you will never see the fault again. Without this >> reproducability, you don't gain anything but the bad stomach feeling >> that something is wrong. > > The standard solution to that is to print out the PRNG initialization > state and provide a way in your test harness to re-initialize it to that > state. I've done things like that in test scenarios where it is > difficult or impossible to cover the problem space deterministically. > >> Your unfortunate case is where test X creates persistent state that must >> be present in order for test X+1 to produce meaningful results. This >> kind of dependency obviously blows, as it means you can't debug test X+1 >> separately. I'd call this operational dependency. >> >> This kind of dependency is IMHO a bug in the tests themselves. > > For the most part, I'm inclined to agree. However, there are scenarios > where having each test build the required state from scratch is > prohibitively expensive. Imagine if you worked at NASA wanted to run > test_booster_ignition(), test_booster_cutoff(), > test_second_stage_ignition(), and test_self_destruct(). I suppose you > could run them in random order, but you'd use up a lot of rockets that > way. > > Somewhat more seriously, let's say you wanted to do test queries against > a database with 100 million records in it. You could rebuild the > database from scratch for each test, but doing so might take hours per > test. Sometimes, real life is just *so* inconvenient. > >> There is another dependency and that I'd call a logical dependency. This >> occurs when e.g. test X tests for an API presence and test Y tests the >> API behaviour. In other words, Y has no chance to succeed if X already >> failed. > > Sure. I run into that all the time. A trivial example would be the > project I'm working on now. I've come to realize that a long unbroken > string of E's means, "Dummy, you forgot to bring the application server > up before you ran the tests". It would be nicer if the test suite could > have run a single test which proved it could create a TCP connection and > when that failed, just stop. Many test cases in the Python test suite have multiple asserts. I believe both resource sharing and sequential dependencies are reasons. I consider 'one assert (test) per testcase' to be on a par with 'one class per file'. -- Terry Jan Reedy From pyscripter at gmail.com Mon Jan 9 23:24:36 2012 From: pyscripter at gmail.com (pyscripter at gmail.com) Date: Mon, 9 Jan 2012 20:24:36 -0800 (PST) Subject: UnicodeEncodeError in compile Message-ID: <9043309.329.1326169476466.JavaMail.geo-discussion-forums@yqhi24> Using python 3.2 in Windows 7 I am getting the following: >>compile('pass', r'c:\temp\??\module1.py', 'exec') UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: invalid character Can anybody explain why the compile statement tries to convert the unicode filename using mbcs? I know that sys.getfilesystemencoding returns 'mbcs' in Windows, but I thought that this is not used when unicode file names are provided. From contropinion at gmail.com Mon Jan 9 23:34:51 2012 From: contropinion at gmail.com (contro opinion) Date: Tue, 10 Jan 2012 12:34:51 +0800 Subject: decorator and wrap Message-ID: def deco(func): def wrap(): print 'i am in deco' return func() return wrap @deco def test(): print "i am in test" when you run it ,there is no result , def deco(func): print 'i am in deco' return func() @deco def test(): print "i am in test" when you run it ,you can get : >>> i am in deco i am in test why?? -------------- next part -------------- An HTML attachment was scrubbed... URL: From duncan at duncf.ca Mon Jan 9 23:43:43 2012 From: duncan at duncf.ca (Duncan Findlay) Date: Mon, 9 Jan 2012 20:43:43 -0800 Subject: Shutting worker threads down gracefully after signal, portably Message-ID: <88E85806-5385-4BF7-A874-889AA0226243@duncf.ca> Suppose I've got a Python daemon that spawns a bunch of worker threads, waits for a singal (e.g. SIGTERM) and then shuts down the worker threads gracefully. What's the simplest way to do the signal handling portably across as many operating systems as possible (at least Linux and FreeBSD). Specifically, I'm interested in solutions where the main thread consumes no CPU, so no time.sleep(n) loops. The most obvious solution (below) does not work with on FreeBSD, because the signal gets delivered to a different thread and signal.pause() doesn't return. _shutdown = False def sig_handler(signum, frame): print 'handled' global _shutdown _shutdown = True if __name__ == '__main__': # Set up signal handling. signal.signal(signal.SIGTERM, sig_handler) # Start worker threads. workers = [Worker() for i in xrange(NUM_THREADS)] for worker in workers: worker.start() # Sleep until woken by a signal. while not _shutdown: signal.pause() # Shutdown work threads gracefully. for worker in workers: worker.shutdown() Any ideas? I've attached a more complete code sample. Thanks Duncan Findlay -------------- next part -------------- A non-text attachment was scrubbed... Name: daemon.py Type: text/x-python-script Size: 1059 bytes Desc: not available URL: From clp2 at rebertia.com Tue Jan 10 00:15:53 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 9 Jan 2012 21:15:53 -0800 Subject: decorator problem In-Reply-To: References: Message-ID: On Mon, Jan 9, 2012 at 8:14 PM, contro opinion wrote: > test1.py > > def deco(func): > ???? print 'i am in deco' > > @deco > def test(): > ?? ? print 'i am in test' > > > when you run it ,you get : > i am in deco > > > > test2.py > > def tsfunc(func): > ???? def wrappedFunc(): > ????????? print 'i am in deco' > ????????? return func() > ????? return wrappedFunc > > @tsfunc > def test(): > ??? print "i am in test" > > when you run test2.py,you can get nothing ,why can't i get :?? > i am in deco Because that `print` is in wrappedFunc() [which in this case is A.K.A. test()], which is only defined, never called. Try adding a call to test() at the end of your script. Contrast this with deco(), which has the `print` directly in its body rather than inside a nested function definition. Also, might I suggest reading a tutorial on decorators or asking on an IRC channel, rather than pelting the mailing list with all these simple and related questions in such a fairly short timeframe? At least please keep all these in a single thread instead of starting a new one every single time... Cheers, Chris From clp2 at rebertia.com Tue Jan 10 00:17:37 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 9 Jan 2012 21:17:37 -0800 Subject: decorator problem1: In-Reply-To: References: Message-ID: On Mon, Jan 9, 2012 at 7:59 PM, contro opinion wrote: > test1.py > > def deco(func): > ?? print 'i am in deco' > ?? return func > > @deco > > def test(): > ? print 'i am in test' > > when you run it ,you get : > > > > test2.py > > def tsfunc(func): > ??? def wrappedFunc(): > ??????? print '[%s] %s() called' % (ctime(), func.__name__) > ??????? print 'i am in deco' > ??????? return func() > ??? return wrappedFunc > > @tsfunc > def test(): > ??? print? "i am in test" > > when you run test2.py,you can get nothing ,why can't i get? :?? > i am in deco Same answer applies as the one I just gave in your other thread. Cheers, Chris From clp2 at rebertia.com Tue Jan 10 00:21:27 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 9 Jan 2012 21:21:27 -0800 Subject: decorator and wrap In-Reply-To: References: Message-ID: Cheers, Chris -- http://rebertia.com On Mon, Jan 9, 2012 at 8:34 PM, contro opinion wrote: > > def?deco(func): > ????def?wrap(): > ????????print?'i?am?in?deco' > ????????return?func() > ????return?wrap > > @deco > def?test(): > ????print??"i?am?in?test" > when you run it ,there is no result , > > def?deco(func): > ????????print?'i?am?in?deco' > ????????return?func() > > > @deco > def?test(): > ????print??"i?am?in?test" > > > when you run it? ,you can get : >>>> > i?am?in?deco > i?am?in?test > > why?? For the third time, it's because the "I am in deco" `print` is not within a nested function definition (such as wrap()). Cheers, Chris From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Jan 10 01:42:17 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 10 Jan 2012 07:42:17 +0100 Subject: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error In-Reply-To: References: <24123dfe-b2fc-4f4c-8dfe-23bfef19b205@m10g2000vbc.googlegroups.com> Message-ID: Am 09.01.2012 23:35 schrieb Dominic Binks: > On 1/9/2012 2:19 PM, ???????? ?????? wrote: >> Can you please explain me what the [0] in host = >> socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] does at the end? >> >> Why not just host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] ) >> instead? what is the need of [0] ? > > The address database can have multiple names for the same IP address so > gethostbyaddr returns a list - [0] being the first item in the list (and > usually considered the canonical name) It might be noteworthy that it is nowadays preferrable to use getaddrinfo() instead. This way, you get all acceptable IP addresses, not only IPv4 ones. And then, you should not only try this one entry - [0] -, but iterate over all of them until you have a connection. BTW: This behaviour might be useful with gethostbyaddr() as well - if the first one returned has gone away, you have the chance to reach the 2nd one... Thomas From dihedral88888 at googlemail.com Tue Jan 10 01:49:29 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Mon, 9 Jan 2012 22:49:29 -0800 (PST) Subject: decorator problem In-Reply-To: References: Message-ID: <32696950.139.1326178169482.JavaMail.geo-discussion-forums@prlh23> Chris Rebert? 2012?1?10????UTC+8??1?15?53???? > On Mon, Jan 9, 2012 at 8:14 PM, contro opinion wrote: > > test1.py > > > > def deco(func): > > ???? print 'i am in deco' > > > > @deco > > def test(): > > ?? ? print 'i am in test' > > > > > > when you run it ,you get : > > i am in deco > > > > > > > > test2.py > > > > def tsfunc(func): > > ???? def wrappedFunc(): > > ????????? print 'i am in deco' > > ????????? return func() > > ????? return wrappedFunc > > > > @tsfunc > > def test(): > > ??? print "i am in test" > > > > when you run test2.py,you can get nothing ,why can't i get :?? > > i am in deco > Try to add testgen=test() or testgent=test in test2.py testgen() # a function is an object, Also you can wrap a function to use yield instead of return. It is trivial to get a call back function in python by a decorator that wraps a non-call back function. > Because that `print` is in wrappedFunc() [which in this case is A.K.A. > test()], which is only defined, never called. Try adding a call to > test() at the end of your script. > Contrast this with deco(), which has the `print` directly in its body > rather than inside a nested function definition. > > Also, might I suggest reading a tutorial on decorators or asking on an > IRC channel, rather than pelting the mailing list with all these > simple and related questions in such a fairly short timeframe? > At least please keep all these in a single thread instead of starting > a new one every single time... > > Cheers, > Chris From dihedral88888 at googlemail.com Tue Jan 10 01:49:29 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Mon, 9 Jan 2012 22:49:29 -0800 (PST) Subject: decorator problem In-Reply-To: References: Message-ID: <32696950.139.1326178169482.JavaMail.geo-discussion-forums@prlh23> Chris Rebert? 2012?1?10????UTC+8??1?15?53???? > On Mon, Jan 9, 2012 at 8:14 PM, contro opinion wrote: > > test1.py > > > > def deco(func): > > ???? print 'i am in deco' > > > > @deco > > def test(): > > ?? ? print 'i am in test' > > > > > > when you run it ,you get : > > i am in deco > > > > > > > > test2.py > > > > def tsfunc(func): > > ???? def wrappedFunc(): > > ????????? print 'i am in deco' > > ????????? return func() > > ????? return wrappedFunc > > > > @tsfunc > > def test(): > > ??? print "i am in test" > > > > when you run test2.py,you can get nothing ,why can't i get :?? > > i am in deco > Try to add testgen=test() or testgent=test in test2.py testgen() # a function is an object, Also you can wrap a function to use yield instead of return. It is trivial to get a call back function in python by a decorator that wraps a non-call back function. > Because that `print` is in wrappedFunc() [which in this case is A.K.A. > test()], which is only defined, never called. Try adding a call to > test() at the end of your script. > Contrast this with deco(), which has the `print` directly in its body > rather than inside a nested function definition. > > Also, might I suggest reading a tutorial on decorators or asking on an > IRC channel, rather than pelting the mailing list with all these > simple and related questions in such a fairly short timeframe? > At least please keep all these in a single thread instead of starting > a new one every single time... > > Cheers, > Chris From rosuav at gmail.com Tue Jan 10 02:29:28 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 10 Jan 2012 18:29:28 +1100 Subject: socket.gethostbyaddr( os.environ['REMOTE_ADDR'] error In-Reply-To: References: <24123dfe-b2fc-4f4c-8dfe-23bfef19b205@m10g2000vbc.googlegroups.com> Message-ID: On Tue, Jan 10, 2012 at 5:42 PM, Thomas Rachel wrote: > BTW: This behaviour might be useful with gethostbyaddr() as well - if the > first one returned has gone away, you have the chance to reach the 2nd > one... In its directest sense, probably not. All you're getting is multiple names for the same IP address. But if some of those names resolve to multiple IP addresses, then it's entirely possible that what you say is so. ChrisA From moijes12 at gmail.com Tue Jan 10 02:52:59 2012 From: moijes12 at gmail.com (moijes12) Date: Mon, 9 Jan 2012 23:52:59 -0800 (PST) Subject: Getting involved References: Message-ID: <45f31025-79ea-43b4-a000-fc0a08790781@v13g2000yqc.googlegroups.com> On Jan 7, 4:13?pm, Chris Angelico wrote: > On Sat, Jan 7, 2012 at 9:59 PM, Sophie Sperner wrote: > > Could you please list me 2 or 3 projects in Python and/or Java which > > are currently active (vivid) and useful? > > Easiest way to find a project to join would be to go to SourceForge, > Google Code, GitHub, BitBucket, or any other large hosting facility, > and browse the project list. Soon as you find one that makes you go > "That is SO COOL!", start reading their bugtracker. There's always > something to play with! > > ChrisA Try out at TwistedMatrix. You can start by fixing some easy tickets. From tjreedy at udel.edu Tue Jan 10 03:08:40 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 10 Jan 2012 03:08:40 -0500 Subject: UnicodeEncodeError in compile In-Reply-To: <9043309.329.1326169476466.JavaMail.geo-discussion-forums@yqhi24> References: <9043309.329.1326169476466.JavaMail.geo-discussion-forums@yqhi24> Message-ID: On 1/9/2012 11:24 PM, pyscripter at gmail.com wrote: > Using python 3.2 in Windows 7 I am getting the following: > >>> compile('pass', r'c:\temp\??\module1.py', 'exec') > UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: invalid character > > Can anybody explain why the compile statement tries to convert the unicode filename using mbcs? I know that sys.getfilesystemencoding returns 'mbcs' in Windows, but I thought that this is not used when unicode file names are provided. I get the same error running 3.2.2 under IDLE but not when pasting into Command Prompt. However, Command Prompt may be cheating by replacing the Chinese chars with '??' upon pasting, so that Python never gets them -- whereas they appear just fine in IDLE. -- Terry Jan Reedy From nikos.kouras at gmail.com Tue Jan 10 04:02:59 2012 From: nikos.kouras at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Tue, 10 Jan 2012 01:02:59 -0800 (PST) Subject: Explanation about for References: Message-ID: <581e9a24-f948-4fc4-ae28-227d6d526780@n6g2000vbg.googlegroups.com> On 10 ???, 03:11, Ian Kelly wrote: > 2012/1/9 ???????? ?????? : > > > if the MySQL query was: > > > cursor.execute( '''SELECT host, hits, agent, date FROM visitors WHERE pin = > > %s ORDER BY date DESC''', pin ) > > > can you help me imagine how the mysql database cursor that holds the query > > results would look like? I must somehow visualize it in order to understand > > it! > > You can think of it as a pointer, traversing over one row of the > result set at a time. ?Hopefully this will come out legibly: > > ----------------------------------------------- > | HOST | HITS | AGENT | DATE | > ----------------------------------------------- ? ? ? ? ? ?------------- > | foo ? ? | 7 ? ? ? | IE6 ? ? ? | 1/1/11 | ? <---- ? | cursor | > ----------------------------------------------- ? ? ? ? ? ?------------- > | bar ? ? | 42 ? ? | Firefox ?| 2/2/10 | > ----------------------------------------------- > | baz ? ?| 4 ? ? ? | Chrome | 3/3/09 | > ------------------------------------------------ Database cursor is the pointer that iterates over the result set one row at a time? I though that it was the name we give to the whole mysql result set returned my cursor.execute. > > > > Also what happend if the query was: > > cursor.execute( '''SELECT host FROM visitors") ? > > > the result would have to be something likelike? > > > ----------------- > > |somehost1| > > ----------------- > > |somehost2| > > ----------------- > > |somehost3| > > ----------------- > > ..................... > > ..................... > > |somehost n| > > ----------------- > > > So what values?host, hits, agent, date would have in 'for?host, hits, agent, > > date in > > ?dataset' ? Every row has one string how can that be split in 4? > > Why don't you try it and see what happens? ?But to spare you the > suspense, you would get: > > ValueError: need more than 1 value to unpack > > Because you can't unpack a 1-length tuple into four variables. ?The > code assumes that the query is selecting exactly 4 columns. ----------------------------------------------- | HOST | HITS | AGENT | DATE | ----------------------------------------------- | foo | 7 | IE6 | 1/1/11 | ----------------------------------------------- | bar | 42 | Firefox | 2/2/10 | ----------------------------------------------- | baz | 4 | Chrome | 3/3/09 | ----------------------------------------------- In this line: for host, hits, agent, date in dataset: 'dataset' is one of the rows of the mysql result or the whole mysql result set like the table above? I still have trouble understanding this line :( From wxjmfauth at gmail.com Tue Jan 10 04:42:21 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Tue, 10 Jan 2012 01:42:21 -0800 (PST) Subject: UnicodeEncodeError in compile References: <9043309.329.1326169476466.JavaMail.geo-discussion-forums@yqhi24> Message-ID: 1) If I copy/paste these CJK chars from Google Groups in two of my interactive interpreters (no "dos/cmd console"), I have no problem. >>> import unicodedata as ud >>> ud.name('?') 'CJK UNIFIED IDEOGRAPH-5DE5' >>> ud.name('?') 'CJK UNIFIED IDEOGRAPH-5177' >>> hex(ord(('?'))) '0x5de5' >>> hex(ord('?')) '0x5177' >>> 2) It semms the mbcs codec has some difficulties with these chars. >>> '\u5de5'.encode('mbcs') Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: invalid character >>> '\u5de5'.encode('utf-8') b'\xe5\xb7\xa5' >>> '\u5de5'.encode('utf-32-be') b'\x00\x00]\xe5' 3) On the usage of mbcs in files IO interaction --> core devs. My conclusion. The bottle neck is on the mbcs side. jmf From pyscripter at gmail.com Tue Jan 10 05:04:10 2012 From: pyscripter at gmail.com (pyscripter at gmail.com) Date: Tue, 10 Jan 2012 02:04:10 -0800 (PST) Subject: UnicodeEncodeError in compile In-Reply-To: <9043309.329.1326169476466.JavaMail.geo-discussion-forums@yqhi24> References: <9043309.329.1326169476466.JavaMail.geo-discussion-forums@yqhi24> Message-ID: <6733632.476.1326189850532.JavaMail.geo-discussion-forums@yqbl25> See a more complete version of the question at http://stackoverflow.com/questions/8798591/unicodeencodeerror-when-using-the-compile-function From dihedral88888 at googlemail.com Tue Jan 10 05:53:55 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 10 Jan 2012 02:53:55 -0800 (PST) Subject: UnicodeEncodeError in compile In-Reply-To: References: <9043309.329.1326169476466.JavaMail.geo-discussion-forums@yqhi24> Message-ID: <28903716.270.1326192835962.JavaMail.geo-discussion-forums@prmu37> Terry Reedy? 2012?1?10????UTC+8??4?08?40???? > On 1/9/2012 11:24 PM, pyscr... at gmail.com wrote: > > Using python 3.2 in Windows 7 I am getting the following: > > > >>> compile('pass', r'c:\temp\??\module1.py', 'exec') > > UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: invalid character > > > > Can anybody explain why the compile statement tries to convert the unicode filename using mbcs? I know that sys.getfilesystemencoding returns 'mbcs' in Windows, but I thought that this is not used when unicode file names are provided. > > I get the same error running 3.2.2 under IDLE but not when pasting into > Command Prompt. However, Command Prompt may be cheating by replacing the > Chinese chars with '??' upon pasting, so that Python never gets them -- > whereas they appear just fine in IDLE. > > -- > Terry Jan Reedy Thank you about the trick. Use some wildcat pattern to get the name.py compiled to pwc in some directory with utf-8 encoded chars. From dihedral88888 at googlemail.com Tue Jan 10 05:53:55 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 10 Jan 2012 02:53:55 -0800 (PST) Subject: UnicodeEncodeError in compile In-Reply-To: References: <9043309.329.1326169476466.JavaMail.geo-discussion-forums@yqhi24> Message-ID: <28903716.270.1326192835962.JavaMail.geo-discussion-forums@prmu37> Terry Reedy? 2012?1?10????UTC+8??4?08?40???? > On 1/9/2012 11:24 PM, pyscr... at gmail.com wrote: > > Using python 3.2 in Windows 7 I am getting the following: > > > >>> compile('pass', r'c:\temp\??\module1.py', 'exec') > > UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: invalid character > > > > Can anybody explain why the compile statement tries to convert the unicode filename using mbcs? I know that sys.getfilesystemencoding returns 'mbcs' in Windows, but I thought that this is not used when unicode file names are provided. > > I get the same error running 3.2.2 under IDLE but not when pasting into > Command Prompt. However, Command Prompt may be cheating by replacing the > Chinese chars with '??' upon pasting, so that Python never gets them -- > whereas they appear just fine in IDLE. > > -- > Terry Jan Reedy Thank you about the trick. Use some wildcat pattern to get the name.py compiled to pwc in some directory with utf-8 encoded chars. From pasparis at noos.fr Tue Jan 10 05:57:38 2012 From: pasparis at noos.fr (pasparis at noos.fr) Date: Tue, 10 Jan 2012 11:57:38 +0100 (CET) Subject: C-API: Pass a tuple to a method of a class Message-ID: An HTML attachment was scrubbed... URL: From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Jan 10 05:57:46 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 10 Jan 2012 11:57:46 +0100 Subject: Explanation about for In-Reply-To: <581e9a24-f948-4fc4-ae28-227d6d526780@n6g2000vbg.googlegroups.com> References: <581e9a24-f948-4fc4-ae28-227d6d526780@n6g2000vbg.googlegroups.com> Message-ID: Am 10.01.2012 10:02 schrieb ???????? ??????: > ----------------------------------------------- > | HOST | HITS | AGENT | DATE | > ----------------------------------------------- > | foo | 7 | IE6 | 1/1/11 | > ----------------------------------------------- > | bar | 42 | Firefox | 2/2/10 | > ----------------------------------------------- > | baz | 4 | Chrome | 3/3/09 | > ----------------------------------------------- > > In this line: > for host, hits, agent, date in dataset: > > 'dataset' is one of the rows of the mysql result or the whole mysql > result set like the table above? dataset is a cursor, representing the whole result set. Iterating over it produces one row at each iteration step: for row in dataset: ... As each row consists of 4 fields, one iteration result is a tuple of 4 elements. In this case, for host, hits, agent, date in dataset: is shorthand for for anyunusedvariablename in dataset: # take complete row host, hits, agent, date = anyunusedvariablename # tuple unpacking del anyunusedvariablename # remove traces exept that the said variable isn't created. Thomas From jeanmichel at sequans.com Tue Jan 10 06:03:12 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 10 Jan 2012 12:03:12 +0100 Subject: Calling a variable inside a function of another class In-Reply-To: <5a91e124-b6e9-4e2f-88d6-50a33eb496db@k29g2000vbl.googlegroups.com> References: <5a91e124-b6e9-4e2f-88d6-50a33eb496db@k29g2000vbl.googlegroups.com> Message-ID: <4F0C1AF0.7020101@sequans.com> Yigit Turgut wrote: > class test(test1): > > def __init__(self, device): > . > . > . > def _something(self, x=1) > self.dt = data > > > if __name__ == "__main__": > test.something.dt ??? > > I am trying to call a variable located in a function of a class from > main but couldn't succeed.Any ideas? > if __name__ == "__main__": aTest = test(whateverdevice) print aTest.dt Some advices: - a common practice in python is to name classes in CamelCase ( read http://www.python.org/dev/peps/pep-0008/ ) - if dt is a shortcut for data, it's a bad one. - default values are for loosers, they should be used only to keep backward compatibility (personal opinion, a lot of ppl would disagree) - "call" is usually reserved for method and function, or any callable object in python. What you're trying to do is to reference an object, not calling it. JM From nikos.kouras at gmail.com Tue Jan 10 06:37:38 2012 From: nikos.kouras at gmail.com (=?UTF-8?B?zp3Ouc66z4zOu86xzr/PgiDOms6/z43Pgc6xz4I=?=) Date: Tue, 10 Jan 2012 03:37:38 -0800 (PST) Subject: Explanation about for References: <581e9a24-f948-4fc4-ae28-227d6d526780@n6g2000vbg.googlegroups.com> Message-ID: On 10 ???, 12:57, Thomas Rachel wrote: > Am 10.01.2012 10:02 schrieb ???????? ??????: > > > ----------------------------------------------- > > | HOST ? ?| HITS ? ?| AGENT ? ? | DATE | > > ----------------------------------------------- > > | foo ? ? | 7 ? ? ? | IE6 ? ? ? | 1/1/11 | > > ----------------------------------------------- > > | bar ? ? | 42 ? ? ?| Firefox ? | 2/2/10 | > > ----------------------------------------------- > > | baz ? ? | 4 ? ? ? | Chrome ? ?| 3/3/09 | > > ----------------------------------------------- > > > In this line: > > for host, hits, agent, date in dataset: > > > 'dataset' is one of the rows of the mysql result or the whole mysql > > result set like the table above? > > dataset is a cursor, representing the whole result set. > > Iterating over it produces one row at each iteration step: > > for row in dataset: > ? ? ?... > > As each row consists of 4 fields, one iteration result is a tuple of 4 > elements. > > In this case, > > for host, hits, agent, date in dataset: So that means that for host, hits, agent, date in dataset: is: for host, hits, agent, date in (foo,7,IE6,1/1/11) and then: for host, hits, agent, date in (bar,42,Firefox,2/2/10) and then: for host, hits, agent, date in (baz,4,Chrome,3/3/09) So 'dataset' is one row at each time? but we said that 'dataset' represent the whole result set. So isnt it wrong iam substituting it with one line per time only? From nikos.kouras at gmail.com Tue Jan 10 06:38:36 2012 From: nikos.kouras at gmail.com (=?UTF-8?B?zp3Ouc66z4zOu86xzr/PgiDOms6/z43Pgc6xz4I=?=) Date: Tue, 10 Jan 2012 03:38:36 -0800 (PST) Subject: Explanation about for References: <581e9a24-f948-4fc4-ae28-227d6d526780@n6g2000vbg.googlegroups.com> Message-ID: <2df0f35e-8c6d-446d-8762-1ad16be3d0c8@f1g2000yqi.googlegroups.com> On 10 ???, 12:57, Thomas Rachel wrote: > Am 10.01.2012 10:02 schrieb ???????? ??????: > > > ----------------------------------------------- > > | HOST ? ?| HITS ? ?| AGENT ? ? | DATE | > > ----------------------------------------------- > > | foo ? ? | 7 ? ? ? | IE6 ? ? ? | 1/1/11 | > > ----------------------------------------------- > > | bar ? ? | 42 ? ? ?| Firefox ? | 2/2/10 | > > ----------------------------------------------- > > | baz ? ? | 4 ? ? ? | Chrome ? ?| 3/3/09 | > > ----------------------------------------------- > > > In this line: > > for host, hits, agent, date in dataset: > > > 'dataset' is one of the rows of the mysql result or the whole mysql > > result set like the table above? > > dataset is a cursor, representing the whole result set. > > Iterating over it produces one row at each iteration step: > > for row in dataset: > ? ? ?... > > As each row consists of 4 fields, one iteration result is a tuple of 4 > elements. > > In this case, > > for host, hits, agent, date in dataset: So that means that for host, hits, agent, date in dataset: is: for host, hits, agent, date in (foo,7,IE6,1/1/11) and then: for host, hits, agent, date in (bar,42,Firefox,2/2/10) and then: for host, hits, agent, date in (baz,4,Chrome,3/3/09) So 'dataset' is one row at each time? but we said that 'dataset' represent the whole result set. So isnt it wrong iam substituting it with one line per time only? From lie.1296 at gmail.com Tue Jan 10 07:22:16 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 10 Jan 2012 23:22:16 +1100 Subject: replacing __dict__ with an OrderedDict In-Reply-To: References: <11jrt8-l32.ln1@satorlaser.homedns.org> Message-ID: On 01/10/2012 12:05 PM, Roy Smith wrote: > Somewhat more seriously, let's say you wanted to do test queries against > a database with 100 million records in it. You could rebuild the > database from scratch for each test, but doing so might take hours per > test. Sometimes, real life is just*so* inconvenient. All serious database has rollback feature when they're available to quickly revert database state in the setUp/cleanUp phase. From wxjmfauth at gmail.com Tue Jan 10 07:28:18 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Tue, 10 Jan 2012 04:28:18 -0800 (PST) Subject: UnicodeEncodeError in compile References: <9043309.329.1326169476466.JavaMail.geo-discussion-forums@yqhi24> Message-ID: On 10 jan, 11:53, 88888 Dihedral wrote: > Terry Reedy? 2012?1?10????UTC+8??4?08?40???? > > > > I get the same error running 3.2.2 under IDLE but not when pasting into > > Command Prompt. However, Command Prompt may be cheating by replacing the > > Chinese chars with '??' upon pasting, so that Python never gets them -- > > whereas they appear just fine in IDLE. > > > -- Tested with *my* Windows GUI interactive intepreters. It seems to me there is a problem with the mbcs codec. >>> hex(ord('?')) '0x5de5' >>> '\u5de5' '?' >>> '\u5de5'.encode('mbcs') Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: invalid character >>> '\u5de5'.encode('utf-8') b'\xe5\xb7\xa5' >>> '\u5de5'.encode('utf-32-be') b'\x00\x00]\xe5' >>> sys.version '3.2.2 (default, Sep 4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)]' >>> '\u5de5'.encode('mbcs', 'replace') b'?' ---------- >>> u'\u5de5'.encode('mbcs', 'replace') '?' >>> repr(u'\u5de5'.encode('utf-8')) "'\\xe5\\xb7\\xa5'" >>> repr(u'\u5de5'.encode('utf-32-be')) "'\\x00\\x00]\\xe5'" >>> sys.version '2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]' jmf From lie.1296 at gmail.com Tue Jan 10 07:31:46 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 10 Jan 2012 23:31:46 +1100 Subject: replacing __dict__ with an OrderedDict In-Reply-To: <6u5rt8-971.ln1@satorlaser.homedns.org> References: <4f079690$0$29966$c3e8da3$5496439d@news.astraweb.com> <10504296-daa3-4c3d-b45a-883af99e6804@z19g2000vbe.googlegroups.com> <6u5rt8-971.ln1@satorlaser.homedns.org> Message-ID: On 01/10/2012 12:16 AM, Ulrich Eckhardt wrote: > Am 09.01.2012 13:10, schrieb Lie Ryan: >> I was just suggesting that what the OP thinks he wants is quite >> likely not what he actually wants. > > Rest assured that the OP has a rather good idea of what he wants and > why, the latter being something you don't know, because he never > bothered to explain it and you never asked. Please don't think he's an > idiot just because he wants something that doesn't make sense to you. The OP explained the "why" clearly in his first post, he wanted to see his test results ordered in a certain way to make debugging easier, to quote the OP: """ ... I just want to take the first test that fails and analyse that instead of guessing the point to start debugging from the N failed tests. """ and then he goes on concluding that he need to reorder the tests itself and to replace __dict__ with OrderedDict. While it is possible to replace __dict__ with OrderedDict and it is possible to reorder the test, those are not his original problem, and the optimal solution to his original problem differs from the optimal solution to what he think he will need. I had said this before and I'm saying it again: the problem is a test result displaying issue, not testing order issue. From stefan_ml at behnel.de Tue Jan 10 07:33:17 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 10 Jan 2012 13:33:17 +0100 Subject: C-API: Pass a tuple to a method of a class In-Reply-To: References: Message-ID: Hi! pasparis at noos.fr, 10.01.2012 11:57: > I am trying to pass a tuple to a method of a class from C++ to Python. I get a > Run Failed from the execution. > thanks for help/suggestions My *suggestion* is to use Cython instead of writing the glue code yourself. There are several bugs and lots of inefficient data conversions in your code below, which are clearly due to your lack of experience with CPython's C-API. The good thing is that you don't need that experience if you use Cython, because it will take care of all those details for you. > the code is the following: > > Python Code: > > class cVector: > def __init__(self,msg): > self.value = msg > def ComputeNorm(self,vecData): > #don't use vecData for instance > result = 12. > return(result) Please take care to properly format your code when you post it here. The best way to do that is to post plain text messages. > C++ Code : > //instances. farenheit will hold our return value > PyObject *ret, *mymod, *pclass, *method, *args, *object; > float retValue; > > Py_Initialize(); > //PySys_SetPath("/home/pascal/projPytCpp/proj1"); > PySys_SetPath("."); > > // Module > mymod = PyImport_ImportModule("mModule8"); > if (mymod == NULL){ > cout << "Can't Open a module:\n" ; > Py_DECREF(mymod); Note that Py_DECREF(null) will crash. It looks like you are embedding Python here. Basically, the code up to this point is all you really have to do. You can leave the rest to Cython, especially the class instantiation and usage parts look much nicer in Python syntax than in C-API code. > // Class > pclass = PyObject_GetAttrString(mymod, "cVector"); > if (pclass == NULL) { > Py_DECREF(pclass); > cout << "Can't find class\n"; > } > > // Parameters/Values > args = Py_BuildValue("(f)", 100.0); > if (args == NULL) { > Py_DECREF(args); > cout << "Can't build argument list for class instance\n"; > } > > // Object with parameter/value > object = PyEval_CallObject(pclass, args); > if (object == NULL) { > Py_DECREF(object); > cout << "Can't create object instance:\n"; > } > > // Decrement the argument counter as we'll be using this again > Py_DECREF(args); > > // Get the object method - note we use the object as the object > // from which we access the attribute by name, not the class > method = PyObject_GetAttrString(object, "ComputeNorm"); > if (method == NULL) { > Py_DECREF(method); > cout << "Can't find method\n"; > } > > // Decrement the counter for our object, since we now just need > // the method reference > Py_DECREF(object); > > // Build our argument list - an empty tuple because there aren't > // any arguments > > cout << "Prepare the Tuple:\n" ; > // WE pass a tuple > args = PyTuple_New( 3 ); > if (args == NULL) { > Py_DECREF(args); > cout << "Can't build argument list for method call\n"; > } > > PyObject *py_argument; > // 1st argument > py_argument = PyFloat_FromDouble(5.); > PyTuple_SetItem(args, 0, py_argument); > > // 2nd argument > py_argument = PyFloat_FromDouble(10.); > PyTuple_SetItem(args, 1, py_argument); > > // 3nd argument > py_argument = PyFloat_FromDouble(15.); > PyTuple_SetItem(args, 2, py_argument); > > cout << "Before the Exec:\n" ; > // Call our object method with arguments > //ret = PyEval_CallObject(method,args); > ret = PyObject_CallObject(method,args); Note that you are calling the method with three arguments here. It appears that what you want is *one* argument instead, which happens to be a tuple. So you need to wrap it in another tuple for calling. As I said, Cython will do that for you. > // Convert the return value back into a C variable and display it > PyArg_Parse(ret, "f", &retValue); > printf("Farenheit: %f\n", retValue); > // Kill the remaining objects we don't need > Py_DECREF(method); > Py_DECREF(ret); > // Close off the interpreter and terminate > Py_Finalize(); That part is ok again. Stefan From lie.1296 at gmail.com Tue Jan 10 07:46:27 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 10 Jan 2012 23:46:27 +1100 Subject: replacing __dict__ with an OrderedDict In-Reply-To: <11jrt8-l32.ln1@satorlaser.homedns.org> References: <11jrt8-l32.ln1@satorlaser.homedns.org> Message-ID: On 01/10/2012 03:59 AM, Ulrich Eckhardt wrote: > > > There is another dependency and that I'd call a logical dependency. This > occurs when e.g. test X tests for an API presence and test Y tests the > API behaviour. In other words, Y has no chance to succeed if X already > failed. Unfortunately, there is no way to express this relation, there > is no "@unittest.depends(test_X)" to decorate test_Y with (Not yet!). The skipIf decorator exists precisely for this purpose. Generally, testing availability of resources (like existence of an API) should be done outside of the testing code. In other words, test_X should never be a test in the first place, it should be part of the setting up of the tests; the tests themselves should be completely independent of each other. From jpiitula at ling.helsinki.fi Tue Jan 10 07:52:32 2012 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 10 Jan 2012 14:52:32 +0200 Subject: Explanation about for References: <581e9a24-f948-4fc4-ae28-227d6d526780@n6g2000vbg.googlegroups.com> <2df0f35e-8c6d-446d-8762-1ad16be3d0c8@f1g2000yqi.googlegroups.com> Message-ID: ???????? ?????? writes: > So that means that > > for host, hits, agent, date in dataset: > > is: > > for host, hits, agent, date in (foo,7,IE6,1/1/11) > > and then: > > for host, hits, agent, date in (bar,42,Firefox,2/2/10) > > and then: > > for host, hits, agent, date in (baz,4,Chrome,3/3/09) > > > So 'dataset' is one row at each time? > but we said that 'dataset' represent the whole result set. > So isnt it wrong iam substituting it with one line per time only? Forget the database and meditate on simpler examples like this: >>> xy = zip("abc", "123") >>> for x, y in xy: print(x, y) ... ('a', '1') ('b', '2') ('c', '3') >>> for x, y in xy: print(xy) ... [('a', '1'), ('b', '2'), ('c', '3')] [('a', '1'), ('b', '2'), ('c', '3')] [('a', '1'), ('b', '2'), ('c', '3')] >>> Or, for that matter, even simpler examples like this: >>> bag = "abc" >>> for x in bag: print(x) ... a b c >>> for x in bag: print(bag) ... abc abc abc >>> And this: >>> a, b, c = bag >>> a, b, c ('a', 'b', 'c') >>> bag 'abc' >>> Go to the Python command line and try things out. From stefan_ml at behnel.de Tue Jan 10 08:01:29 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 10 Jan 2012 14:01:29 +0100 Subject: C-API: Pass a tuple to a method of a class In-Reply-To: References: Message-ID: Hi again, just as a little teaser, to make it clear that I'm not joking, here's your code below translated into Cython. Stefan Behnel, 10.01.2012 13:33: > pasparis at noos.fr, 10.01.2012 11:57: >> the code is the following: > [...] >> // Class >> pclass = PyObject_GetAttrString(mymod, "cVector"); >> if (pclass == NULL) { >> Py_DECREF(pclass); >> cout << "Can't find class\n"; >> } >> >> // Parameters/Values >> args = Py_BuildValue("(f)", 100.0); >> if (args == NULL) { >> Py_DECREF(args); >> cout << "Can't build argument list for class instance\n"; >> } >> >> // Object with parameter/value >> object = PyEval_CallObject(pclass, args); >> if (object == NULL) { >> Py_DECREF(object); >> cout << "Can't create object instance:\n"; >> } >> >> // Decrement the argument counter as we'll be using this again >> Py_DECREF(args); >> >> // Get the object method - note we use the object as the object >> // from which we access the attribute by name, not the class >> method = PyObject_GetAttrString(object, "ComputeNorm"); >> if (method == NULL) { >> Py_DECREF(method); >> cout << "Can't find method\n"; >> } >> >> // Decrement the counter for our object, since we now just need >> // the method reference >> Py_DECREF(object); >> >> // Build our argument list - an empty tuple because there aren't >> // any arguments >> >> cout << "Prepare the Tuple:\n" ; >> // WE pass a tuple >> args = PyTuple_New( 3 ); >> if (args == NULL) { >> Py_DECREF(args); >> cout << "Can't build argument list for method call\n"; >> } >> >> PyObject *py_argument; >> // 1st argument >> py_argument = PyFloat_FromDouble(5.); >> PyTuple_SetItem(args, 0, py_argument); >> >> // 2nd argument >> py_argument = PyFloat_FromDouble(10.); >> PyTuple_SetItem(args, 1, py_argument); >> >> // 3nd argument >> py_argument = PyFloat_FromDouble(15.); >> PyTuple_SetItem(args, 2, py_argument); >> >> cout << "Before the Exec:\n" ; >> // Call our object method with arguments >> //ret = PyEval_CallObject(method,args); >> ret = PyObject_CallObject(method,args); > > Note that you are calling the method with three arguments here. It appears > that what you want is *one* argument instead, which happens to be a tuple. > So you need to wrap it in another tuple for calling. As I said, Cython will > do that for you. And here's the Cython code: """ # in module "gluecode.pyx" (or whatever you want to name it) import mModule8 cdef api float compute_norm(float init_value, float x, float y, float z): vec = mModule8.cVector(init_value) return vec.ComputeNorm( (x,y,z) ) """ At least, that's what I read from your C code above. I'm assuming here that your program is using C or C++, and that you want to embed a CPython runtime in it and be able to execute Python code through it. The above "compute_norm()" function is exported (as a C function) by the "gluecode" module which you can import in your C/C++ code (as you did already). Note also that the Cython code above is substantially more efficient than your implementation, because it uses faster type conversions and interned Python names for looking up the class and its method. Stefan From lie.1296 at gmail.com Tue Jan 10 08:05:36 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 11 Jan 2012 00:05:36 +1100 Subject: python philosophical question - strong vs duck typing In-Reply-To: <4f0a7ca9$0$1727$742ec2ed@news.sonic.net> References: <59305aab-7ddf-4c61-b8ba-025a2ce10b48@d10g2000vbh.googlegroups.com> <4f0a7ca9$0$1727$742ec2ed@news.sonic.net> Message-ID: On 01/09/2012 04:35 PM, John Nagle wrote: > A type-inferring compiler has to analyze the whole program at > once, because the type of a function's arguments is determined > by its callers. This is slow. The alternative is to guess > what the type of something is likely to be, compile code at > run time, and be prepared to back out a bad guess. This > requires a very complex system, but that's how PyPy does it. > Performance does not seem to reach Shed Skin levels. With a smart enough compiler, JIT compiler can actually be faster than compile-time optimizations; the reason being that different people might use the same code differently. For example, say we have a function that takes an array of numbers which can be integer or float or a mix of integers and floats. A compile-time optimizer cannot optimize this function safely; but a run-time optimizer might notice that a certain user only ever use the function with an array of integers and generate an optimized code for that particular case. Profile-guided optimizations (PGO) can do something similar, but then it means a single program will have to have twenty different binaries for twenty different use cases; or a very large binary that contains code optimized for every possible thing. From 1989lzhh at gmail.com Tue Jan 10 08:24:40 2012 From: 1989lzhh at gmail.com (=?GB2312?B?wfXV8bqj?=) Date: Tue, 10 Jan 2012 21:24:40 +0800 Subject: C-API: Pass a tuple to a method of a class In-Reply-To: References: Message-ID: Hi, I have been using Cython for a period of time. But I can not find a description for the "api" key word in Cython documents cdef api float compute_norm(float init_value, float x, float y, float z): Can you explain it a little bit? Thanks! Regards, Liu Zhenhai 2012/1/10 Stefan Behnel > Hi again, > > just as a little teaser, to make it clear that I'm not joking, here's your > code below translated into Cython. > > Stefan Behnel, 10.01.2012 13:33: > > pasparis at noos.fr, 10.01.2012 11:57: > >> the code is the following: > > [...] > >> // Class > >> pclass = PyObject_GetAttrString(mymod, "cVector"); > >> if (pclass == NULL) { > >> Py_DECREF(pclass); > >> cout << "Can't find class\n"; > >> } > >> > >> // Parameters/Values > >> args = Py_BuildValue("(f)", 100.0); > >> if (args == NULL) { > >> Py_DECREF(args); > >> cout << "Can't build argument list for class instance\n"; > >> } > >> > >> // Object with parameter/value > >> object = PyEval_CallObject(pclass, args); > >> if (object == NULL) { > >> Py_DECREF(object); > >> cout << "Can't create object instance:\n"; > >> } > >> > >> // Decrement the argument counter as we'll be using this again > >> Py_DECREF(args); > >> > >> // Get the object method - note we use the object as the object > >> // from which we access the attribute by name, not the class > >> method = PyObject_GetAttrString(object, "ComputeNorm"); > >> if (method == NULL) { > >> Py_DECREF(method); > >> cout << "Can't find method\n"; > >> } > >> > >> // Decrement the counter for our object, since we now just need > >> // the method reference > >> Py_DECREF(object); > >> > >> // Build our argument list - an empty tuple because there aren't > >> // any arguments > >> > >> cout << "Prepare the Tuple:\n" ; > >> // WE pass a tuple > >> args = PyTuple_New( 3 ); > >> if (args == NULL) { > >> Py_DECREF(args); > >> cout << "Can't build argument list for method call\n"; > >> } > >> > >> PyObject *py_argument; > >> // 1st argument > >> py_argument = PyFloat_FromDouble(5.); > >> PyTuple_SetItem(args, 0, py_argument); > >> > >> // 2nd argument > >> py_argument = PyFloat_FromDouble(10.); > >> PyTuple_SetItem(args, 1, py_argument); > >> > >> // 3nd argument > >> py_argument = PyFloat_FromDouble(15.); > >> PyTuple_SetItem(args, 2, py_argument); > >> > >> cout << "Before the Exec:\n" ; > >> // Call our object method with arguments > >> //ret = PyEval_CallObject(method,args); > >> ret = PyObject_CallObject(method,args); > > > > Note that you are calling the method with three arguments here. It > appears > > that what you want is *one* argument instead, which happens to be a > tuple. > > So you need to wrap it in another tuple for calling. As I said, Cython > will > > do that for you. > > And here's the Cython code: > > """ > # in module "gluecode.pyx" (or whatever you want to name it) > > import mModule8 > > cdef api float compute_norm(float init_value, float x, float y, float z): > vec = mModule8.cVector(init_value) > return vec.ComputeNorm( (x,y,z) ) > """ > > At least, that's what I read from your C code above. I'm assuming here that > your program is using C or C++, and that you want to embed a CPython > runtime in it and be able to execute Python code through it. The above > "compute_norm()" function is exported (as a C function) by the "gluecode" > module which you can import in your C/C++ code (as you did already). > > Note also that the Cython code above is substantially more efficient than > your implementation, because it uses faster type conversions and interned > Python names for looking up the class and its method. > > Stefan > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From frank at chagford.com Tue Jan 10 08:39:14 2012 From: frank at chagford.com (Frank Millman) Date: Tue, 10 Jan 2012 15:39:14 +0200 Subject: Explanation about for References: <581e9a24-f948-4fc4-ae28-227d6d526780@n6g2000vbg.googlegroups.com> Message-ID: "???????? ??????" wrote in message news:afd612b7-2366-40be-badf-13c97655f72d at o12g2000vbd.googlegroups.com... > > So that means that > > for host, hits, agent, date in dataset: > > is: > > for host, hits, agent, date in (foo,7,IE6,1/1/11) > > and then: > > for host, hits, agent, date in (bar,42,Firefox,2/2/10) > > and then: > > for host, hits, agent, date in (baz,4,Chrome,3/3/09) > > > So 'dataset' is one row at each time? > but we said that 'dataset' represent the whole result set. > So isnt it wrong iam substituting it with one line per time only? No. 'for host, hits, agent, date in dataset:' is equivalent to - for row in dataset: # iterate over the cursor, return a single row (tuple) for each iteration host, hits, agent, date = row # unpack the tuple and assign the elements to their own names For the first iteration, row is the tuple ('foo', 7, 'IE6', '1/1/11') For the next iteration, row is the tuple ('bar', 42, 'Firefox', '2/2/10') For the next iteration, row is the tuple ('baz', 4, 'Chrome', '3/3/09') The original line uses a python technique that combines these two lines into one. HTH Frank Millman From wxjmfauth at gmail.com Tue Jan 10 08:43:45 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Tue, 10 Jan 2012 05:43:45 -0800 (PST) Subject: UnicodeEncodeError in compile References: <9043309.329.1326169476466.JavaMail.geo-discussion-forums@yqhi24> Message-ID: <3c9fd9e7-6a0e-40cc-a048-1a82e477c013@p4g2000vbt.googlegroups.com> On 10 jan, 13:28, jmfauth wrote: Addendum, Python console ("dos box") D:\>c:\python32\python.exe Python 3.2.2 (default, Sep 4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> '\u5de5'.encode('utf-8') b'\xe5\xb7\xa5' >>> '\u5de5'.encode('mbcs') Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: inval id character >>> ^Z D:\>c:\python27\python.exe Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> u'\u5de5'.encode('utf-8') '\xe5\xb7\xa5' >>> u'\u5de5'.encode('mbcs') '?' >>> ^Z D:\> jmf From stefan_ml at behnel.de Tue Jan 10 09:05:20 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 10 Jan 2012 15:05:20 +0100 Subject: C-API: Pass a tuple to a method of a class In-Reply-To: References: Message-ID: [cleaned up top-posted citation order to make the replies readable] ???, 10.01.2012 14:24: > 2012/1/10 Stefan Behnel >> """ >> # in module "gluecode.pyx" (or whatever you want to name it) >> >> import mModule8 >> >> cdef api float compute_norm(float init_value, float x, float y, float z): >> vec = mModule8.cVector(init_value) >> return vec.ComputeNorm( (x,y,z) ) >> """ I just noticed that this swallows exceptions. It should have one of the "except" declarations at the end of the signature to enable proper exception signalling to the calling C/C++ code. http://docs.cython.org/src/userguide/language_basics.html#error-return-values > I have been using Cython for a period of time. But I can not find a > description for the "api" key word in Cython documents I admit that searching for "api" isn't really helpful here, but at least the page on "interfacing with external C code" shouldn't be all that hard to find in the given context. It contains this section: http://docs.cython.org/src/userguide/external_C_code.html#using-cython-declarations-from-c Stefan From roy at panix.com Tue Jan 10 09:05:42 2012 From: roy at panix.com (Roy Smith) Date: Tue, 10 Jan 2012 09:05:42 -0500 Subject: replacing __dict__ with an OrderedDict References: <11jrt8-l32.ln1@satorlaser.homedns.org> Message-ID: In article , Lie Ryan wrote: > On 01/10/2012 12:05 PM, Roy Smith wrote: > > Somewhat more seriously, let's say you wanted to do test queries against > > a database with 100 million records in it. You could rebuild the > > database from scratch for each test, but doing so might take hours per > > test. Sometimes, real life is just*so* inconvenient. > > All serious database has rollback feature when they're available to > quickly revert database state in the setUp/cleanUp phase. I guess MongoDB is not a serious database? From jeanmichel at sequans.com Tue Jan 10 09:06:50 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 10 Jan 2012 15:06:50 +0100 Subject: your feedback to my first project please In-Reply-To: <2123007772.204183.1326052009748.JavaMail.open-xchange@email.1und1.de References: <2123007772.204183.1326052009748.JavaMail.open-xchange@email.1und1.de Message-ID: <4F0C45FA.2060505@sequans.com> patrick at bierans.de wrote: > Thanks for the feedback! > > I took the time reading and understanding it and to let it getting into my > bones. And I also lost time on reading more of this freaky and interesting > documentation and was testing a lot of different stuff with my enviroment. > > My current code can be seen here if you are interested: > > http://pastebin.com/3fz6qm9z #AverageStack.py > http://pastebin.com/tUSGs3gb #TestAverageStack.py > > Here are my replies to your time consuming and informative replies ;) > > > >> D'Arcy wrote: [code examples] >> > > Python has some really interesting tricks I have not seen in php. > For example: self._data = [default] * dim - That's nice. :) > And allowing the getter to also set a value was a nice idea. > I meant: def avg(self, value=None) > Thanks for that! :) > > But I will keep some of my underscores for "private" attributes and methods. > And I googled: "dim" was basic. I know too many languages and start mixing > the keywords - shame on me. ;) > > > >> D'Arcy and Peter wrote: [about writing testcases] >> > > Good Eye: I wrote the tests after coding - I know that this is the wrong way. > I just wanted to start coding and after some time I decided that I shoud have > some test cases. This is no real TDD - true. ;) I'll do that right next time. > > > >> Peter wrote: You must be doing it [writing test cases] wrong. >> > > After thinking about it: Yupp. You are right. Having written tests to check > "private" attributes really hurts one's pride. ;) > > > >> Peter wrote: You need "from __future__ import division" >> > > Thanks for pointing me to it. I really would have fallen for it! > > > >> Peter wrote: assert False, " %s, %s ?" % ("red", "yellow") >> > > Can you do that with a.avg() instead of a string like "red"? > > > TIA, > Patrick > > > PS: > > >> gene wrote: [plain text emails] >> > > Thanks for pointing me to that. But it was the mistake of my webmailer. I am > well aware of the etiquette of mailing lists. (As you can see my mail was > wordwrapped accordingly.) > > But I will not blame you for full quoting my html email... *cough* ;-P > > I hope I can get my webmailer to go for plain text email. The option is set > but does not seam to apply. ? import unittest from AverageStack import AverageStack - Module names should be lowercase (look at unittest). You can read http://www.python.org/dev/peps/pep-0008/ for details - I quite dislike your avg method which does more than averaging, it also inserts a value and removes another modifying the object in place. It could be very confusing for someone reading your code. Fortunately, you have documented it, that makes it acceptable. Why don't you make avg only averaging. Surely you can use the add method right before. - A very important information is mising from your documentation : the type of the parameters. Someone using your API must know which type is allowed. Replace "value" by "value (int)" for example. - Another way to improve your documenation : read PEP 257 http://www.python.org/dev/peps/pep-0257/ and try to follow these rules. For instance, don't write """Adds value to the stack" but """Add the given value (int) to the stack.""" (I would remove the internal pointer reference, since it's internal, the end user do not need to know about it). - Since you write documentation (good habit :o) ) you may want to look at doc generators like epydoc http://epydoc.sourceforge.net/ and start familiarizing with any markup language (epydoc, reStructuredText ... your pick) JM From as at sci.fi Tue Jan 10 09:47:25 2012 From: as at sci.fi (Anssi Saari) Date: Tue, 10 Jan 2012 16:47:25 +0200 Subject: Help with python-list archives References: <78484055-dd01-4237-9217-9eb038fc744f@p16g2000yqd.googlegroups.com> <14749754.624.1325806776674.JavaMail.geo-discussion-forums@vbgw2> <8f3b98e1-3b21-4f06-8456-0a555a7ee523@u32g2000yqe.googlegroups.com> Message-ID: Ian Kelly writes: > Probably nobody has noticed it until now. It seems to be a quirk of > the archive files that they are double-gzipped... Interesting, but I don't think the files are actually double-gzipped. If I download http://mail.python.org/pipermail/python-list/2012-January.txt.gz with wget in Cygwin or Unix, the file is 226753 bytes and singly gzipped. However, if I download the same file with Firefox in Windows, then it's 226782 bytes and double gzipped. So maybe it's something in the browser or server setup? From pasparis at noos.fr Tue Jan 10 10:18:12 2012 From: pasparis at noos.fr (pasparis at noos.fr) Date: Tue, 10 Jan 2012 16:18:12 +0100 (CET) Subject: C-API: Pass a tuple to a method of a class In-Reply-To: Message-ID: An HTML attachment was scrubbed... URL: From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Tue Jan 10 10:22:18 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Tue, 10 Jan 2012 16:22:18 +0100 Subject: Explanation about for In-Reply-To: References: <581e9a24-f948-4fc4-ae28-227d6d526780@n6g2000vbg.googlegroups.com> Message-ID: Am 10.01.2012 12:37 schrieb ???????? ??????: > So that means that > > for host, hits, agent, date in dataset: > > is: > > for host, hits, agent, date in (foo,7,IE6,1/1/11) > > and then: > > for host, hits, agent, date in (bar,42,Firefox,2/2/10) > > and then: > > for host, hits, agent, date in (baz,4,Chrome,3/3/09) No. As said, dataset is the whole result set. For now, you can see it as a list of all rows (which you get if you do l=list(dataset)). Let's assume you have your data in a list now, which is equivalent concerning the iteration. Then you have something like dataset = [ ('foo',7,'IE6','1/1/11'), ('bar',42,'Firefox','2/2/10'), ('baz',4,'Chrome','3/3/09') ] Doing for row in dataset: print row is equivalent to row = ('foo',7,'IE6','1/1/11') print row row = ('bar',42,'Firefox','2/2/10') print row row = ('baz',4,'Chrome','3/3/09') print row Doing for a, b, c, d in dataset: do_funny_stuff(a, d, c, b) is a, b, c, d = ('foo',7,'IE6','1/1/11'); # which is the same as # a = 'foo'; b = 7; c = 'IE6'; d = '1/1/11'; do_funny_stuff(a, d, c, b) a, b, c, d = ('bar',42,'Firefox','2/2/10') do_funny_stuff(a, d, c, b) a, b, c, d = ('baz',4,'Chrome','3/3/09') do_funny_stuff(a, d, c, b) The "body" of the for suite is executed once for each element. You have read already http://docs.python.org/tutorial/controlflow.html#for-statements http://docs.python.org/library/stdtypes.html#iterator-types ? Thomas From nicholas.dokos at hp.com Tue Jan 10 10:24:10 2012 From: nicholas.dokos at hp.com (Nick Dokos) Date: Tue, 10 Jan 2012 10:24:10 -0500 Subject: Explanation about for In-Reply-To: Message from =?us-ascii?Q?=3D=3FISO-8859-7=3FB=3Fzenq=2FOvh7?= =?us-ascii?Q?=2FIgyu=2F98eHy=3F=3D?= of "Tue\, 10 Jan 2012 01\:02\:59 PST." <581e9a24-f948-4fc4-ae28-227d6d526780@n6g2000vbg.googlegroups.com> References: <581e9a24-f948-4fc4-ae28-227d6d526780@n6g2000vbg.googlegroups.com> Message-ID: <31532.1326209050@gamaville.dokosmarshall.org> ???????? ?????? wrote: > On 10 ???, 03:11, Ian Kelly wrote: > > 2012/1/9 ???????? ?????? : > > > > > if the MySQL query was: > > > > > cursor.execute( '''SELECT host, hits, agent, date FROM visitors WHERE pin = > > > %s ORDER BY date DESC''', pin ) > > > > > can you help me imagine how the mysql database cursor that holds the query > > > results would look like? I must somehow visualize it in order to understand > > > it! > > > > You can think of it as a pointer, traversing over one row of the > > result set at a time. ?Hopefully this will come out legibly: > > > > ----------------------------------------------- > > | HOST | HITS | AGENT | DATE | > > ----------------------------------------------- ? ? ? ? ? ?------------- > > | foo ? ? | 7 ? ? ? | IE6 ? ? ? | 1/1/11 | ? <---- ? | cursor | > > ----------------------------------------------- ? ? ? ? ? ?------------- > > | bar ? ? | 42 ? ? | Firefox ?| 2/2/10 | > > ----------------------------------------------- > > | baz ? ?| 4 ? ? ? | Chrome | 3/3/09 | > > ------------------------------------------------ > > Database cursor is the pointer that iterates over the result set one > row at a time? > I though that it was the name we give to the whole mysql result set > returned my cursor.execute. > > > > > > > > Also what happend if the query was: > > > cursor.execute( '''SELECT host FROM visitors") ? > > > > > the result would have to be something likelike? > > > > > ----------------- > > > |somehost1| > > > ----------------- > > > |somehost2| > > > ----------------- > > > |somehost3| > > > ----------------- > > > ..................... > > > ..................... > > > |somehost n| > > > ----------------- > > > > > So what values?host, hits, agent, date would have in 'for?host, hits, agent, > > > date in > > > ?dataset' ? Every row has one string how can that be split in 4? > > > > Why don't you try it and see what happens? ?But to spare you the > > suspense, you would get: > > > > ValueError: need more than 1 value to unpack > > > > Because you can't unpack a 1-length tuple into four variables. ?The > > code assumes that the query is selecting exactly 4 columns. > > > ----------------------------------------------- > | HOST | HITS | AGENT | DATE | > ----------------------------------------------- > | foo | 7 | IE6 | 1/1/11 | > ----------------------------------------------- > | bar | 42 | Firefox | 2/2/10 | > ----------------------------------------------- > | baz | 4 | Chrome | 3/3/09 | > ----------------------------------------------- > > In this line: > for host, hits, agent, date in dataset: > > 'dataset' is one of the rows of the mysql result or the whole mysql > result set like the table above? > > I still have trouble understanding this line :( You can think of it as a list of tuples. Forget about cursors and databases for now. If l is a list [1, 2, 3, 4] you iterate over it like this: for x in l: print x and you get each element of the list[fn:1]. Similarly if l is a list of tuples l = [(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)] you can iterate over the list: for x in l: print x In this case, x is going to be (1,2,3,4) the first time through the loop, (5,6,7,8) the second time and so on. You can break each x apart within the loop: for x in l: t1, t2, t3, t4 = x print x, t1, t2, t3, t4 or you can break it apart like this - it's essentially the same thing: for t1, t2, t3, t4 in l: print t1, t2, t3, t4 You have been encouraged repeatedly to try these things interactively: please do so with the above examples and all will become clear. Going back to cursors and databases: you *can* think of 'dataset' as being a list of tuples - a list of all the query results, but with one proviso. The difference when you use a cursor is that `dataset' may be a lazy list (an "iterator"): instead of the whole set of results being in memory at the same time, the system will take care of doing whatever is necessary to get more of the results when it needs them. But the behavior is the *same* in the sense that the output that you get is the same (you will only see differences if you are keeping an eye on how much memory and how much time your program is using). Nick Footnotes: [fn:1] ... and, no, you *can't express* this as "the first time it is for x in 1: ... and the second time it is for x in 2: ... " as you asked in another email. That's arrant nonsense: x takes successive values in the list l for every iteration of the for loop. This is elementary Python (nay, elementary programming, period). From stephane at harobed.org Tue Jan 10 10:24:31 2012 From: stephane at harobed.org (=?ISO-8859-1?Q?St=E9phane_Klein?=) Date: Tue, 10 Jan 2012 16:24:31 +0100 Subject: I look for a tool like webalizer in python language Message-ID: Hi, I wonder if there are a tool like webalizer in python language. (http://en.wikipedia.org/wiki/Webalizer). I would like to do some patch in webalizer, but I don't want to spend too many time to do that in C language. In Python I can do this patch in few minute. Do you know a tool like this in Python ? Thanks for your help. Regards, St?phane -- St?phane Klein blog: http://stephane-klein.info Twitter: http://twitter.com/klein_stephane pro: http://www.is-webdesign.com From tim.wintle at teamrubber.com Tue Jan 10 10:45:54 2012 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Tue, 10 Jan 2012 15:45:54 +0000 Subject: replacing __dict__ with an OrderedDict In-Reply-To: References: <11jrt8-l32.ln1@satorlaser.homedns.org> Message-ID: <1326210354.10957.0.camel@tim-laptop> On Tue, 2012-01-10 at 09:05 -0500, Roy Smith wrote: > > I guess MongoDB is not a serious database? That's opening up a can of worms ;) ... anyway, cassandra is far better. Tim From patrick at bierans.de Tue Jan 10 10:46:31 2012 From: patrick at bierans.de (patrick at bierans.de) Date: Tue, 10 Jan 2012 16:46:31 +0100 (CET) Subject: your feedback to my first project please In-Reply-To: <4F0C45FA.2060505@sequans.com> References: <2123007772.204183.1326052009748.JavaMail.open-xchange@email.1und1.de <4F0C45FA.2060505@sequans.com> Message-ID: <640818676.509382.1326210391262.JavaMail.open-xchange@email.1und1.de > Jean-Michel wrote: Module names should be lowercase You're right. I was too lazy and just copied the class name. I will keep that in mind for the future. ;) > Jean-Michel wrote: I quite dislike your avg method which does more than > averaging, it also inserts a value and removes another modifying the > object in place. It could be very confusing for someone reading your code. > Fortunately, you have documented it, that makes it acceptable. Why don't > you make avg only averaging. Surely you can use the add method right before. Hm. It is (in most cases) only used in that way... So because I am lazy I thought it might be a good idea. But If I make add() return self I could do chaining, can't I? p.e.: as = AverageStack(10) avg = as.add(12).avg() Would that be better? > Jean-Michel wrote: A very important information is mising from your > documentation : the type of the parameters. [...] PEP 257 True. I'm still struggling here how to do it. I'd like to write the types into the signature of the method (like in Java) or use some other way like in javadoc. """@param name type description""" Writing it into the docstring as plain text is not very appealing to me. Any concrete tipps or examples? ? TIA, Patrick? From lie.1296 at gmail.com Tue Jan 10 10:57:09 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 11 Jan 2012 02:57:09 +1100 Subject: replacing __dict__ with an OrderedDict In-Reply-To: References: <11jrt8-l32.ln1@satorlaser.homedns.org> Message-ID: On 01/11/2012 01:05 AM, Roy Smith wrote: > In article, > Lie Ryan wrote: > >> On 01/10/2012 12:05 PM, Roy Smith wrote: >>> Somewhat more seriously, let's say you wanted to do test queries against >>> a database with 100 million records in it. You could rebuild the >>> database from scratch for each test, but doing so might take hours per >>> test. Sometimes, real life is just*so* inconvenient. >> >> All serious database has rollback feature when they're available to >> quickly revert database state in the setUp/cleanUp phase. > > I guess MongoDB is not a serious database? I guess there are always those oddball cases, but if you choose MongoDB then you already know the consequences that it couldn't be as easily unit-tested. And in any case, it is generally a bad idea to unittest with a database that contains 100 million items, that's for performance testing. So your point is? From rkosloski at visi.com Tue Jan 10 11:01:45 2012 From: rkosloski at visi.com (Rod Kosloski) Date: Tue, 10 Jan 2012 10:01:45 -0600 Subject: Perplexed by the behavior of import Message-ID: I'm perlexed by an apparent inconsistency in the behavior of the import statement. First, the files. There is a simple package, pkg, containing two files: mod.py and util.py, and a stand-alone module also named util.py: *** ./pkg/__init__.py *** from mod import * *** ./pkg/mod.py *** M = 8 *** ./pkg/util.py *** V = 0 *** ./util.py *** from pkg import * from pkg.util import * U = 0 Next, the Python session: Python 2.6.4 (r264:75706, Dec 13 2009, 19:46:11) [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import util >>> globals() {'__builtins__': , '__name__': '__main__', '__doc__': None 'util': , '__package__': None} >>> from pkg import * >>> globals() {'__builtins__': , 'M': 8, '__package__': None, 'util': , '__name__': '__main__', '__doc__': None, 'mod': } Compare the output of the two globals() statements: Variable util's value has changed from to What's happening to util? OK, maybe pkg.util replaces the original util because of the pkg import statement. But then, what about the following: Python 2.6.4 (r264:75706, Dec 13 2009, 19:46:11) [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> util = 0 >>> globals() {'__builtins__': , '__name__': '__main__', '__doc__': None, 'util': 0, '__package__': None} >>> from pkg import * >>> globals() {'__builtins__': , 'M': 8, '__package__': None, 'util': 0, '__name__': '__main__', '__doc__': None, 'mod': } >>> Now the value of util is unchanged across the pkg import statement. Why the difference? Thanks. From miki.tebeka at gmail.com Tue Jan 10 11:33:53 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Tue, 10 Jan 2012 08:33:53 -0800 (PST) Subject: codecs in a chroot / without fs access In-Reply-To: References: Message-ID: <30380539.934.1326213233044.JavaMail.geo-discussion-forums@yqlf8> Another option is to copy the data to the a location under the new chroot and register a new lookup functions (http://docs.python.org/library/codecs.html#codecs.register). This way you can save some memory. From miki.tebeka at gmail.com Tue Jan 10 11:33:53 2012 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Tue, 10 Jan 2012 08:33:53 -0800 (PST) Subject: codecs in a chroot / without fs access In-Reply-To: References: Message-ID: <30380539.934.1326213233044.JavaMail.geo-discussion-forums@yqlf8> Another option is to copy the data to the a location under the new chroot and register a new lookup functions (http://docs.python.org/library/codecs.html#codecs.register). This way you can save some memory. From __peter__ at web.de Tue Jan 10 11:40:04 2012 From: __peter__ at web.de (Peter Otten) Date: Tue, 10 Jan 2012 17:40:04 +0100 Subject: Perplexed by the behavior of import References: Message-ID: Rod Kosloski wrote: > I'm perlexed by an apparent inconsistency in the behavior of the import > statement. > > First, the files. There is a simple package, pkg, containing two files: > mod.py and util.py, and a stand-alone module also named util.py: > > *** ./pkg/__init__.py *** > from mod import * > *** ./pkg/mod.py *** > M = 8 > *** ./pkg/util.py *** > V = 0 > *** ./util.py *** > from pkg import * > from pkg.util import * > U = 0 > > Next, the Python session: > > Python 2.6.4 (r264:75706, Dec 13 2009, 19:46:11) > [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> import util > >>> globals() > {'__builtins__': , '__name__': > {'__main__', > '__doc__': None 'util': , > '__package__': None} > >>> from pkg import * > >>> globals() > {'__builtins__': , 'M': 8, > {'__package__': > None, 'util': , '__name__': > '__main__', '__doc__': None, > 'mod': } > > Compare the output of the two globals() statements: > Variable util's value has changed from > to > > What's happening to util? > > OK, maybe pkg.util replaces the original util because of the pkg import > statement. That's indeed what happens. > But then, what about the following: > > Python 2.6.4 (r264:75706, Dec 13 2009, 19:46:11) > [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> util = 0 > >>> globals() > {'__builtins__': , '__name__': > {'__main__', > '__doc__': None, 'util': 0, '__package__': None} > >>> from pkg import * > >>> globals() > {'__builtins__': , 'M': 8, > {'__package__': > None, 'util': 0, '__name__': '__main__', '__doc__': None, 'mod': > } > >>> > > Now the value of util is unchanged across the pkg import statement. > > Why the difference? As long as you haven't imported the pkg.util module there isn't an "util" variable in the pkg namespace: $ python -c 'import pkg; print "util" in vars(pkg); import pkg.util; print "util" in vars(pkg)' False True Or, sticking closer to your example: $ python -c 'util = 0; from pkg import *; print util' 0 $ python -c 'util = 0; import pkg.util; from pkg import *; print util' From rich at noir.com Tue Jan 10 11:42:53 2012 From: rich at noir.com (K Richard Pixley) Date: Tue, 10 Jan 2012 08:42:53 -0800 Subject: codecs in a chroot / without fs access In-Reply-To: References: Message-ID: On 1/9/12 16:41 , Philipp Hagemeister wrote: > I want to forbid my application to access the filesystem. The easiest > way seems to be chrooting and droping privileges. However, surprisingly, > python loads the codecs from the filesystem on-demand, which makes my > program crash: > >>>> import os >>>> os.getuid() > 0 >>>> os.chroot('/tmp') >>>> ''.decode('raw-unicode-escape') > Traceback (most recent call last): > File "", line 1, in > > (Interestingly, Python goes looking for the literal file "" in > sys.path. Wonder what happens if I touch > /usr/lib/python2.7/dist-packages/). > > Is there a neat way to solve this problem, i.e. have access to all > codecs in a chroot? The traditional solution is to copy the data you want to make available into the subdirectory tree that will be used as the target of the chroot. > If not, I'd love to have a function codecs.preload_all() that does what > my workaround does: > > import codecs,glob,os.path > encs = [os.path.splitext(os.path.basename(f))[0] > for f in glob.glob('/usr/lib/python*/encodings/*.py')] > for e in encs: > try: > codecs.lookup(e) > except LookupError: > pass # __init__.py or something > > > enumerate /usr/lib/python.*/encodings/*.py and call codecs.lookup for > every os.path.splitext(os.path.basename(filename))[0] > > Dou you see any problem with this design? Only the timing. If you're using the shell level chroot(1) program then you're already chroot'd before this can execute. If you're using os.chroot, then: a) you're unix specific b) your program must initially run as root c) you have to drop privilege yourself rather than letting something like chroot(1) handle it. As alternatives, you might consider building a root file system in a file and mounting it separately on a read-only basis. You can chroot into that without much worry of how it will affect your regular file system. With btrfs as root, you can create snapshots and chroot into those. You can even mount them separately, read-only if you like, before chrooting. The advantage of this approach is that the chroot target is built "automatically" in the sense that it's a direct clone of your underlying root file system, without allowing anything in the underlying root file system to be altered. Files can be changed, but since btrfs is copy-on-write, only the files in the snapshot will be changed. --rich From roy at panix.com Tue Jan 10 11:49:43 2012 From: roy at panix.com (Roy Smith) Date: Tue, 10 Jan 2012 08:49:43 -0800 (PST) Subject: Unclear about verbose regex syntax (excaping whitespace) Message-ID: <27946490.520.1326214183718.JavaMail.geo-discussion-forums@vbnm18> The docs for re.VERBOSE say, "Whitespace within the pattern is ignored, except when [...] preceded by an unescaped backslash". It's unclear exactly what that means. If my pattern is: is the second space considered to be preceded by a backslash, and thus taken literally, or does the backslash only apply to the first ? I suspect the latter, but it's somewhat ambiguous. From ulrich.eckhardt at dominolaser.com Tue Jan 10 12:21:16 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 10 Jan 2012 18:21:16 +0100 Subject: replacing __dict__ with an OrderedDict In-Reply-To: References: <4f079690$0$29966$c3e8da3$5496439d@news.astraweb.com> <10504296-daa3-4c3d-b45a-883af99e6804@z19g2000vbe.googlegroups.com> <6u5rt8-971.ln1@satorlaser.homedns.org> Message-ID: Am 10.01.2012 13:31, schrieb Lie Ryan: > While it is possible to replace __dict__ with OrderedDict and it is > possible to reorder the test, those are not his original problem, and > the optimal solution to his original problem differs from the optimal > solution to what he think he will need. Oh, and you know what is optimal in his environment? You really think you know better what to do based on the little information provided? > I had said this before and I'm saying it again: the problem is a test > result displaying issue, not testing order issue. There are good reasons for not reordering the results of the tests that would be sacrificed by reordering them afterwards. If you'd just step off your high horse you might actually learn something instead of just pissing people off. Uli From python.list at tim.thechases.com Tue Jan 10 12:34:36 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 10 Jan 2012 11:34:36 -0600 Subject: Unclear about verbose regex syntax (excaping whitespace) In-Reply-To: <27946490.520.1326214183718.JavaMail.geo-discussion-forums@vbnm18> References: <27946490.520.1326214183718.JavaMail.geo-discussion-forums@vbnm18> Message-ID: <4F0C76AC.7050805@tim.thechases.com> On 01/10/12 10:49, Roy Smith wrote: > The docs for re.VERBOSE say, "Whitespace within the pattern is > ignored, except when [...] preceded by an unescaped > backslash". It's unclear exactly what that means. If my > pattern is: > > > > is the second space considered to be preceded by a backslash, > and thus taken literally, or does the backslash only apply to > the first? I suspect the latter, but it's somewhat > ambiguous. You're right (easily testable) in your suspicions that the second space is ignored in this case. I suppose the documentation could be tweaked to read "immediately preceded". -tkc From badouglas at gmail.com Tue Jan 10 15:24:46 2012 From: badouglas at gmail.com (bruce) Date: Tue, 10 Jan 2012 15:24:46 -0500 Subject: generating unique set of dicts from a list of dicts Message-ID: trying to figure out how to generate a unique set of dicts from a json/list of dicts. initial list ::: [{"pStart1a": {"termVal":"1122","termMenu":"CLASS_SRCH_WRK2_STRM","instVal":"OSUSI", "instMenu":"CLASS_SRCH_WRK2_INSTITUTION","goBtn":"CLASS_SRCH_WRK2_SSR_PB_SRCH", "pagechk":"CLASS_SRCH_WRK2_SSR_PB_SRCH","nPage":"CLASS_SRCH_WRK2_SSR_PB_CLASS_SRCH"}, "pSearch1a": {"chk":"CLASS_SRCH_WRK2_MON","srchbtn":"DERIVED_CLSRCH_SSR_EXPAND_COLLAPS"}}, {"pStart1":""}, {"pStart1a":{"termVal":"1122","termMenu":"CLASS_SRCH_WRK2_STRM","instVal":"OSUSI", "instMenu":"CLASS_SRCH_WRK2_INSTITUTION","goBtn":"CLASS_SRCH_WRK2_SSR_PB_SRCH", "pagechk":"CLASS_SRCH_WRK2_SSR_PB_SRCH","nPage":"CLASS_SRCH_WRK2_SSR_PB_CLASS_SRCH"}, "pSearch1a": {"chk":"CLASS_SRCH_WRK2_MON","srchbtn":"DERIVED_CLSRCH_SSR_EXPAND_COLLAPS"}}, {"pStart1":""}] As an exmple, the following is the test list: [{"pStart1a": {"termVal":"1122","termMenu":"CLASS_SRCH_WRK2_STRM","instVal":"OSUSI", "instMenu":"CLASS_SRCH_WRK2_INSTITUTION","goBtn":"CLASS_SRCH_WRK2_SSR_PB_SRCH", "pagechk":"CLASS_SRCH_WRK2_SSR_PB_SRCH","nPage":"CLASS_SRCH_WRK2_SSR_PB_CLASS_SRCH"}, "pSearch1a": {"chk":"CLASS_SRCH_WRK2_MON","srchbtn":"DERIVED_CLSRCH_SSR_EXPAND_COLLAPS"}}, {"pStart1":""}, {"pStart1a":{"termVal":"1122","termMenu":"CLASS_SRCH_WRK2_STRM","instVal":"OSUSI", "instMenu":"CLASS_SRCH_WRK2_INSTITUTION","goBtn":"CLASS_SRCH_WRK2_SSR_PB_SRCH", "pagechk":"CLASS_SRCH_WRK2_SSR_PB_SRCH","nPage":"CLASS_SRCH_WRK2_SSR_PB_CLASS_SRCH"}, "pSearch1a": {"chk":"CLASS_SRCH_WRK2_MON","srchbtn":"DERIVED_CLSRCH_SSR_EXPAND_COLLAPS"}}, {"pStart1":""}] Trying to get the following, list of unique dicts, so there aren't duplicate dicts. Searched various sites/SO.. and still have a mental block. [ {"pStart1a": {"termVal":"1122","termMenu":"CLASS_SRCH_WRK2_STRM","instVal":"OSUSI", "instMenu":"CLASS_SRCH_WRK2_INSTITUTION","goBtn":"CLASS_SRCH_WRK2_SSR_PB_SRCH", pagechk":"CLASS_SRCH_WRK2_SSR_PB_SRCH","nPage":"CLASS_SRCH_WRK2_SSR_PB_CLASS_SRCH"}, "pSearch1a": {"chk":"CLASS_SRCH_WRK2_MON","srchbtn":"DERIVED_CLSRCH_SSR_EXPAND_COLLAPS"}}, {"pStart1":""}] I was considering iterating through the initial list, copying each dict into a new list, and doing a basic comparison, adding the next dict if it's not in the new list.. is there another/better way? posted this to StackOverflow as well. >>>> http://stackoverflow.com/questions/8808286/simplifying-a-json-list-to-the-unique-dict-items <<< There was a potential soln that I couldn't understand. ------------------------- The simplest approach -- using list(set(your_list_of_dicts)) won't work because Python dictionaries are mutable and not hashable (that is, they don't implement __hash__). This is because Python can't guarantee that the hash of a dictionary won't change after you insert it into a set or dict. However, in your case, since you (don't seem to be) modifying the data at all, you can compute your own hash, and use this along with a dictionary to relatively easily find the unique JSON objects without having to do a full recursive comparison of each dictionary to the others. First, we need a function to compute a hash of the dictionary. Rather than trying to build our own hash function, let's use one of the built-in ones from hashlib: def dict_hash(d): out = hashlib.md5() for key, value in d.iteritems(): out.update(unicode(key)) out.update(unicode(value)) return out.hexdigest() (Note that this relies on unicode(...) for each of your values returning something unique -- if you have custom classes in the dictionaries whose __unicode__ returns something like "MyClass instance", this will fail or will require modification. Also, in your example, your dictionaries are flat, but I'll leave it as an exercise to the reader how to expand this solution to work with dictionaries that contain other dicts or lists.) Since dict_hash returns a string, which is immutable, you can now use a dictionary to find the unique elements: uniques_map = {} for d in list_of_dicts: uniques[dict_hash(d)] = d unique_dicts = uniques_map.values() >>>>*** not sure what the "uniqes" is, or what/how it should be defined.... thoughts/comments are welcome thanks From d at davea.name Tue Jan 10 15:49:27 2012 From: d at davea.name (Dave Angel) Date: Tue, 10 Jan 2012 15:49:27 -0500 Subject: generating unique set of dicts from a list of dicts In-Reply-To: References: Message-ID: <4F0CA457.5040402@davea.name> On 01/10/2012 03:24 PM, bruce wrote: > > Since dict_hash returns a string, which is immutable, you can now use > a dictionary to find the unique elements: > > uniques_map = {} > for d in list_of_dicts: > uniques[dict_hash(d)] = d > unique_dicts = uniques_map.values() > >>>>> *** not sure what the "uniqes" is, or what/how it should be defined.... Don't know about the rest of the message, but I think there's a typo in the above fragment. On the third line, it should be uniques_map, not uniques that you're adding an item to. And unless you have a really long (and strong) hash, you still have to check for actually equal. In otherwords, the above solution will throw out a dict that happens to have the same hash as one already in the uniques_map. Do you trust the "equals" method for your dicts ? If not, that's your first problem. If you do, then you can simply do unique_dicts = [] for d in list_of_dicts: if d not in unique_dicts: unique_dicts.append(d) Do it, then decide if performance is inadequate. Only then should you worry about faster methods, especially if the faster method is broken. -- DaveA From ether.joe at gmail.com Tue Jan 10 16:43:09 2012 From: ether.joe at gmail.com (Sean Wolfe) Date: Tue, 10 Jan 2012 18:43:09 -0300 Subject: open office in another language? Message-ID: I'm a somewhat-satisfied openoffice.org user. I mean it works, but if it weren't in Java I'd be doing some of my own tweaking. But since it's in Java I stay away... no likey. Has there been any talk of doing another similar office suite, or maybe just writer + spreadsheet, in a better language eg python? I expect it's a huge undertaking but ... thought I'd ask around at least. -- A musician must make music, an artist must paint, a poet must write, if he is to be ultimately at peace with himself. - Abraham Maslow From nelle.varoquaux at gmail.com Tue Jan 10 16:53:23 2012 From: nelle.varoquaux at gmail.com (Nelle Varoquaux) Date: Tue, 10 Jan 2012 22:53:23 +0100 Subject: open office in another language? In-Reply-To: References: Message-ID: On 10 January 2012 22:43, Sean Wolfe wrote: > I'm a somewhat-satisfied openoffice.org user. I mean it works, but if > it weren't in Java I'd be doing some of my own tweaking. But since > it's in Java I stay away... no likey. > Small nitpick: Openoffice.org (and LibreOffice) has in fact very little java. The core of it is written in C++, so if you ever want to extend it (unlikely), you won't be dealing with java code. Has there been any talk of doing another similar office suite, or > maybe just writer + spreadsheet, in a better language eg python? I > expect it's a huge undertaking but ... thought I'd ask around at > least. > > -- > A musician must make music, an artist must paint, a poet must write, > if he is to be ultimately at peace with himself. > - Abraham Maslow > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Jan 10 17:01:47 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 Jan 2012 09:01:47 +1100 Subject: I look for a tool like webalizer in python language In-Reply-To: References: Message-ID: On Wed, Jan 11, 2012 at 2:24 AM, St?phane Klein wrote: > Hi, > > I wonder if there are a tool like webalizer in python language. > (http://en.wikipedia.org/wiki/Webalizer). > > I would like to do some patch in webalizer, but I don't want to spend too > many time to do that in C language. In Python I can do this patch in few > minute. > > Do you know a tool like this in Python ? I use AWStats for my sites; it's not Python but Perl, but at least it is a scripting language. You won't find "Webalizer-in-Python" anywhere; whatever analyzer you find will have different features. So just grab any one, give it a shot, and see how you like it! ChrisA From ether.joe at gmail.com Tue Jan 10 17:17:04 2012 From: ether.joe at gmail.com (Sean Wolfe) Date: Tue, 10 Jan 2012 19:17:04 -0300 Subject: open office in another language? In-Reply-To: References: Message-ID: On Tue, Jan 10, 2012 at 6:53 PM, Nelle Varoquaux wrote: > Small nitpick:?Openoffice.org (and LibreOffice) has in fact very little > java. The core of it is written in C++, so if you ever want to extend it > (unlikely), you won't be dealing with java code. > hmm I didn't know this, nice to know. Yes, C++ is still enough overhead that I wouldn't want to try extending it ... I bet the code is a whole lot to try and grok. It would be nice to have an office suite in a newer language that is easier to tinker with. From ben+python at benfinney.id.au Tue Jan 10 17:29:44 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 11 Jan 2012 09:29:44 +1100 Subject: LibreOffice with Python (was: open office in another language?) References: Message-ID: <87aa5v8a3r.fsf@benfinney.id.au> Sean Wolfe writes: > I'm a somewhat-satisfied openoffice.org user. You may know about the change of focus in recent months to LibreOffice . The Document Foundation is where the majority of the project's institutional knowledge, development effort, open collaboration, and all actual released software over the last year now reside. > I mean it works, but if it weren't in Java I'd be doing some of my own > tweaking. But since it's in Java I stay away... no likey. LibreOffice supports scripting with several languages, including Python . Extensions can also be written in Python, using the UNO runtime API . -- \ ?Pinky, are you pondering what I'm pondering?? ?Well, I think | `\ so, Brain, but ?apply North Pole? to what?? ?_Pinky and The | _o__) Brain_ | Ben Finney From tjreedy at udel.edu Tue Jan 10 17:41:54 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 10 Jan 2012 17:41:54 -0500 Subject: Calling a variable inside a function of another class In-Reply-To: <4F0C1AF0.7020101@sequans.com> References: <5a91e124-b6e9-4e2f-88d6-50a33eb496db@k29g2000vbl.googlegroups.com> <4F0C1AF0.7020101@sequans.com> Message-ID: > Yigit Turgut wrote: >> class test(test1): >> >> def __init__(self, device): >> . >> . >> . >> def _something(self, x=1) >> self.dt = data >> >> >> if __name__ == "__main__": >> test.something.dt ??? >> >> I am trying to call a variable located in a function of a class dt is an attribute of an instance of the class. t = test() # create instance t._something() # call method that assigns attribute to t t.dt # is not the value of dt for t -- Terry Jan Reedy From sebastian_rooks at lavabit.c_o_m Tue Jan 10 18:25:56 2012 From: sebastian_rooks at lavabit.c_o_m (Sebastian Rooks) Date: Wed, 11 Jan 2012 00:25:56 +0100 Subject: An "alternative" to Learning Perl References: Message-ID: On Mon, 9 Jan 2012 00:55:22 -0300, Sean Wolfe wrote: >kindle? ipad? tablet? I'm interested in books, not files ... (seriously, now ... I don't have any of those devices) >also there is python programming for the absolute beginner, which is >agreat book but it's pretty beginner. But well written. At least >Iliked it.http://www.amazon.com/Python-Programming-Absolute-Beginner-3rd/dp/1435455002 >Also byte of python ... I think there's a hardcover version you can >buyhttp://www.swaroopch.com/buybook/ I think I saw that second one somewhere already. I'll check out the first link, also. Thanks! -- Sebastian From someone at someplace.invalid Tue Jan 10 18:44:06 2012 From: someone at someplace.invalid (HoneyMonster) Date: Tue, 10 Jan 2012 23:44:06 +0000 (UTC) Subject: Newbie: Looking for code review on my first Python project. Message-ID: Hi, I'm new to Python and recently completed my first project. I used wxPython with wxGlade to generate the GUI bits.The application seems to work well, but I am entirely self-taught, so have undoubtedly committed a number of howlers in terms of style, design, standards, best practice and so forth. Is there any kind soul here who would be willing to take a look at the code and offer comments? The code is at: Thanks From tjreedy at udel.edu Tue Jan 10 19:04:51 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 10 Jan 2012 19:04:51 -0500 Subject: LibreOffice with Python In-Reply-To: <87aa5v8a3r.fsf@benfinney.id.au> References: <87aa5v8a3r.fsf@benfinney.id.au> Message-ID: On 1/10/2012 5:29 PM, Ben Finney wrote: > LibreOffice supports scripting with several languages, including Python > . So that page says. But it only tells how to attach a Python script once writen, not how to write one that will do anything. Are there any links for that? > Extensions can also be written in Python, using the UNO runtime API > . The one Python example imports Python wrappers for the API. Do you have any idea how to get the importable modules? -- Terry Jan Reedy From tjreedy at udel.edu Tue Jan 10 19:56:39 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 10 Jan 2012 19:56:39 -0500 Subject: UnicodeEncodeError in compile In-Reply-To: <3c9fd9e7-6a0e-40cc-a048-1a82e477c013@p4g2000vbt.googlegroups.com> References: <9043309.329.1326169476466.JavaMail.geo-discussion-forums@yqhi24> <3c9fd9e7-6a0e-40cc-a048-1a82e477c013@p4g2000vbt.googlegroups.com> Message-ID: On 1/10/2012 8:43 AM, jmfauth wrote: > D:\>c:\python32\python.exe > Python 3.2.2 (default, Sep 4 2011, 09:51:08) [MSC v.1500 32 bit > (Intel)] on win > 32 > Type "help", "copyright", "credits" or "license" for more information. >>>> '\u5de5'.encode('utf-8') > b'\xe5\xb7\xa5' >>>> '\u5de5'.encode('mbcs') > Traceback (most recent call last): > File "", line 1, in > UnicodeEncodeError: 'mbcs' codec can't encode characters in position > 0--1: inval > id character > D:\>c:\python27\python.exe > Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit > (Intel)] on win > 32 > Type "help", "copyright", "credits" or "license" for more information. >>>> u'\u5de5'.encode('utf-8') > '\xe5\xb7\xa5' >>>> u'\u5de5'.encode('mbcs') > '?' mbcs encodes according to the current codepage. Only the chinese codepage(s) can encode the chinese char. So the unicode error is correct and 2.7 has a bug in that it is doing "errors='replace'" when it supposedly is doing "errors='strict'". The Py3 fix was done in http://bugs.python.org/issue850997 2.7 was intentionally left alone because of back-compatibility considerations. (None of this addresses the OP's question.) -- Terry Jan Reedy From ben+python at benfinney.id.au Tue Jan 10 19:59:30 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 11 Jan 2012 11:59:30 +1100 Subject: LibreOffice with Python References: <87aa5v8a3r.fsf@benfinney.id.au> Message-ID: <8762gj8365.fsf@benfinney.id.au> Terry Reedy writes: > Are there any links for that? [?] > Do you have any idea how to get the importable modules? Those will have to be exercises for someone with more need than I of hacking on an office suite. I have no experience with that. -- \ ?Your [government] representative owes you, not his industry | `\ only, but his judgment; and he betrays, instead of serving you, | _o__) if he sacrifices it to your opinion.? ?Edmund Burke, 1774 | Ben Finney From ian.g.kelly at gmail.com Tue Jan 10 20:17:48 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 10 Jan 2012 18:17:48 -0700 Subject: Newbie: Looking for code review on my first Python project. In-Reply-To: References: Message-ID: On Tue, Jan 10, 2012 at 4:44 PM, HoneyMonster wrote: > Hi, > > I'm new to Python and recently completed my first project. I used > wxPython with wxGlade to generate the GUI bits.The application seems to > work well, but I am entirely self-taught, so have undoubtedly committed a > number of howlers in terms of style, design, standards, best practice and > so forth. > > Is there any kind soul here who would be willing to take a look at the > code and offer comments? ?The code is at: > Okay, here goes. :-) # Globals Title = 0 Episode = 1 Categories = 2 Channel = 3 PID = 4 Index = 5 The recommended PEP-8 style for names of constants is ALL_CAPS. Also, if you just have a simple enumeration like this, you can avoid setting specific values, which might otherwise lead to the temptation to use the values in some places instead of the constant names. Just tell your program how to generate them, and let it do the work: TITLE, EPISODE, CATEGORIES, CHANNEL, PID, INDEX = range(6) ===== # Error handling: Log to file, show message and abort def ProcessError(text): logging.exception(text) dlg = wx.MessageDialog(None, text + " " + str(sys.exc_info()[1]) + \ "\nSee " + log + " for details.", "BBC Programmes", \ wx.ICON_ERROR|wx.OK) dlg.ShowModal() dlg.Destroy() sys.exit() In the more recent versions of wxPython, which I assume you're using, dialogs provide context managers to handle their destruction. The above would become: def process_error(text): logging.exception(text) with wx.MessageDialog(...) as dlg: dlg.ShowModal() sys.exit() The value of the context manager is that its __exit__ method (which destroys the dialog) is guaranteed to be called when the with block exits, even if an exception is raised inside of it. You'll note I also renamed the function using the PEP-8 style for functions. Another comment here is that the text of the dialog is a good candidate for Python's string formatting feature. Instead of: text + " " + str(sys.exc_info()[1]) + "\nSee " + log + " for details." do: "{} {}\nSee {} for details.".format(text, sys.exc_info()[1], log) which is more legible and also avoids doing multiple string concatenations. ===== class clsUtils(): The parentheses are redundant; this is equivalent to "class clsUtils:". Note that in Python 2.x, classes defined without a base class are old-style classes by default, which have been removed in Python 3. It's recommended that you use new-style classes in your code unless you have a good reason not to. You can accomplish this by inheriting from object explicitly: class Utils(object): Note I also converted the class name to the PEP-8 CapWords convention for classes, and I dropped the redundant 'cls' prefix. My other comment on this class is that it has no state, and no methods apart from __init__. You apparently only instantiate it in order to execute the __init__ method, which seems to initialize some global variables rather than initializing the class instance. If you don't plan on interacting with the Utils instance as an object, then this would make more sense as a function. ===== def OnDescription(self, event): # wxGlade: MyFrame. wx.BeginBusyCursor() if Linux: wx.Yield() pos = self.TopGrid.GetGridCursorRow() TitleEp = self.Prettify(recs[pos][Title], recs[pos][Episode]) self.TopFrame_statusbar.SetStatusText("Retrieving description for " + TitleEp) info = subprocess.check_output("get_iplayer --info " + str(recs[pos][Index]), shell=True) info = str.splitlines(info, False) for line in info: if line[:5] == "desc:": info = line[16:] break wx.EndBusyCursor() ... The BusyCursor is another resource that provides a context manager. You can use it like this: def on_description(self, event): # wxGlade: MyFrame. with wx.BusyCursor(): ... This is a good idea since if an exception is raised in the middle of the method, the mouse pointer won't end up stuck as an hourglass. Also note that I once again meddled with the naming style to conform with PEP-8, this time for the method name. Further, this line: info = str.splitlines(info, False) could be written simply as: info = info.splitlines(False) ===== def OnIdle(self, event): # Instantiate the other classes here, then hand over to TopFrame if self.first_time: self.first_time = False ... An idle event handler is the wrong paradigm here. Idle events are for background computation that you need to do regularly whenever the application becomes idle. For the simpler case of a one-time function call that should not run until after the event loop has started, use the wx.CallAfter() function. ===== I don't have any more specific observations. The only other thing I would comment on is that you seem to be using a fair number of global variables. Your components would be more readily reusable if you would avoid using globals and stick to stateful objects instead. Cheers, Ian From wuwei23 at gmail.com Tue Jan 10 20:20:08 2012 From: wuwei23 at gmail.com (alex23) Date: Tue, 10 Jan 2012 17:20:08 -0800 (PST) Subject: how to install lxml in window xp? References: Message-ID: <7072a93e-4cb5-45a2-8848-02f493255023@p42g2000vbt.googlegroups.com> On Jan 9, 8:19?pm, Stefan Behnel wrote: > Note that lxml currently lacks binary Windows builds for its latest > releases. There are eggs for the original 2.3 release, though. Christoph Gohlke provides a fairly up-to-date set of Python packaged binaries for Windows 32- & 64-bit. There are lxml packages for Python 2.6 to 3.2, and 2.5 for 32-bit only. http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml This is a fantastic resource that more Windows-based Python devs should know about. From edriscoll at wisc.edu Tue Jan 10 20:26:15 2012 From: edriscoll at wisc.edu (Evan Driscoll) Date: Tue, 10 Jan 2012 19:26:15 -0600 Subject: Introspecting optparse/argparse objects Message-ID: <4F0CE537.3010803@wisc.edu> I'd like to be able to be able to define options and then look at the lists. (For a concrete idea of a use case, suppose that it did not directly support the --help option and I wanted to write code that took its place.) Unfortunately, there doesn't seem to be any public API for doing this. Even if I were to do something like options = [ make_option(...), make_option(...) ] (using optparse) and could thus get a handle on the Option objects, there doesn't seem to be a public API for retrieving stuff like the actual options (though available via opt._short_opts and opt._long_opts). This means that either I need to write my own wrappers around options, option groups, and perhaps even an option parser, or I have to dig into _variables _that _are _not _part _of _the _public _api. Both of those choices are distasteful. So, 1) Did I miss anything? 2) Is there some particular reason that this API *isn't* provided, and if I asked for it I might get it in a future version? 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 rosuav at gmail.com Tue Jan 10 20:43:13 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 Jan 2012 12:43:13 +1100 Subject: Newbie: Looking for code review on my first Python project. In-Reply-To: References: Message-ID: On Wed, Jan 11, 2012 at 10:44 AM, HoneyMonster wrote: > Hi, > > I'm new to Python and recently completed my first project. I used > wxPython with wxGlade to generate the GUI bits.The application seems to > work well, but I am entirely self-taught, so have undoubtedly committed a > number of howlers in terms of style, design, standards, best practice and > so forth. Welcome! Ian has already offered some excellent tips, so I'll not repeat him. log = os.environ['HOME'] + "/log/bbc.log" log = os.environ['HOMEPATH'] + "\\log\\bbc.log" Python on Windows will support / for paths; I'd then break out the HOME / HOMEPATH check into a separate variable (eg 'basepath'), and then only that and icondir would need to be in the 'if Linux' block. about = "Built by Walter Hurry using Python and wxPython,\n" + \ "with wxGlade to generate the code for the GUI elements.\n" + \ "Phil Lewis' get_iplayer does the real work.\n\n" + \ "Version 1.05: January 10, 2012" I'd do this with a triple-quoted string: about = """Built by Walter Hurry using Python and wxPython, with wxGlade to generate the code for the GUI elements. Phil Lewis' get_iplayer does the real work. Version 1.05: January 10, 2012""" # Configure the logging # Generate a list for the PVR queue Comments like this aren't much use, although the second would be a good place to expand "PVR". # We only want the PID at the start if the line, and it is always 8 bytes Much more useful :) self.add = wx.MenuItem(self.file, wx.NewId(), "&Add to Queue", "Add a programme to the queue (for download later)", wx.ITEM_NORMAL) self.file.AppendItem(self.add) I don't have/use wxpython so I can't say for sure, but I think AppendItem returns the item appended. This allows you to avoid repeating yourself: self.add = self.file.AppendItem(wx.MenuItem(self.file, wx.NewId(), "&Add to Queue", "Add a programme to the queue (for download later)", wx.ITEM_NORMAL)) This prevents mismatching assignment and append, when you copy/paste/edit etc. Decent bit of code. I've seen far worse... and not from new programmers :) Chris Angelico From tjreedy at udel.edu Tue Jan 10 20:50:18 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 10 Jan 2012 20:50:18 -0500 Subject: Newbie: Looking for code review on my first Python project. In-Reply-To: References: Message-ID: On 1/10/2012 8:17 PM, Ian Kelly wrote: > On Tue, Jan 10, 2012 at 4:44 PM, HoneyMonster wrote: >> Hi, >> >> I'm new to Python and recently completed my first project. I used >> wxPython with wxGlade to generate the GUI bits.The application seems to >> work well, but I am entirely self-taught, so have undoubtedly committed a >> number of howlers in terms of style, design, standards, best practice and >> so forth. >> >> Is there any kind soul here who would be willing to take a look at the >> code and offer comments? The code is at: >> > > Okay, here goes. :-) Nice review. Though OP used and you wrote about wx, when I get deeper into the IDLE code, I will look to see whether tkinter/idle resource provide context managers (if not, try to add) and whether idle is using them. (I won't be surprised if answers are often no and no.) -- Terry Jan Reedy From tjreedy at udel.edu Tue Jan 10 20:53:15 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 10 Jan 2012 20:53:15 -0500 Subject: your feedback to my first project please In-Reply-To: <4F0C45FA.2060505@sequans.com> References: <4F0C45FA.2060505@sequans.com> Message-ID: On 1/10/2012 9:06 AM, Jean-Michel Pichavant wrote: > - I quite dislike your avg method which does more than averaging, it > also inserts a value and removes another modifying the object in place. > It could be very confusing for someone reading your code. Fortunately, > you have documented it, that makes it acceptable. Why don't you make avg > only averaging. Surely you can use the add method right before. Or use a better name, like running_average or run_mean (if that is what it is doing). -- Terry Jan Reedy From ben+python at benfinney.id.au Tue Jan 10 21:05:38 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 11 Jan 2012 13:05:38 +1100 Subject: Newbie: Looking for code review on my first Python project. References: Message-ID: <871ur7803x.fsf@benfinney.id.au> Chris Angelico writes: > On Wed, Jan 11, 2012 at 10:44 AM, HoneyMonster > wrote: > > Hi, > > > > I'm new to Python and recently completed my first project. I used > > wxPython with wxGlade to generate the GUI bits.The application seems to > > work well, but I am entirely self-taught, so have undoubtedly committed a > > number of howlers in terms of style, design, standards, best practice and > > so forth. > > Welcome! > > Ian has already offered some excellent tips, so I'll not repeat him. > > > log = os.environ['HOME'] + "/log/bbc.log" > log = os.environ['HOMEPATH'] + "\\log\\bbc.log" > > Python on Windows will support / for paths Even better, you don't need to worry about what separator to use:: top_dir = os.environ['HOME'] log_filepath = os.path.join(top_dir, "log", "bbc.log") > I'd do this with a triple-quoted string: > > about = """Built by Walter Hurry using Python and wxPython, > with wxGlade to generate the code for the GUI elements. > Phil Lewis' get_iplayer does the real work. > > Version 1.05: January 10, 2012""" Which you can get indented nicely in the source, and strip off the indentation at run-time: import textwrap about = textwrap.dedent("""\ Built by Walter Hurry using Python and wxPython, with wxGlade to generate the code for the GUI elements. Phil Lewis' get_iplayer does the real work. Version 1.05: January 10, 2012 """) > self.add = self.file.AppendItem(wx.MenuItem(self.file, > wx.NewId(), "&Add to Queue", "Add a programme to the queue (for > download later)", wx.ITEM_NORMAL)) Which is a whole lot more readable using the recommendations in PEP 8:: self.add = self.file.AppendItem( wx.MenuItem( self.file, wx.NewId(), "&Add to Queue", "Add a programme to the queue (for download later)", wx.ITEM_NORMAL)) -- \ ?I distrust those people who know so well what God wants them | `\ to do to their fellows, because it always coincides with their | _o__) own desires.? ?Susan Brownell Anthony, 1896 | Ben Finney From roy at panix.com Tue Jan 10 21:47:54 2012 From: roy at panix.com (Roy Smith) Date: Tue, 10 Jan 2012 21:47:54 -0500 Subject: replacing __dict__ with an OrderedDict References: <11jrt8-l32.ln1@satorlaser.homedns.org> Message-ID: In article , Lie Ryan wrote: > >> All serious database has rollback feature when they're available to > >> quickly revert database state in the setUp/cleanUp phase. > > > > I guess MongoDB is not a serious database? > > I guess there are always those oddball cases, but if you choose MongoDB > then you already know the consequences that it couldn't be as easily > unit-tested. And in any case, it is generally a bad idea to unittest > with a database that contains 100 million items, that's for performance > testing. So your point is? My point is that in the real world, what is practical and efficient and sound business is not always what is theoretically correct. From edriscoll at wisc.edu Tue Jan 10 22:20:31 2012 From: edriscoll at wisc.edu (Evan Driscoll) Date: Tue, 10 Jan 2012 21:20:31 -0600 Subject: Ctypes compatibility Message-ID: <4F0CFFFF.80202@wisc.edu> Might as well ask another question of the list. I've written a ctypes-based Python wrapper around the 'readdir' function. (I want access to the dt_type field of the result, without calling stat().) However, it feels very... fragile. What happens on a different *nix which uses a different size of integers? Is Linux even consistent between 32 and 64 bits? (That's a rhetorical question.) What happens on a different *nix with the fields in a different order, or without a dt_type field? It somehow feels wrong that you get way less help with this than you would get even from C. Is that just how it is with ctypes? Or is there some way around it? I'm sort of tempted to write a C module whose sole purpose is to wrap readdir... 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 tjreedy at udel.edu Tue Jan 10 22:50:51 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 10 Jan 2012 22:50:51 -0500 Subject: UnicodeEncodeError in compile In-Reply-To: References: <9043309.329.1326169476466.JavaMail.geo-discussion-forums@yqhi24> Message-ID: On 1/10/2012 3:08 AM, Terry Reedy wrote: > On 1/9/2012 11:24 PM, pyscripter at gmail.com wrote: >> Using python 3.2 in Windows 7 I am getting the following: >> >>>> compile('pass', r'c:\temp\??\module1.py', 'exec') Is this a filename that could be an actual, valid filename on your system? >> UnicodeEncodeError: 'mbcs' codec can't encode characters in position >> 0--1: invalid character >> >> Can anybody explain why the compile statement tries to convert the >> unicode filename using mbcs? Good question. I believe this holdover from 2.x should be deleted. I argued that in http://bugs.python.org/issue10114 (which was about a different problem) and now, directly, in http://bugs.python.org/issue13758 If you (or anyone) can make a better argument for the requested change, or for also changing compile on *nix, than I did, please do so. -- Terry Jan Reedy From tjreedy at udel.edu Tue Jan 10 22:59:23 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 10 Jan 2012 22:59:23 -0500 Subject: Newbie: Looking for code review on my first Python project. In-Reply-To: References: Message-ID: On 1/10/2012 8:43 PM, Chris Angelico wrote: > about = "Built by Walter Hurry using Python and wxPython,\n" + \ > "with wxGlade to generate the code for the GUI elements.\n" + \ > "Phil Lewis' get_iplayer does the real work.\n\n" + \ > "Version 1.05: January 10, 2012" > > I'd do this with a triple-quoted string: > > about = """Built by Walter Hurry using Python and wxPython, > with wxGlade to generate the code for the GUI elements. > Phil Lewis' get_iplayer does the real work. I would too, but if you prefer the indentation, just leave out the '+'s and let Python do the catenation when compiling: >>> s = "abc\n" \ "def\n"\ "ghi" >>> s 'abc\ndef\nghi' -- Terry Jan Reedy From jeffb0098 at gmail.com Tue Jan 10 23:21:15 2012 From: jeffb0098 at gmail.com (Jeffrey Britton) Date: Tue, 10 Jan 2012 20:21:15 -0800 (PST) Subject: cx_Freeze ImportError, how do I debug this Message-ID: <26d2854e-2a4f-4136-9754-1bb3a935c8f1@v14g2000yqh.googlegroups.com> I am building a standalone Windows executable using cx_Freeze. The resulting executable will not run and writes the following error to the console. ImportError: could not import gobject (error was: 'No module named gobject') The project using the gtk libraries for Cairo and Pango on Windows. The program runs fine when run with Python. I have tried copying anything that cx_Freeze may have missed from the gtk installation under the Python directory. My question is, is there a method to debug this, that can tell me more about what is going on? The executable directory already contains _gobject.pyd libgobject-2.0-0.dll libcairo-gobject-2.dll and a bunch of other stuff. I can type import gobject in the Python shell and that works. From steve+comp.lang.python at pearwood.info Tue Jan 10 23:24:21 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Jan 2012 04:24:21 GMT Subject: Newbie: Looking for code review on my first Python project. References: Message-ID: <4f0d0ef5$0$29870$c3e8da3$5496439d@news.astraweb.com> On Tue, 10 Jan 2012 22:59:23 -0500, Terry Reedy wrote: > On 1/10/2012 8:43 PM, Chris Angelico wrote: > >> about = "Built by Walter Hurry using Python and wxPython,\n" + \ >> "with wxGlade to generate the code for the GUI elements.\n" + >> \ "Phil Lewis' get_iplayer does the real work.\n\n" + \ >> "Version 1.05: January 10, 2012" >> >> I'd do this with a triple-quoted string: >> >> about = """Built by Walter Hurry using Python and wxPython, with >> wxGlade to generate the code for the GUI elements. Phil Lewis' >> get_iplayer does the real work. > > I would too, but if you prefer the indentation, just leave out the '+'s > and let Python do the catenation when compiling: > >>> s = "abc\n" \ > "def\n"\ > "ghi" > >>> s > 'abc\ndef\nghi' Actually, in recent Pythons (2.5 or better, I believe) the peephole optimizer will do the concatenation at compile time even if you leave the + signs in, provided that the parts are all literals. >>> from dis import dis >>> dis(compile(r's = "a\n" + "b\n"', '', 'single')) 1 0 LOAD_CONST 3 ('a\nb\n') 3 STORE_NAME 0 (s) 6 LOAD_CONST 2 (None) 9 RETURN_VALUE -- Steven From phamp at mindspring.com Tue Jan 10 23:34:27 2012 From: phamp at mindspring.com (pyotr filipivich) Date: Tue, 10 Jan 2012 20:34:27 -0800 Subject: Lumberjack Song References: Message-ID: <984qg75m9j0q21ouhd6fr2tavrqdj34i51@4ax.com> Tom Zych on Mon, 28 Feb 2011 05:26:35 -0500 typed in comp.lang.python the following: >We all like computers here. No doubt many of us like computer games. >And most of us will be at least somewhat familiar with Monty Python. >Therefore, I present (drum roll)... > >http://www.youtube.com/watch?v=Zh-zL-rhUuU > >(For the Runescape fans out there, this should be quite hilarious. >Possibly not as much for those unfamiliar with Runescape...) Look for the version in German. Viel Spass. tschus pyotr -- APL is a mistake, carried through to perfection. It is the language of the future for the programming techniques of the past: it creates a new generation of coding bums. -- Edsger W. Dijkstra, SIGPLAN Notices, Volume 17, Number 5 From jeffb0098 at gmail.com Tue Jan 10 23:38:29 2012 From: jeffb0098 at gmail.com (Jeffrey Britton) Date: Tue, 10 Jan 2012 20:38:29 -0800 (PST) Subject: cx_Freeze ImportError, how do I debug this References: <26d2854e-2a4f-4136-9754-1bb3a935c8f1@v14g2000yqh.googlegroups.com> Message-ID: On Jan 10, 8:21?pm, Jeffrey Britton wrote: > I am building a standalone Windows executable using cx_Freeze. > The resulting executable will not run and writes the following error > to the console. > > ImportError: could not import gobject (error was: 'No module named > gobject') > > The project using the gtk libraries for Cairo and Pango on Windows. > The program runs fine when run with Python. > I have tried copying anything that cx_Freeze may have missed from the > gtk installation under the Python directory. > > My question is, is there a method to debug this, that can tell me more > about what is going on? > > The executable directory already contains > _gobject.pyd > libgobject-2.0-0.dll > libcairo-gobject-2.dll > and a bunch of other stuff. > > I can type > import gobject > in the Python shell and that works. I just realized that I can import just Cairo and build and executable. However, a test script with simply import Pango print 'hello' fails. This time I tried building with PyInstaller and I get the same error about not being able to load gobject. From alec.taylor6 at gmail.com Tue Jan 10 23:42:47 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Wed, 11 Jan 2012 15:42:47 +1100 Subject: Ctypes compatibility In-Reply-To: <4F0CFFFF.80202@wisc.edu> References: <4F0CFFFF.80202@wisc.edu> Message-ID: Use size_t http://en.wikipedia.org/wiki/C_data_types#Size_and_pointer_difference_types On Wed, Jan 11, 2012 at 2:20 PM, Evan Driscoll wrote: > Might as well ask another question of the list. > > I've written a ctypes-based Python wrapper around the 'readdir' > function. (I want access to the dt_type field of the result, without > calling stat().) > > However, it feels very... fragile. What happens on a different *nix > which uses a different size of integers? Is Linux even consistent > between 32 and 64 bits? (That's a rhetorical question.) What happens on > a different *nix with the fields in a different order, or without a > dt_type field? > > It somehow feels wrong that you get way less help with this than you > would get even from C. Is that just how it is with ctypes? Or is there > some way around it? I'm sort of tempted to write a C module whose sole > purpose is to wrap readdir... > > Evan > > > > -- > http://mail.python.org/mailman/listinfo/python-list > From ben+python at benfinney.id.au Wed Jan 11 00:23:01 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 11 Jan 2012 16:23:01 +1100 Subject: Newbie: Looking for code review on my first Python project. References: Message-ID: <87wr8y7qyy.fsf@benfinney.id.au> Terry Reedy writes: > I would too, but if you prefer the indentation, just leave out the > '+'s and let Python do the catenation when compiling: Or use a trimple quoted string, with indentation in the source, and use Python's batteries to manage it at runtime. Best of both worlds . -- \ ?I have an answering machine in my car. It says, ?I'm home now. | `\ But leave a message and I'll call when I'm out.?? ?Steven Wright | _o__) | Ben Finney From wxjmfauth at gmail.com Wed Jan 11 02:05:27 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Tue, 10 Jan 2012 23:05:27 -0800 (PST) Subject: UnicodeEncodeError in compile References: <9043309.329.1326169476466.JavaMail.geo-discussion-forums@yqhi24> <3c9fd9e7-6a0e-40cc-a048-1a82e477c013@p4g2000vbt.googlegroups.com> Message-ID: <362fecda-1d4a-42d1-8139-4a3b340e44fb@h13g2000vbn.googlegroups.com> On 11 jan, 01:56, Terry Reedy wrote: > On 1/10/2012 8:43 AM, jmfauth wrote: > > ... > > mbcs encodes according to the current codepage. Only the chinese > codepage(s) can encode the chinese char. So the unicode error is correct > and 2.7 has a bug in that it is doing "errors='replace'" when it > supposedly is doing "errors='strict'". The Py3 fix was done inhttp://bugs.python.org/issue850997 > 2.7 was intentionally left alone because of back-compatibility > considerations. (None of this addresses the OP's question.) > > -- win7, cp1252 Ok. I was not aware of this. >>> '\N{CYRILLIC SMALL LETTER A}'.encode('mbcs') Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: invalid character >>> '\N{GREEK SMALL LETTER ALPHA}'.encode('mbcs') Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: invalid character jmf From contropinion at gmail.com Wed Jan 11 02:13:43 2012 From: contropinion at gmail.com (contro opinion) Date: Wed, 11 Jan 2012 15:13:43 +0800 Subject: how to put code on the google app and run it Message-ID: there is a simple code,which can run locally ,and get three csv file in c:/ #coding:utf-8 import urllib import re import os exchange=['NASDAQ','NYSE','AMEX'] for down in exchange: myfile=open('c:/'+down,'w') url=' http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange='+down+'&render=download ' file=urllib.urlopen(url).read() myfile.write(file) print 'ok',down myfile.close() i want to upload it onto my google app (i have one google app account)and let it run on 4 o'clock (with cron) ,and let the downloaded data on my google app, how to do ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From dihedral88888 at googlemail.com Wed Jan 11 02:16:35 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 10 Jan 2012 23:16:35 -0800 (PST) Subject: open office in another language? In-Reply-To: References: Message-ID: <27551273.556.1326266195884.JavaMail.geo-discussion-forums@prhb20> I remembered that the open office was started to promote java long time ago by Sun selling work stations. But the project ended to be practical. From dihedral88888 at googlemail.com Wed Jan 11 02:16:35 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 10 Jan 2012 23:16:35 -0800 (PST) Subject: open office in another language? In-Reply-To: References: Message-ID: <27551273.556.1326266195884.JavaMail.geo-discussion-forums@prhb20> I remembered that the open office was started to promote java long time ago by Sun selling work stations. But the project ended to be practical. From emekamicro at gmail.com Wed Jan 11 02:57:43 2012 From: emekamicro at gmail.com (Emeka) Date: Wed, 11 Jan 2012 09:57:43 +0200 Subject: MySQLdb Error Message-ID: Hello All, I got the below error why trying to create tables of the fly. for item in ['CREATE TABLE AddressTables ( AddressTables_id int (9) unsigned primary key auto_increment not null, city_name char(40) , state_name varchar, street_number int, country_name varchar, street_name char(40) , user_name char(40) references usertables(name))', 'CREATE TABLE UserTables ( age int, UserTables_id int (9) unsigned primary key auto_increment not null, name char(40) , place_of_birth varchar)']: cursor.execute(item) I receive the following errors. File "mor.py", line 98, in cursor.execute(item) File "/usr/lib/pymodules/python2.7/MySQLdb/cursors.py", line 166, in execute self.errorhandler(self, exc, value) File "/usr/lib/pymodules/python2.7/MySQLdb/connections.py", line 35, in defaulterrorhandler raise errorclass, errorvalue _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' street_number int, country_name varchar, street_name char(40) , user_name ch' at line 1") * Regards,* *Emeka * -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Jan 11 04:00:07 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 11 Jan 2012 20:00:07 +1100 Subject: MySQLdb Error In-Reply-To: References: Message-ID: On Wed, Jan 11, 2012 at 6:57 PM, Emeka wrote: > CREATE TABLE AddressTables ( AddressTables_id int (9) unsigned > primary key auto_increment not null, ?city_name char(40) , ?state_name > varchar, ?street_number int, ?country_name varchar, ?street_name char(40) , > user_name char(40) references usertables(name)) > > _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL > syntax; check the manual that corresponds to your MySQL server version for > the right syntax to use near ' ?street_number int, ?country_name varchar, > ?street_name char(40) , user_name ch' at line 1") You're getting an error back from the database. The message suggests that you look around the place cited for some kind of syntactic error. See if you can find the error; often, in situations like this, the actual error is a little bit before what's pointed to. Have a look, I'll wait. Spoiler alert! Try figuring it out yourself before you scroll down. You've been warned! There are spoilers ahead. Okay. The problem is that MySQL requires varchar to be followed by a length: varchar(255) or varchar(32) or whatever. The use of naked 'varchar' is a PostgreSQL feature only. Hope that helps! Chris Angelico From stefan_ml at behnel.de Wed Jan 11 04:08:46 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 11 Jan 2012 10:08:46 +0100 Subject: open office in another language? In-Reply-To: References: Message-ID: Sean Wolfe, 10.01.2012 22:43: > I'm a somewhat-satisfied openoffice.org user. I mean it works, but if > it weren't in Java I'd be doing some of my own tweaking. But since > it's in Java I stay away... no likey. It's been in C++ ever since the old StarOffice days, others have commented on that already. Java is only one way of extending it, and it's not even required by the installation. > Has there been any talk of doing another similar office suite, or > maybe just writer + spreadsheet, in a better language eg python? I > expect it's a huge undertaking but ... thought I'd ask around at > least. OOo has been fully scriptable in Python for ages. It even comes with an embedded Python runtime for that purpose (at least on non-package-management systems like Windows). So, Python is actually a standard component in all installations, whereas Java is not, and is therefore not necessarily available in a deployment. Basically, if you want your scripts to run in all OpenOffice/LibreOffice installations, you either have to write it in StarBasic, or use Python. The OOo extension API is called UNO, so look for the PyUNO bridge. Admittedly, it's somewhat badly documented, but it basically works the same way as the other UNO-API incarnations in other languages, so any UNO documentation will generally apply just fine. Also look for LibreOffice, as Ben Finney hinted. Since Oracle dropped Sun's OOo commitment, many regard it as the future of OOo. It's certainly the place where the development happens these days. Stefan From wxjmfauth at gmail.com Wed Jan 11 04:29:26 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Wed, 11 Jan 2012 01:29:26 -0800 (PST) Subject: UnicodeEncodeError in compile References: <9043309.329.1326169476466.JavaMail.geo-discussion-forums@yqhi24> <3c9fd9e7-6a0e-40cc-a048-1a82e477c013@p4g2000vbt.googlegroups.com> Message-ID: On 11 jan, 01:56, Terry Reedy wrote: > On 1/10/2012 8:43 AM, jmfauth wrote: > > > > > D:\>c:\python32\python.exe > > Python 3.2.2 (default, Sep ?4 2011, 09:51:08) [MSC v.1500 32 bit > > (Intel)] on win > > 32 > > Type "help", "copyright", "credits" or "license" for more information. > >>>> '\u5de5'.encode('utf-8') > > b'\xe5\xb7\xa5' > >>>> '\u5de5'.encode('mbcs') > > Traceback (most recent call last): > > ? ?File "", line 1, in > > UnicodeEncodeError: 'mbcs' codec can't encode characters in position > > 0--1: inval > > id character > > D:\>c:\python27\python.exe > > Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit > > (Intel)] on win > > 32 > > Type "help", "copyright", "credits" or "license" for more information. > >>>> u'\u5de5'.encode('utf-8') > > '\xe5\xb7\xa5' > >>>> u'\u5de5'.encode('mbcs') > > '?' > > mbcs encodes according to the current codepage. Only the chinese > codepage(s) can encode the chinese char. So the unicode error is correct > and 2.7 has a bug in that it is doing "errors='replace'" when it > supposedly is doing "errors='strict'". The Py3 fix was done inhttp://bugs.python.org/issue850997 > 2.7 was intentionally left alone because of back-compatibility > considerations. (None of this addresses the OP's question.) > > -- Ok. I was not aware of this. PS Prev. post gets lost. From info at egenix.com Wed Jan 11 04:41:43 2012 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Wed, 11 Jan 2012 10:41:43 +0100 Subject: ANN: eGenix mx Base Distribution 3.2.2 (mxDateTime, mxTextTools, etc.) Message-ID: <4F0D5957.1050802@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mx Base Distribution Version 3.2.2 for Python 2.4 - 2.7 Open Source Python extensions providing important and useful services for Python programmers. This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mx-Base-Distribution-3.2.2-GA.html ________________________________________________________________________ ABOUT The eGenix.com mx Base Distribution for Python is a collection of professional quality software tools which enhance Python's usability in many important areas such as fast text searching, date/time processing and high speed data types. The tools have a proven record of being portable across many Unix and Windows platforms. You can write applications which use the tools on Windows and then run them on Unix platforms without change due to the consistent platform independent interfaces. Contents of the distribution: * mxDateTime - Easy to use Date/Time Library for Python * mxTextTools - Fast Text Parsing and Processing Tools for Python * mxProxy - Object Access Control for Python * mxBeeBase - On-disk B+Tree Based Database Kit for Python * mxURL - Flexible URL Data-Type for Python * mxUID - Fast Universal Identifiers for Python * mxStack - Fast and Memory-Efficient Stack Type for Python * mxQueue - Fast and Memory-Efficient Queue Type for Python * mxTools - Fast Everyday Helpers for Python The package also include a number of helpful smaller modules in the mx.Misc subpackage, such as mx.Misc.ConfigFile for config file parsing or mx.Misc.CommandLine to quickly write command line applications in Python. All available packages have proven their stability and usefulness in many mission critical applications and various commercial settings all around the world. For more information, please see the distribution page: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ NEWS The 3.2.2 release of the eGenix mx Base Distribution is the latest release of our open-source Python extensions. The new patch-level version includes a few important fixes: * mxDateTime seconds rounding is now more careful to not show 60.00 or 61.00 as second value. * mxDateTime will now correctly work with numeric arrays (numpy) again. Thanks to Christian Marquardt for reporting the problem. * mxDateTime's DateTimeFromAbsDateTime() now accepts leap second values (86400.0 - <86401.0) as well. Thanks to Christian Marquardt for reporting the problem. * Enhanced mx.Misc.ConfigFile. Please see the changelog for details (URL listed below). If you are upgrading from eGenix mx Base 3.1.x, please also see the eGenix mx Base Distribution 3.2.0 release notes for details on what has changed and which new features are available: http://www.egenix.com/company/news/eGenix-mx-Base-Distribution-3.2.0-GA.html As always, we are providing pre-built binaries for all common platforms: Windows 32/64-bit, Linux 32/64-bit, FreeBSD 32/64-bit, Mac OS X 32/64-bit. Source code archives are available for installation on all other Python platforms, such as Solaris, AIX, HP-UX, etc. To simplify installation in Zope/Plone and other egg-based systems, we have also precompiled egg distributions for all platforms. These are available on our own PyPI-style index server for easy and automatic download. Whether you are using a pre-built package or the source distribution, installation is a simple "python setup.py install" command in all cases. The only difference is that the pre-built packages do not require a compiler or the Python development packages to be installed. For a full list of changes, please refer to the eGenix mx Base Distribution change log at http://www.egenix.com/products/python/mxBase/changelog.html and the change logs of the various included Python packages. ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the packages can be found on the eGenix mx Base Distribution page: http://www.egenix.com/products/python/mxBase/ ________________________________________________________________________ LICENSE The eGenix mx Base package is distributed under the eGenix.com Public License 1.1.0 which is an Open Source license similar to the Python license. You can use the packages in both commercial and non-commercial settings without fee or charge. The package comes with full source code ________________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 11 2012) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From paul.nospam at rudin.co.uk Wed Jan 11 05:17:06 2012 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Wed, 11 Jan 2012 10:17:06 +0000 Subject: open office in another language? References: Message-ID: <87hb02y259.fsf@no-fixed-abode.cable.virginmedia.net> Stefan Behnel writes: > OOo has been fully scriptable in Python for ages. It even comes with an > embedded Python runtime for that purpose (at least on > non-package-management systems like Windows). So, Python is actually a > standard component in all installations, whereas Java is not, and is > therefore not necessarily available in a deployment. Basically, if you want > your scripts to run in all OpenOffice/LibreOffice installations, you either > have to write it in StarBasic, or use Python. > > The OOo extension API is called UNO, so look for the PyUNO bridge. > Admittedly, it's somewhat badly documented, but it basically works the same > way as the other UNO-API incarnations in other languages, so any UNO > documentation will generally apply just fine. > > Also look for LibreOffice, as Ben Finney hinted. Since Oracle dropped Sun's > OOo commitment, many regard it as the future of OOo. It's certainly the > place where the development happens these days. I have dabbled with PyUNO in the past. One issue is that the api seems rather unpythonic (to me, at least). From mikaelpetterson1 at gmail.com Wed Jan 11 06:19:32 2012 From: mikaelpetterson1 at gmail.com (mike) Date: Wed, 11 Jan 2012 03:19:32 -0800 (PST) Subject: ERROR:root:code for hash md5 was not found Message-ID: Hi, We are running are running Python program on Redhat 5.5. When executing our program we get the following error ( see below). Any ideas what this is due to? br, //mike /pysibelius/lib/common/ DataTypes.py Overwriten ... ERROR:root:code for hash md5 was not found. Traceback (most recent call last): File "/python/lib/python2.7/hashlib.py", line 139, in globals()[__func_name] = __get_hash(__func_name) File "/python/lib/python2.7/hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type %s' % name) ValueError: unsupported hash type md5 ERROR:root:code for hash sha1 was not found From pyscripter at gmail.com Wed Jan 11 06:27:46 2012 From: pyscripter at gmail.com (pyscripter at gmail.com) Date: Wed, 11 Jan 2012 03:27:46 -0800 (PST) Subject: UnicodeEncodeError in compile In-Reply-To: References: <9043309.329.1326169476466.JavaMail.geo-discussion-forums@yqhi24> Message-ID: <9664479.1553.1326281266242.JavaMail.geo-discussion-forums@yqlp13> On Wednesday, January 11, 2012 5:50:51 AM UTC+2, Terry Reedy wrote: > On 1/10/2012 3:08 AM, Terry Reedy wrote: > Is this a filename that could be an actual, valid filename on your system? Yes it is. open works on that file. > Good question. I believe this holdover from 2.x should be deleted. > I argued that in http://bugs.python.org/issue10114 > (which was about a different problem) and now, directly, in > http://bugs.python.org/issue13758 > Maybe the example of this question can be added to the issue 13785 as a proof that compile fails on valid file names. But I think the real issue is why on modern Windows systems the file system encoding is mbcs. Shouldn't it be utf-16? From pyscripter at gmail.com Wed Jan 11 06:27:46 2012 From: pyscripter at gmail.com (pyscripter at gmail.com) Date: Wed, 11 Jan 2012 03:27:46 -0800 (PST) Subject: UnicodeEncodeError in compile In-Reply-To: References: <9043309.329.1326169476466.JavaMail.geo-discussion-forums@yqhi24> Message-ID: <9664479.1553.1326281266242.JavaMail.geo-discussion-forums@yqlp13> On Wednesday, January 11, 2012 5:50:51 AM UTC+2, Terry Reedy wrote: > On 1/10/2012 3:08 AM, Terry Reedy wrote: > Is this a filename that could be an actual, valid filename on your system? Yes it is. open works on that file. > Good question. I believe this holdover from 2.x should be deleted. > I argued that in http://bugs.python.org/issue10114 > (which was about a different problem) and now, directly, in > http://bugs.python.org/issue13758 > Maybe the example of this question can be added to the issue 13785 as a proof that compile fails on valid file names. But I think the real issue is why on modern Windows systems the file system encoding is mbcs. Shouldn't it be utf-16? From moky.math at gmail.com Wed Jan 11 06:28:52 2012 From: moky.math at gmail.com (Laurent Claessens) Date: Wed, 11 Jan 2012 12:28:52 +0100 Subject: ERROR:root:code for hash md5 was not found In-Reply-To: References: Message-ID: <4F0D7274.9080905@gmail.com> Le 11/01/2012 12:19, mike a ?crit : > Hi, > > We are running are running Python program on Redhat 5.5. > > When executing our program we get the following error ( see below). > > Any ideas what this is due to? On my computer hashlib has "md5" : Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import hashlib >>> h=hashlib.new("md5") >>> h.update("Hello") >>> h.hexdigest() 'd992641f1b2b9c08b569c0a17c4e7cb8' While if I ask for a hash method that hashlib does not know, I get the same error as you : >>> g=hashlib.new("bla") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/hashlib.py", line 101, in __hash_new return __get_builtin_constructor(name)(string) File "/usr/lib/python2.6/hashlib.py", line 80, in __get_builtin_constructor raise ValueError, "unsupported hash type" ValueError: unsupported hash type You should give us a more comprehensive example of your problem. Laurent From someone at someplace.invalid Wed Jan 11 06:39:48 2012 From: someone at someplace.invalid (HoneyMonster) Date: Wed, 11 Jan 2012 11:39:48 +0000 (UTC) Subject: Newbie: Looking for code review on my first Python project. References: Message-ID: On Tue, 10 Jan 2012 18:17:48 -0700, Ian Kelly wrote: > On Tue, Jan 10, 2012 at 4:44 PM, HoneyMonster > wrote: >> Hi, >> >> I'm new to Python and recently completed my first project. I used >> wxPython with wxGlade to generate the GUI bits.The application seems to >> work well, but I am entirely self-taught, so have undoubtedly committed >> a number of howlers in terms of style, design, standards, best practice >> and so forth. < snip constructive and helpful advice > Very many thanks to Ian and to all who responded. I really appreciate the guidance. Cheers. WH From d at davea.name Wed Jan 11 06:45:43 2012 From: d at davea.name (Dave Angel) Date: Wed, 11 Jan 2012 06:45:43 -0500 Subject: UnicodeEncodeError in compile In-Reply-To: <9664479.1553.1326281266242.JavaMail.geo-discussion-forums@yqlp13> References: <9043309.329.1326169476466.JavaMail.geo-discussion-forums@yqhi24> <9664479.1553.1326281266242.JavaMail.geo-discussion-forums@yqlp13> Message-ID: <4F0D7667.3000205@davea.name> On 01/11/2012 06:27 AM, pyscripter at gmail.com wrote: > > Maybe the example of this question can be added to the issue 13785 as a proof that compile fails on valid file names. > > But I think the real issue is why on modern Windows systems the file system encoding is mbcs. Shouldn't it be utf-16? Depends what you mean by modern. The following isn't true for Windows 95, 98, nor ME. But they weren't modern when they were first released. NT systems, (which includes Win2k, XP, Vista, and Win7) for at least the last 15 years, have used Unicode for the file system. They also supply an "ASCII" interface. If Python is using the latter, then it won't be able to access all possible files. Now, it may be the fault of the C library that CPython uses. I haven't looked at any of the code for CPython. This is all from memory, as I haven't actively used Windows for some time now. But I think the DLL name is kernel32.dll, and the entry points have names like CreateFileW() for the unicode open, and CreateFileA() for the "ASCII" open. -- DaveA From pyscripter at gmail.com Wed Jan 11 07:14:56 2012 From: pyscripter at gmail.com (pyscripter at gmail.com) Date: Wed, 11 Jan 2012 04:14:56 -0800 (PST) Subject: UnicodeEncodeError in compile In-Reply-To: References: <9043309.329.1326169476466.JavaMail.geo-discussion-forums@yqhi24> <9664479.1553.1326281266242.JavaMail.geo-discussion-forums@yqlp13> Message-ID: <11173914.1374.1326284096109.JavaMail.geo-discussion-forums@yqiq10> Indeed, on Windows NT the file system encoding should not be mbcs, since it creates UnicodeEncodeErrors on perfectly valid file names. From pyscripter at gmail.com Wed Jan 11 07:14:56 2012 From: pyscripter at gmail.com (pyscripter at gmail.com) Date: Wed, 11 Jan 2012 04:14:56 -0800 (PST) Subject: UnicodeEncodeError in compile In-Reply-To: References: <9043309.329.1326169476466.JavaMail.geo-discussion-forums@yqhi24> <9664479.1553.1326281266242.JavaMail.geo-discussion-forums@yqlp13> Message-ID: <11173914.1374.1326284096109.JavaMail.geo-discussion-forums@yqiq10> Indeed, on Windows NT the file system encoding should not be mbcs, since it creates UnicodeEncodeErrors on perfectly valid file names. From stefan_ml at behnel.de Wed Jan 11 08:06:24 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 11 Jan 2012 14:06:24 +0100 Subject: open office in another language? In-Reply-To: <87hb02y259.fsf@no-fixed-abode.cable.virginmedia.net> References: <87hb02y259.fsf@no-fixed-abode.cable.virginmedia.net> Message-ID: Paul Rudin, 11.01.2012 11:17: > Stefan Behnel writes: >> OOo has been fully scriptable in Python for ages. It even comes with an >> embedded Python runtime for that purpose [...] > > I have dabbled with PyUNO in the past. One issue is that the api seems > rather unpythonic (to me, at least). Sure, UNO wasn't designed for Python. It's mostly a 1:1 mapping of the C++ API. I didn't find anything in a quick web search, but I'm pretty sure the wrapper is auto-generated in some way. But still: it's there, it's usable and it's even object oriented. And I estimate that it's much easier to use from Python than from C++ (which I never tried). If you want something better, feel free to write a pythonic Cython wrapper of the C++ UNO API. May take a while, though, and you'll also have to rewrite the entire UNO documentation to match your new wrapper, so that people can actually start using it effectively. Stefan From antoon.pardon at rece.vub.ac.be Wed Jan 11 08:21:57 2012 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 11 Jan 2012 14:21:57 +0100 Subject: import problems. Message-ID: <4F0D8CF5.1090508@rece.vub.ac.be> I have an import problem I can't figure out. I am using python 2.6.6 on a debian box In one directory (pylib) I have a file misc.py and the file testutil.py. -------------------- testutil.py ---------------------- print "in", __name__ from misc import Rec -------------------------------------------------------- calling this file in that directory gives me this: $ python testutil.py in __main__ In a neighbour directory I have the file ats ------------------------ atst ---------------------------- import sys from os.path import join as pj, abspath print abspath("../pylib") sys.path.append(abspath("../pylib")) import testutil ----------------------------------------------------------- Now calling this file in its directory gives me the following problem: $ python atst /local/home/apardon/src/projecten/pylib in testutil Traceback (most recent call last): File "atst", line 9, in import testutil File "/local/home/apardon/src/projecten/pylib/testutil.py", line 4, in from misc import Rec ImportError: cannot import name Rec Why can I import Rec from misc in testutil when I call testutil.py directly but not when testutil was imported itself? From d at davea.name Wed Jan 11 08:44:19 2012 From: d at davea.name (Dave Angel) Date: Wed, 11 Jan 2012 08:44:19 -0500 Subject: import problems. In-Reply-To: <4F0D8CF5.1090508@rece.vub.ac.be> References: <4F0D8CF5.1090508@rece.vub.ac.be> Message-ID: <4F0D9233.9050303@davea.name> On 01/11/2012 08:21 AM, Antoon Pardon wrote: > I have an import problem I can't figure out. > I am using python 2.6.6 on a debian box > > In one directory (pylib) I have a file misc.py and > the file testutil.py. > > -------------------- testutil.py ---------------------- > > print "in", __name__ > > from misc import Rec > > -------------------------------------------------------- > > calling this file in that directory gives me this: > > $ python testutil.py > in __main__ > > In a neighbour directory I have the file ats > > ------------------------ atst ---------------------------- > > import sys > > from os.path import join as pj, abspath > > print abspath("../pylib") > > sys.path.append(abspath("../pylib")) > > import testutil > > ----------------------------------------------------------- > > Now calling this file in its directory gives me the following problem: > $ python atst > /local/home/apardon/src/projecten/pylib > in testutil > Traceback (most recent call last): > File "atst", line 9, in > import testutil > File "/local/home/apardon/src/projecten/pylib/testutil.py", line 4, > in > from misc import Rec > ImportError: cannot import name Rec > > Why can I import Rec from misc in testutil when I call testutil.py > directly but not when testutil was imported itself? In your first case, Rec.py was in the current directory, which is one of the specs in classpath. In the second case, your current directory was somewhere else. -- DaveA From mateusz at loskot.net Wed Jan 11 08:50:37 2012 From: mateusz at loskot.net (Mateusz Loskot) Date: Wed, 11 Jan 2012 13:50:37 +0000 Subject: How do I tell "incomplete input" from "invalid input"? Message-ID: Hi, I have been trying to figure out a reliable way to determine incomplete Python script input using Python C API. (Apology if it is OT here, I'm not sure where my post belongs, perhaps to cplusplus-sig list.) Apparently, most pointers lead to the Python FAQ [1] question: How do I tell "incomplete input" from "invalid input"? Unfortunately, this FAQ is either old or incomplete thus incorrect. First, the proposed testcomplete() function uses internal symbols which are not available to Python C API users. So, "whoever wrote that FAQ should be given 20 lashes with a short piece of string" [2]. The second solution is incomplete or incorrect. It does not handle correctly multi-line input longer than two lines with more flow control statements. For example: ########################################################################## >>> n = 10 >>> if n > 0: ... if n < 100: File "", line 2 if n < 100: ^ IndentationError: expected an indented block >>> ########################################################################## or ########################################################################## >>> for n in range(0, 5): ... if n > 2: File "", line 2 if n > 2: ^ IndentationError: expected an indented block >>> ########################################################################## I have attached a slightly modified C++ version of the second program from the FAQ question [1], file faq_incomplete_input.cpp which is also available from my GitHub repo [3] In this program, I added several FIX comments with proposed corrections. The idea is to additionally check for PyErr_ExceptionMatches (PyExc_IndentationError) and strcmp (msg, "expected an indented block") and prompt is sys.ps2, means more code expected. And, ignore errors until user confirms the input is finished, so the whole input is eventually sent to the Py_CompileString and then all exceptions are not ignored, but considered as real result of compilation. I simply wanted to achieve similar semantic to codeop._maybe_compile() (called by codeop.compile_command) which performs some sort of dirty hack in the following line: if not code1 and repr(err1) == repr(err2): So, the test in action for multi-line multi-statement input gives: ########################################################################## >>> c = codeop.compile_command("for n in range(0, 3):", "test", "single") err1 SyntaxError('unexpected EOF while parsing', ('test', 1, 22, 'for n in range(0, 3):\n')) err2 IndentationError('expected an indented block', ('test', 2, 1, '\n')) comparison.err1 SyntaxError('unexpected EOF while parsing', ('test', 1, 22, 'for n in range(0, 3):\n')) comparison.err2 IndentationError('expected an indented block', ('test', 2, 1, '\n')) code None code1 None >>> c = codeop.compile_command("for n in range(0, 3):\n\tif n > 0:", "test", "single") err1 IndentationError('expected an indented block', ('test', 2, 11, '\tif n > 0:\n')) err2 IndentationError('expected an indented block', ('test', 3, 1, '\n')) comparison.err1 IndentationError('expected an indented block', ('test', 2, 11, '\tif n > 0:\n')) comparison.err2 IndentationError('expected an indented block', ('test', 3, 1, '\n')) code None code1 None >>> ########################################################################## So, I reckon it make sense to use the same logic to when calling Py_CompileString. Does it sound as reasonable solution? Basically, there seem to be no canonical solution anywhere presented on how to perform incomplete input tests in reliable manner, how to perform parsing/compilation in subsequent steps against Python code given line-by-line. The C API used by Python function compile() is not publicly available. There is PyRun_InteractiveLoop mechanism but it is tightly coupled to FILE-based I/O which is not always available when Python is embedded, so the loop is useless in number of situations. Have I overlooked any other obvious solution? Finally, it would be helpful if the Python FAQ is up to date. [1] http://docs.python.org/py3k/faq/extending.html#how-do-i-tell-incomplete-input-from-invalid-input [2] http://mail.python.org/pipermail/python-list/2004-August/887195.html [3] https://github.com/mloskot/workshop/blob/master/python/ Best regards, -- Mateusz Loskot, http://mateusz.loskot.net -------------- next part -------------- A non-text attachment was scrubbed... Name: faq_incomplete_input.cpp Type: text/x-c++src Size: 4938 bytes Desc: not available URL: From __peter__ at web.de Wed Jan 11 08:57:35 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 11 Jan 2012 14:57:35 +0100 Subject: import problems. References: <4F0D8CF5.1090508@rece.vub.ac.be> Message-ID: Antoon Pardon wrote: > I have an import problem I can't figure out. > I am using python 2.6.6 on a debian box > > In one directory (pylib) I have a file misc.py and > the file testutil.py. > from misc import Rec > ImportError: cannot import name Rec > > Why can I import Rec from misc in testutil when I call testutil.py > directly but not when testutil was imported itself? Without looking into the details, could it be that you have two misc.py files one with and one without Rec? From antoon.pardon at rece.vub.ac.be Wed Jan 11 09:45:36 2012 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 11 Jan 2012 15:45:36 +0100 Subject: import problems. In-Reply-To: References: <4F0D8CF5.1090508@rece.vub.ac.be> Message-ID: <4F0DA090.7080601@rece.vub.ac.be> On 01/11/2012 02:57 PM, Peter Otten wrote: > Antoon Pardon wrote: > > >> I have an import problem I can't figure out. >> I am using python 2.6.6 on a debian box >> >> In one directory (pylib) I have a file misc.py and >> the file testutil.py. >> > >> from misc import Rec >> ImportError: cannot import name Rec >> >> Why can I import Rec from misc in testutil when I call testutil.py >> directly but not when testutil was imported itself? >> > Without looking into the details, could it be that you have two misc.py > files one with and one without Rec Well that depends on what you mean with "have". This is what turned up when I searched for "misc.py" $ find /usr/local/lib /usr/lib /local/home/apardon -name misc.py -print 2> /dev/null /usr/lib/python2.6/compiler/misc.py /usr/lib/pymodules/python2.6/PyQt4/uic/Compiler/misc.py /usr/lib/pymodules/python2.6/numpy/oldnumeric/misc.py /usr/lib/pymodules/python2.6/docutils/transforms/misc.py /usr/lib/pymodules/python2.6/docutils/parsers/rst/directives/misc.py /local/home/apardon/src/projecten/pylib/misc.py That last one is my file, the rest doesn't seem to be in sys.path so they shouldn't interfere as far as I understand. Changing the name of my file to miscutil.py resolves the problem though. I'll see if I can figure out more. From antoon.pardon at rece.vub.ac.be Wed Jan 11 10:14:57 2012 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 11 Jan 2012 16:14:57 +0100 Subject: import problems. In-Reply-To: <4F0DA090.7080601@rece.vub.ac.be> References: <4F0D8CF5.1090508@rece.vub.ac.be> <4F0DA090.7080601@rece.vub.ac.be> Message-ID: <4F0DA771.4060000@rece.vub.ac.be> On 01/11/2012 03:45 PM, Antoon Pardon wrote: > On 01/11/2012 02:57 PM, Peter Otten wrote: >> Antoon Pardon wrote: >> >>> I have an import problem I can't figure out. >>> I am using python 2.6.6 on a debian box >>> >>> In one directory (pylib) I have a file misc.py and >>> the file testutil.py. >>> from misc import Rec >>> ImportError: cannot import name Rec >>> >>> Why can I import Rec from misc in testutil when I call testutil.py >>> directly but not when testutil was imported itself? >> Without looking into the details, could it be that you have two misc.py >> files one with and one without Rec > Well that depends on what you mean with "have". This is what > turned up when I searched for "misc.py" > > $ find /usr/local/lib /usr/lib /local/home/apardon -name misc.py > -print 2> /dev/null > /usr/lib/python2.6/compiler/misc.py > /usr/lib/pymodules/python2.6/PyQt4/uic/Compiler/misc.py > /usr/lib/pymodules/python2.6/numpy/oldnumeric/misc.py > /usr/lib/pymodules/python2.6/docutils/transforms/misc.py > /usr/lib/pymodules/python2.6/docutils/parsers/rst/directives/misc.py > /local/home/apardon/src/projecten/pylib/misc.py > > That last one is my file, the rest doesn't seem to be in sys.path so > they shouldn't interfere > as far as I understand. Changing the name of my file to miscutil.py > resolves the problem though. > > I'll see if I can figure out more. It seems there is a directory /usr/lib/pymodules/python2.6/misc in which is an empty __init.py__ file. As far as I understand this makes misc a package on sys.path causing the problem. From ether.joe at gmail.com Wed Jan 11 10:19:46 2012 From: ether.joe at gmail.com (Sean Wolfe) Date: Wed, 11 Jan 2012 12:19:46 -0300 Subject: An "alternative" to Learning Perl In-Reply-To: References: Message-ID: On Tue, Jan 10, 2012 at 8:25 PM, Sebastian Rooks wrote: > On Mon, 9 Jan 2012 00:55:22 -0300, Sean Wolfe > wrote: > >>kindle? ipad? tablet? > > I'm interested in books, not files ... > (seriously, now ... I don't have any of those devices) > >>also there is python programming for the absolute beginner, which is >>agreat book but it's pretty beginner. But well written. At least >>Iliked it.http://www.amazon.com/Python-Programming-Absolute-Beginner-3rd/dp/1435455002 >>Also byte of python ... I think there's a hardcover version you can >>buyhttp://www.swaroopch.com/buybook/ > > I think I saw that second one somewhere already. I'll check out the > first link, also. Thanks! > Yeah I hear you, I moved to Argentina from the US this year and my ipad + kindle app has been great. I can buy lots of books which I can't get down here and get access to them immediately, and I can carry a whole library in my backpack. So +1 if you are thinking about it. I like physical books as well but the portability factor is awesome. From peterirbizon at gmail.com Wed Jan 11 10:28:01 2012 From: peterirbizon at gmail.com (Peter Irbizon) Date: Wed, 11 Jan 2012 16:28:01 +0100 Subject: =?UTF-8?Q?after_applicatio=E2=80=8Bn_close_MS_Visual_C=2B=2B_runtime_lib?= =?UTF-8?Q?rary_error_occurs?= Message-ID: Hello, I am using psycopg2 in windows app, example: import psycopg2 import psycopg2.extras self.con = psycopg2.connect("dbname= host= user= password= port="); self.cur = self.con.cursor(cursor_factory=psycopg2.extras.DictCursor) SELECT = "select something" self.cur.execute(SELECT) for row in self.cur: ... self.cur.close() self.con.close() But when I click on exit button in application MS Visual C++ runtime library error occurs: This application has requested the runtime to terminate it in unusual way. What am I doing wrong? -------------- next part -------------- An HTML attachment was scrubbed... URL: From johannh at gmail.com Wed Jan 11 10:45:15 2012 From: johannh at gmail.com (johannh at gmail.com) Date: Wed, 11 Jan 2012 07:45:15 -0800 (PST) Subject: contextlib.contextmanager and try/finally Message-ID: <10841855.1646.1326296715536.JavaMail.geo-discussion-forums@yqiz15> I'm trying to write a context manager to handle database connections, under the principle that I should not rely on CPython's reference-counting semantics to clean up scarce resources, like connections. I wrote: @contexlib.contextmanager def ensure_connection(con=None): con_created = False if con is None: con_created, con = True, make_connection() try: yield con finally: if con_created: con.close() However, then I read the following paragraph from PEP-343: Note that we're not guaranteeing that the finally-clause is executed immediately after the generator object becomes unused, even though this is how it will work in CPython. This is similar to auto-closing files: while a reference-counting implementation like CPython deallocates an object as soon as the last reference to it goes away, implementations that use other GC algorithms do not make the same guarantee. This applies to Jython, IronPython, and probably to Python running on Parrot. That suggests that I cannot rely on the contextlib.contextmanager decorator to ensure that the connection is closed and would have to write my own object with __enter__ and __exit__ methods to guarantee this. Is this understanding accurate? If so, could someone illustrate why this is so? Thanks, Johann From neilc at norwich.edu Wed Jan 11 11:46:17 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 11 Jan 2012 16:46:17 GMT Subject: contextlib.contextmanager and try/finally References: <10841855.1646.1326296715536.JavaMail.geo-discussion-forums@yqiz15> Message-ID: <9n5smpFm0dU1@mid.individual.net> On 2012-01-11, johannh at gmail.com wrote: > That suggests that I cannot rely on the > contextlib.contextmanager decorator to ensure that the > connection is closed and would have to write my own object with > __enter__ and __exit__ methods to guarantee this. contextmanager wraps your generator in an object with __enter__ and __exit__ methods for you. -- Neil Cerutti From robert.kern at gmail.com Wed Jan 11 12:14:40 2012 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 11 Jan 2012 17:14:40 +0000 Subject: contextlib.contextmanager and try/finally In-Reply-To: <10841855.1646.1326296715536.JavaMail.geo-discussion-forums@yqiz15> References: <10841855.1646.1326296715536.JavaMail.geo-discussion-forums@yqiz15> Message-ID: On 1/11/12 3:45 PM, johannh at gmail.com wrote: > I'm trying to write a context manager to handle database connections, under the principle that I should not rely on CPython's reference-counting semantics to clean up scarce resources, like connections. > > I wrote: > > @contexlib.contextmanager > def ensure_connection(con=None): > con_created = False > if con is None: > con_created, con = True, make_connection() > try: > yield con > finally: > if con_created: > con.close() > > However, then I read the following paragraph from PEP-343: > > Note that we're not guaranteeing that the finally-clause is > executed immediately after the generator object becomes unused, > even though this is how it will work in CPython. This is similar > to auto-closing files: while a reference-counting implementation > like CPython deallocates an object as soon as the last reference > to it goes away, implementations that use other GC algorithms do > not make the same guarantee. This applies to Jython, IronPython, > and probably to Python running on Parrot. > > That suggests that I cannot rely on the contextlib.contextmanager decorator to ensure that the connection is closed and would have to write my own object with __enter__ and __exit__ methods to guarantee this. > > Is this understanding accurate? If so, could someone illustrate why this is so? Looking at the paragraph before this one, it appears that the PEP is talking about the .close() method on generators, which is really just a general purpose API for closing generators that might not be exhausted yet. It's not really related to the context manager stuff except that it came up during the design process of the context manager along with the related .send() and .throw() methods. __enter__() will call .next() once to execute the code up to the yield statement. Then __exit__() will call .next() once again to execute the code after the yield statement, including the finally: clause. That's the only thing you need to rely on. Your connection-closing code will be called if __exit__() gets called. That will exhaust your generator, so the .close() method will not really do anything helpful or hurtful in such a case. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From ian.g.kelly at gmail.com Wed Jan 11 12:20:19 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 11 Jan 2012 10:20:19 -0700 Subject: contextlib.contextmanager and try/finally In-Reply-To: <10841855.1646.1326296715536.JavaMail.geo-discussion-forums@yqiz15> References: <10841855.1646.1326296715536.JavaMail.geo-discussion-forums@yqiz15> Message-ID: On Wed, Jan 11, 2012 at 8:45 AM, wrote: > However, then I read the following paragraph from PEP-343: > > ? ?Note that we're not guaranteeing that the finally-clause is > ? ?executed immediately after the generator object becomes unused, > ? ?even though this is how it will work in CPython. ?This is similar > ? ?to auto-closing files: while a reference-counting implementation > ? ?like CPython deallocates an object as soon as the last reference > ? ?to it goes away, implementations that use other GC algorithms do > ? ?not make the same guarantee. ?This applies to Jython, IronPython, > ? ?and probably to Python running on Parrot. > > That suggests that I cannot rely on the contextlib.contextmanager decorator to ensure that the connection is closed and would have to write my own object with __enter__ and __exit__ methods to guarantee this. > > Is this understanding accurate? ?If so, could someone illustrate why this is so? First, this is just a timing issue. There is no guarantee that the finally clause will be executed immediately, but it is guaranteed to be executed at some point. In the other implementations, it would happen whenever the GC algorithm runs. Second, I believe that passage is not referring to the contextmanager decorator specifically, but more generally to the changes that were made to allow generators to yield from within a try-finally construct (previously this would have been illegal syntax, since there was no way to guarantee the finally block would be performed). Like Neil mentioned, a contextmanager generator is wrapped with an __exit__ method that is guaranteed to be called and that explicitly resumes or closes the generator. So as long as your contextmanager generator is properly written (i.e. it yields exactly once), the finally block will execute in a timely fashion. From johannh at gmail.com Wed Jan 11 12:30:58 2012 From: johannh at gmail.com (johannh at gmail.com) Date: Wed, 11 Jan 2012 09:30:58 -0800 (PST) Subject: contextlib.contextmanager and try/finally In-Reply-To: References: <10841855.1646.1326296715536.JavaMail.geo-discussion-forums@yqiz15> Message-ID: <10027125.1816.1326303058381.JavaMail.geo-discussion-forums@yqcb25> On Wednesday, January 11, 2012 11:20:19 AM UTC-6, Ian wrote: > > Second, I believe that passage is not referring to the contextmanager > decorator specifically, but more generally to the changes that were > made to allow generators to yield from within a try-finally construct > (previously this would have been illegal syntax, since there was no > way to guarantee the finally block would be performed). Thanks. You and Robert have shown me the light. That paragraph was talking about the finalization that happens to a suspended generator when it is GC'd. Meanwhile, the contextmanager decorator ensures that its generator is run all the way through, so it would never be left in a suspended state, so its GC/finalization semantics are irrelevant. (Please correct, if wrong.) (Neil: I understood that it created a context manager object, but I had been reading the quoted paragraph to mean that by going through a generator the decorator was re-introducing a dependency on GC time. But I was wrong.) Regards, Johann From johannh at gmail.com Wed Jan 11 12:30:58 2012 From: johannh at gmail.com (johannh at gmail.com) Date: Wed, 11 Jan 2012 09:30:58 -0800 (PST) Subject: contextlib.contextmanager and try/finally In-Reply-To: References: <10841855.1646.1326296715536.JavaMail.geo-discussion-forums@yqiz15> Message-ID: <10027125.1816.1326303058381.JavaMail.geo-discussion-forums@yqcb25> On Wednesday, January 11, 2012 11:20:19 AM UTC-6, Ian wrote: > > Second, I believe that passage is not referring to the contextmanager > decorator specifically, but more generally to the changes that were > made to allow generators to yield from within a try-finally construct > (previously this would have been illegal syntax, since there was no > way to guarantee the finally block would be performed). Thanks. You and Robert have shown me the light. That paragraph was talking about the finalization that happens to a suspended generator when it is GC'd. Meanwhile, the contextmanager decorator ensures that its generator is run all the way through, so it would never be left in a suspended state, so its GC/finalization semantics are irrelevant. (Please correct, if wrong.) (Neil: I understood that it created a context manager object, but I had been reading the quoted paragraph to mean that by going through a generator the decorator was re-introducing a dependency on GC time. But I was wrong.) Regards, Johann From tjreedy at udel.edu Wed Jan 11 13:25:16 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 Jan 2012 13:25:16 -0500 Subject: ERROR:root:code for hash md5 was not found In-Reply-To: References: Message-ID: On 1/11/2012 6:19 AM, mike wrote: > Hi, > > We are running are running Python program on Redhat 5.5. > > When executing our program we get the following error ( see below). > > Any ideas what this is due to? > > br, > > //mike > > /pysibelius/lib/common/ > DataTypes.py > Overwriten ... > ERROR:root:code for hash md5 was not found. These 3 lines do not come from the interpreter. It might come from the hashlib module. > Traceback (most recent call last): > File "/python/lib/python2.7/hashlib.py", line 139, in > globals()[__func_name] = __get_hash(__func_name) > File "/python/lib/python2.7/hashlib.py", line 91, in > __get_builtin_constructor > raise ValueError('unsupported hash type %s' % name) > ValueError: unsupported hash type md5 This is a standard traceback from the interpreter. The manual says that md5 should always be available. On the other hand, hashlib depends on the OpenSSL library on your system. Perhaps RedHat removed md5 because it has been broken. I suggest you ask them or check your OpenSSL doc. The Python manual may need to be changed. > ERROR:root:code for hash sha1 was not found -- Terry Jan Reedy From tjreedy at udel.edu Wed Jan 11 13:28:37 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 Jan 2012 13:28:37 -0500 Subject: How do I tell "incomplete input" from "invalid input"? In-Reply-To: References: Message-ID: On 1/11/2012 8:50 AM, Mateusz Loskot wrote: > Unfortunately, this FAQ is either old or incomplete thus incorrect. If you have a suggested change to the current text, please submit it to the tracker at bugs.python.org -- Terry Jan Reedy From darcy at druid.net Wed Jan 11 14:14:35 2012 From: darcy at druid.net (D'Arcy Cain) Date: Wed, 11 Jan 2012 14:14:35 -0500 Subject: your feedback to my first project please In-Reply-To: <2123007772.204183.1326052009748.JavaMail.open-xchange@email.1und1.de References: <2123007772.204183.1326052009748.JavaMail.open-xchange@email.1und1.de Message-ID: <4F0DDF9B.8090100@druid.net> On 12-01-08 02:46 PM, patrick at bierans.de wrote: > Thanks for the feedback! You're welcome. >> D'Arcy wrote: [code examples] > But I will keep some of my underscores for "private" attributes and methods. > And I googled: "dim" was basic. I know too many languages and start mixing > the keywords - shame on me. ;) No problem but don't overuse the underscores. It starts to look like Perl. The parameters to the methods and the local variables in the methods will not pollute your namespace. The only area you need to concern yourself with is module level object references. >>> import mymodule >>> print dir(mymodule) that's the list you need to be concerned with. You will see that a lot of names are already private. In the case you present I don't think that anything there was private that is not already private based on what it inherits from object. > Good Eye: I wrote the tests after coding - I know that this is the wrong way. > I just wanted to start coding and after some time I decided that I shoud have > some test cases. This is no real TDD - true. ;) I'll do that right next time. This is the number one lesson you should take to heart from this. > After thinking about it: Yupp. You are right. Having written tests to check > "private" attributes really hurts one's pride. ;) And you don't want to. The test cases should make sure that public objects and methods act as specified. That's what allows you to refactor any time you want. -- 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 nikos.kouras at gmail.com Wed Jan 11 14:47:14 2012 From: nikos.kouras at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Wed, 11 Jan 2012 21:47:14 +0200 Subject: Explanation about for In-Reply-To: <31532.1326209050@gamaville.dokosmarshall.org> References: <581e9a24-f948-4fc4-ae28-227d6d526780@n6g2000vbg.googlegroups.com> <31532.1326209050@gamaville.dokosmarshall.org> Message-ID: Thank you All for the detailed examples. I tried them all in IDLE and i finally understood them. Thanks for your patience with me until i understand! 2012/1/10 Nick Dokos > ???????? ?????? wrote: > > > On 10 ???, 03:11, Ian Kelly wrote: > > > 2012/1/9 ???????? ?????? : > > > > > > > if the MySQL query was: > > > > > > > cursor.execute( '''SELECT host, hits, agent, date FROM visitors > WHERE pin = > > > > %s ORDER BY date DESC''', pin ) > > > > > > > can you help me imagine how the mysql database cursor that holds the > query > > > > results would look like? I must somehow visualize it in order to > understand > > > > it! > > > > > > You can think of it as a pointer, traversing over one row of the > > > result set at a time. Hopefully this will come out legibly: > > > > > > ----------------------------------------------- > > > | HOST | HITS | AGENT | DATE | > > > ----------------------------------------------- > ------------- > > > | foo | 7 | IE6 | 1/1/11 | <---- | cursor | > > > ----------------------------------------------- > ------------- > > > | bar | 42 | Firefox | 2/2/10 | > > > ----------------------------------------------- > > > | baz | 4 | Chrome | 3/3/09 | > > > ------------------------------------------------ > > > > Database cursor is the pointer that iterates over the result set one > > row at a time? > > I though that it was the name we give to the whole mysql result set > > returned my cursor.execute. > > > > > > > > > > > > Also what happend if the query was: > > > > cursor.execute( '''SELECT host FROM visitors") ? > > > > > > > the result would have to be something likelike? > > > > > > > ----------------- > > > > |somehost1| > > > > ----------------- > > > > |somehost2| > > > > ----------------- > > > > |somehost3| > > > > ----------------- > > > > ..................... > > > > ..................... > > > > |somehost n| > > > > ----------------- > > > > > > > So what values host, hits, agent, date would have in 'for host, > hits, agent, > > > > date in > > > > dataset' ? Every row has one string how can that be split in 4? > > > > > > Why don't you try it and see what happens? But to spare you the > > > suspense, you would get: > > > > > > ValueError: need more than 1 value to unpack > > > > > > Because you can't unpack a 1-length tuple into four variables. The > > > code assumes that the query is selecting exactly 4 columns. > > > > > > ----------------------------------------------- > > | HOST | HITS | AGENT | DATE | > > ----------------------------------------------- > > | foo | 7 | IE6 | 1/1/11 | > > ----------------------------------------------- > > | bar | 42 | Firefox | 2/2/10 | > > ----------------------------------------------- > > | baz | 4 | Chrome | 3/3/09 | > > ----------------------------------------------- > > > > In this line: > > for host, hits, agent, date in dataset: > > > > 'dataset' is one of the rows of the mysql result or the whole mysql > > result set like the table above? > > > > I still have trouble understanding this line :( > > You can think of it as a list of tuples. Forget about cursors and > databases for now. If l is a list [1, 2, 3, 4] you iterate over it like > this: > > for x in l: > print x > > and you get each element of the list[fn:1]. Similarly if l is a list of > tuples > l = [(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)] you can iterate over the > list: > > for x in l: > print x > > In this case, x is going to be (1,2,3,4) the first time through the loop, > (5,6,7,8) > the second time and so on. You can break each x apart within the loop: > > for x in l: > t1, t2, t3, t4 = x > print x, t1, t2, t3, t4 > > or you can break it apart like this - it's essentially the same thing: > > for t1, t2, t3, t4 in l: > print t1, t2, t3, t4 > > You have been encouraged repeatedly to try these things interactively: > please do so with the above examples and all will become clear. > > Going back to cursors and databases: you *can* think of 'dataset' as > being a list of tuples - a list of all the query results, but with one > proviso. The difference when you use a cursor is that `dataset' may > be a lazy list (an "iterator"): instead of the whole set of results > being in memory at the same time, the system will take care of doing > whatever is necessary to get more of the results when it needs them. But > the behavior is the *same* in the sense that the output that you get is > the same (you will only see differences if you are keeping an eye on how > much memory and how much time your program is using). > > Nick > > Footnotes: > > [fn:1] ... and, no, you *can't express* this as > "the first time it is > > for x in 1: > ... > > and the second time it is > > for x in 2: > ... > > " as you asked in another email. That's arrant nonsense: x takes > successive values in the list l for every iteration of the for > loop. This is elementary Python (nay, elementary programming, period). > -------------- next part -------------- An HTML attachment was scrubbed... URL: From koch.mate at me.com Wed Jan 11 15:16:45 2012 From: koch.mate at me.com (=?iso-8859-1?Q?M=E1t=E9_Koch?=) Date: Wed, 11 Jan 2012 21:16:45 +0100 Subject: stable object serialization to text file Message-ID: <030AD516-2A52-411B-9A20-BD60DF8AE75B@me.com> Hello All, I'm developing an app which stores the data in file system database. The data in my case consists of large python objects, mostly dicts, containing texts and numbers. The easiest way to dump and load them would be pickle, but I have a problem with it: I want to keep the data in version control, and I would like to use it as efficiently as possible. Is it possible to force pickle to store the otherwise unordered (e.g. dictionary) data in a kind of ordered way, so that if I dump a large dict, then change 1 tiny thing in it and dump again, the diff of the former and the new file will be minimal? If pickle is not the best choice for me, can you suggest anything else? (If there isn't any solution for it so far, I will write the module of course, but first I'd like to look around and make sure it hasn't been created yet.) Thanks, Mate From koch.mate at me.com Wed Jan 11 15:22:51 2012 From: koch.mate at me.com (=?utf-8?B?TcOhdMOpIEtvY2g=?=) Date: Wed, 11 Jan 2012 20:22:51 +0000 (GMT) Subject: stable object serialization to text file Message-ID: Hello All, I'm developing an app which stores the data in file system database. The data in my case consists of large python objects, mostly dicts, containing texts and numbers. The easiest way to dump and load them would be pickle, but I have a problem with it: I want to keep the data in version control, and I would like to use it as efficiently as possible. Is it possible to force pickle to store the otherwise unordered (e.g. dictionary) data in a kind of ordered way, so that if I dump a large dict, then change 1 tiny thing in it and dump again, the diff of the former and the new file will be minimal? If pickle is not the best choice for me, can you suggest anything else? (If there isn't any solution for it so far, I will write the module of course, but first I'd like to look around and make sure it hasn't been created yet.) Thanks, Mate -------------- next part -------------- An HTML attachment was scrubbed... URL: From emekamicro at gmail.com Wed Jan 11 15:23:54 2012 From: emekamicro at gmail.com (Emeka) Date: Wed, 11 Jan 2012 22:23:54 +0200 Subject: MySQLdb Error In-Reply-To: <9rbrg7lhenbc2tmtkb0n461r0u2lijq2vo@4ax.com> References: <9rbrg7lhenbc2tmtkb0n461r0u2lijq2vo@4ax.com> Message-ID: Thanks. Regards, Janus On Wed, Jan 11, 2012 at 7:12 PM, Dennis Lee Bieber wrote: > On Wed, 11 Jan 2012 09:57:43 +0200, Emeka wrote: > > > >_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL > >syntax; check the manual that corresponds to your MySQL server version for > >the right syntax to use near ' street_number int, country_name varchar, > > street_name char(40) , user_name ch' at line 1") > >* > > > > Per http://dev.mysql.com/doc/refman/5.1/en/create-table.html and > http://dev.mysql.com/doc/refman/5.1/en/char.html VARCHAR fields > /require/ the maximum length of the field to be defined. Length appears > optional for CHAR -- probably defaulting to 1 character. > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -- *Satajanus Nig. Ltd * -------------- next part -------------- An HTML attachment was scrubbed... URL: From someone at someplace.invalid Wed Jan 11 16:09:13 2012 From: someone at someplace.invalid (HoneyMonster) Date: Wed, 11 Jan 2012 21:09:13 +0000 (UTC) Subject: Newbie: Looking for code review on my first Python project. References: Message-ID: On Wed, 11 Jan 2012 11:39:48 +0000, HoneyMonster wrote: > On Tue, 10 Jan 2012 18:17:48 -0700, Ian Kelly wrote: > >> On Tue, Jan 10, 2012 at 4:44 PM, HoneyMonster >> wrote: >>> Hi, >>> >>> I'm new to Python and recently completed my first project. I used >>> wxPython with wxGlade to generate the GUI bits.The application seems >>> to work well, but I am entirely self-taught, so have undoubtedly >>> committed a number of howlers in terms of style, design, standards, >>> best practice and so forth. > < snip constructive and helpful advice > > > Very many thanks to Ian and to all who responded. I really appreciate > the guidance. Cheers. I have taken on board the helpful suggestions offered, and looked though the PEP-8 document which has been mentioned. As a result, there are a number of changes to the code. My second attempt is in the same place: A couple of points: 1) I'm reluctant to try to improve this bit of code: ------------------------------------------------------------- self.add = wx.MenuItem(self.file, wx.NewId(), "&Add to Queue", "Add a programme to the queue (for download later)", wx.ITEM_NORMAL) self.file.AppendItem(self.add) ------------------------------------------------------------- since it is generated by wxGlade and so will be overwritten. 2) I was very unsure about the wx.CallAfter, and suspect that I have put it in the wrong place. It seems to pass off well enough in Linux, but on Windows it appears to prevent the widgets on the splash frame being drawn properly. If anyone would be kind enough, further comments would be welcomed. Thanks, WH From mmanns at gmx.net Wed Jan 11 16:35:08 2012 From: mmanns at gmx.net (Martin Manns) Date: Wed, 11 Jan 2012 22:35:08 +0100 Subject: open office in another language? References: Message-ID: <20120111223508.413f2b68@Fuddel> On Tue, 10 Jan 2012 18:43:09 -0300 Sean Wolfe wrote: > Has there been any talk of doing another similar office suite, or > maybe just writer + spreadsheet, in a better language eg python? I > expect it's a huge undertaking but ... thought I'd ask around at > least. If you are looking for Python based spreadsheets, you may be interested in ResolverOne (commercial product) http://www.resolversystems.com/products/resolver-one/ or in pyspread (GPL, my own effort) http://manns.github.com/pyspread/ Martin From emekamicro at gmail.com Wed Jan 11 16:38:22 2012 From: emekamicro at gmail.com (Emeka) Date: Wed, 11 Jan 2012 23:38:22 +0200 Subject: Python lib for creating Database tables Message-ID: Hello All, I just made something pretty simple that I intend to use while creating database tables. It is still in the basic form, and much needs to be added. However, I use introspection to make it a bit easier and less work on the user. I would want my code to be reviewed by this great group. I look forward to your feedback and comments. https://github.com/janus/cheeta Thanks in advance! Regards, Emeka * * -------------- next part -------------- An HTML attachment was scrubbed... URL: From ether.joe at gmail.com Wed Jan 11 16:39:55 2012 From: ether.joe at gmail.com (Sean Wolfe) Date: Wed, 11 Jan 2012 18:39:55 -0300 Subject: open office in another language? In-Reply-To: <20120111223508.413f2b68@Fuddel> References: <20120111223508.413f2b68@Fuddel> Message-ID: On Wed, Jan 11, 2012 at 6:35 PM, Martin Manns wrote: > or in pyspread (GPL, my own effort) > > http://manns.github.com/pyspread/ > Checking this out now. Do you have text boxes? Cause maybe I will add some ... cool! From mixolydian at postersRUS Wed Jan 11 17:03:32 2012 From: mixolydian at postersRUS (mixolydian) Date: Wed, 11 Jan 2012 16:03:32 -0600 Subject: Newbie Help References: Message-ID: mixolydian wrote: >I want to get into Python progamming for both local database applications and >dynamic web pages. Maybe some Q&D scripts. >There is a ton of excellent language books. > >I have downloaded and installed 2.7.2 and got it working by pasting samples >into IDLE, and uploading to my web server and doing trial CGI samples. >So far, so good. > >I would like some advice on: > 1. IDEs > 2. GUI tools, tkinter and others > 3. An integrated web server package for Win Vista for testing web apps >before >deploying. Uploading to my ISP to run is a PIA. I've installed VertrigoServ to >try, but am chasing my tail around the Apache configuration. > Is there something easier? >Just pointers to get me started would be fine. > >More info.I will be migrating data base apps from MSAccess 2000. I know, I >know, but it was free on my original Win 95 PC. >I've been programming for 50 years and have had to learn (and unlearn) a lot, >and I'm eager to learn new stuff. > Thanks to all those who replied. I am using Notepad++ and WampServer. My hosting service is Apache/phpMyAdmin/MySQL and I decided it was best to use the same on my Windoze development system. Right now I'm revising my site HTML (much of it is 15 yrs old!). Later it will be upgraded to use server-side scripts. Perhaps then I'll look at Django, Cherrpy; etc. >Thanks. From andrei.avk at gmail.com Wed Jan 11 17:39:14 2012 From: andrei.avk at gmail.com (RainyDay) Date: Wed, 11 Jan 2012 14:39:14 -0800 (PST) Subject: Explanation about for References: <581e9a24-f948-4fc4-ae28-227d6d526780@n6g2000vbg.googlegroups.com> Message-ID: On Jan 10, 6:37?am, ???????? ?????? wrote: > On 10 ???, 12:57, Thomas Rachel > > > > > > > > > a470-7603bd3aa... at spamschutz.glglgl.de> wrote: > > Am 10.01.2012 10:02 schrieb ???????? ??????: > > > > ----------------------------------------------- > > > | HOST ? ?| HITS ? ?| AGENT ? ? | DATE | > > > ----------------------------------------------- > > > | foo ? ? | 7 ? ? ? | IE6 ? ? ? | 1/1/11 | > > > ----------------------------------------------- > > > | bar ? ? | 42 ? ? ?| Firefox ? | 2/2/10 | > > > ----------------------------------------------- > > > | baz ? ? | 4 ? ? ? | Chrome ? ?| 3/3/09 | > > > ----------------------------------------------- > > > > In this line: > > > for host, hits, agent, date in dataset: > > > > 'dataset' is one of the rows of the mysql result or the whole mysql > > > result set like the table above? > > > dataset is a cursor, representing the whole result set. > > > Iterating over it produces one row at each iteration step: > > > for row in dataset: > > ? ? ?... > > > As each row consists of 4 fields, one iteration result is a tuple of 4 > > elements. > > > In this case, > > > for host, hits, agent, date in dataset: > > So that means that > > for host, hits, agent, date in dataset: > > is: > > for host, hits, agent, date in ?(foo,7,IE6,1/1/11) > > and then: > > for host, hits, agent, date in ?(bar,42,Firefox,2/2/10) > > and then: > > for host, hits, agent, date in ?(baz,4,Chrome,3/3/09) > > So 'dataset' is one row at each time? > but we said that 'dataset' represent the whole result set. > So isnt it wrong iam substituting it with one line per time only? It maps naturally to a phrase 'for page in a book'. Book refers to a complete book with all pages, but 'for page in a book' refers to each page, one by one. 'for each page in book: turn it'. The meaning is to turn each page, so your question is equivalent to asking 'so book is one page at each time'? No, it is not and doesn't have to be (unless it's a really short book!) -ak From nikos.kouras at gmail.com Wed Jan 11 17:50:33 2012 From: nikos.kouras at gmail.com (=?UTF-8?B?zp3Ouc66z4zOu86xzr/PgiDOms6/z43Pgc6xz4I=?=) Date: Wed, 11 Jan 2012 14:50:33 -0800 (PST) Subject: Explanation about for References: <581e9a24-f948-4fc4-ae28-227d6d526780@n6g2000vbg.googlegroups.com> Message-ID: <4ba0c650-ffc7-448d-a2f3-af8abca92812@cf6g2000vbb.googlegroups.com> On 10 ???, 17:24, Nick Dokos wrote: > You have been encouraged repeatedly to try these things interactively: > please do so with the above examples and all will become clear. I tried all those examples you provided me in IDLE and finally graps they idea behind it. Thanks for all your detailed explanations and the patience you showed me until i finally understood this concept. From mateusz at loskot.net Wed Jan 11 18:02:46 2012 From: mateusz at loskot.net (mloskot) Date: Wed, 11 Jan 2012 15:02:46 -0800 (PST) Subject: How do I tell "incomplete input" from "invalid input"? In-Reply-To: References: Message-ID: <1326322966944-3632798.post@n6.nabble.com> Terry Reedy wrote > > On 1/11/2012 8:50 AM, Mateusz Loskot wrote: >> Unfortunately, this FAQ is either old or incomplete thus incorrect. > > If you have a suggested change to the current text, please submit it to > the tracker at bugs.python.org > Yes, this is quite obvious procedure to me, but first I wanted to discuss the problem and to try to find proper solution worth to be included in the FAQ. Best regards, ----- -- Mateusz Loskot http://mateusz.loskot.net -- View this message in context: http://python.6.n6.nabble.com/How-do-I-tell-incomplete-input-from-invalid-input-tp3585241p3632798.html Sent from the Python - python-list mailing list archive at Nabble.com. From steve+comp.lang.python at pearwood.info Wed Jan 11 18:28:10 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Jan 2012 23:28:10 GMT Subject: ERROR:root:code for hash md5 was not found References: <4F0D7274.9080905@gmail.com> <390272b8-a041-4ece-a414-13bc9c120f61@d10g2000vbh.googlegroups.com> Message-ID: <4f0e1b0a$0$29966$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 Jan 2012 05:54:29 -0800, mike wrote: > I did some more digging and found that our class imports a "yacc.py" > that uses > > import re, types, sys, cStringIO, hashlib, os.path > > so it has hashlib. > > yacc.py seems to be an old version 1.3 ( I found 2.3 -->). > > Reading about hashlib it seems to be dependent on os installation of > OpenSSL but I cannot find out how. It shouldn't be. It will use OpenSSL if available, otherwise it will fall back on its own code. > br, > > //mike > > yacc.py > =============== > #----------------------------------------------------------------------------- > # ply: yacc.py [snip over TWO THOUSAND lines of code] Mike, what lead you to believe that an error in hashlib could be solved by posting the ENTIRE two thousand lines of yacc.py? Please do not post such huge chunks of code unless asked. It is unnecessary and annoying. Try this. Open a terminal window and enter "python" at the prompt to start a clean interactive session. Then enter the following commands: import sys print(sys.version) import hashlib print(hashlib.__file__) print(hashlib.md5) import _md5 print(_md5.__file__) and copy and paste (do not retype) the full output of these commands. Thank you. -- Steven From dihedral88888 at googlemail.com Wed Jan 11 19:24:31 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Wed, 11 Jan 2012 16:24:31 -0800 (PST) Subject: Newbie: Looking for code review on my first Python project. In-Reply-To: References: Message-ID: <21559416.867.1326327871036.JavaMail.geo-discussion-forums@prli40> HoneyMonster? 2012?1?12????UTC+8??5?09?13???? > On Wed, 11 Jan 2012 11:39:48 +0000, HoneyMonster wrote: > > > On Tue, 10 Jan 2012 18:17:48 -0700, Ian Kelly wrote: > > > >> On Tue, Jan 10, 2012 at 4:44 PM, HoneyMonster > >> wrote: > >>> Hi, > >>> > >>> I'm new to Python and recently completed my first project. I used > >>> wxPython with wxGlade to generate the GUI bits.The application seems > >>> to work well, but I am entirely self-taught, so have undoubtedly > >>> committed a number of howlers in terms of style, design, standards, > >>> best practice and so forth. > > < snip constructive and helpful advice > > > > > Very many thanks to Ian and to all who responded. I really appreciate > > the guidance. Cheers. > > > I have taken on board the helpful suggestions offered, and looked though > the PEP-8 document which has been mentioned. > > As a result, there are a number of changes to the code. My second attempt > is in the same place: > > > > A couple of points: > > 1) I'm reluctant to try to improve this bit of code: > ------------------------------------------------------------- > self.add = wx.MenuItem(self.file, wx.NewId(), "&Add to Queue", > "Add a programme to the queue (for download later)", wx.ITEM_NORMAL) > self.file.AppendItem(self.add) > ------------------------------------------------------------- > since it is generated by wxGlade and so will be overwritten. > > 2) I was very unsure about the wx.CallAfter, and suspect that I have put > it in the wrong place. It seems to pass off well enough in Linux, but on > Windows it appears to prevent the widgets on the splash frame being drawn > properly. > > If anyone would be kind enough, further comments would be welcomed. > > Thanks, > WH I haven't tried wxGlade for several years. I checked BOA, WxGlade and Wxpython and pygame 4 years ago. Auto code generators in BOA and WxGlade are more helpful to python programmers. One can develop GUI by python with Tcl/tk or Qt, too. But the license conditions in software packages are not all the same. From jason at powerpull.net Wed Jan 11 19:31:44 2012 From: jason at powerpull.net (Jason Friedman) Date: Thu, 12 Jan 2012 00:31:44 +0000 Subject: Python lib for creating Database tables In-Reply-To: References: Message-ID: > Hello All, > > I just made something pretty simple that I intend to use while creating > database tables. It is still in the basic form, and much needs to be added. > However, I use introspection to make it a bit easier and less work on the > user. > > I would want my code to be reviewed by this great group. I look forward to > your feedback ?and comments. > https://github.com/janus/cheeta Cheeta has similarities to http://www.sqlalchemy.org/. From dihedral88888 at googlemail.com Wed Jan 11 20:37:11 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Wed, 11 Jan 2012 17:37:11 -0800 (PST) Subject: open office in another language? In-Reply-To: References: <20120111223508.413f2b68@Fuddel> Message-ID: <1609164.984.1326332231661.JavaMail.geo-discussion-forums@prmu37> Open Office suite software users are most non-programmers. Software to be used by non-programmers are different from most free python packages shared by programmers. From dihedral88888 at googlemail.com Wed Jan 11 20:37:11 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Wed, 11 Jan 2012 17:37:11 -0800 (PST) Subject: open office in another language? In-Reply-To: References: <20120111223508.413f2b68@Fuddel> Message-ID: <1609164.984.1326332231661.JavaMail.geo-discussion-forums@prmu37> Open Office suite software users are most non-programmers. Software to be used by non-programmers are different from most free python packages shared by programmers. From wuwei23 at gmail.com Wed Jan 11 20:37:27 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 11 Jan 2012 17:37:27 -0800 (PST) Subject: Introspecting optparse/argparse objects References: Message-ID: On Jan 11, 11:26?am, Evan Driscoll wrote: > (For a concrete idea of a use case, suppose that it did not > directly support the --help option and I wanted to write code that took > its place.) That's a pretty weird definition of 'concrete use case', but anyway... > This means that either I need to write my own wrappers around options, > option groups, and perhaps even an option parser, or I have to dig into > _variables _that _are _not _part _of _the _public _api. Both of those > choices are distasteful. If you're wanting to extend the behaviour of the options, won't you need to wrap them anyway? But more to the point, you already have the data: you used it to create the options. Why not just keep a handle on that data and refer to what you need directly? > 2) Is there some particular reason that this API *isn't* provided, and > if I asked for it I might get it in a future version? Not in optparse, as it's no longer being developed. For argparse, you might want a better use case: adding functionality to support a hypothetical "lack" of functionality (which is _actually_ provides) seems like a pedantic exercise to me. From matt.pounsett at gmail.com Wed Jan 11 21:19:16 2012 From: matt.pounsett at gmail.com (Matthew Pounsett) Date: Wed, 11 Jan 2012 18:19:16 -0800 (PST) Subject: Two questions about logging Message-ID: <7dabf43f-3814-47b6-966a-1439f56548b5@i6g2000vbk.googlegroups.com> I'm trying to figure out a couple of things with the logging module, and I'm hoping someone can provide some pointers. I've read through the module docs on python.org, the basic and advanced tutorials, and the cookbook post, but a couple of things still elude me. First, I'd like to be able to permit users to do more typical log rotation, based on their OS's log rotation handler, rather than rotating logs from inside an application. This is usually handled by signalling an application with a HUP, whereupon it closes and then re- opens all of its logs, getting new file handles (and new inodes). I don't see anything in the Handler methods (or anywhere else) that would let me tell a logger object to refresh the file handles on a log file. Is there some standard way to deal with this? Second, I'm trying to get a handle on how libraries are meant to integrate with the applications that use them. The naming advice in the advanced tutorial is to use __name__ to name loggers, and to allow log messages to pass back up to the using application's logger for processing, but these two pieces of advice seem contradictory.. since log messages only pass back up to the root if the loggers are named hierarchically. > cat foo.py #!/usr/bin/env python import logging import bar logger = logging.getLogger(__name__) fh = logging.FileHandler('foo.log') ch = logging.StreamHandler() logger.addHandler(fh) logger.addHandler(ch) logger.warning('from the first') bar.funct() > cat bar.py #!/usr/bin/env python import logging def funct(): logger = logging.getLogger(__name__) logger.warning('from the second') > ./foo.py from the first No handlers could be found for logger "bar" So, given this state of affairs, how is a library author to use loggers, given that he or she can't know how authors who use the library will name their logger objects? In the above example, what would the author of bar.py do to hook up bar's logger with foo's, without knowing in advance what foo's logger will be named? Thanks very much for any suggestions, or pointers to documentation that I've missed. From roy at panix.com Wed Jan 11 21:34:23 2012 From: roy at panix.com (Roy Smith) Date: Wed, 11 Jan 2012 21:34:23 -0500 Subject: Two questions about logging References: <7dabf43f-3814-47b6-966a-1439f56548b5@i6g2000vbk.googlegroups.com> Message-ID: In article <7dabf43f-3814-47b6-966a-1439f56548b5 at i6g2000vbk.googlegroups.com>, Matthew Pounsett wrote: > First, I'd like to be able to permit users to do more typical log > rotation, based on their OS's log rotation handler, rather than > rotating logs from inside an application. This is usually handled by > signalling an application with a HUP, whereupon it closes and then re- > opens all of its logs, getting new file handles (and new inodes). I > don't see anything in the Handler methods (or anywhere else) that > would let me tell a logger object to refresh the file handles on a log > file. Is there some standard way to deal with this? What I would do is log to syslog (logging.handlers.SysLogHandler) and let syslog worry about rotating log files. Why reinvent the wheel? From edriscoll at wisc.edu Wed Jan 11 21:44:28 2012 From: edriscoll at wisc.edu (Evan Driscoll) Date: Wed, 11 Jan 2012 20:44:28 -0600 Subject: Introspecting optparse/argparse objects In-Reply-To: References: Message-ID: <4F0E490C.7040009@wisc.edu> On 1/11/2012 19:37, alex23 wrote: > On Jan 11, 11:26 am, Evan Driscoll wrote: >> (For a concrete idea of a use case, suppose that it did not >> directly support the --help option and I wanted to write code that took >> its place.) > That's a pretty weird definition of 'concrete use case', but anyway... It's actually closer to the truth than it might seem. I want to feed a bash-completion-style thing, using the same data structure to both figure out the possible completions and also do the actual parsing. "Do the actual parsing" = optparse/argparse, while "figure out the possible completions" = I need to be able to look at a list. > If you're wanting to extend the behaviour of the options, won't you > need to wrap them anyway? I don't have any need to extend the parsers other than to get the list of options. (Though now that you've brought that up, perhaps looking at the _private fields in a subclass would be the best tradeoff? Hmmm.) > But more to the point, you already have the data: you used it to > create the options. Why not just keep a handle on that data and refer > to what you need directly? But now you're talking about wrapping the parser, because there's no builtin way (at least that I know of) to store the information in such a way that you can call the function, because it uses a mix of positional and keyword arguments. E.g. I can't say just args = ('-f', '--foo', help='do foo') ... parser.add_argument(*args) but would have to say something like args = ( ('-f', '-foo'), {'help': 'do foo'}) ... parser.add_argument(*args[0], *args[1]) or something like that. I'd want to add some function like 'make_option' which wraps all that up, and then provide a nicer interface for add_argument, etc., and it seems like pretty soon I're reimplementing the optparse API. :-) Or at least it might be that way. 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 edriscoll at wisc.edu Wed Jan 11 21:49:14 2012 From: edriscoll at wisc.edu (Evan Driscoll) Date: Wed, 11 Jan 2012 20:49:14 -0600 Subject: Ctypes compatibility In-Reply-To: References: <4F0CFFFF.80202@wisc.edu> Message-ID: <4F0E4A2A.9020500@wisc.edu> On 1/10/2012 22:42, Alec Taylor wrote: > Use size_t > > http://en.wikipedia.org/wiki/C_data_types#Size_and_pointer_difference_types Um, perhaps you misunderstand. I don't control the C API, I'm calling a function that just exists in libc (unless I do what I said and write a wrapper). If you're saying I should use c_size_t on the Python side, I think that's outright wrong since I think some of the fields in the dirent struct are 64 bits even on 32-bit systems. (I might be wrong about that though.) And even neglecting that, the types of the fields is only part of the problem. 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 matt.pounsett at gmail.com Wed Jan 11 22:31:41 2012 From: matt.pounsett at gmail.com (Matthew Pounsett) Date: Wed, 11 Jan 2012 19:31:41 -0800 (PST) Subject: Two questions about logging References: <7dabf43f-3814-47b6-966a-1439f56548b5@i6g2000vbk.googlegroups.com> Message-ID: <8055301a-3a4e-4162-ae24-af004da6139c@t13g2000vbt.googlegroups.com> On Jan 11, 9:34?pm, Roy Smith wrote: > What I would do is log to syslog (logging.handlers.SysLogHandler) and > let syslog worry about rotating log files. ?Why reinvent the wheel? Syslog is fine for an application run by an administrator, but isn't an option for a user. From th982a at googlemail.com Thu Jan 12 00:01:36 2012 From: th982a at googlemail.com (Tamer Higazi) Date: Thu, 12 Jan 2012 06:01:36 +0100 Subject: how to install lxml in window xp? In-Reply-To: References: Message-ID: <4F0E6930.6070701@googlemail.com> Use Linux! Specially Gentoo Linux! Tamer Am 09.01.2012 10:18, schrieb ????: > in my xp ,python26,easy_install installed. > i want to install lxml in window xp > 1.c:\python26\scripts\easy_install lxml > > what i get is: > > Reading http://codespeak.net/lxml > Best match: lxml 2.3.3 > Downloading http://lxml.de/files/lxml-2.3.3.tgz > Processing lxml-2.3.3.tgz > Running lxml-2.3.3\setup.py -q bdist_egg --dist-dir > c:\windows\temp\easy_install > -58e4ap\lxml-2.3.3\egg-dist-tmp-hyg1bg > Building lxml version 2.3.3. > Building with Cython 0.15.1. > ERROR: 'xslt-config' is not recognized as an internal or external command, > operable program or batch file. > > ** make sure the development packages of libxml2 and libxslt are > installed ** > > Using build configuration of libxslt > warning: no files found matching 'lxml.etree.c' under directory 'src\lxml' > warning: no files found matching 'lxml.objectify.c' under directory > 'src\lxml' > warning: no files found matching 'lxml.etree.h' under directory 'src\lxml' > warning: no files found matching 'lxml.etree_api.h' under directory > 'src\lxml' > warning: no files found matching 'etree_defs.h' under directory 'src\lxml' > > > Reading http://codespeak.net/lxml > Best match: lxml 2.3.3 > Downloading http://lxml.de/files/lxml-2.3.3.tgz > Processing lxml-2.3.3.tgz > Running lxml-2.3.3\setup.py -q bdist_egg --dist-dir > c:\windows\temp\easy_install > -58e4ap\lxml-2.3.3\egg-dist-tmp-hyg1bg > Building lxml version 2.3.3. > Building with Cython 0.15.1. > ERROR: 'xslt-config' is not recognized as an internal or external command, > operable program or batch file. > > ** make sure the development packages of libxml2 and libxslt are > installed ** > > Using build configuration of libxslt > warning: no files found matching 'lxml.etree.c' under directory 'src\lxml' > warning: no files found matching 'lxml.objectify.c' under directory > 'src\lxml' > warning: no files found matching 'lxml.etree.h' under directory 'src\lxml' > warning: no files found matching 'lxml.etree_api.h' under directory > 'src\lxml' > warning: no files found matching 'etree_defs.h' under directory 'src\lxml' > warning: no files found matching 'pubkey.asc' under directory 'doc' > warning: no files found matching 'tagpython*.png' under directory 'doc' > warning: no files found matching 'Makefile' under directory 'doc' > > error: Setup script exited with error: None > > how can i install the lxml in my xp?? > > From brian at python.org Thu Jan 12 00:08:00 2012 From: brian at python.org (Brian Curtin) Date: Wed, 11 Jan 2012 23:08:00 -0600 Subject: how to install lxml in window xp? In-Reply-To: <4F0E6930.6070701@googlemail.com> References: <4F0E6930.6070701@googlemail.com> Message-ID: On Wed, Jan 11, 2012 at 23:01, Tamer Higazi wrote: > Use Linux! > Specially Gentoo Linux! Not a useful answer. From kushal.kumaran+python at gmail.com Thu Jan 12 00:23:47 2012 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Thu, 12 Jan 2012 10:53:47 +0530 Subject: pipe into preallocated buffer? In-Reply-To: References: Message-ID: On Wed, Jan 4, 2012 at 8:05 PM, Mihai Badoiu wrote: > is there a way to pipe directly into a preallocated buffer? > ?(subprocessing.pipe.stdout) > Does io.StringIO fit your needs? http://docs.python.org/py3k/library/io.html#io.StringIO -- regards, kushal From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Thu Jan 12 01:11:15 2012 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Thu, 12 Jan 2012 07:11:15 +0100 Subject: pipe into preallocated buffer? In-Reply-To: References: Message-ID: Am 12.01.2012 06:23 schrieb Kushal Kumaran: > On Wed, Jan 4, 2012 at 8:05 PM, Mihai Badoiu wrote: >> is there a way to pipe directly into a preallocated buffer? >> (subprocessing.pipe.stdout) >> > > Does io.StringIO fit your needs? > > http://docs.python.org/py3k/library/io.html#io.StringIO Probably not. A file object used in the subprocess context needs a fileno() method. StringIO objects don't have such. Probably it is necessary to use subprocess.communicate() (for rather small data lengths) or to use sp.stdout.read() to read it manually. Thomas From mikaelpetterson1 at gmail.com Thu Jan 12 01:13:16 2012 From: mikaelpetterson1 at gmail.com (mike) Date: Wed, 11 Jan 2012 22:13:16 -0800 (PST) Subject: ERROR:root:code for hash md5 was not found References: <4F0D7274.9080905@gmail.com> <390272b8-a041-4ece-a414-13bc9c120f61@d10g2000vbh.googlegroups.com> <4f0e1b0a$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Jan 12, 12:28?am, Steven D'Aprano wrote: > On Wed, 11 Jan 2012 05:54:29 -0800, mike wrote: > > I did some more digging and found that our class imports a "yacc.py" > > that uses > > > import re, types, sys, cStringIO, hashlib, os.path > > > so it has hashlib. > > > yacc.py seems to be an old version 1.3 ( I found 2.3 -->). > > > Reading about hashlib it seems to be dependent on os installation of > > OpenSSL but I cannot find out how. > > It shouldn't be. It will use OpenSSL if available, otherwise it will fall > back on its own code. > > > br, > > > //mike > > > yacc.py > > =============== > > #-----------------------------------------------------------------------------> # ply: yacc.py > > [snip over TWO THOUSAND lines of code] > > Mike, what lead you to believe that an error in hashlib could be solved > by posting the ENTIRE two thousand lines of yacc.py? Please do not post > such huge chunks of code unless asked. It is unnecessary and annoying. > > Try this. Open a terminal window and enter "python" at the prompt to > start a clean interactive session. Then enter the following commands: > > import sys > print(sys.version) > import hashlib > print(hashlib.__file__) > print(hashlib.md5) > import _md5 > print(_md5.__file__) > > and copy and paste (do not retype) the full output of these commands. > > Thank you. > > -- > Steven Hi, Sorry for posting huge file. I added your copy-paste snippet. esekilx5030 [7:09am] [roamFroBl/pysibelius/bin] -> python Python 2.7.2 (default, Jun 16 2011, 15:05:49) [GCC 4.5.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys print(sys.version) import hashlib print(hashlib.__file__) print(hashlib.md5) import _md5 print(_md5.__file__) >>> 2.7.2 (default, Jun 16 2011, 15:05:49) [GCC 4.5.0] >>> ERROR:root:code for hash md5 was not found. Traceback (most recent call last): File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ hashlib.py", line 139, in globals()[__func_name] = __get_hash(__func_name) File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type %s' % name) ValueError: unsupported hash type md5 ERROR:root:code for hash sha1 was not found. Traceback (most recent call last): File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ hashlib.py", line 139, in globals()[__func_name] = __get_hash(__func_name) File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type %s' % name) ValueError: unsupported hash type sha1 ERROR:root:code for hash sha224 was not found. Traceback (most recent call last): File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ hashlib.py", line 139, in globals()[__func_name] = __get_hash(__func_name) File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type %s' % name) ValueError: unsupported hash type sha224 ERROR:root:code for hash sha256 was not found. Traceback (most recent call last): File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ hashlib.py", line 139, in globals()[__func_name] = __get_hash(__func_name) File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type %s' % name) ValueError: unsupported hash type sha256 ERROR:root:code for hash sha384 was not found. Traceback (most recent call last): File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ hashlib.py", line 139, in globals()[__func_name] = __get_hash(__func_name) File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type %s' % name) ValueError: unsupported hash type sha384 ERROR:root:code for hash sha512 was not found. Traceback (most recent call last): File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ hashlib.py", line 139, in globals()[__func_name] = __get_hash(__func_name) File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type %s' % name) ValueError: unsupported hash type sha512 >>> /vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/hashlib.pyc >>> Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'md5' >>> Traceback (most recent call last): File "", line 1, in ImportError: No module named _md5 Thanks for support! //mike From mobilebackup77 at gmail.com Thu Jan 12 01:34:21 2012 From: mobilebackup77 at gmail.com (Ram) Date: Wed, 11 Jan 2012 22:34:21 -0800 (PST) Subject: Bug in logutils package Message-ID: <23549037-c9a0-4712-9bef-1f0f590032d8@v13g2000yqc.googlegroups.com> Does anyone have any inkling on how to fix this bug? http://code.google.com/p/logutils/issues/detail?id=3 Or any good pointers on how to find out whats wrong and how to fix it would be nice. Thanks, --Ram From mikaelpetterson1 at gmail.com Thu Jan 12 02:25:09 2012 From: mikaelpetterson1 at gmail.com (mike) Date: Wed, 11 Jan 2012 23:25:09 -0800 (PST) Subject: ERROR:root:code for hash md5 was not found References: <4F0D7274.9080905@gmail.com> <390272b8-a041-4ece-a414-13bc9c120f61@d10g2000vbh.googlegroups.com> <4f0e1b0a$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <36deda3e-bbed-4979-b668-7dcaf5452bc5@p13g2000yqd.googlegroups.com> On Jan 12, 7:13?am, mike wrote: > On Jan 12, 12:28?am, Steven D'Aprano > > > > > > > > > +comp.lang.pyt... at pearwood.info> wrote: > > On Wed, 11 Jan 2012 05:54:29 -0800, mike wrote: > > > I did some more digging and found that our class imports a "yacc.py" > > > that uses > > > > import re, types, sys, cStringIO, hashlib, os.path > > > > so it has hashlib. > > > > yacc.py seems to be an old version 1.3 ( I found 2.3 -->). > > > > Reading about hashlib it seems to be dependent on os installation of > > > OpenSSL but I cannot find out how. > > > It shouldn't be. It will use OpenSSL if available, otherwise it will fall > > back on its own code. > > > > br, > > > > //mike > > > > yacc.py > > > =============== > > > #-----------------------------------------------------------------------------> # ply: yacc.py > > > [snip over TWO THOUSAND lines of code] > > > Mike, what lead you to believe that an error in hashlib could be solved > > by posting the ENTIRE two thousand lines of yacc.py? Please do not post > > such huge chunks of code unless asked. It is unnecessary and annoying. > > > Try this. Open a terminal window and enter "python" at the prompt to > > start a clean interactive session. Then enter the following commands: > > > import sys > > print(sys.version) > > import hashlib > > print(hashlib.__file__) > > print(hashlib.md5) > > import _md5 > > print(_md5.__file__) > > > and copy and paste (do not retype) the full output of these commands. > > > Thank you. > > > -- > > Steven > > Hi, > > Sorry for posting huge file. I added your copy-paste snippet. > > esekilx5030 [7:09am] [roamFroBl/pysibelius/bin] -> python > Python 2.7.2 (default, Jun 16 2011, 15:05:49) > [GCC 4.5.0] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> import sys > > print(sys.version) > import hashlib > print(hashlib.__file__) > print(hashlib.md5) > import _md5 > print(_md5.__file__) >>> 2.7.2 (default, Jun 16 2011, 15:05:49) > [GCC 4.5.0]>>> ERROR:root:code for hash md5 was not found. > > Traceback (most recent call last): > ? File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ > hashlib.py", line 139, in > ? ? globals()[__func_name] = __get_hash(__func_name) > ? File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ > hashlib.py", line 91, in __get_builtin_constructor > ? ? raise ValueError('unsupported hash type %s' % name) > ValueError: unsupported hash type md5 > ERROR:root:code for hash sha1 was not found. > Traceback (most recent call last): > ? File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ > hashlib.py", line 139, in > ? ? globals()[__func_name] = __get_hash(__func_name) > ? File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ > hashlib.py", line 91, in __get_builtin_constructor > ? ? raise ValueError('unsupported hash type %s' % name) > ValueError: unsupported hash type sha1 > ERROR:root:code for hash sha224 was not found. > Traceback (most recent call last): > ? File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ > hashlib.py", line 139, in > ? ? globals()[__func_name] = __get_hash(__func_name) > ? File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ > hashlib.py", line 91, in __get_builtin_constructor > ? ? raise ValueError('unsupported hash type %s' % name) > ValueError: unsupported hash type sha224 > ERROR:root:code for hash sha256 was not found. > Traceback (most recent call last): > ? File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ > hashlib.py", line 139, in > ? ? globals()[__func_name] = __get_hash(__func_name) > ? File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ > hashlib.py", line 91, in __get_builtin_constructor > ? ? raise ValueError('unsupported hash type %s' % name) > ValueError: unsupported hash type sha256 > ERROR:root:code for hash sha384 was not found. > Traceback (most recent call last): > ? File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ > hashlib.py", line 139, in > ? ? globals()[__func_name] = __get_hash(__func_name) > ? File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ > hashlib.py", line 91, in __get_builtin_constructor > ? ? raise ValueError('unsupported hash type %s' % name) > ValueError: unsupported hash type sha384 > ERROR:root:code for hash sha512 was not found. > Traceback (most recent call last): > ? File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ > hashlib.py", line 139, in > ? ? globals()[__func_name] = __get_hash(__func_name) > ? File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ > hashlib.py", line 91, in __get_builtin_constructor > ? ? raise ValueError('unsupported hash type %s' % name) > ValueError: unsupported hash type sha512>>> /vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/hashlib.pyc > >>> Traceback (most recent call last): > > ? File "", line 1, in > AttributeError: 'module' object has no attribute 'md5'>>> Traceback (most recent call last): > > ? File "", line 1, in > ImportError: No module named _md5 > > Thanks for support! > > //mike Hi, I did some more testing. The python 2.7.2 lib is stored in a clearcase vob. When I set the env. and run suggested lines ( with slight modification), on Redhat 5.5, ( by Steven) I get the following: -> python Python 2.7.2 (default, Jun 16 2011, 15:05:49) [GCC 4.5.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys print(sys.version) import hashlib print(hashlib.__file__) print(hashlib.md5) import md5 print(md5.__file__)>>> 2.7.2 (default, Jun 16 2011, 15:05:49) [GCC 4.5.0] >>> ERROR:root:code for hash md5 was not found. Traceback (most recent call last): File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ hashlib.py", line 139, in globals()[__func_name] = __get_hash(__func_name) File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type %s' % name) ValueError: unsupported hash type md5 ERROR:root:code for hash sha1 was not found. Traceback (most recent call last): File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ hashlib.py", line 139, in globals()[__func_name] = __get_hash(__func_name) File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type %s' % name) ValueError: unsupported hash type sha1 ERROR:root:code for hash sha224 was not found. Traceback (most recent call last): File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ hashlib.py", line 139, in globals()[__func_name] = __get_hash(__func_name) File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type %s' % name) ValueError: unsupported hash type sha224 ERROR:root:code for hash sha256 was not found. Traceback (most recent call last): File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ hashlib.py", line 139, in globals()[__func_name] = __get_hash(__func_name) File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type %s' % name) ValueError: unsupported hash type sha256 ERROR:root:code for hash sha384 was not found. Traceback (most recent call last): File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ hashlib.py", line 139, in globals()[__func_name] = __get_hash(__func_name) File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type %s' % name) ValueError: unsupported hash type sha384 ERROR:root:code for hash sha512 was not found. Traceback (most recent call last): File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ hashlib.py", line 139, in globals()[__func_name] = __get_hash(__func_name) File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type %s' % name) ValueError: unsupported hash type sha512 >>> /vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/hashlib.pyc >>> Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'md5' >>> Traceback (most recent call last): File "", line 1, in File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ md5.py", line 10, in from hashlib import md5 ImportError: cannot import name md5 But when I execute the same lines on a Suse 10.4 I get the following output: python Python 2.7.2 (default, Jun 16 2011, 15:05:49) [GCC 4.5.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> print(sys.version) 2.7.2 (default, Jun 16 2011, 15:05:49) [GCC 4.5.0] >>> import hashlib >>> print(hashlib.__file__) /vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/hashlib.pyc >>> print(hashlib.md5) >>> import md5 >>> print(md5.__file__) /vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/md5.pyc That looks correct to me. It really confuses me!? br, //mike Ps. Thanks for all the replies. From jeanmichel at sequans.com Thu Jan 12 05:28:55 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 12 Jan 2012 11:28:55 +0100 Subject: Two questions about logging In-Reply-To: <7dabf43f-3814-47b6-966a-1439f56548b5@i6g2000vbk.googlegroups.com> References: <7dabf43f-3814-47b6-966a-1439f56548b5@i6g2000vbk.googlegroups.com> Message-ID: <4F0EB5E7.4030602@sequans.com> Matthew Pounsett wrote: > [snip] > > Second, I'm trying to get a handle on how libraries are meant to > integrate with the applications that use them. The naming advice in > the advanced tutorial is to use __name__ to name loggers, and to allow > log messages to pass back up to the using application's logger for > processing, but these two pieces of advice seem contradictory.. since > log messages only pass back up to the root if the loggers are named > hierarchically. > > [snip] > > So, given this state of affairs, how is a library author to use > loggers, given that he or she can't know how authors who use the > library will name their logger objects? In the above example, what > would the author of bar.py do to hook up bar's logger with foo's, > without knowing in advance what foo's logger will be named? > > > Thanks very much for any suggestions, or pointers to documentation > that I've missed. > All loggers share at least one parent : the root logger. In the standard way of using the loggers, the root logger is *the* logger responsible of processing logs. Considering that extlib is an external library from anApp, and intlib an internal library to the anApp application: People may expect logs that way: anApp.extlib : INFO : a log message anApp.intlib : INFO : another message However, what will happen is : extlib : INFO : message from the external lib anApp.intlib : INFO : message from the internal lib As you mentioned in your post, there is no way to 'attach' an external lib to your application since the external lib knows nothing about the application, but there is no need to attach it actually. JM From th982a at googlemail.com Thu Jan 12 06:24:15 2012 From: th982a at googlemail.com (Tamer Higazi) Date: Thu, 12 Jan 2012 12:24:15 +0100 Subject: how to install lxml in window xp? In-Reply-To: References: <4F0E6930.6070701@googlemail.com> Message-ID: <4F0EC2DF.7030504@googlemail.com> Am 12.01.2012 06:08, schrieb Brian Curtin: > On Wed, Jan 11, 2012 at 23:01, Tamer Higazi wrote: >> Use Linux! >> Specially Gentoo Linux! > > Not a useful answer. then take windows 7 instead of something that is no more supported by the vendor itself. I am running Python 64Bit on my Windows machine and almost every library could have been installed my sides with the MSSDK and the Visual C++ 2008 Express Edition compiler in the background, that tasks are invoked automatically by easy_install. So, instead of making yourself continuously headache for an outdated OS I advise taking a low performance OS like, let us say, xubunutu that has a light environment instead of gnome3 or kde4 for a WindowsXP designed CPU. Tamer From __peter__ at web.de Thu Jan 12 07:24:32 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 12 Jan 2012 13:24:32 +0100 Subject: stable object serialization to text file References: <030AD516-2A52-411B-9A20-BD60DF8AE75B@me.com> Message-ID: M?t? Koch wrote: > I'm developing an app which stores the data in file system database. The > data in my case consists of large python objects, mostly dicts, containing > texts and numbers. The easiest way to dump and load them would be pickle, > but I have a problem with it: I want to keep the data in version control, > and I would like to use it as efficiently as possible. Is it possible to > force pickle to store the otherwise unordered (e.g. dictionary) data in a > kind of ordered way, so that if I dump a large dict, then change 1 tiny > thing in it and dump again, the diff of the former and the new file will > be minimal? > > If pickle is not the best choice for me, can you suggest anything else? > (If there isn't any solution for it so far, I will write the module of > course, but first I'd like to look around and make sure it hasn't been > created yet.) Have you considered json? http://docs.python.org/library/json.html The encoder features a sort_keys flag which might help. From koch.mate at me.com Thu Jan 12 08:32:19 2012 From: koch.mate at me.com (=?iso-8859-1?Q?M=E1t=E9_Koch?=) Date: Thu, 12 Jan 2012 14:32:19 +0100 Subject: stable object serialization to text file In-Reply-To: References: <030AD516-2A52-411B-9A20-BD60DF8AE75B@me.com> Message-ID: <0E405AE1-341E-4D81-9474-34DDDD3AE933@me.com> That's probably the easiest way as I don't store any binary data just strings and numbers. Thanks! On Jan 12, 2012, at 1:24 PM, Peter Otten wrote: > M?t? Koch wrote: > >> I'm developing an app which stores the data in file system database. The >> data in my case consists of large python objects, mostly dicts, containing >> texts and numbers. The easiest way to dump and load them would be pickle, >> but I have a problem with it: I want to keep the data in version control, >> and I would like to use it as efficiently as possible. Is it possible to >> force pickle to store the otherwise unordered (e.g. dictionary) data in a >> kind of ordered way, so that if I dump a large dict, then change 1 tiny >> thing in it and dump again, the diff of the former and the new file will >> be minimal? >> >> If pickle is not the best choice for me, can you suggest anything else? >> (If there isn't any solution for it so far, I will write the module of >> course, but first I'd like to look around and make sure it hasn't been >> created yet.) > > Have you considered json? > > http://docs.python.org/library/json.html > > The encoder features a sort_keys flag which might help. > > -- > http://mail.python.org/mailman/listinfo/python-list From nathan.alexander.rice at gmail.com Thu Jan 12 11:04:26 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Thu, 12 Jan 2012 11:04:26 -0500 Subject: Python lib for creating Database tables In-Reply-To: References: Message-ID: On Wed, Jan 11, 2012 at 4:38 PM, Emeka wrote: > Hello All, > > I just made something pretty simple that I intend to use while creating > database tables. It is still in the basic form, and much needs to be added. > However, I use introspection to make it a bit easier and less work on the > user. > > I would want my code to be reviewed by this great group. I look forward to > your feedback ?and comments. > https://github.com/janus/cheeta Having done a LOT of work with SQL Alchemy, I would definitely encourage you to just bite the bullet and get on board with it now. I routinely do very challenging things with it, and it has yet to be a roadblock. The learning curve can be somewhat steep but it is absolutely worth it. Nathan From dreadpiratejeff at gmail.com Thu Jan 12 11:04:27 2012 From: dreadpiratejeff at gmail.com (J) Date: Thu, 12 Jan 2012 11:04:27 -0500 Subject: Is there a way to merge two XML files via Python? Message-ID: This is more a theory exercise and something I'm trying to figure out, and this is NOT a homework assignment... I'm trying to make a tool I use at work more efficient :) So this is at test tool that generates an XML file as it's output that is eventually used by a web service to display test results and system information. The problem is that the testing is broken down into to different runs: Functional and Automated where the Functional tests are all manual, then the automated tests are run separately, usually overnight. Each of those test runs generates essentially an identical XML file. What I want to learn is a way to merge them. In abstract terms, the idea is essentially to diff the two files creating a patch and then use that patch to merge the two files into a single XML file. SO what I was hoping I could get pointers on from those of you who are experienced in using Python with XML is what python libraries or means are there for working with XML files specifically, and how easy or difficult would this be? I'm also doing research on my own in my spare time on this, but I also wanted to ask here to get the opinion of developers who are more experienced in working with XML than I am. Thanks Jeff From stefan_ml at behnel.de Thu Jan 12 11:39:06 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 12 Jan 2012 17:39:06 +0100 Subject: Is there a way to merge two XML files via Python? In-Reply-To: References: Message-ID: J, 12.01.2012 17:04: > This is more a theory exercise and something I'm trying to figure out, > and this is NOT a homework assignment... > > I'm trying to make a tool I use at work more efficient :) > > So this is at test tool that generates an XML file as it's output that > is eventually used by a web service to display test results and system > information. > > The problem is that the testing is broken down into to different runs: > Functional and Automated where the Functional tests are all manual, > then the automated tests are run separately, usually overnight. > > Each of those test runs generates essentially an identical XML file. > What I want to learn is a way to merge them. Ok - how large are these files? (i.e., do they easily fit into memory?) > In abstract terms, the idea is essentially to diff the two files > creating a patch and then use that patch to merge the two files into a > single XML file. I wouldn't go through patch. If they fit into memory, just load both, merge one into the other eliminating duplicates, and save that. Or rather, load just one and process the other one incrementally using ElementTree's iterparse(). > SO what I was hoping I could get pointers on from those of you who are > experienced in using Python with XML is what python libraries or means > are there for working with XML files specifically, and how easy or > difficult would this be? Depends on how easy it is to recognise duplicates in your specific data format. Once you've managed to do that, the rest is trivial. > I'm also doing research on my own in my spare time on this, but I also > wanted to ask here to get the opinion of developers who are more > experienced in working with XML than I am. I recommend looking at the stdlib xml.etree.ElementTree module or the external lxml package (which contains the ElementTree compatible lxml.etree module). The latter will (likely) make things easier due to full XPath support and some other goodies, but ElementTree is also quite quick and easy to use by itself. Stefan From d at davea.name Thu Jan 12 12:02:41 2012 From: d at davea.name (Dave Angel) Date: Thu, 12 Jan 2012 12:02:41 -0500 Subject: Is there a way to merge two XML files via Python? In-Reply-To: References: Message-ID: <4F0F1231.7050000@davea.name> On 01/12/2012 11:39 AM, Stefan Behnel wrote: > J, 12.01.2012 17:04: >> This is more a theory exercise and something I'm trying to figure out, >> and this is NOT a homework assignment... >> >> I'm trying to make a tool I use at work more efficient :) >> >> So this is at test tool that generates an XML file as it's output that >> is eventually used by a web service to display test results and system >> information. >> >> The problem is that the testing is broken down into to different runs: >> Functional and Automated where the Functional tests are all manual, >> then the automated tests are run separately, usually overnight. >> >> Each of those test runs generates essentially an identical XML file. >> What I want to learn is a way to merge them. > Ok - how large are these files? (i.e., do they easily fit into memory?) > > >> In abstract terms, the idea is essentially to diff the two files >> creating a patch and then use that patch to merge the two files into a >> single XML file. > I wouldn't go through patch. If they fit into memory, just load both, merge > one into the other eliminating duplicates, and save that. > > Or rather, load just one and process the other one incrementally using > ElementTree's iterparse(). > > >> SO what I was hoping I could get pointers on from those of you who are >> experienced in using Python with XML is what python libraries or means >> are there for working with XML files specifically, and how easy or >> difficult would this be? > Depends on how easy it is to recognise duplicates in your specific data > format. Once you've managed to do that, the rest is trivial. > > >> I'm also doing research on my own in my spare time on this, but I also >> wanted to ask here to get the opinion of developers who are more >> experienced in working with XML than I am. > I recommend looking at the stdlib xml.etree.ElementTree module or the > external lxml package (which contains the ElementTree compatible lxml.etree > module). The latter will (likely) make things easier due to full XPath > support and some other goodies, but ElementTree is also quite quick and > easy to use by itself. > > Stefan > Question for jeff: Have you tried doing it by hand? Do you know when a duplicate should be ignored, when it should be replicated, when it should be represented by incrementing a count? xml is very flexible, but the final reader of your file may not be so flexible. (e.g. if it has to match a wsdl) If two runs differ only by some timing field, then you might need to sum those times, and produce an average in the final run. Or a max value, or both. -- DaveA From info at wingware.com Thu Jan 12 15:02:08 2012 From: info at wingware.com (Wingware) Date: Thu, 12 Jan 2012 15:02:08 -0500 Subject: Wing IDE 4.1.3 released Message-ID: <4F0F3C40.8090004@wingware.com> Hi, Wingware has released version 4.1.3 of Wing IDE, an integrated development environment designed specifically for the Python programming language. Wing IDE is a cross-platform Python IDE that provides a professional code editor with vi, emacs, and other key bindings, auto-completion, call tips, refactoring, context-aware auto-editing, a powerful graphical debugger, version control, unit testing, search, and many other features. **Changes in Version 4.1.3** Highlights of this release include: * Added move-line-up and move-line-down line editing commands * Added Open From Project option to search only on the file name * Added goto-overridden-method command * Added copy-reference command to copy filename, line number(s), scope, and optionally the current or selected lines to the clipboard * Added experimental Eclipse style key binding * Several auto-editing improvements * 12 vi mode fixes * Avoid grouping snippets and arg entry into a single undo action * Speed up auto-completion and auto-editing * About 25 other bug fixes and minor improvements Complete change log: http://wingware.com/pub/wingide/4.1.3/CHANGELOG.txt **New Features in Version 4** Version 4 adds the following new major features: * Refactoring -- Rename/move symbols, extract to function/method, and introduce variable * Find Uses -- Find all points of use of a symbol * Auto-Editing -- Reduce typing burden by auto-entering expected code * Diff/Merge -- Graphical file and repository comparison and merge * Django Support -- Debug Django templates, run Django unit tests, and more * matplotlib Support -- Maintains live-updating plots in shell and debugger * Simplified Licensing -- Includes all OSes and adds Support+Upgrades subscriptions Details on licensing changes: http://wingware.com/news/2011-02-16 **About Wing IDE** Wing IDE is an integrated development environment designed specifically for the Python programming language. It provides powerful editing, testing, and debugging features that help reduce development and debugging time, cut down on coding errors, and make it easier to understand and navigate Python code. Wing IDE can be used to develop Python code for web, GUI, and embedded scripting applications. Wing IDE is available in three product levels: Wing IDE Professional is the full-featured Python IDE, Wing IDE Personal offers a reduced feature set at a low price, and Wing IDE 101 is a free simplified version designed for teaching beginning programming courses with Python. Version 4.0 of Wing IDE Professional includes the following major features: * Professional quality code editor with vi, emacs, and other keyboard personalities * Code intelligence for Python: Auto-completion, call tips, find uses, goto-definition, error indicators, refactoring, context-aware auto-editing, smart indent and rewrapping, and source navigation * Advanced multi-threaded debugger with graphical UI, command line interaction, conditional breakpoints, data value tooltips over code, watch tool, and externally launched and remote debugging * Powerful search and replace options including keyboard driven and graphical UIs, multi-file, wild card, and regular expression search and replace * Version control integration for Subversion, CVS, Bazaar, git, Mercurial, and Perforce * Integrated unit testing with unittest, nose, and doctest frameworks * Django support: Debugs Django templates, provides project setup tools, and runs Django unit tests * Many other features including project manager, bookmarks, code snippets, diff/merge tool, OS command integration, indentation manager, PyLint integration, and perspectives * Extremely configurable and may be extended with Python scripts * Extensive product documentation and How-Tos for Django, matplotlib, Plone, wxPython, PyQt, mod_wsgi, Autodesk Maya, and many other frameworks Please refer to http://wingware.com/wingide/features for a detailed listing of features by product level. System requirements are Windows 2000 or later, OS X 10.3.9 or later (requires X11 Server), or a recent Linux system (either 32 or 64 bit). Wing IDE supports Python versions 2.0.x through 3.2.x and Stackless Python. For more information, see the http://wingware.com/ **Downloads** Wing IDE Professional and Wing IDE Personal are commercial software and require a license to run. A free trial can be obtained directly from the product when launched. Wing IDE Pro -- Full-featured product: http://wingware.com/downloads/wingide/4.1 Wing IDE Personal -- A simplified IDE: http://wingware.com/downloads/wingide-personal/4.1 Wing IDE 101 -- For teaching with Python: http://wingware.com/downloads/wingide-101/4.1 **Purchasing and Upgrading** Wing 4.x requires an upgrade for Wing IDE 2.x and 3.x users at a cost of 1/2 the full product pricing. Upgrade a license: https://wingware.com/store/upgrade Purchase a new license: https://wingware.com/store/purchase Optional Support+Upgrades subscriptions are available for expanded support coverage and free upgrades to new major releases: http://wingware.com/support/agreement Thanks! -- The Wingware Team Wingware | Python IDE Advancing Software Development www.wingware.com From tjreedy at udel.edu Thu Jan 12 15:15:54 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 Jan 2012 15:15:54 -0500 Subject: stable object serialization to text file In-Reply-To: References: <030AD516-2A52-411B-9A20-BD60DF8AE75B@me.com> Message-ID: On 1/12/2012 7:24 AM, Peter Otten wrote: > M?t? Koch wrote: > >> I'm developing an app which stores the data in file system database. The >> data in my case consists of large python objects, mostly dicts, containing >> texts and numbers. The easiest way to dump and load them would be pickle, >> but I have a problem with it: I want to keep the data in version control, >> and I would like to use it as efficiently as possible. Is it possible to >> force pickle to store the otherwise unordered (e.g. dictionary) data in a >> kind of ordered way, so that if I dump a large dict, then change 1 tiny >> thing in it and dump again, the diff of the former and the new file will >> be minimal? >> >> If pickle is not the best choice for me, can you suggest anything else? >> (If there isn't any solution for it so far, I will write the module of >> course, but first I'd like to look around and make sure it hasn't been >> created yet.) > > Have you considered json? > > http://docs.python.org/library/json.html > > The encoder features a sort_keys flag which might help. If that does not do it for you, consider that a dict is a two-column table, with arbitrary structures in each column. Convert to list with sorted(somedict.items()). This is basically what json should do. Then write to a text stream, one line per key,value pair. Whether you put the text into an os file in a directory (a hierachical database ;-) or a text field in another database is up to you. Either way, diffs are easy. -- Terry Jan Reedy From nathan.alexander.rice at gmail.com Thu Jan 12 15:45:48 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Thu, 12 Jan 2012 15:45:48 -0500 Subject: Symbolic expressions (or: partials and closures from the inside out) Message-ID: Greetings, I have been writing a lot of code lately that involves creating symbolic expressions of one form or another, which are then fully evaluated at a later time. Examples of this include Elementwise, where I create expressions that act on every member of an iterable (there is a much improved new version coming soon, by the way), and a design by contract/validation lib I'm working on (which shall remain nameless :D) that uses symbolic expressions in the *args of the metaclass __new__ method to generate a constraint class which validates input using __instancecheck__. I do most of this with lambdas, a little hacking with closures and FunctionType(), and chainable objects. I am very impressed that python is this flexible, but there are some issues with the approach that I would like to rectify, namely: 1. Because of the early binding behavior of most things in Python, if I want to include isinstance(X, someclass) in a symbolic expression, I have to wrap it in a lambda (or use .apply(), in the case of Elementwise). This is not a huge deal for me, but it forces me to create wrappers for lots of functions (e.g. isinstance_(X, someclass)) and/or have users wrap every such function they want to use in a symbolic expression. Having to do this also bloats the code a lot; the github version of Elementwise is over 3,000 LoC at this point (including prodigious documentation, but still...). 2. Python expects that certain functions, such as int(), str(), etc, will have a specific return type. While in general I agree with this, it makes Elementwise somewhat inconsistent (and it will do the same to anything else that wants to work with symbolic expressions). I'm interested in fixing both issues. I believe both issues I've had could be solved by having a robust "symbolic object". These objects would basically usable like ordinary objects, however upon any attribute access or other form of interaction, the object would basically short circuit the calling function, and return a symbolic object directly to the outer scope. The symbolic object would behave like a generator function frozen at the point of attribute access, and upon send()-ing (or whatever method), it would behave exactly as if the values sent had been the ones passed in originally (ideally without consuming the generator). I have thought about ways to approximate this behavior python currently, and while I could hack something together using inspect to pull relevant info from the stack, then break out using a special exception (potentially passing a generator with state as an exception arg), this approach strikes me as VERY brittle, implementation dependent, ugly and difficult to work with. Additionally, you would need to catch the special exception somewhere in the stack, so this trick wouldn't work on the first thing in an expression to be evaluated. As an aside, I'd like to solicit some feedback on the validation syntax I've been working on. Currently, I have code that support things like: X = SymbolicObject() const = Constraints(X * 2 + 1 >= 5, X % 2 != 0) const2 = Constraints(X[-1] == "h") const3 = Constraints(X[-1].upper() == "H") >>> print isinstance(3, const) True >>> print isinstance(2, const) False >>> print isinstance(1, const) False >>> print isinstance("bleh", const2) True >> print isinstance("bleh", const3) True Callables are supported as well, so if you wanted to do something like: Constraints(isinstance(X.attr, someclass), somefunc(X[-2].attr, args)) You could approximate that with: Constraints(lambda x: isinstance(x.attr, someclass), lambda x: somefunc(x[-2].attr, args)) As I mentioned in the first paragraph, Constraints is a metaclass, so your validations are checked using __instancecheck__. I'm also considering having __init__ generate mock objects (for certain straight-forward cases, anyhow). Thanks for your time, Nathan From g.rodola at gmail.com Thu Jan 12 16:04:41 2012 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Thu, 12 Jan 2012 22:04:41 +0100 Subject: ANN: pysendfile 0.2.0 released Message-ID: Hi folks, I'm pleased to announce the 0.2.0 release of pysendfile: http://code.google.com/p/pysendfile === About === This is a python interface to sendfile(2) system call available on most UNIX systems. sendfile(2) provides a "zero-copy" way of copying data from one file descriptor to another (a socket). The phrase "zero-copy" refers to the fact that all of the copying of data between the two descriptors is done entirely by the kernel, with no copying of data into userspace buffers, resuting in file transfers being from 2x to 3x faster. Basically, any application sending files over the network can take advantage of it. HTTP and FTP servers are a typical example. === Supported platforms === * Linux * Mac OSX * FreeBSD * Dragon Fly BSD * Sun OS * AIX (not properly tested) === Supported python versions === >From 2.5 to 3.3. === Links === * Home page: http://code.google.com/p/pysendfile * Source tarball: http://pysendfile.googlecode.com/files/pysendfile-0.2.0.tar.gz --- Giampaolo Rodola' http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ http://code.google.com/p/pysendfile/ From dennisachang at gmail.com Thu Jan 12 17:26:40 2012 From: dennisachang at gmail.com (Denhua) Date: Thu, 12 Jan 2012 14:26:40 -0800 (PST) Subject: Reading and writing to a file creates null characters Message-ID: <4f7d125a-2713-4b57-a108-2a56ae6531dc@h3g2000yqe.googlegroups.com> Hi, I've got a file which I'd like to read, modify and write. # file contents a b c d My script reads the file contents into a list and rotates the list and writes it back to the same file. Problem is that the output contains null characters. I don't know where they are coming from. #!/usr/bin/env python def rotate(l): return l[1:] + [l[0]] f = open("/tmp/.rrd", 'r+') lines = [ line.strip() for line in f.readlines() ] newlist = rotate(lines) print newlist f.truncate(0) f.write("\n".join(newlist)) f.close() # output [root at Inferno html]# python rotate.py ['b', 'c', 'd', 'a'] [root at Inferno html]# python rotate.py ['c', 'd', 'a', '\x00\x00\x00\x00\x00\x00\x00\x00b'] [root at Inferno html]# What's going on? Thanks for your help, Dennis From roy at panix.com Thu Jan 12 18:14:35 2012 From: roy at panix.com (Roy Smith) Date: Thu, 12 Jan 2012 18:14:35 -0500 Subject: Reading and writing to a file creates null characters References: <4f7d125a-2713-4b57-a108-2a56ae6531dc@h3g2000yqe.googlegroups.com> Message-ID: In article <4f7d125a-2713-4b57-a108-2a56ae6531dc at h3g2000yqe.googlegroups.com>, Denhua wrote: > [omitted] > f.write("\n".join(newlist)) > f.close() > > # output > > [root at Inferno html]# python rotate.py > ['b', 'c', 'd', 'a'] > [root at Inferno html]# python rotate.py > ['c', 'd', 'a', '\x00\x00\x00\x00\x00\x00\x00\x00b'] > [root at Inferno html]# > > > What's going on? Thanks for your help, > Dennis Step 1 in debugging any problem -- try to isolate the smallest possible test case. In your example, can you figure out if the weirdness is happening in f.write(), or in what is being passed to f.write()? Try breaking it down into something like: > output = "\n".join(newlist) > print output > f.write(output) > f.close() Next, figure out if it happens whenever you write() to a file, or only if you write() after you do a truncate(). Once you can answer those questions, you'll have a much smaller problem to try and solve. From python at mrabarnett.plus.com Thu Jan 12 18:21:07 2012 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 12 Jan 2012 23:21:07 +0000 Subject: Reading and writing to a file creates null characters In-Reply-To: <4f7d125a-2713-4b57-a108-2a56ae6531dc@h3g2000yqe.googlegroups.com> References: <4f7d125a-2713-4b57-a108-2a56ae6531dc@h3g2000yqe.googlegroups.com> Message-ID: <4F0F6AE3.9040503@mrabarnett.plus.com> On 12/01/2012 22:26, Denhua wrote: > Hi, > > I've got a file which I'd like to read, modify and write. > > # file contents > a > b > c > d > > My script reads the file contents into a list and rotates the list and > writes it back to the same file. > Problem is that the output contains null characters. I don't know > where they are coming from. > > #!/usr/bin/env python > > def rotate(l): > return l[1:] + [l[0]] > > > f = open("/tmp/.rrd", 'r+') > > lines = [ line.strip() for line in f.readlines() ] > > > newlist = rotate(lines) > > print newlist > f.truncate(0) > > f.write("\n".join(newlist)) > f.close() > > # output > > [root at Inferno html]# python rotate.py > ['b', 'c', 'd', 'a'] > [root at Inferno html]# python rotate.py > ['c', 'd', 'a', '\x00\x00\x00\x00\x00\x00\x00\x00b'] > [root at Inferno html]# > > > What's going on? Thanks for your help, > I think this is the relevant part of the documentation: """The current file position is not changed. Note that if a specified size exceeds the file?s current size, the result is platform-dependent: possibilities include that the file may remain unchanged, increase to the specified size as if zero-filled, or increase to the specified size with undefined new content. """ In other words, you also need to reset the file pointer to the start of the file. From rich at noir.com Thu Jan 12 20:03:59 2012 From: rich at noir.com (K Richard Pixley) Date: Thu, 12 Jan 2012 17:03:59 -0800 Subject: Two questions about logging In-Reply-To: <7dabf43f-3814-47b6-966a-1439f56548b5@i6g2000vbk.googlegroups.com> References: <7dabf43f-3814-47b6-966a-1439f56548b5@i6g2000vbk.googlegroups.com> Message-ID: <3qLPq.3424$nn3.827@newsfe16.iad> On 1/11/12 18:19 , Matthew Pounsett wrote: > Second, I'm trying to get a handle on how libraries are meant to > integrate with the applications that use them. The naming advice in > the advanced tutorial is to use __name__ to name loggers, and to allow > log messages to pass back up to the using application's logger for > processing, but these two pieces of advice seem contradictory.. since > log messages only pass back up to the root if the loggers are named > hierarchically. Here's the confusion. Each log named __name__ is under the root logger. If you want them all, then catch them all with the root logger. In foo.py, change getLogger(__name__) to getLogger(''). Only the included modules need __name__. Or use two - one logger for setting handlers based on the root logger, and another based on __name__ for logging from the top level. --rich From rich at noir.com Thu Jan 12 20:08:03 2012 From: rich at noir.com (K Richard Pixley) Date: Thu, 12 Jan 2012 17:08:03 -0800 Subject: stable object serialization to text file In-Reply-To: References: Message-ID: On 1/11/12 12:16 , M?t? Koch wrote: > Hello All, > > I'm developing an app which stores the data in file system database. The data in my case consists of large python objects, mostly dicts, containing texts and numbers. The easiest way to dump and load them would be pickle, but I have a problem with it: I want to keep the data in version control, and I would like to use it as efficiently as possible. Is it possible to force pickle to store the otherwise unordered (e.g. dictionary) data in a kind of ordered way, so that if I dump a large dict, then change 1 tiny thing in it and dump again, the diff of the former and the new file will be minimal? > > If pickle is not the best choice for me, can you suggest anything else? (If there isn't any solution for it so far, I will write the module of course, but first I'd like to look around and make sure it hasn't been created yet.) Json kinda sucks. Try yaml. If your data is simple enough, you can just write and read your own format. Sort it first and you're golden. You might also try sorted dicts. I don't know if those will come out of pickle any differently than regular dicts, but it's worth trying. You can also write your own serializer for any of the previously mentioned serializers. If you sort during serialization, then they'll be sorted in the disk file. --rich From wuwei23 at gmail.com Thu Jan 12 21:50:13 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 12 Jan 2012 18:50:13 -0800 (PST) Subject: how to install lxml in window xp? References: <4F0E6930.6070701@googlemail.com> Message-ID: <5e6e9e04-82de-4e8f-ba1f-b110ca25c2f0@a8g2000pbi.googlegroups.com> Tamer Higazi wrote: > So, instead of making yourself continuously headache for an outdated OS > I advise [...] Please don't recommend people use another OS when they ask an explicit question about a particular OS. It just makes you come across as a zealot. Not everyone is working within an environment that they control. I'm aware of quite a few local government agencies that will be stuck on XP for quite some time, expecting any employee of such organisations to install whatever they want on their computers is laughable. From steve+comp.lang.python at pearwood.info Thu Jan 12 22:34:41 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Jan 2012 03:34:41 GMT Subject: ERROR:root:code for hash md5 was not found References: <4F0D7274.9080905@gmail.com> <390272b8-a041-4ece-a414-13bc9c120f61@d10g2000vbh.googlegroups.com> <4f0e1b0a$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f0fa650$0$29984$c3e8da3$5496439d@news.astraweb.com> On Wed, 11 Jan 2012 22:13:16 -0800, mike wrote: [...] > esekilx5030 [7:09am] [roamFroBl/pysibelius/bin] -> python Python 2.7.2 > (default, Jun 16 2011, 15:05:49) [GCC 4.5.0] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import sys > print(sys.version) > import hashlib > print(hashlib.__file__) > print(hashlib.md5) > import _md5 > print(_md5.__file__) >>> 2.7.2 (default, Jun 16 2011, 15:05:49) [GCC > 4.5.0] >>>> ERROR:root:code for hash md5 was not found. > Traceback (most recent call last): > File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ > hashlib.py", line 139, in > globals()[__func_name] = __get_hash(__func_name) > File "/vobs/rnc/rrt/roam1/roamSs/roamFroBl/python/lib/python2.7/ > hashlib.py", line 91, in __get_builtin_constructor > raise ValueError('unsupported hash type %s' % name) It looks like pysibelius comes with its own Python installation, which is *seriously* broken. What is pysibelius? I can't find it on the web. Does it have anything to do with Sibelius the music composition software? It looks like the installation you are trying to use is missing modules. You might need to consult the pysibelius forums or mailing lists, if they have any, or the author, or possibly re-install it and see if the problem goes away. -- Steven From jasonveldicott at gmail.com Thu Jan 12 23:34:08 2012 From: jasonveldicott at gmail.com (Jason Veldicott) Date: Fri, 13 Jan 2012 15:34:08 +1100 Subject: How to remove ellipses from long paths in traceback? Message-ID: Hi, Long paths in python traceback are contracted with ellipses. eg: TclError: couldn't load library "C:/Python26/tcl/tk8.5/../../bin/tk85.dll" Is there any way to see the full path? Surprisingly, search didn't reveal an answer to this question. Thanks Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Thu Jan 12 23:41:13 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 12 Jan 2012 20:41:13 -0800 (PST) Subject: ERROR:root:code for hash md5 was not found References: <4F0D7274.9080905@gmail.com> <390272b8-a041-4ece-a414-13bc9c120f61@d10g2000vbh.googlegroups.com> <4f0e1b0a$0$29966$c3e8da3$5496439d@news.astraweb.com> <4f0fa650$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: <13ebaf39-49d6-48d9-8a32-deab1f6f6bab@iv6g2000pbc.googlegroups.com> On Jan 13, 1:34?pm, Steven D'Aprano wrote: > What is pysibelius? I can't find it on the web. Does it have anything to > do with Sibelius the music composition software? Yes, please provide more information about the pysibelius package, especially if this is the case. The few tenuous Python/Sibelius links I found didn't have anything on pysibelius, unfortunately. From steve+comp.lang.python at pearwood.info Fri Jan 13 00:02:09 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Jan 2012 05:02:09 GMT Subject: Zealotry [was Re: how to install lxml in window xp?] References: <4F0E6930.6070701@googlemail.com> <5e6e9e04-82de-4e8f-ba1f-b110ca25c2f0@a8g2000pbi.googlegroups.com> Message-ID: <4f0fbad0$0$29984$c3e8da3$5496439d@news.astraweb.com> On Thu, 12 Jan 2012 18:50:13 -0800, alex23 wrote: > Tamer Higazi wrote: >> So, instead of making yourself continuously headache for an outdated OS >> I advise [...] > > Please don't recommend people use another OS when they ask an explicit > question about a particular OS. It just makes you come across as a > zealot. Why is it that only Linux and Mac users are accused of being "zealots"? If I ask how to install (say) MYOB or Photoshop on Linux, and people tell me that I will have to use Windows if I want to easily run that software, I don't accuse them of being a zealot. I've had Quicken tell me that Quickbooks can only store its data files on a Windows file server. The fact that I've been successfully running it in a VM with the data files stored on a Samba file share without any problems proves them wrong, but if I accused Quicken technical support of being "zealots" I'd be considered a loon. Yet Windows users get away with calling others zealots all the time. > Not everyone is working within an environment that they control. I'm > aware of quite a few local government agencies that will be stuck on XP > for quite some time, expecting any employee of such organisations to > install whatever they want on their computers is laughable. That may be true, but the advice remains reasonable advice. If somebody asks you how to get from Iceland to Norway by car, it is perfectly reasonable to tell them that they will find it much easier to use a plane or boat. The existence of people who, for whatever reason, can't or won't use a plane or boat doesn't change the fact that using a car will be extremely difficult, if not impossible. Some Windows users are so used to being the centre of the computing universe that any time they hit a problem that is easier to solve on another OS, and people dare remind them of that fact, they get their nose out of joint. If your OS does everything you need it to do, great. I personally am happy running Windows Server 2000 for my needs, and don't need any Windows software that doesn't run on it. But my sympathies go out to those who are stuck (for whatever reason) on an OS (of any flavour) that doesn't do what they want. Just don't blame the messenger. -- Steven From wuwei23 at gmail.com Fri Jan 13 00:41:29 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 12 Jan 2012 21:41:29 -0800 (PST) Subject: Zealotry [was Re: how to install lxml in window xp?] References: <4F0E6930.6070701@googlemail.com> <5e6e9e04-82de-4e8f-ba1f-b110ca25c2f0@a8g2000pbi.googlegroups.com> <4f0fbad0$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: <24235015-76f8-47fb-a726-646b3c155590@c6g2000pbd.googlegroups.com> On Jan 13, 3:02?pm, Steven D'Aprano wrote: > Why is it that only Linux and Mac users are accused of being "zealots"? Oh please. Don't tar me with the Windows brush. I'd have used the same term no matter what OS was being recommended. > If I ask how to install (say) MYOB or Photoshop on Linux, and people tell > me that I will have to use Windows if I want to easily run that software, > I don't accuse them of being a zealot. And if lxml didn't have Windows binaries, then maybe this would be the case. [snippety snippety to the rest of your straw men] > That may be true, but the advice remains reasonable advice. If somebody > asks you how to get from Iceland to Norway by car, it is perfectly > reasonable to tell them that they will find it much easier to use a plane > or boat. In what way is downloading pre-built binaries and then installing lxml on Windows like driving across the ocean? This is a new low in pedantry for you. > Some Windows users are so used to being the centre of the computing > universe that any time they hit a problem that is easier to solve on > another OS, and people dare remind them of that fact, they get their nose > out of joint. Because suggesting people ditch their environment whenever they hit a single bit of friction - whether it's one they've chosen or had forced upon them - is absolutely ridiculous. And believe me, _no_ user of Windows' Python would ever make the mistake of thinking they were the centre of _that_ world. Recommending another OS to a clearly phrased problem is the IT equivalent of the old joke about the doctor saying "well don't do that then". It doesn't do _anything_ to address the actual problem the person is trying to solve. From wuwei23 at gmail.com Fri Jan 13 00:47:41 2012 From: wuwei23 at gmail.com (alex23) Date: Thu, 12 Jan 2012 21:47:41 -0800 (PST) Subject: Zealotry [was Re: how to install lxml in window xp?] References: <4F0E6930.6070701@googlemail.com> <5e6e9e04-82de-4e8f-ba1f-b110ca25c2f0@a8g2000pbi.googlegroups.com> <4f0fbad0$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: <625a4de0-069f-4033-9e2b-1ed0d477402d@vy16g2000pbb.googlegroups.com> On Jan 13, 3:02?pm, Steven D'Aprano wrote: > Why is it that only Linux and Mac users are accused of being "zealots"? Incidentally, in the post I replied to, Tamer was talking about Windows 7, so there's that too. Are you just riding out the Friday afternoon clock? From brian at python.org Fri Jan 13 00:54:35 2012 From: brian at python.org (Brian Curtin) Date: Thu, 12 Jan 2012 23:54:35 -0600 Subject: How to remove ellipses from long paths in traceback? In-Reply-To: References: Message-ID: On Thu, Jan 12, 2012 at 22:34, Jason Veldicott wrote: > Hi, > > Long paths in python traceback are contracted with ellipses. ?eg: > ??TclError: couldn't load library "C:/Python26/tcl/tk8.5/../../bin/tk85.dll" > > Is there any way to see the full path? > > Surprisingly, search didn't reveal an answer to this question. > > Thanks > > Jason Is this tcl/tk specific or have you seen it in other places? Either way, you may want to submit a report to http://bugs.python.org From ben+python at benfinney.id.au Fri Jan 13 01:02:43 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 13 Jan 2012 17:02:43 +1100 Subject: Zealotry References: <4F0E6930.6070701@googlemail.com> <5e6e9e04-82de-4e8f-ba1f-b110ca25c2f0@a8g2000pbi.googlegroups.com> <4f0fbad0$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87r4z45ed8.fsf@benfinney.id.au> Steven D'Aprano writes: > On Thu, 12 Jan 2012 18:50:13 -0800, alex23 wrote: > > > Tamer Higazi wrote: > >> So, instead of making yourself continuously headache for an > >> outdated OS I advise [...] > > > > Please don't recommend people use another OS when they ask an > > explicit question about a particular OS. It just makes you come > > across as a zealot. > > Why is it that only Linux and Mac users are accused of being > "zealots"? If I ask how to install (say) MYOB or Photoshop on Linux, > and people tell me that I will have to use Windows if I want to easily > run that software, I don't accuse them of being a zealot. Agreed. Giving a recommendation for a different OS is not zealotry. Even if it were expressed passionately (and I don't think this case qualifies), a recommendation of software on its merits is still not zealotry. When someone starts being extremely emotional, or even militant, it might be appropriate to break out the ?zealot? label. Short of that, it's an attempt to slur someone enthusiastically giving advice. -- \ ?I am amazed, O Wall, that you have not collapsed and fallen, | `\ since you must bear the tedious stupidities of so many | _o__) scrawlers.? ?anonymous graffiti, Pompeii, 79 CE | Ben Finney From lists at cheimes.de Fri Jan 13 01:09:53 2012 From: lists at cheimes.de (Christian Heimes) Date: Fri, 13 Jan 2012 07:09:53 +0100 Subject: How to remove ellipses from long paths in traceback? In-Reply-To: References: Message-ID: Am 13.01.2012 05:34, schrieb Jason Veldicott: > Hi, > > Long paths in python traceback are contracted with ellipses. eg: > TclError: couldn't load library "C:/Python26/tcl/tk8.5/../../bin/tk85.dll" > > Is there any way to see the full path? The dots don't look like an ellipses to me. An ellipses has three dots "...". It might be an unnormalized path. In paths two dots mean parent directory, so the path references C:/Python26/bin/tk85.dll. Christian From rosuav at gmail.com Fri Jan 13 01:17:15 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 Jan 2012 17:17:15 +1100 Subject: Zealotry In-Reply-To: <87r4z45ed8.fsf@benfinney.id.au> References: <4F0E6930.6070701@googlemail.com> <5e6e9e04-82de-4e8f-ba1f-b110ca25c2f0@a8g2000pbi.googlegroups.com> <4f0fbad0$0$29984$c3e8da3$5496439d@news.astraweb.com> <87r4z45ed8.fsf@benfinney.id.au> Message-ID: On Fri, Jan 13, 2012 at 5:02 PM, Ben Finney wrote: > Giving a recommendation for a different OS is not zealotry. The line to zealotry is (probably) crossed when _every_ problem is met with "Install XYZ then". But that can still be correct. If you're currently using flat files and NetBEUI to manage your customer names and addresses across the internet, then every problem you have will be answered with "Migrate to a real database". Zealotry? Probably. Correct? Yes. ChrisA From pyideas at rebertia.com Fri Jan 13 01:22:26 2012 From: pyideas at rebertia.com (Chris Rebert) Date: Thu, 12 Jan 2012 22:22:26 -0800 Subject: [Python-ideas] Symbolic expressions (or: partials and closures from the inside out) In-Reply-To: References: Message-ID: On Thu, Jan 12, 2012 at 3:03 PM, Terry Reedy wrote: > On 1/12/2012 3:45 PM, Nathan Rice wrote: >>>>> print isinstance(3, const) >> >> True > > > A Contraints instance defines a set. 'const' is the set 'odd_ge_3' > It would look better if you used standard syntax and do the inclusion check > in a __contains__ method. > >>>> 3 in odd_ge_3 > > True But what are types but abstract sets of values? Phrasing it as a typecheck is perfectly sensible from a type-theoretic standpoint. Also, the problem of representing `isinstance(X.attr, someclass)` [for non-Constraint someclass, e.g. str] in a Constraint would still remain, since there's no "__lcontains__" (thus precluding `X.attr in str`). >> so your validations are checked using __instancecheck__. > > But it is a fake check in that 3 is not really an instance of the class, > which has no instances. The same can be true for abstract base classes, which have been sufficiently accepted to warrant adding __instancecheck__() in the first place and also to be added to the std lib (witness the `abc` and `collections` modules). It may seem unfamiliar, but then again it was only made possible starting with v2.6, which is pretty recent. Cheers, Chris -- http://rebertia.com From nathan.alexander.rice at gmail.com Fri Jan 13 01:24:35 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 13 Jan 2012 01:24:35 -0500 Subject: [Python-ideas] Symbolic expressions (or: partials and closures from the inside out) In-Reply-To: References: Message-ID: >> I have been writing a lot of code lately that involves creating >> symbolic expressions of one form or another, which are then fully >> evaluated at a later time. ?Examples of this include Elementwise, > > > Python is designed for concrete, rather than symbolic computation. But the > latter has been done. Being able to create abstract expressions that are later realized is super useful and neat. You can do this decently right now, but life would be better if you didn't have to jump through so many hoops. Having symbolic variables override *anything* would also make lambdas obsolete and greatly increase the potential for lazy evaluation. > 0: rewrite the text -- a bit awkward in Python. > > action = compile("read({this})".format(this=), 'xxx', 'eval') Yeah, that is something I'd expect to see in Perl code :) > 1. default args -- has to be done when the function is defined. > > def action(this = ): read(this) > > 2. closures (nested functions) -- also requires a planned-ahead definition. > > make_read(x): > ?return lambda: read(x) > action = make_read() I use this extensively in Elementwise. > 3. bound methods -- only works for classes with methods. > > Class Book: > ? ?def read(self): pass > action = Book().read > > 4. partial binding of function params -- generalizes bound methods; works > for any function and argument. > > from functools import partial > action = partial(read, ) > >> if I want to include isinstance(X, someclass) in a symbolic expression, > > > Consider using partial, which can totally bind all needed args *now* for > *later* action. The issue isn't so much that I *can't* do things as they are more trouble than they should be, and it makes the end user interface for the stuff I write less elegant. For example, if I want to work with a symbolic object, but include a function that is not well behaved, or if I was creating a constraint on the result of a function applied to a symbolic object, I have to know ahead of time everything I want to do, so I can wrap the whole expression in a lambda. Once I wrap it, the nice generative chaining property disappears and I'm stuck with a callable. >>>> from functools import partial >>>> t = partial(isinstance, 1, int) >>>> t() > True >>>> f = partial(isinstance, 1, float) >>>> f() > False > > >> I have to wrap it in a lambda > > > Are you sure that partial will not work for you? Since partial is written in > Python, you can grab and adjust the code to your needs. It amounts to adding > default args after the fact by using a generic closure. In some cases it would, in some cases it wouldn't. Since I basically never do */** expansion on wrappers, lambdas tend to be my go-to more often. >> (or use .apply(), in the case of >> >> Elementwise). ?This is not a huge deal for me, but it forces me to >> create wrappers for lots of functions (e.g. isinstance_(X, someclass)) >> and/or have users wrap every such function they want to use in a >> symbolic expression. ? Having to do this also bloats the code a lot; >> the github version of Elementwise is over 3,000 LoC at this point >> (including prodigious documentation, but still...). >> >> 2. ?Python expects that certain functions, such as int(), str(), etc, >> will have a specific return type. ?While in general I agree with this, > > > People expect that class constructors produce an instance of the class. It > is surprising when one does otherwise ;-). Builtin classes like int, bool, > and str are classes just like ones you write. type/str/int/etc as types is definitely semi-coherent, since the language really treats them more like functions. They are treated that way all over the docs as well. >From the data model page: "object.__str__(self) Called by the str() built-in function and by the..." "object.__nonzero__(self) Called to implement truth value testing and the built-in operation bool()" "object.__complex__(self) object.__int__(self) object.__long__(self) object.__float__(self) Called to implement the built-in functions complex(), int(), long(), and float(). Should return a value of the appropriate type." So clearly this is an area that needs some polish :) >> X = SymbolicObject() >> >> const = Constraints(X * 2 + 1>= 5, X % 2 != 0) >> const2 = Constraints(X[-1] == "h") >> const3 = Constraints(X[-1].upper() == "H") > > > Using a special class is a standard way to delay concrete execution. Standard, and currently a pain in the butt, starting from the fact that operators don't hook into __getattribute__ and getting progressively worse from there. >>>>> print isinstance(3, const) >> >> True > > > A Contraints instance defines a set. 'const' is the set 'odd_ge_3' > It would look better if you used standard syntax and do the inclusion check > in a __contains__ method. Used standard syntax? Can you elaborate please? Also, a set is one of many things a Constraints instance could logically be represented with, as well as a discontinuous interval, a class in the colloquial sense, etc. The nice thing about __instancecheck__ is that every possible constraint reduces to a type check. Of course, you could rephrase all type checking in terms of set membership easily, but I don't think it is quite as intuitive to most folks. Your preference has been noted though. >> As I mentioned in the first paragraph, Constraints is a metaclass, > > > This is your first mention, actually. Feeling feisty? I'm actually curious to see what sort of rational you come up with to back up that statement; should be interesting :) > >> so your validations are checked using __instancecheck__. > > But it is a fake check in that 3 is not really an instance of the class, > which has no instances. It is hard for me to believe that you cannot put the > same constraint data in an instance of Constraint as a class and the > inclusion logic in __contains__. If you customize __instancecheck__ for each > instance of Constraints, then write It is a fake check, like any abstract base class instancecheck is a fake check. > ?def__contains__(self, ob): return self._check(ob) > > where _check does the same as your current __instancecheck__ > > Even if you *have* to make Constraints a metaclass, for other reasons, I > believe you could still give it the same __contains__ method. A metaclass > *is* a class, and if its class instances represent collections, inclusion in > the colleciton should be tested in the standard way. It could be any sort of callable. __instancecheck__ is the only reason it is a metaclass. Otherwise, I probably wouldn't bother with classes at all; returning a check inner function with constraints in the closure would be easy. Cheers, Nathan From noah.hall at fuduntu.org Fri Jan 13 02:29:09 2012 From: noah.hall at fuduntu.org (Noah Hall) Date: Fri, 13 Jan 2012 07:29:09 +0000 Subject: Zealotry [was Re: how to install lxml in window xp?] In-Reply-To: <625a4de0-069f-4033-9e2b-1ed0d477402d@vy16g2000pbb.googlegroups.com> References: <4F0E6930.6070701@googlemail.com> <5e6e9e04-82de-4e8f-ba1f-b110ca25c2f0@a8g2000pbi.googlegroups.com> <4f0fbad0$0$29984$c3e8da3$5496439d@news.astraweb.com> <625a4de0-069f-4033-9e2b-1ed0d477402d@vy16g2000pbb.googlegroups.com> Message-ID: On Fri, Jan 13, 2012 at 5:47 AM, alex23 wrote: > On Jan 13, 3:02?pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> Why is it that only Linux and Mac users are accused of being "zealots"? > > Incidentally, in the post I replied to, Tamer was talking about > Windows 7, so there's that too. I agree with what you posted. If there was a single bad thing I would point out to anyone about the Python community, it would be that there are a huge amount of "freetards" - people who believe that Linux is the only way, or that Linux is the best way. Protip: It's not the only way, and it's not always the best way. Use what works for you. If Windows works for you, great. Same applies to every OS. It's not then unreasonable to ask others for support for that OS - they may not have the ability to provide support, but it's always good to ask. If you have no choice in the matter, sucks to be you, but live with it. Worse things have happened than having to use Windows XP, as much as I *personally* dislike XP. Claiming that x OS is best, and that every other OS is rubbish is insane. Different operating systems do things differently, and are therefore suited for different tasks and for different people. Suggesting to someone that doing a task is easier on a different OS - "Yeah, I can't help you but I might I suggest you do Python development on Linux - these sort of problems are much easier to handle when you have a package manager system and Linux distros have awesome Python support" is fine and perfectly sensible - "USE LINUX OMFG!111!! YOU'RE SO LAME, WINDOZE SUCKS OMFG YOU N00B! I'M SO COOL USE MY HARDCORE GENTOO INSTALL THAT TOOK 36 HOURS AND SHAVED 2 SECONDS OFF MY BOOTUP TIME! LOOK AT THE SPINY COMPIZ CUBE! I DON'T KNOW WHAT I DID BEFORE I COULD MAKE MY DESKTOP CUBE-Y!", as in the post you referred to, is not. I see this kind of nonsense everywhere, but it tends to be in the Linux and Apple community more - I've no idea why, probably has something to do with being a minority. For reference, I am a Linux developer who uses Windows, Linux, *BSD and OS X, each in a place where it's suitable. tl;dr - Use what works for you. Suggest, don't preach. From stefan_ml at behnel.de Fri Jan 13 02:51:37 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 13 Jan 2012 08:51:37 +0100 Subject: Zealotry [was Re: how to install lxml in window xp?] In-Reply-To: <24235015-76f8-47fb-a726-646b3c155590@c6g2000pbd.googlegroups.com> References: <4F0E6930.6070701@googlemail.com> <5e6e9e04-82de-4e8f-ba1f-b110ca25c2f0@a8g2000pbi.googlegroups.com> <4f0fbad0$0$29984$c3e8da3$5496439d@news.astraweb.com> <24235015-76f8-47fb-a726-646b3c155590@c6g2000pbd.googlegroups.com> Message-ID: alex23, 13.01.2012 06:41: > On Jan 13, 3:02 pm, Steven D'Aprano wrote: >> Why is it that only Linux and Mac users are accused of being "zealots"? > > Oh please. Don't tar me with the Windows brush. I'd have used the same > term no matter what OS was being recommended. > >> If I ask how to install (say) MYOB or Photoshop on Linux, and people tell >> me that I will have to use Windows if I want to easily run that software, >> I don't accuse them of being a zealot. > > And if lxml didn't have Windows binaries, then maybe this would be the > case. [...] > In what way is downloading pre-built binaries and then installing lxml > on Windows like driving across the ocean? Note the two sides to this problem. On the one side, there is a Windows user who is unable to easy_install lxml because the latest binaries are not on PyPI. It's an obvious first reaction to blame the project for not putting them there. On the other side, there's the lxml project which can't currently produce binaries due to the lack of a proper maintainer who has a legal and properly configured copy of that commercial operating system installed. It's an obvious first reaction to blame the Windows user who is unable to configure his/her own system to properly build lxml there. Who's to blame here? Personally, I think that solving the problem on the second side is much closer to actually driving across the ocean, whereas the first side sounds more like it's recommending it. But I guess that's just because I *am* on the second side. Now, you are saying that this problem is easily solved by downloading binary packages from an unknown third-party source and installing them on your machine. I've already seen requests to upload those specific binaries to PyPI a couple of times. This appears to be a normal way of thinking specifically amongst many Windows users, simply because this system trains them to download opaque binary software packages from arbitrary external sources in order to install them manually and use them. Coming from a Linux angle, where signed and trusted software has been the normal case for more than a decade now, so much that an attempt to install unsigned or untrusted software actually leads to a clear warning, I cannot see this as a reasonable recommendation. It may well be that Christoph Gohlke is generally trustworthy enough to install the software he builds in a given user setting. However, presenting this as the ultimate solution to any software installation problems is clear zealotry in my eyes, because it ignores the fact that software from unknown third-party sources may simply not be a valid alternative in a given setting, e.g. on a company computer. As usual, it's not all that easy, but IMHO, recommending to use Linux isn't that much worse than recommending to install untrusted binary software. Stefan From stefan_ml at behnel.de Fri Jan 13 02:54:57 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 13 Jan 2012 08:54:57 +0100 Subject: Zealotry [was Re: how to install lxml in window xp?] (OT) In-Reply-To: References: <4F0E6930.6070701@googlemail.com> <5e6e9e04-82de-4e8f-ba1f-b110ca25c2f0@a8g2000pbi.googlegroups.com> <4f0fbad0$0$29984$c3e8da3$5496439d@news.astraweb.com> <625a4de0-069f-4033-9e2b-1ed0d477402d@vy16g2000pbb.googlegroups.com> Message-ID: Noah Hall, 13.01.2012 08:29: > I'M SO COOL > USE MY HARDCORE GENTOO INSTALL THAT TOOK 36 HOURS AND SHAVED 2 SECONDS > OFF MY BOOTUP TIME Just an off-topic thing that your comment above reminded me of: has anyone ever noticed that there are even quick install guides for Gentoo Linux? I think that's funny. Stefan From rosuav at gmail.com Fri Jan 13 02:57:36 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 Jan 2012 18:57:36 +1100 Subject: Zealotry [was Re: how to install lxml in window xp?] In-Reply-To: <24235015-76f8-47fb-a726-646b3c155590@c6g2000pbd.googlegroups.com> References: <4F0E6930.6070701@googlemail.com> <5e6e9e04-82de-4e8f-ba1f-b110ca25c2f0@a8g2000pbi.googlegroups.com> <4f0fbad0$0$29984$c3e8da3$5496439d@news.astraweb.com> <24235015-76f8-47fb-a726-646b3c155590@c6g2000pbd.googlegroups.com> Message-ID: On Fri, Jan 13, 2012 at 4:41 PM, alex23 wrote: > Oh please. Don't tar me with the Windows brush. Wouldn't the Windows brush zip you instead? ChrisA definitely ready for the weekend now From enalicho at gmail.com Fri Jan 13 03:20:43 2012 From: enalicho at gmail.com (Noah Hall) Date: Fri, 13 Jan 2012 08:20:43 +0000 Subject: Zealotry [was Re: how to install lxml in window xp?] (OT) In-Reply-To: References: <4F0E6930.6070701@googlemail.com> <5e6e9e04-82de-4e8f-ba1f-b110ca25c2f0@a8g2000pbi.googlegroups.com> <4f0fbad0$0$29984$c3e8da3$5496439d@news.astraweb.com> <625a4de0-069f-4033-9e2b-1ed0d477402d@vy16g2000pbb.googlegroups.com> Message-ID: On Fri, Jan 13, 2012 at 7:54 AM, Stefan Behnel wrote: > Noah Hall, 13.01.2012 08:29: >> I'M SO COOL >> USE MY HARDCORE GENTOO INSTALL THAT TOOK 36 HOURS AND SHAVED 2 SECONDS >> OFF MY BOOTUP TIME > > Just an off-topic thing that your comment above reminded me of: has anyone > ever noticed that there are even quick install guides for Gentoo Linux? Gentoo Linux - for when life's just too simple. From jeanmichel at sequans.com Fri Jan 13 05:34:01 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 13 Jan 2012 11:34:01 +0100 Subject: Zealotry In-Reply-To: <87r4z45ed8.fsf@benfinney.id.au> References: <4F0E6930.6070701@googlemail.com> <5e6e9e04-82de-4e8f-ba1f-b110ca25c2f0@a8g2000pbi.googlegroups.com> <4f0fbad0$0$29984$c3e8da3$5496439d@news.astraweb.com> <87r4z45ed8.fsf@benfinney.id.au> Message-ID: <4F100899.2010705@sequans.com> Ben Finney wrote: > Steven D'Aprano writes: > > >> On Thu, 12 Jan 2012 18:50:13 -0800, alex23 wrote: >> >> >>> Tamer Higazi wrote: >>> >>>> So, instead of making yourself continuously headache for an >>>> outdated OS I advise [...] >>>> >>> Please don't recommend people use another OS when they ask an >>> explicit question about a particular OS. It just makes you come >>> across as a zealot. >>> >> Why is it that only Linux and Mac users are accused of being >> "zealots"? If I ask how to install (say) MYOB or Photoshop on Linux, >> and people tell me that I will have to use Windows if I want to easily >> run that software, I don't accuse them of being a zealot. >> > > Agreed. > > Giving a recommendation for a different OS is not zealotry. > > Even if it were expressed passionately (and I don't think this case > qualifies), a recommendation of software on its merits is still not > zealotry. > > When someone starts being extremely emotional, or even militant, it > might be appropriate to break out the ?zealot? label. Short of that, > it's an attempt to slur someone enthusiastically giving advice. > > Recommending an OS to solve one python package installation is zealotry. At least, advise to use a virtual machine software to try it out, there are some VM softwares for free working with windows. JM From rosuav at gmail.com Fri Jan 13 05:51:36 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 Jan 2012 21:51:36 +1100 Subject: Zealotry In-Reply-To: <4F100899.2010705@sequans.com> References: <4F0E6930.6070701@googlemail.com> <5e6e9e04-82de-4e8f-ba1f-b110ca25c2f0@a8g2000pbi.googlegroups.com> <4f0fbad0$0$29984$c3e8da3$5496439d@news.astraweb.com> <87r4z45ed8.fsf@benfinney.id.au> <4F100899.2010705@sequans.com> Message-ID: On Fri, Jan 13, 2012 at 9:34 PM, Jean-Michel Pichavant wrote: > Recommending an OS to solve one python package installation is zealotry. At > least, advise to use a virtual machine software to try it out, there are > some VM softwares for free working with windows. If I recommend Python to someone, I don't (usually) care whether he runs it under Windows or Linux. If I recommend the use of a computer, I don't care whether he runs it on 220V or 110V. A virtual machine doesn't have anything to do with the issue, and "install Debian" doesn't specify _where_. He could replace his Windows, use a virtualizer, or buy a brand new box for it - makes no diff. ChrisA From steve+comp.lang.python at pearwood.info Fri Jan 13 06:22:32 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Jan 2012 11:22:32 GMT Subject: Zealotry [was Re: how to install lxml in window xp?] References: <4F0E6930.6070701@googlemail.com> <5e6e9e04-82de-4e8f-ba1f-b110ca25c2f0@a8g2000pbi.googlegroups.com> <4f0fbad0$0$29984$c3e8da3$5496439d@news.astraweb.com> <24235015-76f8-47fb-a726-646b3c155590@c6g2000pbd.googlegroups.com> Message-ID: <4f1013f8$0$29999$c3e8da3$5496439d@news.astraweb.com> On Thu, 12 Jan 2012 21:41:29 -0800, alex23 wrote: > On Jan 13, 3:02?pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> Why is it that only Linux and Mac users are accused of being "zealots"? > > Oh please. Don't tar me with the Windows brush. I'd have used the same > term no matter what OS was being recommended. I didn't tar you with anything, let alone being a Windows fan-boy. I took great care to avoid making any accusations about you. Perhaps you're a tad over-sensitive? >> If I ask how to install (say) MYOB or Photoshop on Linux, and people >> tell me that I will have to use Windows if I want to easily run that >> software, I don't accuse them of being a zealot. > > And if lxml didn't have Windows binaries, then maybe this would be the > case. The Original Poster was attempting to build lxml binaries under XP. Apparently this is difficult enough that the best answer anyone can give is "download some pre-built binary from some guy on the Internet, and hope it is up to date and works". (I'm paraphrasing from memory.) It isn't clear to me whether the OP doesn't give a monkey's toss where the binaries come from so long as they get installed, or whether he is hoping to build them himself (for fun, for education, because he doesn't trust some guy on the Internet). If the second case, then "download binaries" is no more helpful than "INSTALL LINUX!!!" would be. > [snippety snippety to the rest of your straw men] I really get frustrated by people who use "straw man" as a meaningless term of abuse for any argument they don't like or disagree with. "Straw man argument" has a specific meaning, and it doesn't apply to what I wrote: I did not attack a weakened or extreme version of your argument, but made a complaint about the double standards in accusations of "zealotry". If you want to accuse me of anything, it is use of weasel words like "some Windows users" [citation required]. But not straw man. >> That may be true, but the advice remains reasonable advice. If somebody >> asks you how to get from Iceland to Norway by car, it is perfectly >> reasonable to tell them that they will find it much easier to use a >> plane or boat. > > In what way is downloading pre-built binaries and then installing lxml > on Windows like driving across the ocean? Now *there's* a straw man. It is *building* the binaries under XP that are like driving across the ocean: difficult enough that the best advice given is "leave it to someone else". > This is a new low in pedantry for you. And misuse of the word pedantry too, tsk tsk. >> Some Windows users are so used to being the centre of the computing >> universe that any time they hit a problem that is easier to solve on >> another OS, and people dare remind them of that fact, they get their >> nose out of joint. > > Because suggesting people ditch their environment whenever they hit a > single bit of friction - whether it's one they've chosen or had forced > upon them - is absolutely ridiculous. Perhaps. It depends on how important the task is, and how much friction is there. If the task is important enough, and the friction great enough, then it isn't ridiculous at all. My wife ditched KDE 4 as her desktop due to a single point of friction: the inability to get Bluetooth working correctly. > And believe me, _no_ user of > Windows' Python would ever make the mistake of thinking they were the > centre of _that_ world. Oh I don't know, I long ago have ceased to be surprised by the narcissism of some computer users. > Recommending another OS to a clearly phrased problem is the IT > equivalent of the old joke about the doctor saying "well don't do that > then". It doesn't do _anything_ to address the actual problem the person > is trying to solve. On the contrary, it prevents the symptoms of the problem, which very often is good enough, or even the best that can be done. Look, I'm not and never did defend the *specific* argument that upgrading to Windows 7 or cross-grading to Gentoo Linux was the right solution for the failure to compile lxml under Windows XP. I've never tried to compile lxml at all, and for all I know, it might be *more difficult* under Linux than Windows. (Stranger things have happened.) I'm just making a point about perceptions of zealotry. -- Steven From esuarez at itccanarias.org Fri Jan 13 06:33:24 2012 From: esuarez at itccanarias.org (Eduardo Suarez-Santana) Date: Fri, 13 Jan 2012 11:33:24 +0000 Subject: copy on write Message-ID: <4F101684.2060502@itccanarias.org> I wonder whether this is normal behaviour. I would expect equal sign to copy values from right to left. However, it seems there is a copy-on-write mechanism that is not working. Anyone can explain and provide a working example? Thanks, -Eduardo $ python Python 2.7.2 (default, Oct 31 2011, 11:54:55) [GCC 4.5.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class n: ... def __init__(self, id, cont): ... self.id = id; ... self.cont = cont; ... >>> r={'a':1}; >>> d={}; >>> d['x']=r; >>> d['y']=r; >>> x1 = n('x',d['x']); >>> y1 = n('y',d['y']); >>> x1.cont['a']=2; >>> y1.cont {'a': 2} >>> From esuarez at itccanarias.org Fri Jan 13 06:44:56 2012 From: esuarez at itccanarias.org (Eduardo Suarez-Santana) Date: Fri, 13 Jan 2012 11:44:56 +0000 Subject: copy on write In-Reply-To: <4F101684.2060502@itccanarias.org> References: <4F101684.2060502@itccanarias.org> Message-ID: <4F101938.1030806@itccanarias.org> El 13/01/12 11:33, Eduardo Suarez-Santana escribi?: > I wonder whether this is normal behaviour. > Even simpler: $ python Python 2.7.2 (default, Oct 31 2011, 11:54:55) [GCC 4.5.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> r={'a':1}; >>> d={}; >>> d['x']=r; >>> d['y']=r; >>> d['x']['a']=3 >>> d['y'] {'a': 3} >>> From jeanmichel at sequans.com Fri Jan 13 07:07:05 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 13 Jan 2012 13:07:05 +0100 Subject: copy on write In-Reply-To: <4F101938.1030806@itccanarias.org> References: <4F101684.2060502@itccanarias.org> <4F101938.1030806@itccanarias.org> Message-ID: <4F101E69.7030705@sequans.com> Eduardo Suarez-Santana wrote: > El 13/01/12 11:33, Eduardo Suarez-Santana escribi?: >> I wonder whether this is normal behaviour. >> > Even simpler: > > $ python > Python 2.7.2 (default, Oct 31 2011, 11:54:55) > [GCC 4.5.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> r={'a':1}; > >>> d={}; > >>> d['x']=r; > >>> d['y']=r; > >>> d['x']['a']=3 > >>> d['y'] > {'a': 3} > >>> > yes it is. >>> d['x']=r; >>> d['y']=r; means that both d['x'] and d['y'] name the same object r. If you change r, you'll see these changes wheter using d['x'] or d['y']. The operator '=' does not copy objects, it binds an object to a name, and an object can have multiple names. Use the dictionary copy method to copy a dictionary: d['x'] = r.copy() JM From steve+comp.lang.python at pearwood.info Fri Jan 13 07:10:45 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Jan 2012 12:10:45 GMT Subject: copy on write References: Message-ID: <4f101f45$0$29999$c3e8da3$5496439d@news.astraweb.com> On Fri, 13 Jan 2012 11:33:24 +0000, Eduardo Suarez-Santana wrote: > I wonder whether this is normal behaviour. > > I would expect equal sign to copy values from right to left. Assignment in Python never copies values. > However, it > seems there is a copy-on-write mechanism that is not working. There is no copy-on-write. Assignment in Python is name binding: the name on the left hand side is bound to the object on the right. An object can have zero, one or many names. If the object is mutable, changes to the object will be visible via any name: >>> x = [] # lists are mutable objects >>> y = x # not a copy of x, but x and y point to the same object >>> x.append(42) # mutates the object in place >>> print y [42] The same rules apply not just to names, but also to list items and dict items, as well as attributes, and any other reference: >>> z = [x, y] # z is a list containing the same sublist twice >>> z[0].append(23) >>> print z [[42, 23], [42, 23]] When you work with floats, ints or strings, you don't notice this because those types are immutable: you can't modify those objects in place. So for example: >>> a = 42 # binds the name 'a' to the object 42 >>> b = a # a and b point to the same object >>> a += 1 # creates a new object, and binds it to a >>> print b # leaving b still pointing to the old object 42 -- Steven From jeanmichel at sequans.com Fri Jan 13 07:11:32 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 13 Jan 2012 13:11:32 +0100 Subject: Zealotry In-Reply-To: References: <4F0E6930.6070701@googlemail.com> <5e6e9e04-82de-4e8f-ba1f-b110ca25c2f0@a8g2000pbi.googlegroups.com> <4f0fbad0$0$29984$c3e8da3$5496439d@news.astraweb.com> <87r4z45ed8.fsf@benfinney.id.au> <4F100899.2010705@sequans.com> Message-ID: <4F101F74.6080405@sequans.com> Chris Angelico wrote: > On Fri, Jan 13, 2012 at 9:34 PM, Jean-Michel Pichavant > wrote: > >> Recommending an OS to solve one python package installation is zealotry. At >> least, advise to use a virtual machine software to try it out, there are >> some VM softwares for free working with windows. >> > > If I recommend Python to someone, I don't (usually) care whether he > runs it under Windows or Linux. If I recommend the use of a computer, > I don't care whether he runs it on 220V or 110V. A virtual machine > doesn't have anything to do with the issue, and "install Debian" > doesn't specify _where_. He could replace his Windows, use a > virtualizer, or buy a brand new box for it - makes no diff. > > ChrisA > People may not know that they can have multiple OS on the same machine, that lowers the cost a lot, that's all I was saying. JM From rosuav at gmail.com Fri Jan 13 07:30:56 2012 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 Jan 2012 23:30:56 +1100 Subject: copy on write In-Reply-To: <4f101f45$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <4f101f45$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Jan 13, 2012 at 11:10 PM, Steven D'Aprano wrote: >>>> z = [x, y] ?# z is a list containing the same sublist twice >>>> z[0].append(23) >>>> print z > [[42, 23], [42, 23]] > > When you work with floats, ints or strings, you don't notice this because > those types are immutable: you can't modify those objects in place. So > for example: > >>>> a = 42 ?# binds the name 'a' to the object 42 >>>> b = a ?# a and b point to the same object >>>> a += 1 ?# creates a new object, and binds it to a >>>> print b ?# leaving b still pointing to the old object > 42 I was about to say that it's a difference between ".append()" which is a method on the object, and "+=" which is normally a rebinding, but unfortunately: >>> a=[] >>> b=a >>> a+=[1] >>> a [1] >>> b [1] >>> b+=[2] >>> a [1, 2] >>> a [1, 2] >>> a=a+[3] >>> a [1, 2, 3] >>> b [1, 2] (tested in Python 3.2 on Windows) It seems there's a distinct difference between a+=b (in-place addition/concatenation) and a=a+b (always rebinding), which is sorely confusing to C programmers. But then, there's a lot about Python that's sorely confusing to C programmers. ChrisA From steve+comp.lang.python at pearwood.info Fri Jan 13 08:04:16 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Jan 2012 13:04:16 GMT Subject: copy on write References: <4f101f45$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f102bd0$0$29999$c3e8da3$5496439d@news.astraweb.com> On Fri, 13 Jan 2012 23:30:56 +1100, Chris Angelico wrote: > It seems there's a distinct difference between a+=b (in-place > addition/concatenation) and a=a+b (always rebinding), Actually, both are always rebinding. It just happens that sometimes a+=b rebinds to the same object that it was originally bound to. In the case of ints, a+=b creates a new object (a+b) and rebinds a to it. In the case of lists, a+=b nominally creates a list a+b, but in fact it implements that as an in-place operation a.extend(b), and then rebinds the name a to the list already bound to a. It does that because the Python VM doesn't know at compile time whether a+=b will be in-place or not, and so it has to do the rebinding in order to support the fall-back case of a+=b => a=a+b. Or something -- go read the PEP if you really care :) Normally this is harmless, but there is one interesting little glitch you can get: >>> t = ('a', [23]) >>> t[1] += [42] Traceback (most recent call last): File "", line 1, in TypeError: 'tuple' object does not support item assignment >>> t ('a', [23, 42]) > which is sorely > confusing to C programmers. But then, there's a lot about Python > that's sorely confusing to C programmers. I prefer to think of it as "there's a lot about C that is sorely confusing to anyone who isn't a C programmer" -- Steven From jeanpierreda at gmail.com Fri Jan 13 08:45:38 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Fri, 13 Jan 2012 08:45:38 -0500 Subject: [Python-ideas] Symbolic expressions (or: partials and closures from the inside out) In-Reply-To: References: Message-ID: On Thu, Jan 12, 2012 at 3:45 PM, Nathan Rice wrote: > I'm interested in fixing both issues. I believe both issues I've had > could be solved by having a robust "symbolic object". These objects > would basically usable like ordinary objects, however upon any > attribute access or other form of interaction, the object would > basically short circuit the calling function, and return a symbolic > object directly to the outer scope. The symbolic object would behave > like a generator function frozen at the point of attribute access, and > upon send()-ing (or whatever method), it would behave exactly as if > the values sent had been the ones passed in originally (ideally > without consuming the generator). I find the way you've formalized this a bit "weird". It looks like you're suggesting adding laziness to Python. If that's what you want, maybe you should try PyPy and the thunk object space: http://doc.pypy.org/en/latest/objspace-proxies.html#the-thunk-object-space -- Devin From jeanpierreda at gmail.com Fri Jan 13 08:50:23 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Fri, 13 Jan 2012 08:50:23 -0500 Subject: copy on write In-Reply-To: References: <4f101f45$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Jan 13, 2012 at 7:30 AM, Chris Angelico wrote: > It seems there's a distinct difference between a+=b (in-place > addition/concatenation) and a=a+b (always rebinding), which is sorely > confusing to C programmers. But then, there's a lot about Python > that's sorely confusing to C programmers. I think this is confusing to just about everyone, when they first encounter it. -- Devin From mikaelpetterson1 at gmail.com Fri Jan 13 09:14:50 2012 From: mikaelpetterson1 at gmail.com (mike) Date: Fri, 13 Jan 2012 06:14:50 -0800 (PST) Subject: ERROR:root:code for hash md5 was not found References: <4F0D7274.9080905@gmail.com> <390272b8-a041-4ece-a414-13bc9c120f61@d10g2000vbh.googlegroups.com> <4f0e1b0a$0$29966$c3e8da3$5496439d@news.astraweb.com> <4f0fa650$0$29984$c3e8da3$5496439d@news.astraweb.com> <13ebaf39-49d6-48d9-8a32-deab1f6f6bab@iv6g2000pbc.googlegroups.com> Message-ID: On Jan 13, 5:41?am, alex23 wrote: > On Jan 13, 1:34?pm, Steven D'Aprano > +comp.lang.pyt... at pearwood.info> wrote: > > What is pysibelius? I can't find it on the web. Does it have anything to > > do with Sibelius the music composition software? > > Yes, please provide more information about the pysibelius package, > especially if this is the case. > > The few tenuous Python/Sibelius links I found didn't have anything on > pysibelius, unfortunately. Hi, pysibelius is a lib that we use. I am not sure that is the problem since the python program works on SuSE but not on RH server. And AFAIK the only difference ( well that I can see) is the OpenSSL version. According to code it uses openssl: So I need to find a way to convince the linux sys admin to install same version of openssl on both servers. Thanks a lot for your valuable time. //mike From nathan.alexander.rice at gmail.com Fri Jan 13 09:21:07 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Fri, 13 Jan 2012 09:21:07 -0500 Subject: [Python-ideas] Symbolic expressions (or: partials and closures from the inside out) In-Reply-To: References: Message-ID: On Fri, Jan 13, 2012 at 8:45 AM, Devin Jeanpierre wrote: > On Thu, Jan 12, 2012 at 3:45 PM, Nathan Rice > wrote: >> I'm interested in fixing both issues. I believe both issues I've had >> could be solved by having a robust "symbolic object". ?These objects >> would basically usable like ordinary objects, however upon any >> attribute access or other form of interaction, the object would >> basically short circuit the calling function, and return a symbolic >> object directly to the outer scope. ?The symbolic object would behave >> like a generator function frozen at the point of attribute access, and >> upon send()-ing (or whatever method), it would behave exactly as if >> the values sent had been the ones passed in originally (ideally >> without consuming the generator). > > I find the way you've formalized this a bit "weird". It looks like > you're suggesting adding laziness to Python. > > If that's what you want, maybe you should try PyPy and the thunk object space: While thunk is neat, it doesn't accomplish precisely what I'm describing in this instance. When a function starts to run under thunk, the computations take place as soon as the function gets to the object inside its scope. What I'm after is the ability to basically create functions using only expressions, in a generative manner. Lambda does accomplish this, but in an extremely clunky manner... for example: X = lambda x: x + 1 Y = lambda y: y * 2 Z = lambda z: z % 3 (or XYZ = lambda x: (((x + 1) * 2) % 3) If I want to perform a second step after this, I need create another lambda, because they don't chain/aren't generative. The thing that Elementwise does that is very appealing is that most operations are generative, so if you have an ElementwiseProxy object x, x2 = (((x + 1) * 2) % 3) basically does the same thing as the above, but you can then do x3 = x2 ** 3, and so on until you are ready to get your results. Once you have your results, you can use the same ElementwiseProxy again with different inputs. It is just a function generation technique which has some elegant properties. Having a native object type designed to facilitate this would let people do a lot of interesting things, and make things like Elementwise be a lot more "consistent". I bet you could do some really neat things by subclassing such an object as well. This is certainly not a common programming paradigm, but I think most people could reap a lot of benefits from it while being oblivious to its presence. Nathan From dennisachang at gmail.com Fri Jan 13 10:05:20 2012 From: dennisachang at gmail.com (Denhua) Date: Fri, 13 Jan 2012 07:05:20 -0800 (PST) Subject: Reading and writing to a file creates null characters References: <4f7d125a-2713-4b57-a108-2a56ae6531dc@h3g2000yqe.googlegroups.com> Message-ID: <357a64a6-d41e-446d-84c9-8b00419b5ad8@k28g2000yqc.googlegroups.com> On Jan 12, 6:21?pm, MRAB wrote: > On 12/01/2012 22:26, Denhua wrote: > > > > > > > > > Hi, > > > I've got a file which I'd like to read, modify and write. > > > # file contents > > a > > b > > c > > d > > > My script reads the file contents into a list and rotates the list and > > writes it back to the same file. > > Problem is that the output contains null characters. I don't know > > where they are coming from. > > > #!/usr/bin/env python > > > def rotate(l): > > ? ? ? ? ?return l[1:] + [l[0]] > > > f = open("/tmp/.rrd", 'r+') > > > lines = [ line.strip() for line in f.readlines() ] > > > newlist = rotate(lines) > > > print newlist > > f.truncate(0) > > > f.write("\n".join(newlist)) > > f.close() > > > # output > > > [root at Inferno html]# python rotate.py > > ['b', 'c', 'd', 'a'] > > [root at Inferno html]# python rotate.py > > ['c', 'd', 'a', '\x00\x00\x00\x00\x00\x00\x00\x00b'] > > [root at Inferno html]# > > > What's going on? Thanks for your help, > > ?> > I think this is the relevant part of the documentation: > > """The current file position is not changed. Note that if a specified > size exceeds the file?s current size, the result is platform-dependent: > possibilities include that the file may remain unchanged, increase to > the specified size as if zero-filled, or increase to the specified size > with undefined new content. > """ > > In other words, you also need to reset the file pointer to the start of > the file. Great! I added the line: f.seek(0) and that solved the problem. Thanks to both of you for your help. Dennis P.s. I made assumptions about the truncate function. I assumed that since the truncate function was clearing the file therefore I assumed with nothing in the file that the file pointer would be at the first position. root at Inferno html]# python rotate.py ['b', 'c', 'd', 'a'] [root at Inferno html]# python rotate.py ['c', 'd', 'a', 'b'] [root at Inferno html]# python rotate.py ['d', 'a', 'b', 'c'] [root at Inferno html]# python rotate.py ['a', 'b', 'c', 'd'] [root at Inferno html]# python rotate.py ['b', 'c', 'd', 'a'] [root at Inferno html]# python rotate.py ['c', 'd', 'a', 'b'] [root at Inferno html]# python rotate.py ['d', 'a', 'b', 'c'] [root at Inferno html]# python rotate.py ['a', 'b', 'c', 'd'] [root at Inferno html]# python rotate.py ['b', 'c', 'd', 'a'] [root at Inferno html]# python rotate.py ['c', 'd', 'a', 'b'] [root at Inferno html]# python rotate.py ['d', 'a', 'b', 'c'] [root at Inferno html]# From invalid at invalid.invalid Fri Jan 13 10:13:33 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 13 Jan 2012 15:13:33 +0000 (UTC) Subject: copy on write References: <4f101f45$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2012-01-13, Devin Jeanpierre wrote: > On Fri, Jan 13, 2012 at 7:30 AM, Chris Angelico wrote: >> It seems there's a distinct difference between a+=b (in-place >> addition/concatenation) and a=a+b (always rebinding), which is sorely >> confusing to C programmers. But then, there's a lot about Python >> that's sorely confusing to C programmers. > > I think this is confusing to just about everyone, when they first > encounter it. That depends on what languages they've used in the past and whether they skip reading any documentation and just assume that all languages work the same way. I would agree that for the majority of new users, they previously used only languages where an assignment operator does a "copy value", and that 90+ percent of the time those new users they assume all languages work that way. I'm not sure what we can do about that -- Python's semantics are well documented. -- Grant Edwards grant.b.edwards Yow! If our behavior is at strict, we do not need fun! gmail.com From gordon at panix.com Fri Jan 13 10:32:06 2012 From: gordon at panix.com (John Gordon) Date: Fri, 13 Jan 2012 15:32:06 +0000 (UTC) Subject: Zealotry [was Re: how to install lxml in window xp?] References: <4F0E6930.6070701@googlemail.com> <5e6e9e04-82de-4e8f-ba1f-b110ca25c2f0@a8g2000pbi.googlegroups.com> <4f0fbad0$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: In <4f0fbad0$0$29984$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano writes: > Why is it that only Linux and Mac users are accused of being "zealots"? Perhaps because Windows, being in a position of market dominance, doesn't *need* zealots. -- 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 feliphil at gmx.net Fri Jan 13 11:22:55 2012 From: feliphil at gmx.net (Wolfgang Keller) Date: Fri, 13 Jan 2012 17:22:55 +0100 Subject: open office in another language? References: Message-ID: <20120113172255.8d299c26.feliphil@gmx.net> > I'm a somewhat-satisfied openoffice.org user. I mean it works, but if > it weren't in Java I'd be doing some of my own tweaking. But since > it's in Java I stay away... no likey. OpenOffice (now LibreOffice, btw.) is not implemented in Java, if that's what you mean. It _is_ scriptable in Python, however there doesn't seem to be any documentation available. Ask on the Libreoffice-users list. > Has there been any talk of doing another similar office suite, or > maybe just writer + spreadsheet, in a better language eg python? You wouldn't implement "Office"-style software entirely in Python. Other FOSS "Office"-style software apart from LibreOffice is, e.g. Abiword and GNUmeric. Both are scriptable in Python as well, iirc. And, of course, there's LyX (also scriptable in Python), which I do prefer a L-O-T over "word processor" applications for writing. And there is Pyspread. Sincerely, Wolfgang -- HOMO HOMINI HOSTIS IN FELIBUS FELICITAS From dotancohen at gmail.com Fri Jan 13 11:39:00 2012 From: dotancohen at gmail.com (Dotan Cohen) Date: Fri, 13 Jan 2012 18:39:00 +0200 Subject: open office in another language? In-Reply-To: References: Message-ID: On Wed, Jan 11, 2012 at 00:17, Sean Wolfe wrote: > hmm I didn't know this, nice to know. Yes, C++ is still enough > overhead that I wouldn't want to try extending it ... I bet the code > is a whole lot to try and grok. > When Apache got the LibreOffice project they heavily refactored the code. As a result, LO is considered less of a monstrosity to hack on than Open Office. That said, if your goal is to "try to extend" an application, then being written in Java as opposed to C++ would be an advantage, not a disadvantage. Especially in an application the size of OOo. That said, only a few dialogues and wizards (none critical) are written in Java. Most is C++. > It would be nice to have an office suite in a newer language that is > easier to tinker with. Take a look at Calligra, C++ with Qt. It is supposed to be very easy to extend and port, in fact that was a design goal. http://calligra-suite.org/ -- Dotan Cohen http://what-is-what.com/what_is/python.html From nelle.varoquaux at gmail.com Fri Jan 13 11:46:28 2012 From: nelle.varoquaux at gmail.com (Nelle Varoquaux) Date: Fri, 13 Jan 2012 17:46:28 +0100 Subject: open office in another language? In-Reply-To: References: Message-ID: On 13 January 2012 17:39, Dotan Cohen wrote: > On Wed, Jan 11, 2012 at 00:17, Sean Wolfe wrote: > > hmm I didn't know this, nice to know. Yes, C++ is still enough > > overhead that I wouldn't want to try extending it ... I bet the code > > is a whole lot to try and grok. > > > > When Apache got the LibreOffice project they heavily refactored the > code. As a result, LO is considered less of a monstrosity to hack on > than Open Office. > Once again, a nitpick. Apache did not get the LibreOffice project, but the Openoffice.org project from Oracle. LibreOffice is a fork of openoffice and a foundation independant from Apache. Work has been done to simplify the code, but I wouldn't say it is much better: they can do a limited amount of job with a limited amount of developpers (mostly old OOo devs). So yes, there are less comments written in german than there used to, but it is still a very old, buggy code in which changing a line causes lots of pain. > That said, if your goal is to "try to extend" an application, then > being written in Java as opposed to C++ would be an advantage, not a > disadvantage. Especially in an application the size of OOo. That said, > only a few dialogues and wizards (none critical) are written in Java. > Most is C++. > > > > It would be nice to have an office suite in a newer language that is > > easier to tinker with. > > Take a look at Calligra, C++ with Qt. It is supposed to be very easy > to extend and port, in fact that was a design goal. > http://calligra-suite.org/ > > -- > Dotan Cohen > > http://what-is-what.com/what_is/python.html > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanpierreda at gmail.com Fri Jan 13 11:48:31 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Fri, 13 Jan 2012 11:48:31 -0500 Subject: copy on write In-Reply-To: References: <4f101f45$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Jan 13, 2012 at 10:13 AM, Grant Edwards wrote: > On 2012-01-13, Devin Jeanpierre wrote: >> On Fri, Jan 13, 2012 at 7:30 AM, Chris Angelico wrote: >>> It seems there's a distinct difference between a+=b (in-place >>> addition/concatenation) and a=a+b (always rebinding), which is sorely >>> confusing to C programmers. But then, there's a lot about Python >>> that's sorely confusing to C programmers. >> >> I think this is confusing to just about everyone, when they first >> encounter it. > > That depends on what languages they've used in the past and whether > they skip reading any documentation and just assume that all languages > work the same way. > > I would agree that for the majority of new users, they previously used > only languages where an assignment operator does a "copy value", and > that 90+ percent of the time those new users they assume all languages > work that way. That isn't what I was referring to. Specifically, it confuses almost everyone the first time they encounter it that "a += b" is not the same as "a = a + b". And sure, it's documented. That's a bit of a cop-out though... it isn't in the tutorial, and even if it were, it's not as if people remember everything they read. It's not about whether you _can_ know it as much as whether it is """obvious"". There's a bit of a feeling that code should "do what it looks like" and be sort of understandable without exactly understanding everything. Maybe this idea is wrong if taken to an extreme (since it's really impossible to do completely), but the feeling of it is probably decent. It's why we use "+" for addition and "-" for subtraction, and not the other way around. You don't need to know the details of operator overloading and NotImplemented and so on to get what X + Y means for numbers, or even for lists. I feel like "a += b" is sort of implicitly understood by most programmers to be the same as "a = a + b". If you asked someone what it meant, their first answer would be "Oh, it means a = a + b"[*]. That is why it's confusing -- even to people that weren't already exposed to that idea that these are equivalent, they get infected fast. And then expectations get broken, because they're only *usually* equivalent. [*] Before posting this, I actually tried this on a Python IRC channel -- and it happened exactly as so. -- Devin From torriem at gmail.com Fri Jan 13 11:49:35 2012 From: torriem at gmail.com (Michael Torrie) Date: Fri, 13 Jan 2012 09:49:35 -0700 Subject: ERROR:root:code for hash md5 was not found In-Reply-To: References: <4F0D7274.9080905@gmail.com> <390272b8-a041-4ece-a414-13bc9c120f61@d10g2000vbh.googlegroups.com> <4f0e1b0a$0$29966$c3e8da3$5496439d@news.astraweb.com> <4f0fa650$0$29984$c3e8da3$5496439d@news.astraweb.com> <13ebaf39-49d6-48d9-8a32-deab1f6f6bab@iv6g2000pbc.googlegroups.com> Message-ID: <4F10609F.7060305@gmail.com> On 01/13/2012 07:14 AM, mike wrote: > pysibelius is a lib that we use. > > I am not sure that is the problem since the python program works on > SuSE but not on RH server. And AFAIK > the only difference ( well that I can see) is the OpenSSL version. > > According to code it uses openssl: > > > > So I need to find a way to convince the linux sys admin to install > same version of openssl on both servers. Unfortunately that's going to be fairly difficult, as they would have to install a new version of openssl alongside the existing system version, which you can't just replace. Or it might be possible to copy the openssl libraries from SuSE over. Either way you will have to use the LD_LIBRARY_PATH or the LD_LIBRARY_PRELOAD environment variables to get PySibelius to load that version instead of the system one. From dotancohen at gmail.com Fri Jan 13 11:52:29 2012 From: dotancohen at gmail.com (Dotan Cohen) Date: Fri, 13 Jan 2012 18:52:29 +0200 Subject: open office in another language? In-Reply-To: References: Message-ID: On Fri, Jan 13, 2012 at 18:46, Nelle Varoquaux > Once again, a nitpick. Apache did not get the LibreOffice project, but the > Openoffice.org project from Oracle. LibreOffice is a fork of openoffice and > a foundation independant from Apache. Work has been done to simplify the > code, but I wouldn't say it is much better: they can do a limited amount of > job with a limited amount of developpers (mostly old OOo devs). So yes, > there are less comments written in german than there used to, but it is > still a very old, buggy code in which changing a line causes lots of pain. > Sorry, you are correct. Apache did refactor OOo in order to integrate it with Apache coding practices. LO is, however, heavily refactored from what I understand. Note that this may all be heresy, I've not looked at the code of either! -- Dotan Cohen http://gibberish.co.il http://what-is-what.com From neilc at norwich.edu Fri Jan 13 11:54:35 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 13 Jan 2012 16:54:35 GMT Subject: copy on write References: <4f101f45$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9nb5ubFu17U2@mid.individual.net> On 2012-01-13, Devin Jeanpierre wrote: > On Fri, Jan 13, 2012 at 10:13 AM, Grant Edwards wrote: >> On 2012-01-13, Devin Jeanpierre wrote: >>> On Fri, Jan 13, 2012 at 7:30 AM, Chris Angelico wrote: >>>> It seems there's a distinct difference between a+=b (in-place >>>> addition/concatenation) and a=a+b (always rebinding), which is sorely >>>> confusing to C programmers. But then, there's a lot about Python >>>> that's sorely confusing to C programmers. >>> >>> I think this is confusing to just about everyone, when they first >>> encounter it. >> >> That depends on what languages they've used in the past and whether >> they skip reading any documentation and just assume that all languages >> work the same way. >> >> I would agree that for the majority of new users, they previously used >> only languages where an assignment operator does a "copy value", and >> that 90+ percent of the time those new users they assume all languages >> work that way. > > That isn't what I was referring to. Specifically, it confuses > almost everyone the first time they encounter it that "a += b" > is not the same as "a = a + b". If you've ever implemented operator=, operator+, and operator+= in C++ you'll know how and why they are different. A C++ programmer would be wondering how either can work on immutable objects, and that's where Python's magical rebinding semantics come into play. -- Neil Cerutti From nikos.kouras at gmail.com Fri Jan 13 12:02:17 2012 From: nikos.kouras at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Fri, 13 Jan 2012 09:02:17 -0800 (PST) Subject: Problem filling an html form Message-ID: # get some enviromental values form = cgi.FieldStorage() mail = form.getvalue('mail') or '' comment = form.getvalue('comment') or '' # insert guest comments into database if form was submitted if '@' in mail and comment not in ("??????? ?? ???????..."): try: cursor.execute( '''INSERT INTO users(mail, comment) VALUES(%s, %s)''', (mail, comment) ) except MySQLdb.Error, e: print ( "Error %d: %s" % (e.args[0], e.args[1]) ) print ( "

????????? ??? ??? ???????! ?? ??? ???????? ?? ??????????? ??????!" ) sys.exit(0) else: print ( "

?????????? ????? ?? mail ??? ??? ???? ?? ????????? ???!" ) sys.exit(0) ============================================== In my webpage here http://superhost.gr/hosting.html i ask the users mail and comment in a html form. No matter what info the user gives after he submits the form, nothing else happens instead of reloading the page itself while what i want the code to do is to enter the if structure and display the appropriate message, depending if the user entered data in the imput box or not. Am i missing something here? From stefan_ml at behnel.de Fri Jan 13 12:30:21 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 13 Jan 2012 18:30:21 +0100 Subject: open office in another language? In-Reply-To: <20120113172255.8d299c26.feliphil@gmx.net> References: <20120113172255.8d299c26.feliphil@gmx.net> Message-ID: Wolfgang Keller, 13.01.2012 17:22: >> I'm a somewhat-satisfied openoffice.org user. I mean it works, but if >> it weren't in Java I'd be doing some of my own tweaking. But since >> it's in Java I stay away... no likey. > > OpenOffice (now LibreOffice, btw.) is not implemented in Java, if that's > what you mean. > > It _is_ scriptable in Python, however there doesn't seem to be any > documentation available. Erm - care to take a look before making such a statement? http://www.openoffice.org/udk/python/python-bridge.html http://www.openoffice.org/udk/ Stefan From nagle at animats.com Fri Jan 13 12:30:45 2012 From: nagle at animats.com (John Nagle) Date: Fri, 13 Jan 2012 09:30:45 -0800 Subject: python philosophical question - strong vs duck typing In-Reply-To: References: <59305aab-7ddf-4c61-b8ba-025a2ce10b48@d10g2000vbh.googlegroups.com> <4f0a7ca9$0$1727$742ec2ed@news.sonic.net> Message-ID: <4f106a50$0$1721$742ec2ed@news.sonic.net> On 1/9/2012 2:45 AM, Robert Kern wrote: > On 1/9/12 5:35 AM, John Nagle wrote: > >> Python has some serious problems that preclude optimization. >> Basically, the language is designed to be run by a naive (non-optimizing) >> interpreter, and allows things that are easy >> for such an implementation but very tough to optimize. An >> example is the ability to store into the variables of a module >> from outside it, and even from another thread. Every attempt >> to get rid of the Global Interpreter Lock has hit that problem. > > You keep repeating this falsehood about the GIL. You have been > repeatedly shown that this is false[1][2], though I have yet to see you > acknowledge it. The GIL exists to protect Python's internal data > structures, mostly the reference counts on objects. The reason that the > attempts to remove the GIL from CPython have not been accepted is > because they cause unacceptable performance losses in the common > unthreaded case. In implementations of Python that do not use reference > counting, there is no GIL. Neither Jython nor IronPython have a GIL, but > they both have the standard Python semantics that let you store > variables into modules from the outside, even from other threads. > > [1] http://mail.python.org/pipermail/python-list/2011-February/1265760.html > [2] http://mail.python.org/pipermail/python-list/2011-April/1269056.html If you don't have a global lock, then you have to have lots of implicit locks, probably one on every symbol dictionary. IronPython does this well, though; their dictionaries do not require locking for read access, only for writes. So they avoid running up the overhead on routine symbol access. Some operations which CPython users assume are atomic, such as list append, are not atomic in IronPython. (See "http://ironpython.codeplex.com/wikipage?title=FAQ") The GIL does more than just protect memory allocation. If you want to retain the semantics of CPython, the implementation pretty much has to be slow. The "Unladen Swallow" project crashed and burned because of that fact. They couldn't even get 2x over CPython. There are still too many unnecessary dictionary lookups when running Python. Most of those could be optimized out at compile time if, when compiling a module, the compiler didn't have to worry about the module being altered from outside itself. John Nagle From invalid at invalid.invalid Fri Jan 13 13:15:00 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 13 Jan 2012 18:15:00 +0000 (UTC) Subject: copy on write References: <4f101f45$0$29999$c3e8da3$5496439d@news.astraweb.com> <9nb5ubFu17U2@mid.individual.net> Message-ID: On 2012-01-13, Neil Cerutti wrote: > If you've ever implemented operator=, operator+, and operator+= > in C++ you'll know how and why they are different. That assumes that C++ programmers understand C++. ;) > A C++ programmer would be wondering how either can work on immutable > objects, and that's where Python's magical rebinding semantics come > into play. -- Grant Edwards grant.b.edwards Yow! Thousands of days of at civilians ... have produced gmail.com a ... feeling for the aesthetic modules -- From rosuav at gmail.com Fri Jan 13 13:26:05 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 Jan 2012 05:26:05 +1100 Subject: copy on write In-Reply-To: References: <4f101f45$0$29999$c3e8da3$5496439d@news.astraweb.com> <9nb5ubFu17U2@mid.individual.net> Message-ID: On Sat, Jan 14, 2012 at 5:15 AM, Grant Edwards wrote: > That assumes that C++ programmers understand C++. I understand C++ very well. That's why I use Python or Pike. (With apologies to Larry Wall) ChrisA From ethan at stoneleaf.us Fri Jan 13 13:40:47 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 13 Jan 2012 10:40:47 -0800 Subject: copy on write In-Reply-To: <4f102bd0$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <4f101f45$0$29999$c3e8da3$5496439d@news.astraweb.com> <4f102bd0$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F107AAF.5000600@stoneleaf.us> Steven D'Aprano wrote: > Normally this is harmless, but there is one interesting little glitch you > can get: > >>>> t = ('a', [23]) >>>> t[1] += [42] > Traceback (most recent call last): > File "", line 1, in > TypeError: 'tuple' object does not support item assignment >>>> t > ('a', [23, 42]) There is one other glitch, and possibly my only complaint: --> a = [1, 2, 3] --> b = 'hello, world' --> a = a + b Traceback (most recent call last): File "", line 1, in TypeError: can only concatenate list (not "str") to list --> a += b --> a [1, 2, 3, 'h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd'] IMO, either both + and += should succeed, or both should fail. ~Ethan~ From ethan at stoneleaf.us Fri Jan 13 14:04:48 2012 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 13 Jan 2012 11:04:48 -0800 Subject: NaN, Null, and Sorting Message-ID: <4F108050.4030407@stoneleaf.us> With NaN, it is possible to get a list that will not properly sort: --> NaN = float('nan') --> spam = [1, 2, NaN, 3, NaN, 4, 5, 7, NaN] --> sorted(spam) [1, 2, nan, 3, nan, 4, 5, 7, nan] I'm constructing a Null object with the semantics that if the returned object is Null, it's actual value is unknown. From a purist point of view if it is unknown then comparison results are also unknown since the actual value might be greater, lesser, or the same as the value being compared against. From a practical point of view a list with Nulls scattered throughout is a pain in the backside. So I am strongly leaning towards implementing the comparisons such that Null objects are less than other objects so they will always sort together. Thoughts/advice/criticisms/etc? ~Ethan~ From edriscoll at wisc.edu Fri Jan 13 14:24:28 2012 From: edriscoll at wisc.edu (Evan Driscoll) Date: Fri, 13 Jan 2012 13:24:28 -0600 Subject: copy on write In-Reply-To: <9nb5ubFu17U2@mid.individual.net> References: <4f101f45$0$29999$c3e8da3$5496439d@news.astraweb.com> <9nb5ubFu17U2@mid.individual.net> Message-ID: <4F1084EC.5030100@wisc.edu> On 01/13/2012 10:54 AM, Neil Cerutti wrote: > If you've ever implemented operator=, operator+, and operator+= > in C++ you'll know how and why they are different. At the same time, you'd also know that that implementing them in such a way that 'a += b' does *not* perform the same action as 'a = a + b' is considered very bad-mannered. In fact, it's often suggested (e.g. in "More Effective C++"'s Item 22, though this is not the main thrust of that section) to implement operator+ in terms of += to ensure that this is the case: MyType operator+ (MyType left, MyType right) { MyType copy = left; copy += right; return copy; } > A C++ > programmer would be wondering how either can work on immutable > objects, and that's where Python's magical rebinding semantics > come into play. IMO a C++ programmer wouldn't be likely to wonder that much at all because he or she wouldn't view the objects as immutable to begin with. :-) 'x = 5; x += 1;' makes perfect sense in C++, just for a somewhat different reason. Evan From invalid at invalid.invalid Fri Jan 13 14:30:11 2012 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 13 Jan 2012 19:30:11 +0000 (UTC) Subject: copy on write References: <4f101f45$0$29999$c3e8da3$5496439d@news.astraweb.com> <9nb5ubFu17U2@mid.individual.net> Message-ID: On 2012-01-13, Chris Angelico wrote: > On Sat, Jan 14, 2012 at 5:15 AM, Grant Edwards wrote: >> That assumes that C++ programmers understand C++. > > I understand C++ very well. That's why I use Python or Pike. > > (With apologies to Larry Wall) Were one inclined to troll a bit, one might be tempted to claim that using C++ is prima facie evidence of not understanding C++. Not that I would ever claim something inflamitory like that... -- Grant Edwards grant.b.edwards Yow! Thousands of days of at civilians ... have produced gmail.com a ... feeling for the aesthetic modules -- From python at mrabarnett.plus.com Fri Jan 13 14:35:41 2012 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 13 Jan 2012 19:35:41 +0000 Subject: Problem filling an html form In-Reply-To: References: Message-ID: <4F10878D.7000803@mrabarnett.plus.com> On 13/01/2012 17:02, ???????? ?????? wrote: > # get some enviromental values > form = cgi.FieldStorage() > mail = form.getvalue('mail') or '' > comment = form.getvalue('comment') or '' > > # insert guest comments into database if form was submitted > if '@' in mail and comment not in ("??????? ?? ???????..."): [snip] Do you really want to look for the comment in that string instead of looking for that string in the comment? From rosuav at gmail.com Fri Jan 13 14:58:53 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 Jan 2012 06:58:53 +1100 Subject: NaN, Null, and Sorting In-Reply-To: <4F108050.4030407@stoneleaf.us> References: <4F108050.4030407@stoneleaf.us> Message-ID: On Sat, Jan 14, 2012 at 6:04 AM, Ethan Furman wrote: > So I am strongly leaning towards implementing the comparisons such that Null > objects are less than other objects so they will always sort together. This is a perfectly plausible view, and is the one adopted by SQL (I'm pretty sure the "NULLS FIRST" / "NULLS LAST" clause is standard - you get to choose whether they're less than everything or more than everything). ChrisA From th982a at googlemail.com Fri Jan 13 15:07:13 2012 From: th982a at googlemail.com (Tamer Higazi) Date: Fri, 13 Jan 2012 21:07:13 +0100 Subject: Zealotry [was Re: how to install lxml in window xp?] In-Reply-To: References: <4F0E6930.6070701@googlemail.com> <5e6e9e04-82de-4e8f-ba1f-b110ca25c2f0@a8g2000pbi.googlegroups.com> <4f0fbad0$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F108EF1.7030908@googlemail.com> dear people! I have just opened my MTU client, and figured out that through my comment, i caused a complete NONSENSE discussion at all. 1. I am not a zealot or whatever. I code on Linux and port it on MAC and WINDOWS. I do write solutions for customers across the whole 3 platform, and mostly I succeed because I have to figure out in advance which software (packages) are being supported and how far. 2. There are many open source projects out (don't ask where, look for yourself, you are old enough!) as well commercial software vendors who don't offer their products, or give support for Windows XP. 3. All of you know, that windows xp is by Microsoft not anymore supported. Neither with Security Updated, Enhancements with Software, SDK or whatever. and not only XP, also Win95,98,ME, and 2000 Professional (not the server editions). 4. Of course any OS has it's advantages and disadvantages. Gentoo is a rolling distribution, when it's set up it works nicely. Of course, you have to invest a lot of effort to get in what doesn't mean that Debian and Ubuntu, and the others are worse. Those who want to get packages maintained by others and love to get the System to run quickly is very good with the other distributions, and coding on those platforms make fun too. >From my personal point of view, I will never set up a gentoo machine as a server in a datacenter, I would rather use BSD Unix. But this is something that personally everybody has to decide for him/herself. Now, I hope that I put a line under this discussions and beg the kids between the age of 18 - 24 who are really impulsive to fire around with the guns on others to stop this nonsense thread. That doesn't leave a nice picture in the community. PS: However, I will read the next mails in the list according this subject but I will stop commenting it, because it's getting for me too childish. Tamer Am 13.01.2012 16:32, schrieb John Gordon: > In <4f0fbad0$0$29984$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano writes: > >> Why is it that only Linux and Mac users are accused of being "zealots"? > > Perhaps because Windows, being in a position of market dominance, doesn't > *need* zealots. > From neilc at norwich.edu Fri Jan 13 15:11:23 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 13 Jan 2012 20:11:23 GMT Subject: copy on write References: <4f101f45$0$29999$c3e8da3$5496439d@news.astraweb.com> <9nb5ubFu17U2@mid.individual.net> Message-ID: <9nbhfbFs74U2@mid.individual.net> On 2012-01-13, Grant Edwards wrote: > On 2012-01-13, Chris Angelico wrote: >> On Sat, Jan 14, 2012 at 5:15 AM, Grant Edwards >> wrote: >>> That assumes that C++ programmers understand C++. >> >> I understand C++ very well. That's why I use Python or Pike. >> >> (With apologies to Larry Wall) > > Were one inclined to troll a bit, one might be tempted to claim > that using C++ is prima facie evidence of not understanding > C++. > > Not that I would ever claim something inflamitory like that... On the Python newsgroup, it's funny. ;) -- Neil Cerutti From nikos.kouras at gmail.com Fri Jan 13 15:16:43 2012 From: nikos.kouras at gmail.com (=?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?=) Date: Fri, 13 Jan 2012 12:16:43 -0800 (PST) Subject: Problem filling an html form References: Message-ID: <41330576-e597-4e7a-82b1-1aeca9434b00@n6g2000vbz.googlegroups.com> On 13 ???, 21:35, MRAB wrote: > On 13/01/2012 17:02, ???????? ?????? wrote: > > > # get some enviromental values > > form = cgi.FieldStorage() > > mail = form.getvalue('mail') or '' > > comment = form.getvalue('comment') or '' > > > ? ?# insert guest comments into database if form was submitted > > ? ?if '@' in mail and comment not in ("??????? ?? ???????..."): > > [snip] > > Do you really want to look for the comment in that string instead of > looking for that string in the comment? What do you mean? I just want to check that the user hasnt pressed the submit button leaving the default values with the input comment box. Iam not sure what you mean. From chris at simplistix.co.uk Fri Jan 13 15:17:23 2012 From: chris at simplistix.co.uk (Chris Withers) Date: Fri, 13 Jan 2012 20:17:23 +0000 Subject: SMTPHandler and Unicode In-Reply-To: <02f2f8f9-e563-4677-97e2-74e91c623853@c10g2000yqi.googlegroups.com> References: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> <02f2f8f9-e563-4677-97e2-74e91c623853@c10g2000yqi.googlegroups.com> Message-ID: <4F109153.3040409@simplistix.co.uk> Hi Norbert, On 05/07/2010 13:22, norbert wrote: > On 5 juil, 13:17, Chris Withers wrote: >> try MailingLogger: >> >> If you have unicode problems with that, I'd be interested in fixing them! > > Your package has the same unicode problem : > import logging,logging.handlers > from mailinglogger.MailingLogger import MailingLogger > mailingLogger = MailingLogger(mailhost=('smtp.example.com', > 25),fromaddr='toto at example.com',toaddrs=('toto at example.com',)) > LOG = logging.getLogger() > LOG.addHandler(mailingLogger) > LOG.error(u"sans accent") > LOG.error(u"accentu\u00E9") > > --> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' > in position 7: ordinal not in range(128) It's taken a ridiculously long amount of time (sadly due to no-one else complaining) but this is now fixed in the source control for mailinglogger, and will be in the next release: https://github.com/Simplistix/testfixtures cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From affdfsdfdsfsd at b.com Fri Jan 13 15:29:11 2012 From: affdfsdfdsfsd at b.com (Tracubik) Date: 13 Jan 2012 20:29:11 GMT Subject: understanding a program project Message-ID: <4f109417$0$1387$4fafbaef@reader1.news.tin.it> Hi all, i hope not to be too much OT with this request. I'ld like to modify/contribute some open source in python, but first i've to read and understand the code. So, is there some guide lines / procedure to follow to help me in this process. I remember at school time there was some schema or something to create to display the interaction of different functions / modules My idea was to create a model with all the methods and arrows to link they... any link of post explaining some "learning procedure" or "programs schema" would be really appreciated thanks MedeoTL From noah.hall at fuduntu.org Fri Jan 13 15:42:18 2012 From: noah.hall at fuduntu.org (Noah Hall) Date: Fri, 13 Jan 2012 20:42:18 +0000 Subject: Zealotry [was Re: how to install lxml in window xp?] In-Reply-To: <4F108EF1.7030908@googlemail.com> References: <4F0E6930.6070701@googlemail.com> <5e6e9e04-82de-4e8f-ba1f-b110ca25c2f0@a8g2000pbi.googlegroups.com> <4f0fbad0$0$29984$c3e8da3$5496439d@news.astraweb.com> <4F108EF1.7030908@googlemail.com> Message-ID: On Fri, Jan 13, 2012 at 8:07 PM, Tamer Higazi wrote: > dear people! > I have just opened my MTU client, and figured out that through my > comment, i caused a complete NONSENSE discussion at all. > > > 1. I am not a zealot or whatever. I code on Linux and port it on MAC and > WINDOWS. I do write solutions for customers across the whole 3 platform, > and mostly I succeed because I have to figure out in advance which > software (packages) are being supported and how far. > Use Linux! > Specially Gentoo Linux! Screams zealot to me. If not, certainly not a very useful reply. "Hey guys, I want to cut the bread, can someone tell me how to use the knife?" "Use a futuristic laser! Build it yourself for the uber 1337 status!" > 2. There are many open source projects out (don't ask where, look for > yourself, you are old enough!) as well commercial software vendors who > don't offer their products, or give support for Windows XP. More fool them; XP is still (unfortunately) heavily used in workplaces and in Universities. Luckily, Windows, unlike Linux, is largely backwards compatible - it's rare to find a program which won't run on XP if it can run on Vista+, unless it's a game that relies on DX11 or something. > 3. All of you know, that windows xp is by Microsoft not anymore > supported. Neither with Security Updated, Enhancements with Software, > SDK or whatever. and not only XP, also Win95,98,ME, and 2000 > Professional (not the server editions). Mainstream support ended, yes, but extended support lasts until 2014. Extended support is security updates and the like. http://support.microsoft.com/lifecycle/?C2=1173 > 4. Of course any OS has it's advantages and disadvantages. Gentoo is a > rolling distribution, when it's set up it works nicely. Of course, you > have to invest a lot of effort to get in what doesn't mean that Debian > and Ubuntu, and the others are worse. Yeah, no. I prefer an operating system that's stable and secure for my servers and for my development. Call me crazy, but I like to get work done. > >From my personal point of view, I will never set up a gentoo machine as > a server in a datacenter, I would rather use BSD Unix. But this is > something that personally everybody has to decide for him/herself. Good boy you! I'm glad you've got some sense, there. > Now, I hope that I put a line under this discussions and beg the kids > between the age of 18 - 24 who are really impulsive to fire around with > the guns on others to stop this nonsense thread. > > That doesn't leave a nice picture in the community. Hate to break it to you, but you started it with > Use Linux! > Specially Gentoo Linux! From python at mrabarnett.plus.com Fri Jan 13 16:06:46 2012 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 13 Jan 2012 21:06:46 +0000 Subject: NaN, Null, and Sorting In-Reply-To: References: <4F108050.4030407@stoneleaf.us> Message-ID: <4F109CE6.7080306@mrabarnett.plus.com> On 13/01/2012 19:58, Chris Angelico wrote: > On Sat, Jan 14, 2012 at 6:04 AM, Ethan Furman wrote: >> So I am strongly leaning towards implementing the comparisons such that Null >> objects are less than other objects so they will always sort together. > > This is a perfectly plausible view, and is the one adopted by SQL (I'm > pretty sure the "NULLS FIRST" / "NULLS LAST" clause is standard - you > get to choose whether they're less than everything or more than > everything). > +1 From python at mrabarnett.plus.com Fri Jan 13 16:13:40 2012 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 13 Jan 2012 21:13:40 +0000 Subject: Problem filling an html form In-Reply-To: <41330576-e597-4e7a-82b1-1aeca9434b00@n6g2000vbz.googlegroups.com> References: <41330576-e597-4e7a-82b1-1aeca9434b00@n6g2000vbz.googlegroups.com> Message-ID: <4F109E84.9000506@mrabarnett.plus.com> On 13/01/2012 20:16, ???????? ?????? wrote: > On 13 ???, 21:35, MRAB wrote: >> On 13/01/2012 17:02, ???????? ?????? wrote: >> >> > # get some enviromental values >> > form = cgi.FieldStorage() >> > mail = form.getvalue('mail') or '' >> > comment = form.getvalue('comment') or '' >> >> > # insert guest comments into database if form was submitted >> > if '@' in mail and comment not in ("??????? ?? ???????..."): >> >> [snip] >> >> Do you really want to look for the comment in that string instead of >> looking for that string in the comment? > > What do you mean? > > I just want to check that the user hasnt pressed the submit button > leaving the default values with the input comment box. > > Iam not sure what you mean. In the first part of the condition you're asking: '@' in mail which is OK, but in the second part of the condition you're asking: comment not in ("??????? ?? ???????...") which I think should be: "??????? ?? ???????..." not in comment Incidentally, it looks to me like you're using Python 2, in which case it's probably a good idea to use Unicode, so that would be: u"??????? ?? ???????..." not in comment and so forth. From ben+python at benfinney.id.au Fri Jan 13 16:17:46 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 14 Jan 2012 08:17:46 +1100 Subject: open office in another language? References: Message-ID: <87ehv35mkl.fsf@benfinney.id.au> Dotan Cohen writes: > On Wed, Jan 11, 2012 at 00:17, Sean Wolfe wrote: > > hmm I didn't know this, nice to know. Yes, C++ is still enough > > overhead that I wouldn't want to try extending it ... I bet the code > > is a whole lot to try and grok. > > > > When Apache got the LibreOffice project they heavily refactored the > code. As a result, LO is considered less of a monstrosity to hack on > than Open Office. You're referring to the Document Foundation, the organisation behind LibreOffice . The confusion is understandable, since it's been actively fomented for years. Apache have the code base named OpenOffice.org (which is why the Document Foundation had no option but to re-name their project), but that's not where the action is now for the office suite we know and love. It's merely where Oracle pushed their officially blessed code under a different license, though without the majority of developers and without any free-software operating systems actually using it, the writing is on the wall for that code. Oracle are being actively confusing about the name, too. Not only did they (like Sun before them) act so hostile to the OpenOffice.org project that the LibreOffice fork resulted, they then chose not to bless that fork with the OpenOffice name. They also didn't pass the name to Apache, instead releasing another, different code dump with the OpenOffice name for more confusion , undermining the Apache *and* Document Foundation projects. LibreOffice is the one with the large active developer community and the healthy independent foundation and huge funding from dozens of organisations and the refactored code base and a new major release and several versions released in the past year and lots of improvements every time and adoption by every major free-software operating system. It's a shame that corporate politics resulted in this legacy of confusion that needs untangling. The simple take-away is: OpenOffice is dead, long live LibreOffice. -- \ ?[W]hoever is able to make you absurd is able to make you | `\ unjust.? ?Voltaire | _o__) | Ben Finney From neilc at norwich.edu Fri Jan 13 16:20:49 2012 From: neilc at norwich.edu (Neil Cerutti) Date: 13 Jan 2012 21:20:49 GMT Subject: copy on write References: <4f101f45$0$29999$c3e8da3$5496439d@news.astraweb.com> <9nb5ubFu17U2@mid.individual.net> Message-ID: <9nblhhFr5bU1@mid.individual.net> On 2012-01-13, Evan Driscoll wrote: > On 01/13/2012 10:54 AM, Neil Cerutti wrote: >> If you've ever implemented operator=, operator+, and operator+= >> in C++ you'll know how and why they are different. > > At the same time, you'd also know that that implementing them > in such a way that 'a += b' does *not* perform the same action > as 'a = a + b' is considered very bad-mannered. > > In fact, it's often suggested (e.g. in "More Effective C++"'s Item 22, > though this is not the main thrust of that section) to implement > operator+ in terms of += to ensure that this is the case: > MyType operator+ (MyType left, MyType right) { > MyType copy = left; copy += right; return copy; > } They perform the same action, but their semantics are different. operator+ will always return a new object, thanks to its signature, and operator+= shall never do so. That's the main difference I was getting at. >> A C++ programmer would be wondering how either can work on >> immutable objects, and that's where Python's magical rebinding >> semantics come into play. > > IMO a C++ programmer wouldn't be likely to wonder that much at > all because he or she wouldn't view the objects as immutable to > begin with. :-) 'x = 5; x += 1;' makes perfect sense in C++, > just for a somewhat different reason. I was thinking of const objects, but you are correct that immutable isn't really a C++ concept. -- Neil Cerutti From nikos.kouras at gmail.com Fri Jan 13 16:30:40 2012 From: nikos.kouras at gmail.com (=?UTF-8?B?zp3Ouc66z4zOu86xzr/PgiDOms6/z43Pgc6xz4I=?=) Date: Fri, 13 Jan 2012 13:30:40 -0800 (PST) Subject: Problem filling an html form References: <41330576-e597-4e7a-82b1-1aeca9434b00@n6g2000vbz.googlegroups.com> Message-ID: On 13 ???, 23:13, MRAB wrote: > On 13/01/2012 20:16, ???????? ?????? wrote: > > > > > > > > > > > On 13 ???, 21:35, MRAB ?wrote: > >> ?On 13/01/2012 17:02, ???????? ?????? wrote: > > >> ?> ?# get some enviromental values > >> ?> ?form = cgi.FieldStorage() > >> ?> ?mail = form.getvalue('mail') or '' > >> ?> ?comment = form.getvalue('comment') or '' > > >> ?> ? ? ?# insert guest comments into database if form was submitted > >> ?> ? ? ?if '@' in mail and comment not in ("??????? ?? ???????..."): > > >> ?[snip] > > >> ?Do you really want to look for the comment in that string instead of > >> ?looking for that string in the comment? > > > What do you mean? > > > I just want to check that the user hasnt pressed the submit button > > leaving the default values with the input comment box. > > > Iam not sure what you mean. > > In the first part of the condition you're asking: > > ? ? ?'@' in mail > > which is OK, but in the second part of the condition you're asking: > > ? ? ?comment not in ("??????? ?? ???????...") > > which I think should be: > > ? ? ?"??????? ?? ???????..." not in comment > > Incidentally, it looks to me like you're using Python 2, in which case > it's probably a good idea to use Unicode, so that would be: > > ? ? ?u"??????? ?? ???????..." not in comment > > and so forth. Ah yes i have had them reversed! I corrected that now but still if the user submits the form by not entering any input all the program does is reloads itself. So the question now is why the program flow doesn't enter the if code block since its conditions are met? ps. http//superhost.gr/hosting.html is now http//superhost.gr/ directly. From dihedral88888 at googlemail.com Fri Jan 13 17:26:09 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 13 Jan 2012 14:26:09 -0800 (PST) Subject: copy on write In-Reply-To: References: <4f101f45$0$29999$c3e8da3$5496439d@news.astraweb.com> <4f102bd0$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <26273221.813.1326493569973.JavaMail.geo-discussion-forums@prok2> Ethan Furman? 2012?1?14????UTC+8??2?40?47???? > Steven D'Aprano wrote: > > Normally this is harmless, but there is one interesting little glitch you > > can get: > > > >>>> t = ('a', [23]) > >>>> t[1] += [42] > > Traceback (most recent call last): > > File "", line 1, in > > TypeError: 'tuple' object does not support item assignment > >>>> t > > ('a', [23, 42]) > > > There is one other glitch, and possibly my only complaint: > > --> a = [1, 2, 3] > --> b = 'hello, world' > --> a = a + b > Traceback (most recent call last): > File "", line 1, in > TypeError: can only concatenate list (not "str") to list > --> a += b > --> a > [1, 2, 3, 'h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd'] > > IMO, either both + and += should succeed, or both should fail. > > ~Ethan~ The += operator is not only for value types in the above example. An operator of two operands and an operator of three operands of general object types are two different operators. From dihedral88888 at googlemail.com Fri Jan 13 17:26:09 2012 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 13 Jan 2012 14:26:09 -0800 (PST) Subject: copy on write In-Reply-To: References: <4f101f45$0$29999$c3e8da3$5496439d@news.astraweb.com> <4f102bd0$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <26273221.813.1326493569973.JavaMail.geo-discussion-forums@prok2> Ethan Furman? 2012?1?14????UTC+8??2?40?47???? > Steven D'Aprano wrote: > > Normally this is harmless, but there is one interesting little glitch you > > can get: > > > >>>> t = ('a', [23]) > >>>> t[1] += [42] > > Traceback (most recent call last): > > File "", line 1, in > > TypeError: 'tuple' object does not support item assignment > >>>> t > > ('a', [23, 42]) > > > There is one other glitch, and possibly my only complaint: > > --> a = [1, 2, 3] > --> b = 'hello, world' > --> a = a + b > Traceback (most recent call last): > File "", line 1, in > TypeError: can only concatenate list (not "str") to list > --> a += b > --> a > [1, 2, 3, 'h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd'] > > IMO, either both + and += should succeed, or both should fail. > > ~Ethan~ The += operator is not only for value types in the above example. An operator of two operands and an operator of three operands of general object types are two different operators. From edriscoll at wisc.edu Fri Jan 13 17:48:29 2012 From: edriscoll at wisc.edu (Evan Driscoll) Date: Fri, 13 Jan 2012 16:48:29 -0600 Subject: copy on write In-Reply-To: <9nblhhFr5bU1@mid.individual.net> References: <4f101f45$0$29999$c3e8da3$5496439d@news.astraweb.com> <9nb5ubFu17U2@mid.individual.net> <9nblhhFr5bU1@mid.individual.net> Message-ID: <4F10B4BD.2010500@wisc.edu> On 01/13/2012 03:20 PM, Neil Cerutti wrote: > They perform the same action, but their semantics are different. > operator+ will always return a new object, thanks to its > signature, and operator+= shall never do so. That's the main > difference I was getting at. I was talking about the combination of + and =, since the discussion is about 'a = a + b' vs 'a += b', not 'a + b' vs 'a += b' (where the differences are obvious). And I stand by my statement. In 'a = a + b', operator+ obviously returns a new object, but operator= should then go and assign the result to and return a reference to 'a', just like how 'a += b' will return a reference to 'a'. If you're working in C++ and overload your operators so that 'a += b' and 'a = a + b' have different observable behaviors (besides perhaps time), then either your implementation is buggy or your design is very bad-mannered. Evan From tjreedy at udel.edu Fri Jan 13 21:39:03 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 13 Jan 2012 21:39:03 -0500 Subject: Zealotry [was Re: how to install lxml in window xp?] In-Reply-To: References: <4F0E6930.6070701@googlemail.com> <5e6e9e04-82de-4e8f-ba1f-b110ca25c2f0@a8g2000pbi.googlegroups.com> <4f0fbad0$0$29984$c3e8da3$5496439d@news.astraweb.com> <4F108EF1.7030908@googlemail.com> Message-ID: On 1/13/2012 3:42 PM, Noah Hall wrote: > On Fri, Jan 13, 2012 at 8:07 PM, Tamer Higazi wrote: >> dear people! >> I have just opened my MTU client, and figured out that through my >> comment, i caused a complete NONSENSE discussion at all. >> 1. I am not a zealot or whatever. I code on Linux and port it on MAC and >> WINDOWS. I do write solutions for customers across the whole 3 platform, >> and mostly I succeed because I have to figure out in advance which >> software (packages) are being supported and how far. >> Use Linux! >> Specially Gentoo Linux! > > Screams zealot to me. If not, certainly not a very useful reply. Noah, those last two lines you quoted are NOT in the post you are quoting. Perhaps Tamer said them previously. If so, you should say so: "In a previous post, you said...". Otherwise, it looks like you made those up and put words in his pen. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Fri Jan 13 23:19:45 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Jan 2012 04:19:45 GMT Subject: Zealotry [was Re: how to install lxml in window xp?] References: <4F0E6930.6070701@googlemail.com> <5e6e9e04-82de-4e8f-ba1f-b110ca25c2f0@a8g2000pbi.googlegroups.com> <4f0fbad0$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f110261$0$29988$c3e8da3$5496439d@news.astraweb.com> On Fri, 13 Jan 2012 15:32:06 +0000, John Gordon wrote: > In <4f0fbad0$0$29984$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano > writes: > >> Why is it that only Linux and Mac users are accused of being "zealots"? > > Perhaps because Windows, being in a position of market dominance, > doesn't *need* zealots. There are plenty of Windows zealots around. They just don't get called zealots, because they are the establishment. "Treason doth never prosper: what's the reason? For if it prosper, none dare call it treason." Sir John Harington -- Steven From steve+comp.lang.python at pearwood.info Fri Jan 13 23:30:24 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Jan 2012 04:30:24 GMT Subject: ERROR:root:code for hash md5 was not found References: <4F0D7274.9080905@gmail.com> <390272b8-a041-4ece-a414-13bc9c120f61@d10g2000vbh.googlegroups.com> <4f0e1b0a$0$29966$c3e8da3$5496439d@news.astraweb.com> <4f0fa650$0$29984$c3e8da3$5496439d@news.astraweb.com> <13ebaf39-49d6-48d9-8a32-deab1f6f6bab@iv6g2000pbc.googlegroups.com> Message-ID: <4f1104e0$0$29988$c3e8da3$5496439d@news.astraweb.com> On Fri, 13 Jan 2012 06:14:50 -0800, mike wrote: > On Jan 13, 5:41?am, alex23 wrote: >> On Jan 13, 1:34?pm, Steven D'Aprano > >> +comp.lang.pyt... at pearwood.info> wrote: >> > What is pysibelius? I can't find it on the web. Does it have anything >> > to do with Sibelius the music composition software? >> >> Yes, please provide more information about the pysibelius package, >> especially if this is the case. >> >> The few tenuous Python/Sibelius links I found didn't have anything on >> pysibelius, unfortunately. > > Hi, > > pysibelius is a lib that we use. > > I am not sure that is the problem since the python program works on SuSE > but not on RH server. And AFAIK > the only difference ( well that I can see) is the OpenSSL version. OpenSSL is irrelevant. If it isn't available, or doesn't provide md5, then the hashlib library will use its own implementation. But the _md5 module is missing in the pysibelius Python on your RedHat system. As I said, your Python installation is seriously broken. Required modules are just *gone*. pysibelius appears to have patched Python in some way, because strange unexpected error messages are being printed that do not happen on a normal unpatched Python, e.g.: ERROR:root:code for hash sha224 was not found. That is not a normal Python error message. That looks like something added by pysibelius. -- Steven From steve+comp.lang.python at pearwood.info Fri Jan 13 23:42:31 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Jan 2012 04:42:31 GMT Subject: Hash stability Message-ID: <4f1107b7$0$29988$c3e8da3$5496439d@news.astraweb.com> On the Python Dev mailing list, there is a discussion going on about the stability of the hash function for strings. How many people rely on hash(some_string) being stable across Python versions? Does anyone have code that will be broken if the string hashing algorithm changes? -- Steven From steve+comp.lang.python at pearwood.info Fri Jan 13 23:54:46 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Jan 2012 04:54:46 GMT Subject: NaN, Null, and Sorting References: Message-ID: <4f110a95$0$29988$c3e8da3$5496439d@news.astraweb.com> On Fri, 13 Jan 2012 11:04:48 -0800, Ethan Furman wrote: > With NaN, it is possible to get a list that will not properly sort: > > --> NaN = float('nan') > --> spam = [1, 2, NaN, 3, NaN, 4, 5, 7, NaN] --> sorted(spam) > [1, 2, nan, 3, nan, 4, 5, 7, nan] > > I'm constructing a Null object with the semantics that if the returned > object is Null, it's actual value is unknown. > > From a purist point of view if it is unknown then comparison results > are also unknown since the actual value might be greater, lesser, or the > same as the value being compared against. >From a purist point of view, NANs are unordered with respect to numbers, and so one of two behaviours should occur: (1) nan OP x should raise an exception, for all comparison operators except == and != (2) nan OP x should return False for all OPs except != I believe the current version of the standard supports operators for both sets of behaviour; the 1990s version of Apple's numeric framework (SANE) included both. I think Python chooses the second behaviour, although it may be version and platform dependent. This is from Python 2.6: >>> float('nan') < 0 False >>> float('nan') > 0 False I would expect the same behaviour for your Null objects. But as you say: > From a practical point of view a list with Nulls scattered throughout > is a pain in the backside. And this is why sorting should be defined in terms of a separate sorting operator, not < or >, so that lists containing unordered values like NANs, Nulls, and complex numbers, can be sorted. "Sorted" is a property of the list, not the values within the list. > So I am strongly leaning towards implementing the comparisons such that > Null objects are less than other objects so they will always sort > together. > > Thoughts/advice/criticisms/etc? Possibly the least-worst solution. -- Steven From jason at powerpull.net Sat Jan 14 00:28:27 2012 From: jason at powerpull.net (Jason Friedman) Date: Sat, 14 Jan 2012 05:28:27 +0000 Subject: logging and httphandler Message-ID: I am logging to my Apache web server, using this Apache format: LogFormat "%{%Y-%m-%d %H:%M:%S}t %U %q" scriptlog CustomLog /var/log/apache2/script.log scriptlog My code is as follows: #!/usr/bin/env python3 import logging, logging.handlers, sys logger = logging.getLogger('simple_example') logger.setLevel(logging.DEBUG) host = "localhost:9090" url = "make_deployment_group" http_handler = logging.handlers.HTTPHandler(host, url, method='GET') http_formatter = logging.Formatter('%(name)s - %(levelname)8s - %(message)s') http_handler.setFormatter(http_formatter) logger.addHandler(http_handler) logger.warn('warn message') which results in a entry at /var/log/apache2/script.log: 2012-01-14 05:22:52 make_deployment_group?threadName=MainThread&name=simple_example&thread=139923654465280&created=1326518572.83&process=31122&processName=MainProcess&args=%28%29&module=my-logging&filename=my-logging.py&levelno=30&exc_text=None&pathname=my-logging.py&lineno=33&asctime=2012-01-14+05%3A22%3A52%2C825&msg=warn+message&exc_info=None&message=warn+message&funcName=%3Cmodule%3E&relativeCreated=20.0970172882&levelname=WARNING&msecs=825.411081314 All the information one could want, which is nice, but is there a way to specify I want only certain information sent via the HTTP request? From shearichard at gmail.com Sat Jan 14 02:21:21 2012 From: shearichard at gmail.com (Richard Shea) Date: Fri, 13 Jan 2012 23:21:21 -0800 (PST) Subject: =?windows-1252?Q?Interpreting_Surface_Weather_Stations_reports_=28FM_12?= =?windows-1252?Q?=96XIV_SYNOP=29?= Message-ID: <1ccbe31b-5707-416a-830b-e2552703089b@r5g2000yqc.googlegroups.com> Does anyone have some code which interprets Surface Weather Stations reports (formally termed 'FM 12?XIV SYNOP' reports) ? I've tried the cheese shop but no joy. I've seen PyMetar (http://schwarzvogel.de/software-pymetar.shtml) but I don't believe it covers this format. I can't believe I'm the first person who wished to parse these reports so I'm hoping there's someone out there who's willing to share. I've been referred to http://www.wmo.int/pages/prog/www/WMOCodes/Manual/Volume-I-selection/Sel2.pdf as an explanation of their structure but I would prefer not to delve into that if I could avoid it. From wxjmfauth at gmail.com Sat Jan 14 02:43:57 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Fri, 13 Jan 2012 23:43:57 -0800 (PST) Subject: NaN, Null, and Sorting References: Message-ID: <3b5278a0-9612-4c34-a743-df463f5bedc4@w4g2000vbc.googlegroups.com> On 13 jan, 20:04, Ethan Furman wrote: > With NaN, it is possible to get a list that will not properly sort: > > --> NaN = float('nan') > --> spam = [1, 2, NaN, 3, NaN, 4, 5, 7, NaN] > --> sorted(spam) > [1, 2, nan, 3, nan, 4, 5, 7, nan] > > I'm constructing a Null object with the semantics that if the returned > object is Null, it's actual value is unknown. > Short answer. - NaN != NA() - I find the actual implementation (Py3.2) quite satisfying. (M. Dickinson's work) jmf From shearichard at gmail.com Sat Jan 14 03:17:56 2012 From: shearichard at gmail.com (Richard Shea) Date: Sat, 14 Jan 2012 00:17:56 -0800 (PST) Subject: understanding a program project References: <4f109417$0$1387$4fafbaef@reader1.news.tin.it> Message-ID: <79e1ce5d-2ddf-4e33-b3bf-dceb98f1a551@a17g2000yqj.googlegroups.com> On Jan 14, 9:29?am, Tracubik wrote: > Hi all, > i hope not to be too much OT with this request. > I'ld like to modify/contribute some open source in python, but first i've > to read and understand the code. > So, is there some guide lines / procedure to follow to help me in this > process. > I remember at school time there was some schema or something to create to > display the interaction of different functions / modules > > My idea was to create a model with all the methods and arrows to link > they... > > any link of post explaining some "learning procedure" or "programs > schema" would be really appreciated > I don't know of a general answer to your question. I've seen tools such as you're describing but they tend to be languages other than Python (eg Java or C#). There are tools such as : * Sphinx * EpyDoc * pycco all of which will produce friendly documentation automatically but the quality of the doco is dependent somewhat upon the amount and nature of comments originally put into the code. I don't think that's much help but I hope it may be some. regards Richard. From chris at simplistix.co.uk Sat Jan 14 03:25:39 2012 From: chris at simplistix.co.uk (Chris Withers) Date: Sat, 14 Jan 2012 08:25:39 +0000 Subject: SMTPHandler and Unicode In-Reply-To: <4F109153.3040409@simplistix.co.uk> References: <6cc17e2c-6560-4bc2-968f-1d23f288dc7c@b35g2000yqi.googlegroups.com> <02f2f8f9-e563-4677-97e2-74e91c623853@c10g2000yqi.googlegroups.com> <4F109153.3040409@simplistix.co.uk> Message-ID: <4F113C03.6070105@simplistix.co.uk> On 13/01/2012 20:17, Chris Withers wrote: >> Your package has the same unicode problem : >> import logging,logging.handlers >> from mailinglogger.MailingLogger import MailingLogger >> mailingLogger = MailingLogger(mailhost=('smtp.example.com', >> 25),fromaddr='toto at example.com',toaddrs=('toto at example.com',)) >> LOG = logging.getLogger() >> LOG.addHandler(mailingLogger) >> LOG.error(u"sans accent") >> LOG.error(u"accentu\u00E9") >> >> --> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' >> in position 7: ordinal not in range(128) > > It's taken a ridiculously long amount of time (sadly due to no-one else > complaining) but this is now fixed in the source control for > mailinglogger, and will be in the next release: > > https://github.com/Simplistix/testfixtures Sorry, I meant this: https://github.com/Simplistix/mailinglogger/commit/1c95f532c65ab18e1dd8513e1aa1ae328a19d249 cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From __peter__ at web.de Sat Jan 14 03:49:54 2012 From: __peter__ at web.de (Peter Otten) Date: Sat, 14 Jan 2012 09:49:54 +0100 Subject: logging and httphandler References: Message-ID: Jason Friedman wrote: > I am logging to my Apache web server, using this Apache format: > > LogFormat "%{%Y-%m-%d %H:%M:%S}t %U %q" scriptlog > CustomLog /var/log/apache2/script.log scriptlog > > My code is as follows: > > #!/usr/bin/env python3 > import logging, logging.handlers, sys > logger = logging.getLogger('simple_example') > logger.setLevel(logging.DEBUG) > host = "localhost:9090" > url = "make_deployment_group" > http_handler = logging.handlers.HTTPHandler(host, url, method='GET') > http_formatter = logging.Formatter('%(name)s - %(levelname)8s - > %(message)s') http_handler.setFormatter(http_formatter) > logger.addHandler(http_handler) > logger.warn('warn message') > > which results in a entry at /var/log/apache2/script.log: > > 2012-01-14 05:22:52 > make_deployment_group?threadName=MainThread&name=simple_example&thread=139923654465280&created=1326518572.83&process=31122&processName=MainProcess&args=%28%29&module=my- logging&filename=my-logging.py&levelno=30&exc_text=None&pathname=my- logging.py&lineno=33&asctime=2012-01-14+05%3A22%3A52%2C825&msg=warn+message&exc_info=None&message=warn+message&funcName=%3Cmodule%3E&relativeCreated=20.0970172882&levelname=WARNING&msecs=825.411081314 > > All the information one could want, which is nice, but is there a way > to specify I want only certain information sent via the HTTP request? >>> help(logging.handlers.HTTPHandler.mapLogRecord) Help on function mapLogRecord in module logging.handlers: mapLogRecord(self, record) Default implementation of mapping the log record into a dict that is sent as the CGI data. Overwrite in your class. Contributed by Franz Glasner. Applied to your example: import logging, logging.handlers, sys class HTTPHandler(logging.handlers.HTTPHandler): wanted = ["levelname", "msg", "yadda"] def mapLogRecord(self, record): return {name: getattr(record, name, "#missing") for name in self.wanted} logger = logging.getLogger('simple_example') logger.setLevel(logging.DEBUG) host = "localhost:9090" url = "make_deployment_group" http_handler = HTTPHandler(host, url, method='GET') http_formatter = logging.Formatter('%(name)s - %(levelname)8s - %(message)s') http_handler.setFormatter(http_formatter) logger.addHandler(http_handler) logger.warn('warn message') From __peter__ at web.de Sat Jan 14 04:46:35 2012 From: __peter__ at web.de (Peter Otten) Date: Sat, 14 Jan 2012 10:46:35 +0100 Subject: Hash stability References: <4f1107b7$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On the Python Dev mailing list, there is a discussion going on about the > stability of the hash function for strings. > > How many people rely on hash(some_string) being stable across Python > versions? Does anyone have code that will be broken if the string hashing > algorithm changes? Nobody who understands the question ;) From usenet at solar-empire.de Sat Jan 14 07:33:12 2012 From: usenet at solar-empire.de (Marc Christiansen) Date: Sat, 14 Jan 2012 13:33:12 +0100 Subject: ERROR:root:code for hash md5 was not found References: <4F0D7274.9080905@gmail.com> <390272b8-a041-4ece-a414-13bc9c120f61@d10g2000vbh.googlegroups.com> <4f0e1b0a$0$29966$c3e8da3$5496439d@news.astraweb.com> <4f0fa650$0$29984$c3e8da3$5496439d@news.astraweb.com> <13ebaf39-49d6-48d9-8a32-deab1f6f6bab@iv6g2000pbc.googlegroups.com> <4f1104e0$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8998u8-c73.ln1@pluto.solar-empire.de> Steven D'Aprano wrote: > On Fri, 13 Jan 2012 06:14:50 -0800, mike wrote: >> pysibelius is a lib that we use. >> >> I am not sure that is the problem since the python program works on SuSE >> but not on RH server. And AFAIK >> the only difference ( well that I can see) is the OpenSSL version. > > OpenSSL is irrelevant. If it isn't available, or doesn't provide md5, > then the hashlib library will use its own implementation. But the _md5 > module is missing in the pysibelius Python on your RedHat system. > > As I said, your Python installation is seriously broken. Required modules > are just *gone*. > > pysibelius appears to have patched Python in some way, because strange > unexpected error messages are being printed that do not happen on a > normal unpatched Python, e.g.: > > ERROR:root:code for hash sha224 was not found. > > That is not a normal Python error message. That looks like something > added by pysibelius. Steven, I think you're wrong with regard to the error message. Straight from the tarball, Python-2.7.2/Lib/hashlib.py line 135ff: for __func_name in __always_supported: # try them all, some may not work due to the OpenSSL # version not supporting that algorithm. try: globals()[__func_name] = __get_hash(__func_name) except ValueError: import logging logging.exception('code for hash %s was not found.', __func_name) Of course this does not invalidate the fact (is that even possible?) of the brokenness of the installation. Ciao Marc From noah.hall at fuduntu.org Sat Jan 14 08:44:30 2012 From: noah.hall at fuduntu.org (Noah Hall) Date: Sat, 14 Jan 2012 13:44:30 +0000 Subject: Zealotry [was Re: how to install lxml in window xp?] In-Reply-To: References: <4F0E6930.6070701@googlemail.com> <5e6e9e04-82de-4e8f-ba1f-b110ca25c2f0@a8g2000pbi.googlegroups.com> <4f0fbad0$0$29984$c3e8da3$5496439d@news.astraweb.com> <4F108EF1.7030908@googlemail.com> Message-ID: On Sat, Jan 14, 2012 at 2:39 AM, Terry Reedy wrote: > On 1/13/2012 3:42 PM, Noah Hall wrote: >> >> On Fri, Jan 13, 2012 at 8:07 PM, Tamer Higazi >> ?wrote: >>> >>> dear people! >>> I have just opened my MTU client, and figured out that through my >>> comment, i caused a complete NONSENSE discussion at all. > > >>> 1. I am not a zealot or whatever. I code on Linux and port it on MAC and >>> WINDOWS. I do write solutions for customers across the whole 3 platform, >>> and mostly I succeed because I have to figure out in advance which >>> software (packages) are being supported and how far. > > >>> Use Linux! >>> Specially Gentoo Linux! >> >> >> Screams zealot to me. If not, certainly not a very useful reply. > > > Noah, those last two lines you quoted are NOT in the post you are quoting. > Perhaps Tamer said them previously. If so, you should say so: "In a previous > post, you said...". Otherwise, it looks like you made those up and put words > in his pen. Good point. In a previous post, that started all this, he said > Use Linux! > Specially Gentoo Linux! when replying to someone who asked > how can i install the lxml in my xp?? From afylot at gmail.com Sat Jan 14 10:27:04 2012 From: afylot at gmail.com (simona bellavista) Date: Sat, 14 Jan 2012 07:27:04 -0800 (PST) Subject: scientific notation in legend (pylab) Message-ID: Hi, I I would like to have numbers expressed in scientific notation in legend annotations. Does anybody know how to do that? Cheers, S. From milleja46 at gmail.com Sat Jan 14 12:06:28 2012 From: milleja46 at gmail.com (Joshua Miller) Date: Sat, 14 Jan 2012 12:06:28 -0500 Subject: Can someone explain 2to3? Message-ID: Ok i'm trying to convert https://github.com/rdeaton/spyral to python3 but i'm at a loss on how to actually use 2to3. Can someone explain it's proper use to me so i can do the conversion? prefereably where i can take "C:\Python32\Lib\site-packages\spyral\" and put it in a new directory that i will name "C:\Python32\Lib\site-packages\spyralpy3\"? Thanks in advance for the help -- ~ Josh Miller A young guy learning to program and develop websites all while still in school From enalicho at gmail.com Sat Jan 14 12:56:28 2012 From: enalicho at gmail.com (Noah Hall) Date: Sat, 14 Jan 2012 17:56:28 +0000 Subject: Can someone explain 2to3? In-Reply-To: References: Message-ID: On Sat, Jan 14, 2012 at 5:06 PM, Joshua Miller wrote: > Ok i'm trying to convert https://github.com/rdeaton/spyral to python3 > but i'm at a loss on how to actually use 2to3. Can someone explain > it's proper use to me so i can do the conversion? prefereably where i > can take "C:\Python32\Lib\site-packages\spyral\" and put it in a new > directory that i will name "C:\Python32\Lib\site-packages\spyralpy3\"? > Thanks in advance for the help Have a read of the docs[0]. 2to3 will convert it to 3, but it may need more fixes to run as well. [0] - http://docs.python.org/library/2to3.html From dotancohen at gmail.com Sat Jan 14 13:25:02 2012 From: dotancohen at gmail.com (Dotan Cohen) Date: Sat, 14 Jan 2012 20:25:02 +0200 Subject: open office in another language? In-Reply-To: <87ehv35mkl.fsf@benfinney.id.au> References: <87ehv35mkl.fsf@benfinney.id.au> Message-ID: Enjoy this relevant article: http://developers.slashdot.org/story/12/01/14/008236/code-cleanup-culls-libreoffice-cruft Dotan Cohen http://what-is-what.com/what_is/open_office.html From rantingrickjohnson at gmail.com Sat Jan 14 13:54:57 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 14 Jan 2012 10:54:57 -0800 (PST) Subject: PyWarts: time, datetime, and calendar modules Message-ID: The interface for these modules is not intuitive. Instead of creating true OOP objects we have lists and strings. Any calendar object should expose string names of both: days of the week and months of the year. It seems one (or possibly more) of the three expose this important info however i cannot find it *easily* enough. It seems we need to combine the three in some shape or form. time and datetime would no doubt be great bedfellows. Or maybe datetime should be attached to time, like os.path. In any event the interfaces are horrendous. From jeanpierreda at gmail.com Sat Jan 14 14:01:11 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sat, 14 Jan 2012 14:01:11 -0500 Subject: PyWarts: time, datetime, and calendar modules In-Reply-To: References: Message-ID: On Sat, Jan 14, 2012 at 1:54 PM, Rick Johnson wrote: > The interface for these modules is not intuitive. Instead of creating > true OOP objects we have lists and strings. Any calendar object should > expose string names of both: days of the week and months of the year. > It seems one (or possibly more) of the three expose this important > info however i cannot find it *easily* enough. > > It seems we need to combine the three in some shape or form. time and > datetime would no doubt be great bedfellows. Or maybe datetime should > be attached to time, like os.path. In any event the interfaces are > horrendous. What's "horrendous" about the datetime module interface? Your listed complaints (OOP etc.) don't seem to have anything to do with it. -- Devin From enalicho at gmail.com Sat Jan 14 14:17:56 2012 From: enalicho at gmail.com (Noah Hall) Date: Sat, 14 Jan 2012 19:17:56 +0000 Subject: Can someone explain 2to3? In-Reply-To: References: Message-ID: On Sat, Jan 14, 2012 at 7:08 PM, Joshua Miller wrote: > I've looked there and it didn't work....i may've made all the nesscary > changes manually anyways though i'm not sure... What about it didn't work? Have a read of this too - http://wiki.python.org/moin/PortingPythonToPy3k and if you're still stuck, contact the developer of the program in question. From rantingrickjohnson at gmail.com Sat Jan 14 14:23:29 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 14 Jan 2012 11:23:29 -0800 (PST) Subject: PyWarts: time, datetime, and calendar modules References: Message-ID: <15cdd8f1-35ef-43ea-a1c9-db90bc16f4ad@r16g2000yqi.googlegroups.com> On Jan 14, 1:01?pm, Devin Jeanpierre wrote: > What's "horrendous" about the datetime module interface? Your listed > complaints (OOP etc.) don't seem to have anything to do with it. Well my immediate complaint about date-time is actually a problem with the syntactic quandaries of the Python language itself. I find myself navigating an objects API using the dir function or the autocomplete function of my IDE. Now. One the continuing issues of the Python's syntax (and the syntax of many other languages) is the fact that a reader has no idea which names belonging to an object are methods and which names are instance/class variables. The status quo has been to use verbs for methods but you cannot always find the perfect verb, or even sometimes, anyverb! Consider this: >>> import datetime, time, calendar >>> d = datetime.date.today() >>> d.day 14 >>> d.month 1 >>> d.year 2012 >>> d.weekday THAT PISSES ME OFF!!! >:( We should never be forced to guess if a name is a callable or a variable! So how do we solve this dilemma you ask??? Well, we need to "mark" method OR variable names (OR both!) with syntactic markers so there will be NO confusion. Observe: def $method(self):pass self. at instanceveriable self.@@classvariable I dunno if these are the best markers but the "marker" must be succinct! Of course if we choose to use the "@" and "@@" then we might as well drop the redundant "self" and allow the compiler to parse out the difference. From jeanpierreda at gmail.com Sat Jan 14 15:11:31 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sat, 14 Jan 2012 15:11:31 -0500 Subject: PyWarts: time, datetime, and calendar modules In-Reply-To: <15cdd8f1-35ef-43ea-a1c9-db90bc16f4ad@r16g2000yqi.googlegroups.com> References: <15cdd8f1-35ef-43ea-a1c9-db90bc16f4ad@r16g2000yqi.googlegroups.com> Message-ID: On Sat, Jan 14, 2012 at 2:23 PM, Rick Johnson wrote: > THAT PISSES ME OFF!!! >:( We should never be forced to guess if a name > is a callable or a variable! > > So how do we solve this dilemma you ask??? Well, we need to "mark" > method OR variable names (OR both!) with syntactic markers so there > will be NO confusion. I might be being bit OT, but, you should give Common Lisp a try. It does something similar for functions versus variables. As for the issue, I suppose I can see how this would be confusing. I don't agree with your solution, though. I happen to like the interchangeability of the different sorts of attributes, so that x.foo() can be a method call, a classmethod call, or a call on a function that is an attribute. -- Devin From edriscoll at wisc.edu Sat Jan 14 15:58:26 2012 From: edriscoll at wisc.edu (Evan Driscoll) Date: Sat, 14 Jan 2012 14:58:26 -0600 Subject: PyWarts: time, datetime, and calendar modules In-Reply-To: References: <15cdd8f1-35ef-43ea-a1c9-db90bc16f4ad@r16g2000yqi.googlegroups.com> Message-ID: <4F11EC72.3000909@wisc.edu> On 01/14/2012 02:11 PM, Devin Jeanpierre wrote: > On Sat, Jan 14, 2012 at 2:23 PM, Rick Johnson > wrote: >> THAT PISSES ME OFF!!!>:( We should never be forced to guess if a name >> is a callable or a variable! >> >> So how do we solve this dilemma you ask??? Well, we need to "mark" >> method OR variable names (OR both!) with syntactic markers so there >> will be NO confusion. > > I might be being bit OT, but, you should give Common Lisp a try. It > does something similar for functions versus variables. > > As for the issue, I suppose I can see how this would be confusing. I > don't agree with your solution, though. It also has some problems. For instance, if an object has a member which is a type that implements __call__ but is also useful to access "on its own", is that a field or a function? Personally, I'd suggest the thing to "fix" to solve your confusion would be how things like your code completion and dir() display the results, not anything fundamental about the language. (And also the datetime API.) PyDev, for instance, tries to show you what "kind" of thing each entry in its completion menu are. Evan From franke.daniel at gmail.com Sat Jan 14 16:15:36 2012 From: franke.daniel at gmail.com (Daniel Franke) Date: Sat, 14 Jan 2012 22:15:36 +0100 Subject: defining class and subclass in C Message-ID: <2921241.kWnIB6QQbB@silence> Hi all. I spent some days and nights on this already and my google-fu is running out. I'd like to implement the equivalent of this Python code in a C-extension: >>> class A(object): ... pass >>> class B(A): ... pass >>> A >>> B >>> B.__bases__ (,) However, loading my C-code (quoted below) I get: >>> import ca >>> ca >>> ca.ca Here I'd expect "" instead?! And I never managed a proper subclass :| The point of the excercise: with "ca" and "cb" properly implemented, I'd like to subclass "cb" not from "ca", but from the Python "class A" - if possible?! Could somepne kindly point out my mistake(s) and set me back on track? Thanks Daniel -- #include typedef struct { PyObject_HEAD } ca; static PyTypeObject ca_Type = { PyObject_HEAD_INIT(NULL) }; PyMODINIT_FUNC initca(void) { PyObject *ca; ca_Type.tp_name = "ca.ca"; ca_Type.tp_basicsize = sizeof(ca); ca_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; if (PyType_Ready(&ca_Type) < 0) return; ca = Py_InitModule3("ca", NULL, "ca module"); if (ca == NULL) return; Py_INCREF(&ca_Type); PyModule_AddObject(ca, "ca", (PyObject*)&ca_Type); } $ gcc -Wall -Wextra -g -fPIC -I/usr/include/python2.7 ca.c \ -shared -Wl,-soname,ca.so -o ca.so -lpython2.7 From rantingrickjohnson at gmail.com Sat Jan 14 16:31:38 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 14 Jan 2012 13:31:38 -0800 (PST) Subject: PyWarts: time, datetime, and calendar modules References: <15cdd8f1-35ef-43ea-a1c9-db90bc16f4ad@r16g2000yqi.googlegroups.com> Message-ID: On Jan 14, 1:23?pm, Rick Johnson wrote: > ? def $method(self):pass > ? self. at instanceveriable > ? self.@@classvariable Actually, class level methods can be accessed through ClassIdentifier.method, and instance methods through instanceidentifier.instancemethod. So decorating methods becomes moot. From rosuav at gmail.com Sat Jan 14 16:56:03 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Jan 2012 08:56:03 +1100 Subject: PyWarts: time, datetime, and calendar modules In-Reply-To: <15cdd8f1-35ef-43ea-a1c9-db90bc16f4ad@r16g2000yqi.googlegroups.com> References: <15cdd8f1-35ef-43ea-a1c9-db90bc16f4ad@r16g2000yqi.googlegroups.com> Message-ID: On Sun, Jan 15, 2012 at 6:23 AM, Rick Johnson wrote: > Observe: > ?def $method(self):pass > ?self. at instanceveriable > ?self.@@classvariable Are you deliberately inverting what PHP does, with $variablename? (Incidentally, that's one of the things that irks me about PHP - adorned variable names.) In any case: Python does not distinguish between functions and other sorts of objects. It makes no sense to adorn things in this way. ChrisA From modelnine at modelnine.org Sat Jan 14 17:45:59 2012 From: modelnine at modelnine.org (Heiko Wundram) Date: Sat, 14 Jan 2012 23:45:59 +0100 Subject: Hash stability In-Reply-To: References: <4f1107b7$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4F1205A7.70303@modelnine.org> Am 14.01.2012 10:46, schrieb Peter Otten: > Steven D'Aprano wrote: >> How many people rely on hash(some_string) being stable across Python >> versions? Does anyone have code that will be broken if the string hashing >> algorithm changes? > > Nobody who understands the question ;) Erm, not exactly true. There are actually some packages out there (take suds [https://fedorahosted.org/suds/], for example) that rely on the hashing algorithm to be stable to function "properly" (suds uses hash() of strings to create caches of objects/XML Schemas on the filesystem). This, in a different context, bit me at the end of last week, when required to use suds to access EWS. I'd personally start debating the sensibility of this decision on the part of the suds developers, but... That's not the question. ;-) -- --- Heiko. From rantingrickjohnson at gmail.com Sat Jan 14 18:19:09 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 14 Jan 2012 15:19:09 -0800 (PST) Subject: PyWarts: time, datetime, and calendar modules References: <15cdd8f1-35ef-43ea-a1c9-db90bc16f4ad@r16g2000yqi.googlegroups.com> Message-ID: <5f7637ca-40a2-4d77-bb47-598bc272b739@g27g2000yqa.googlegroups.com> On Jan 14, 2:58?pm, Evan Driscoll wrote: > On 01/14/2012 02:11 PM, Devin Jeanpierre wrote: > It also has some problems. For instance, if an object has a member which > is a type that implements __call__ but is also useful to access "on its > own", is that a field or a function? Can you site a real world example that would prove your point? > Personally, I'd suggest the thing to "fix" to solve your confusion would > be how things like your code completion and dir() display the results, I must admit this would be the low cost solution, although, i have always been irked by the obfuscation of programming language syntax. I don't need the manual anymore. I just need some introspection tools. HOWEVER, even the best introspection tools in the world cannot make up for obfuscation. Consider the case of the obfuscation of sex by certain "gender neutral" names. males and females frequent usenet and forums around the net, and in most cases we know that a "Tom", "Dick", and "Harry" are going be males, and that "June", "April", and "May" are going to be females. But what about "August", "Jamie", "Payton", or "Parker"? ...and don't forget about that boy named Sue! In face to face communication we will know (most times) who is male, who is female, and who is other. But when all we have to go by is a simple name, well, that name MUST be descriptive. It must carry some hint as to sex. "Hello Mr, urrr Mrs., urrr Payton" EGG ON FACE! Same in programming. We need syntactical clues. When we are removed from the visual, and have no proper syntactic clues, we are then forced to guess! -- and nobody wants to be accused of being the opposite sex! From franke.daniel at gmail.com Sat Jan 14 18:29:20 2012 From: franke.daniel at gmail.com (Daniel Franke) Date: Sun, 15 Jan 2012 00:29:20 +0100 Subject: defining class and subclass in C In-Reply-To: <2921241.kWnIB6QQbB@silence> References: <2921241.kWnIB6QQbB@silence> Message-ID: <6230087.P1ttLEB7Nx@silence> On Saturday 14 January 2012 22:15:36 Daniel Franke wrote: > Here I'd expect "" instead?! And I never managed a proper > subclass :| Found an explanation on type/class at [1]: "he difference between the two is whether the C-level type instance structure is flagged as having been allocated on the heap or not" - hu? With this info, I went ahead and tried the code quoted below. Now I get: >>> import cmod >>> cmod.ca >>> cmod.cb >>> cmod.ca.__bases__ (,) >>> cmod.cb.__bases__ (,) which seems to make sense besides the "type" instead of "class"?! What threw me is that I expected that I'd need to explicitly subclass the "object" type, from which I assumed for some reason I'd also inherit the .tp_new member. This is obviously not the case. Now the last question is, how do I get the a_type of Python class to use it as base for "cb"? On lives and learns. Daniel [1] http://utcc.utoronto.ca/~cks/space/blog/python/ClassesAndTypes -- #include typedef struct { PyObject_HEAD } ca; static PyTypeObject ca_Type = { PyObject_HEAD_INIT(NULL) }; typedef struct { PyObject_HEAD } cb; static PyTypeObject cb_Type = { PyObject_HEAD_INIT(NULL) }; PyMODINIT_FUNC initcmod(void) { PyObject *cmod; ca_Type.tp_name = "cmod.ca"; ca_Type.tp_basicsize = sizeof(ca); ca_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; ca_Type.tp_new = PyType_GenericNew; ca_Type.tp_base = &PyBaseObject_Type; if (PyType_Ready(&ca_Type) < 0) return; cb_Type.tp_name = "cmod.cb"; cb_Type.tp_basicsize = sizeof(cb); cb_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; cb_Type.tp_base = &ca_Type; if (PyType_Ready(&cb_Type) < 0) return; cmod = Py_InitModule3("cmod", NULL, "c module"); if (cmod == NULL) return; Py_INCREF(&ca_Type); PyModule_AddObject(cmod, "ca", (PyObject*)&ca_Type); Py_INCREF(&cb_Type); PyModule_AddObject(cmod, "cb", (PyObject*)&cb_Type); } From rosuav at gmail.com Sat Jan 14 19:36:00 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Jan 2012 11:36:00 +1100 Subject: Hash stability In-Reply-To: <4f1107b7$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <4f1107b7$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jan 14, 2012 at 3:42 PM, Steven D'Aprano wrote: > On the Python Dev mailing list, there is a discussion going on about the > stability of the hash function for strings. > > How many people rely on hash(some_string) being stable across Python > versions? Does anyone have code that will be broken if the string hashing > algorithm changes? On reading your post I immediately thought that you could, if changing algorithm, simultaneously fix the issue of malicious collisions, but that appears to be what you're doing it for primarily :) Suggestion: Create a subclass of dict, the SecureDict or something, which could either perturb the hashes or even use a proper cryptographic hash function; normal dictionaries can continue to use the current algorithm. The description in Objects/dictnotes.txt suggests that it's still well worth keeping the current system for programmer-controlled dictionaries, and only change user-controlled ones (such as POST data etc). It would then be up to the individual framework and module authors to make use of this, but it would not impose any cost on the myriad other uses of dictionaries - there's no point adding extra load to every name lookup just because of a security issue in an extremely narrow situation. It would also mean that code relying on hash(str) stability wouldn't be broken. ChrisA From rosuav at gmail.com Sat Jan 14 19:42:29 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Jan 2012 11:42:29 +1100 Subject: PyWarts: time, datetime, and calendar modules In-Reply-To: <5f7637ca-40a2-4d77-bb47-598bc272b739@g27g2000yqa.googlegroups.com> References: <15cdd8f1-35ef-43ea-a1c9-db90bc16f4ad@r16g2000yqi.googlegroups.com> <5f7637ca-40a2-4d77-bb47-598bc272b739@g27g2000yqa.googlegroups.com> Message-ID: On Sun, Jan 15, 2012 at 10:19 AM, Rick Johnson wrote: > On Jan 14, 2:58?pm, Evan Driscoll wrote: >> On 01/14/2012 02:11 PM, Devin Jeanpierre wrote: > >> It also has some problems. For instance, if an object has a member which >> is a type that implements __call__ but is also useful to access "on its >> own", is that a field or a function? > > Can you site a real world example that would prove your point? Not without breaking a non-disclosure agreement and copyright. ChrisA From timr at probo.com Sat Jan 14 20:26:51 2012 From: timr at probo.com (Tim Roberts) Date: Sat, 14 Jan 2012 17:26:51 -0800 Subject: defining class and subclass in C References: Message-ID: Daniel Franke wrote: > >I'd like to implement the equivalent of this Python code in a C-extension: > >>>> class A(object): >... pass >>>> class B(A): >... pass >>>> A > >>>> B > >>>> B.__bases__ >(,) > >However, loading my C-code (quoted below) I get: > >>>> import ca >>>> ca > >>>> ca.ca > > >Here I'd expect "" instead?! And I never managed a proper >subclass :| Notice this in your code: static PyTypeObject ca_Type = { PyObject_HEAD_INIT(NULL) }; You are creating a "type" object. It shouldn't be a surprise that it is displayed as a , just like int and dict. In a sweeping overgenerality, C modules define types and Python modules define classes. You could redefine the __repr__ method to display "" if you want. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From matt.pounsett at gmail.com Sat Jan 14 21:03:20 2012 From: matt.pounsett at gmail.com (Matthew Pounsett) Date: Sat, 14 Jan 2012 18:03:20 -0800 (PST) Subject: Two questions about logging References: <7dabf43f-3814-47b6-966a-1439f56548b5@i6g2000vbk.googlegroups.com> <3qLPq.3424$nn3.827@newsfe16.iad> Message-ID: On Jan 12, 8:03?pm, K Richard Pixley wrote: > Here's the confusion. ?Each log named __name__ is under the root logger. > ? If you want them all, then catch them all with the root logger. Thanks! I knew I was missing something obvious. Between you and Jean- Michael Pichavant I've figured out what I need to do here. On Jan 11, 9:34 pm, Roy Smith wrote: > What I would do is log to syslog (logging.handlers.SysLogHandler) and > let syslog worry about rotating log files. Why reinvent the wheel? I've also worked out what I need to reset file handles, although it took a lot of reading in the various logging.Handler subclasses. What I needed isn't explicitly documented anywhere, but it turns out that calling the close() method on a FileHandler instance does what I need. There's no method to re-open the handler, but the next call to emit() will automatically re-open the file if it isn't already open. The upshot is that this does the expected thing if you rename its log file and then send the running script a HUP signal. #!/usr/bin/env python import logging import signal import time logger = logging.getLogger() lh = logging.FileHandler('./foo.log') lh.setFormatter(logging.Formatter('%(asctime)s %(name)s: %(message)s', '%T')) logger.addHandler(lh) def sighup(signum, frame): lh.close() logger.error("handled {0}: {1}".format(signum, frame)) def main(): signal.signal(signal.SIGHUP, sighup) while 1: time.sleep(1) logger.error('a message') if __name__ == '__main__': main() From roy at panix.com Sat Jan 14 21:26:27 2012 From: roy at panix.com (Roy Smith) Date: Sat, 14 Jan 2012 21:26:27 -0500 Subject: Hash stability References: <4f1107b7$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <4f1107b7$0$29988$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > On the Python Dev mailing list, there is a discussion going on about the > stability of the hash function for strings. > > How many people rely on hash(some_string) being stable across Python > versions? Does anyone have code that will be broken if the string hashing > algorithm changes? I would never rely on something like that unless the docs unambiguously stated it were so. Which they don't. All I can find about hash() is: "Return the hash value of the object (if it has one). Hash values are integers. They are used to quickly compare dictionary keys during a dictionary lookup. Numeric values that compare equal have the same hash value (even if they are of different types, as is the case for 1 and 1.0)." From contropinion at gmail.com Sat Jan 14 21:34:23 2012 From: contropinion at gmail.com (contro opinion) Date: Sun, 15 Jan 2012 10:34:23 +0800 Subject: mechanize can't get address Message-ID: here is my code # -*- coding: gbk -*- import mechanize import cookielib target="http://v.163.com/movie/2008/10/O/Q/M7F57SUCS_M7F5R3DOQ.html" # Browser br = mechanize.Browser() # Cookie Jar cj = cookielib.LWPCookieJar() br.set_cookiejar(cj) # Browser options br.set_handle_equiv(True) br.set_handle_gzip(True) br.set_handle_redirect(True) br.set_handle_referer(True) #br.set_handle_robots(False) # Follows refresh 0 but not hangs on refresh > 0 br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1) # Want debugging messages? #br.set_debug_http(True) #br.set_debug_redirects(True) #br.set_debug_responses(True) # User-Agent (this is cheating, ok?) br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/4.0.0')] br.open(target) web=br.response().read() file=open('c:\\v','w') file.write(web) file.close() why i can't get the address of movie?? -------------- next part -------------- An HTML attachment was scrubbed... URL: From jason at powerpull.net Sat Jan 14 22:27:12 2012 From: jason at powerpull.net (Jason Friedman) Date: Sun, 15 Jan 2012 03:27:12 +0000 Subject: scientific notation in legend (pylab) In-Reply-To: References: Message-ID: > I I would like to have numbers expressed in scientific notation in > legend annotations. Does anybody know how to do that? > Not sure why legend annotations makes the problem different, but perhaps this is a start: $ python3 Python 3.2 (r32:88445, Jun 11 2011, 10:38:04) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> print("{:e}".format(1000)) 1.000000e+03 http://docs.python.org/library/string.html From steve+comp.lang.python at pearwood.info Sat Jan 14 22:53:21 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Jan 2012 03:53:21 GMT Subject: PyWarts: time, datetime, and calendar modules References: Message-ID: <4f124db1$0$29987$c3e8da3$5496439d@news.astraweb.com> On Sat, 14 Jan 2012 10:54:57 -0800, Rick Johnson wrote: > The interface for these modules is not intuitive. Instead of creating > true OOP objects we have lists and strings. Lists and strings are true OOP objects. -- Steven From contropinion at gmail.com Sat Jan 14 22:54:34 2012 From: contropinion at gmail.com (contro opinion) Date: Sun, 15 Jan 2012 11:54:34 +0800 Subject: why i can get nothing? Message-ID: here is my code : import urllib import lxml.html down='http://download.v.163.com/dl/open/00DL0QDR0QDS0QHH.html' file=urllib.urlopen(down). read() root=lxml.html.document_fromstring(file) tnodes = root.xpath("//a/@href[contains(string(),'mp4')]") for i,add in enumerate(tnodes): print i,add why i can get nothing? -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sat Jan 14 23:07:13 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Jan 2012 23:07:13 -0500 Subject: Hash stability In-Reply-To: References: <4f1107b7$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 1/14/2012 9:26 PM, Roy Smith wrote: > Steven D'Aprano wrote: >> How many people rely on hash(some_string) being stable across Python >> versions? Does anyone have code that will be broken if the string hashing >> algorithm changes? > > I would never rely on something like that unless the docs unambiguously > stated it were so. Which they don't. All I can find about hash() is: > > "Return the hash value of the object (if it has one). Based on the pydev discussion since, it appears that enough people have inferred stability either from that or empirical stability that it will not be broken, by default, in pre-3.3 releases. What ever option is chosen to guard against attacks will probably be the default in 3.3. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Sat Jan 14 23:23:40 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Jan 2012 04:23:40 GMT Subject: PyWarts: time, datetime, and calendar modules References: <15cdd8f1-35ef-43ea-a1c9-db90bc16f4ad@r16g2000yqi.googlegroups.com> Message-ID: <4f1254cb$0$29987$c3e8da3$5496439d@news.astraweb.com> On Sat, 14 Jan 2012 11:23:29 -0800, Rick Johnson wrote: > On Jan 14, 1:01?pm, Devin Jeanpierre wrote: > >> What's "horrendous" about the datetime module interface? Your listed >> complaints (OOP etc.) don't seem to have anything to do with it. > > Well my immediate complaint about date-time is actually a problem with > the syntactic quandaries of the Python language itself. > > I find myself navigating an objects API using the dir function or the > autocomplete function of my IDE. Now. One the continuing issues of the > Python's syntax (and the syntax of many other languages) is the fact > that a reader has no idea which names belonging to an object are methods > and which names are instance/class variables. This is not Java, and we prefer Python terminology. A variable holding an int is an int variable. A variable holding a string is a string variable. A variable holding a list is a list variable. A variable holding an instance is an instance variable. A variable holding a class is a class variable. Clarity of language is your friend. Perhaps you mean instance and class ATTRIBUTES, since dotted names are attributes, not variables. x # x is a variable x.y # y is an attribute of x Methods ARE attributes. You are asking for a distinction which does not exist. This is Python, not Java, and methods are attributes which happen to be callable. (Actually, to be technical they are attributes which use the descriptor protocol to return a callable.) In some other languages, methods (and functions and classes) are second-class entities created at compile time. In Python, they are first-class objects created at runtime like all other objects. Distinguishing methods from other attributes by syntax alone is ugly and artificial. > The status quo has been to > use verbs for methods but you cannot always find the perfect verb, or > even sometimes, anyverb! Consider this: > >>>> import datetime, time, calendar >>>> d = datetime.date.today() >>>> d.day > 14 >>>> d.month > 1 >>>> d.year > 2012 >>>> d.weekday > > > THAT PISSES ME OFF!!! >:( We should never be forced to guess if a name > is a callable or a variable! Guessing is for fourth-class programmers who don't know their language and are too lazy to RTFM. py> import datetime py> d = datetime.date.today() py> hasattr(d.weekday, '__call__') True help(d) is also your friend. > So how do we solve this dilemma you ask??? Well, we need to "mark" > method OR variable names (OR both!) with syntactic markers so there will > be NO confusion. No we don't. There is no dilemma. At worst, we might agree that the datetime API is old and tired, and that if descriptors existed back in Python 1.x then datetime.weekday could have been a computed property instead of a method, but alas we've lost the opportunity for this. Any changes to datetime need to be backward compatible. If you want to actually do something useful, instead of just big-noting yourself and trolling about how bad Python is because it doesn't work like the language you have in your head, I suggest you write a datetime wrapper class and offer it to the community via PyPI. If it is good, and becomes popular, then in Python 3.4 or 3.5 it may become part of the standard library. -- Steven From steve+comp.lang.python at pearwood.info Sat Jan 14 23:26:13 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Jan 2012 04:26:13 GMT Subject: PyWarts: time, datetime, and calendar modules References: <15cdd8f1-35ef-43ea-a1c9-db90bc16f4ad@r16g2000yqi.googlegroups.com> Message-ID: <4f125564$0$29987$c3e8da3$5496439d@news.astraweb.com> On Sat, 14 Jan 2012 14:58:26 -0600, Evan Driscoll wrote: > On 01/14/2012 02:11 PM, Devin Jeanpierre wrote: >> On Sat, Jan 14, 2012 at 2:23 PM, Rick Johnson >> wrote: >>> THAT PISSES ME OFF!!!>:( We should never be forced to guess if a name >>> is a callable or a variable! >>> >>> So how do we solve this dilemma you ask??? Well, we need to "mark" >>> method OR variable names (OR both!) with syntactic markers so there >>> will be NO confusion. >> >> I might be being bit OT, but, you should give Common Lisp a try. It >> does something similar for functions versus variables. >> >> As for the issue, I suppose I can see how this would be confusing. I >> don't agree with your solution, though. > > It also has some problems. For instance, if an object has a member which > is a type that implements __call__ but is also useful to access "on its > own", is that a field or a function? This is the problem with Ruby's syntax for calling functions with no argument with brackets. Since f on its own is interpreted as "call f with no arguments", there is no easy way to get a reference to the object f. This makes functions second-class objects in Ruby, since you can't refer to them easily by name like you can other objects. -- Steven From ichineseflashcards3 at gmail.com Sun Jan 15 00:05:05 2012 From: ichineseflashcards3 at gmail.com (ichineseflashcards 3) Date: Sat, 14 Jan 2012 21:05:05 -0800 (PST) Subject: Learn Chinese (Mandarin) faster by using flashcards with pictures Message-ID: <085e5ce5-e7cf-486f-b7a9-af3e9eadc594@s6g2000pbi.googlegroups.com> http://www.ichineseflashcards.com will help you learn Chinese (Mandarin) faster by using flashcards with pictures, thanks From rantingrickjohnson at gmail.com Sun Jan 15 00:27:32 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 14 Jan 2012 21:27:32 -0800 (PST) Subject: PyWarts: time, datetime, and calendar modules References: <15cdd8f1-35ef-43ea-a1c9-db90bc16f4ad@r16g2000yqi.googlegroups.com> <4f1254cb$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: <09e6c247-f3b1-47f2-9b8a-b6de67dc7111@r16g2000yqi.googlegroups.com> On Jan 14, 10:23?pm, Steven D'Aprano wrote: > This is not Java, and we prefer Python terminology. > > A variable holding an int is an int variable. > A variable holding a string is a string variable. > A variable holding a list is a list variable. > A variable holding an instance is an instance variable. > A variable holding a class is a class variable. You went to a lot of trouble to prove nothing. Here allow me to retort: A box holding an apple is an apple box. A box holding a pear is a pear box. A box holding an orange is a orange box. A box holding an banana is an banana box. And a box that penis comes in is a vagina! > Guessing is for fourth-class programmers who don't know their language > and are too lazy to RTFM. Oh really. I don't know about you Steven but i am not JUST a Python programmer. I write tons of code with Python but i also write tons of code in many other languages too. Not only am i emerged in many aspects of the IT world, i have a WIDE scope of knowledge in many other fields and disciplines; all of which is ongoing because let's face it, the minute you _think_ you know everything is the second you become obsolete. But i digress... Making claims that obfuscated syntax and insufficient APIs are *somehow* the programmers fault, because he (or she!) does not have EVERY *SINGLE* corner of the Python library memorized, is quite preposterous. > At worst, we might agree that the datetime API is old and tired, and that > if descriptors existed back in Python 1.x then datetime.weekday could > have been a computed property instead of a method, but alas we've lost > the opportunity for this. Any changes to datetime need to be backward > compatible. Why? "print()" is not backward compatible? Face it, Guido has broken Python's cherry. She is no longer pure. You're acting like some over- protective father. WAKE UP! Python is a promiscuous little whore and she's on girls gone wild (Volume 4000) shaking her little money maker. We should at least profit from the immorality. From steve+comp.lang.python at pearwood.info Sun Jan 15 02:00:49 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Jan 2012 07:00:49 GMT Subject: PyWarts: time, datetime, and calendar modules References: <15cdd8f1-35ef-43ea-a1c9-db90bc16f4ad@r16g2000yqi.googlegroups.com> <4f1254cb$0$29987$c3e8da3$5496439d@news.astraweb.com> <09e6c247-f3b1-47f2-9b8a-b6de67dc7111@r16g2000yqi.googlegroups.com> Message-ID: <4f1279a1$0$29987$c3e8da3$5496439d@news.astraweb.com> On Sat, 14 Jan 2012 21:27:32 -0800, Rick Johnson wrote: > On Jan 14, 10:23?pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: > >> This is not Java, and we prefer Python terminology. >> >> A variable holding an int is an int variable. A variable holding a >> string is a string variable. A variable holding a list is a list >> variable. A variable holding an instance is an instance variable. A >> variable holding a class is a class variable. > > You went to a lot of trouble to prove nothing. Here allow me to retort: > > A box holding an apple is an apple box. A box holding a pear is a pear > box. > A box holding an orange is a orange box. A box holding an banana is an > banana box. And a box that penis comes in is a vagina! Penises aren't supplied in boxes. About 50% of the population already has one, the other 50% can get as many as they want. >> Guessing is for fourth-class programmers who don't know their language >> and are too lazy to RTFM. > > Oh really. I don't know about you Steven but i am not JUST a Python > programmer. I write tons of code with Python but i also write tons of > code in many other languages too. Why don't you approach those other languages and demand that they change to match Python's model then? See how well that goes over. >> At worst, we might agree that the datetime API is old and tired, and >> that if descriptors existed back in Python 1.x then datetime.weekday >> could have been a computed property instead of a method, but alas we've >> lost the opportunity for this. Any changes to datetime need to be >> backward compatible. > > Why? "print()" is not backward compatible? You missed your opportunity by two versions. The time to have made the change was before Python 3.0 came out. We're now up to 3.2 and 3.3 is under development. The opportunity for breaking backward compatibility was 3-4 years ago. Now we're back to the normal paradigm of caring about backward compatibility. > Face it, Guido has broken Python's cherry. She is no longer pure. You need to get yourself a girlfriend. Or at least a subscription to Playboy. -- Steven From edriscoll at wisc.edu Sun Jan 15 02:37:22 2012 From: edriscoll at wisc.edu (Evan Driscoll) Date: Sun, 15 Jan 2012 01:37:22 -0600 Subject: Extension module question Message-ID: <4F128232.8020801@wisc.edu> As I hinted at in an earlier email, I'm working on a module which will allow calling readdir() (and FindFirstFile on Windows, hopefully pretty uniformly) from Python. The responses I got convinced me that it was a good idea to write a C-to-Python bridge as an extension module. What I'm not sure about is how to store pointers to *C* stuff between calls. In particular, opendir() returns a DIR* which you then need to pass to calls to readdir() in the future (and closedir()). So I've got this: static PyObject* py_opendir(PyObject* self, PyObject* args) { const char* dirname = 0; if (!PyArg_ParseTuple(args, "s", &dirname)) { return NULL; } // Eventually want to Py_BEGIN_ALLOW_THREADS here DIR* directory = opendir(dirname); PyObject out = PyBuildValue( ???, directory ); return out; } but I don't know what to build. (I might want to wrap it in a custom handle class or something, but I still need to know how to build the value I eventually store in an attribute of that class.) My best idea is to use an unsigned long (so "k") and add a static assertion that sizeof(long)==sizeof(void*). Is this the canonical way of doing something like this, or am I missing a better way? 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 stefan_ml at behnel.de Sun Jan 15 05:13:56 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 15 Jan 2012 11:13:56 +0100 Subject: Hash stability In-Reply-To: <4F1205A7.70303@modelnine.org> References: <4f1107b7$0$29988$c3e8da3$5496439d@news.astraweb.com> <4F1205A7.70303@modelnine.org> Message-ID: Heiko Wundram, 14.01.2012 23:45: > Am 14.01.2012 10:46, schrieb Peter Otten: >> Steven D'Aprano wrote: >>> How many people rely on hash(some_string) being stable across Python >>> versions? Does anyone have code that will be broken if the string hashing >>> algorithm changes? >> >> Nobody who understands the question ;) > > Erm, not exactly true. There are actually some packages out there (take > suds [https://fedorahosted.org/suds/], for example) that rely on the > hashing algorithm to be stable to function "properly" (suds uses hash() of > strings to create caches of objects/XML Schemas on the filesystem). That's a stupid design. Using a hash function that the application does not control to index into persistent storage just screams for getting the code broken at some point. Stefan From stefan_ml at behnel.de Sun Jan 15 05:24:12 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 15 Jan 2012 11:24:12 +0100 Subject: defining class and subclass in C In-Reply-To: <2921241.kWnIB6QQbB@silence> References: <2921241.kWnIB6QQbB@silence> Message-ID: Daniel Franke, 14.01.2012 22:15: > I spent some days and nights on this already and my google-fu is running out. > I'd like to implement the equivalent of this Python code in a C-extension: > > >>> class A(object): > .... pass > >>> class B(A): > .... pass > >>> A > > >>> B > > >>> B.__bases__ > (,) > > However, loading my C-code (quoted below) I get: > > >>> import ca > >>> ca > > >>> ca.ca > > > Here I'd expect "" instead?! You already got the response (and found for yourself) that this is normal. CPython makes a distinction between classes defined the Python way and extension types, the latter of which you define in your code. As a general advice: if your primary interest is in implementing some kind of functionality, instead of just learning about the bits and pieces of CPython's C-API, you may want to take a look at Cython. It makes writing efficient C extension modules fast and easy, especially when it comes to class hierarchies and similarly things. Stefan From stefan_ml at behnel.de Sun Jan 15 05:48:22 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 15 Jan 2012 11:48:22 +0100 Subject: Extension module question In-Reply-To: <4F128232.8020801@wisc.edu> References: <4F128232.8020801@wisc.edu> Message-ID: Evan Driscoll, 15.01.2012 08:37: > As I hinted at in an earlier email, I'm working on a module which will > allow calling readdir() (and FindFirstFile on Windows, hopefully pretty > uniformly) from Python. The responses I got convinced me that it was a > good idea to write a C-to-Python bridge as an extension module. An even better idea is to write an extension module in Cython. Much faster and simpler to learn and do. > What I'm not sure about is how to store pointers to *C* stuff between > calls. In particular, opendir() returns a DIR* which you then need to > pass to calls to readdir() in the future (and closedir()). > > So I've got this: > > static PyObject* > py_opendir(PyObject* self, PyObject* args) > { > const char* dirname = 0; > if (!PyArg_ParseTuple(args, "s", &dirname)) { > return NULL; > } > // Eventually want to Py_BEGIN_ALLOW_THREADS here Cython allows you to do that by simply putting it into a "with nogil" block. > DIR* directory = opendir(dirname); > > PyObject out = PyBuildValue( ???, directory ); > return out; > } > > but I don't know what to build. (I might want to wrap it in a custom > handle class or something, but I still need to know how to build the > value I eventually store in an attribute of that class.) I suggest you write an extension type and store the pointer in it directly. Untested Cython code example: filesystem_encoding = sys.getfilesystemencoding() cdef class Directory: cdef DIR* c_directory def __cinit__(self, directory): if isinstance(directory, unicode): directory = directory.encode(filesystem_encoding) cdef char* c_dirname = directory # raises TypeError on failure with nogil: self.c_directory = opendir(c_dirname) def __iter__(self): cdef char* name cdef size_t name_length for name in however_you_list_the_content_of(self.c_directory): name_length = length_which_you_may_know_of(name) yield name[:name_length].decode(filesystem_encoding) and so on. Note how Cython does all sorts of things automatically for you here, e.g. type conversions and the corresponding error handling as well as all those nasty details of the C-level extension type implementation. Also note that I'm using __cinit__() instead of __init__() for safety. See here: http://docs.cython.org/src/userguide/special_methods.html#initialisation-methods-cinit-and-init To implement the same interface for Unices and Windows, I suggest you write two separate extension modules and hide them in a Python package that does the appropriate platform specific imports at runtime. Stefan From modelnine at modelnine.org Sun Jan 15 06:46:18 2012 From: modelnine at modelnine.org (Heiko Wundram) Date: Sun, 15 Jan 2012 12:46:18 +0100 Subject: Hash stability In-Reply-To: References: <4f1107b7$0$29988$c3e8da3$5496439d@news.astraweb.com> <4F1205A7.70303@modelnine.org> Message-ID: <4F12BC8A.9040205@modelnine.org> Am 15.01.2012 11:13, schrieb Stefan Behnel: > That's a stupid design. Using a hash function that the application does not > control to index into persistent storage just screams for getting the code > broken at some point. I agree completely with that (I hit the corresponding problem with suds while transitioning from 32-bit Python to 64-bit Python, where hashes aren't stable either), but as stated in my mail: that wasn't the original question. ;-) -- --- Heiko. From bryanjugglercryptographer at yahoo.com Sun Jan 15 07:03:53 2012 From: bryanjugglercryptographer at yahoo.com (Bryan) Date: Sun, 15 Jan 2012 04:03:53 -0800 (PST) Subject: Hash stability References: <4f1107b7$0$29988$c3e8da3$5496439d@news.astraweb.com> Message-ID: <994ca5fa-59b0-4128-8f9a-696d46db6856@4g2000pbz.googlegroups.com> Chris Angelico wrote: > Suggestion: Create a subclass of dict, the SecureDict or something, > which could either perturb the hashes or even use a proper > cryptographic hash function; normal dictionaries can continue to use > the current algorithm. The description in Objects/dictnotes.txt > suggests that it's still well worth keeping the current system for > programmer-controlled dictionaries, and only change user-controlled > ones (such as POST data etc). I have to disagree; that's not how the world works, at least not anymore. Competent, skilled, dedicated programmers have over and over again failed to appreciate the importance and the difficulty of maintaining proper function in an adversarial environment. The tactic of ignoring security issues unless and until they are proven problematic stands utterly discredited. > It would then be up to the individual framework and module authors to > make use of this, but it would not impose any cost on the myriad other > uses of dictionaries - there's no point adding extra load to every > name lookup just because of a security issue in an extremely narrow > situation. It would also mean that code relying on hash(str) stability > wouldn't be broken. That seemingly "extremely narrow situation" turns out to be wide as Montana. Maybe Siberia. Does your program take input? Does it accept a format that could possibly be downloaded from a malicious site on the Internet? Does your market include users who occasionally make mistakes? If not, enjoy your utter irrelevance. If so, congratulations: you write Internet software. Varying the hash function is just the first step. Plausible attacks dynamically infer how to induce degenerate behavior. Replacing the dictionary hash function with a "proper cryptographic hash function" is a naive non-solution; all things considered it's somewhat worse than useless. An old and interesting and relevant exercise is to implement a dictionary with O(1) insert, look-up, and delete in the average non-adversarial case; and O(lg n) insert, look-up, and delete in the worse case. From rosuav at gmail.com Sun Jan 15 07:21:24 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Jan 2012 23:21:24 +1100 Subject: Hash stability In-Reply-To: <994ca5fa-59b0-4128-8f9a-696d46db6856@4g2000pbz.googlegroups.com> References: <4f1107b7$0$29988$c3e8da3$5496439d@news.astraweb.com> <994ca5fa-59b0-4128-8f9a-696d46db6856@4g2000pbz.googlegroups.com> Message-ID: On Sun, Jan 15, 2012 at 11:03 PM, Bryan wrote: > Chris Angelico wrote: >> Suggestion: Create a subclass of dict, the SecureDict or something, >> ... there's no point adding extra load to every >> name lookup just because of a security issue in an extremely narrow >> situation. > > That seemingly "extremely narrow situation" turns out to be wide as > Montana. Maybe Siberia. Does your program take input? Does it accept a > format that could possibly be downloaded from a malicious site on the > Internet? Does your market include users who occasionally make > mistakes? If not, enjoy your utter irrelevance. If so, > congratulations: you write Internet software. Yes, but in that "Internet software", there will only be a small number of dictionaries that an attacker can stuff with keys (GET/POST data, headers, cookies, etc, and anything derived therefrom); compare the huge number of dictionaries that exist elsewhere in your Python program. Adding load to dictionaries will add load to a huge number of lookups that can never come under attack. However, since posting that I've read the entire thread on the python-dev archive. (It is, I might mention, a LOT of text.) A number of suggestions and arguments are put forth, including a subclassing notion similar to my postulation, and the same point is raised: that app/framework developers won't secure their apps. Other options are also offered (personally, I'm liking the one where an exception is raised if something collides with too many keys - current suggestion 1000, although it could possibly work well with something that scales with the dictionary size), and I'm sure that something will be done that's a lot smarter than one quick idea spun off in response to a separate query. So, I retract this idea :) ChrisA From __peter__ at web.de Sun Jan 15 07:22:21 2012 From: __peter__ at web.de (Peter Otten) Date: Sun, 15 Jan 2012 13:22:21 +0100 Subject: Hash stability References: <4f1107b7$0$29988$c3e8da3$5496439d@news.astraweb.com> <4F1205A7.70303@modelnine.org> <4F12BC8A.9040205@modelnine.org> Message-ID: Heiko Wundram wrote: > Am 15.01.2012 11:13, schrieb Stefan Behnel: >> That's a stupid design. Using a hash function that the application does >> not control to index into persistent storage just screams for getting the >> code broken at some point. > > I agree completely with that (I hit the corresponding problem with suds > while transitioning from 32-bit Python to 64-bit Python, where hashes > aren't stable either), but as stated in my mail: that wasn't the > original question. ;-) I'm curious: did you actually get false cache hits or just slower responses? From contropinion at gmail.com Sun Jan 15 08:59:02 2012 From: contropinion at gmail.com (contro opinion) Date: Sun, 15 Jan 2012 21:59:02 +0800 Subject: problem:emulate it in python with mechanize Message-ID: you can do it by hand , 1.open http://www.flvcd.com/' 2.input http://v.163.com/movie/2008/10/O/Q/M7F57SUCS_M7F5R3DOQ.html 3.click submit you can get http://mov.bn.netease.com/movie/2012/1/V/7/S7MKQOBV7.flv i want to emulate it in python with mechanize,here is my code ,why i can't get the right result: http://mov.bn.netease.com/movie/2012/1/V/7/S7MKQOBV7.flv import mechanize import cookielib import lxml.html br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')] br = mechanize.Browser() br.set_handle_robots(False) r = br.open('http://www.flvcd.com/') for f in br.forms(): print f br.select_form(nr=0) br.form['kw']='http://v.163.com/movie/2008/10/O/Q/M7F57SUCS_M7F5R3DOQ.html' print br.submit().read() why?? -------------- next part -------------- An HTML attachment was scrubbed... URL: From kevin.p.dwyer at gmail.com Sun Jan 15 09:20:36 2012 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sun, 15 Jan 2012 14:20:36 +0000 Subject: problem:emulate it in python with mechanize References: Message-ID: contro opinion wrote: > you can do it by hand , > 1.open > http://www.flvcd.com/' > 2.input > http://v.163.com/movie/2008/10/O/Q/M7F57SUCS_M7F5R3DOQ.html > 3.click submit > you can get > http://mov.bn.netease.com/movie/2012/1/V/7/S7MKQOBV7.flv > > i want to emulate it in python with mechanize,here is my code ,why i > can't get the right result: > http://mov.bn.netease.com/movie/2012/1/V/7/S7MKQOBV7.flv > > > > import mechanize > import cookielib > import lxml.html > br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; > rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')] > br = mechanize.Browser() > br.set_handle_robots(False) > > r = br.open('http://www.flvcd.com/') > for f in br.forms(): > print f > br.select_form(nr=0) > br.form['kw']='http://v.163.com/movie/2008/10/O/Q/M7F57SUCS_M7F5R3DOQ.html' > print br.submit().read() > > why?? Hello, I think the page uses javascript to submit the form, so mechanize may not work with it directly. See http://stackoverflow.com/questions/3798550/python-mechanize-javascript- submit-button-problem for a similar problem and suggested workaround. Cheers, Kev From lie.1296 at gmail.com Sun Jan 15 10:13:12 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Mon, 16 Jan 2012 02:13:12 +1100 Subject: PyWarts: time, datetime, and calendar modules In-Reply-To: <15cdd8f1-35ef-43ea-a1c9-db90bc16f4ad@r16g2000yqi.googlegroups.com> References: <15cdd8f1-35ef-43ea-a1c9-db90bc16f4ad@r16g2000yqi.googlegroups.com> Message-ID: On 01/15/2012 06:23 AM, Rick Johnson wrote: > So how do we solve this dilemma you ask??? Well, we need to "mark" > method OR variable names (OR both!) with syntactic markers so there > will be NO confusion. > > Observe: > def $method(self):pass > self. at instanceveriable > self.@@classvariable There is no need for a language-level support for Hungarian notation. From jason at powerpull.net Sun Jan 15 10:40:56 2012 From: jason at powerpull.net (Jason Friedman) Date: Sun, 15 Jan 2012 15:40:56 +0000 Subject: why i can get nothing? In-Reply-To: References: Message-ID: > here is my code : > import urllib > import lxml.html > down='http://download.v.163.com/dl/open/00DL0QDR0QDS0QHH.html' > file=urllib.urlopen(down). > read() > root=lxml.html.document_fromstring(file) > tnodes = root.xpath("//a/@href[contains(string(),'mp4')]") > for i,add in enumerate(tnodes): > ??? print? i,add > > why i can get nothing? What version of python is this? Based on the naked "print" I guess 2.x, and I got: $ /opt/python2/bin/python2.7 Python 2.7.2 (default, Oct 10 2011, 03:43:34) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import lxml.html Traceback (most recent call last): File "", line 1, in ImportError: No module named lxml.html From modelnine at modelnine.org Sun Jan 15 11:07:52 2012 From: modelnine at modelnine.org (Heiko Wundram) Date: Sun, 15 Jan 2012 17:07:52 +0100 Subject: Hash stability In-Reply-To: References: <4f1107b7$0$29988$c3e8da3$5496439d@news.astraweb.com> <4F1205A7.70303@modelnine.org> <4F12BC8A.9040205@modelnine.org> Message-ID: <4F12F9D8.5080904@modelnine.org> Am 15.01.2012 13:22, schrieb Peter Otten: > Heiko Wundram wrote: >> I agree completely with that (I hit the corresponding problem with suds >> while transitioning from 32-bit Python to 64-bit Python, where hashes >> aren't stable either), but as stated in my mail: that wasn't the >> original question. ;-) > > I'm curious: did you actually get false cache hits or just slower responses? It broke the application using suds, not due to false cache hits, but due to not getting a cache hit anymore at all. Long story: to interpret WSDL-files, suds has to get all related DTDs for the WSDL file, and Microsoft (as I wrote I was querying Exchange Web Services) insists on using http://www.w3.org/2001/xml.dtd for the XML spec path. This path is sometimes functional as a GET URL, but mostly not (due to overload of the W3-servers), so basically I worked around the problem by creating an appropriate cache entry with the appropriate name based on hash() using a local copy of xml.dtd I had around. This took place on a development machine (32-bit), and when migrating the application to a production machine (64-bit), the cache file wasn't used anymore (due to the hash not being stable). It's not that this came as a surprise (I quickly knew the "workaround" by simply rehashing on the target machine and moving the cache file appropriately), and I already said that this is mostly just a plain bad design decision on the part of the suds developers, but it's one of those cases where a non-stable hash() can break applications, and except if you know the internal workings of suds, this will seriously bite the developer. I don't know the prevalence of suds, but I guess there's more people than me using it to query SOAP-services - all of those will be affected if the hash() output is changed. Additionally, if hash() isn't stable between runs (the randomized hash() solution which is preferred, and would also be my preference), suds caching becomes completely useless. And for the results, see above. -- --- Heiko. From rosuav at gmail.com Sun Jan 15 11:13:01 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 Jan 2012 03:13:01 +1100 Subject: Hash stability In-Reply-To: <4F12F9D8.5080904@modelnine.org> References: <4f1107b7$0$29988$c3e8da3$5496439d@news.astraweb.com> <4F1205A7.70303@modelnine.org> <4F12BC8A.9040205@modelnine.org> <4F12F9D8.5080904@modelnine.org> Message-ID: On Mon, Jan 16, 2012 at 3:07 AM, Heiko Wundram wrote: > I don't know the prevalence of suds, but I guess there's more people than me > using it to query SOAP-services - all of those will be affected if the > hash() output is changed. Additionally, if hash() isn't stable between runs > (the randomized hash() solution which is preferred, and would also be my > preference), suds caching becomes completely useless. And for the results, > see above. Or you could just monkey-patch it so that 'hash' points to an old hashing function. If the current hash() is kept in builtins as (say) hash_320() or hash_272() or something, then anyone who wants the old version of the hash can still get it. Of course, it's still dodgy to depend on the stability of something that isn't proclaimed stable, and would be far better to use some other hashing algorithm (MD5 or SHA for uberreliability). ChrisA From modelnine at modelnine.org Sun Jan 15 11:51:12 2012 From: modelnine at modelnine.org (Heiko Wundram) Date: Sun, 15 Jan 2012 17:51:12 +0100 Subject: Hash stability In-Reply-To: References: <4f1107b7$0$29988$c3e8da3$5496439d@news.astraweb.com> <4F1205A7.70303@modelnine.org> <4F12BC8A.9040205@modelnine.org> <4F12F9D8.5080904@modelnine.org> Message-ID: <4F130400.9020801@modelnine.org> Am 15.01.2012 17:13, schrieb Chris Angelico: > On Mon, Jan 16, 2012 at 3:07 AM, Heiko Wundram wrote: >> I don't know the prevalence of suds, but I guess there's more people than me >> using it to query SOAP-services - all of those will be affected if the >> hash() output is changed. Additionally, if hash() isn't stable between runs >> (the randomized hash() solution which is preferred, and would also be my >> preference), suds caching becomes completely useless. And for the results, >> see above. > > Or you could just monkey-patch it so that 'hash' points to an old > hashing function. If the current hash() is kept in builtins as (say) > hash_320() or hash_272() or something, then anyone who wants the old > version of the hash can still get it. Or even easier: overwrite the default caching module (called FileCache) with something that implements "sensible" caching, for example by using the complete URL (with special characters replaced) of the DTD as a cache index, instead of hash()ing it. ;-) There's "workarounds", I know - and I may be implementing one of them if the time comes. Again, my mail was only to point at the fact that there are (serious) projects out there relying on the "stableness" of hash(), and that these will get bitten when hash() is replaced. Which is not a bad thing if you ask me. ;-) -- --- Heiko. From stefan_ml at behnel.de Sun Jan 15 12:20:02 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 15 Jan 2012 18:20:02 +0100 Subject: Hash stability In-Reply-To: References: <4f1107b7$0$29988$c3e8da3$5496439d@news.astraweb.com> <4F1205A7.70303@modelnine.org> <4F12BC8A.9040205@modelnine.org> <4F12F9D8.5080904@modelnine.org> Message-ID: Chris Angelico, 15.01.2012 17:13: > Of course, it's still dodgy to depend on the stability of something > that isn't proclaimed stable, and would be far better to use some > other hashing algorithm (MD5 or SHA for uberreliability). I've seen things like MD5 or SHA* being used quite commonly for file caches (or file storage in general, e.g. for related files referenced in a text document). Given that these algorithms are right there in the stdlib, I find them a rather obvious choice. However, note that they may also be subject to complexity attacks at some point, although likely requiring substantially more input data. In the specific case of a cache, an attacker may only need an arbitrary set of colliding hashes. Those can be calculated in advance for a given hash function. For example, Wikipedia currently presents MD5 with a collision complexity of ~2^20, that sounds a bit weak. Something like SHA256 should be substantially more robust. https://en.wikipedia.org/wiki/Cryptographic_hash_function#Cryptographic_hash_algorithms Stefan From saqib.ali.75 at gmail.com Sun Jan 15 12:51:44 2012 From: saqib.ali.75 at gmail.com (Saqib Ali) Date: Sun, 15 Jan 2012 09:51:44 -0800 (PST) Subject: Problem while doing a cat on a tabbed file with pexpect Message-ID: I am using Solaris 10, python 2.6.2, pexpect 2.4 I create a file called me.txt which contains the letters "A", "B", "C" on the same line separated by tabs. My shell prompt is "% " I then do the following in the python shell: >>> import pexpect >>> x = pexpect.spawn("/bin/tcsh") >>> x.sendline("cat me.txt") 11 >>> x.expect([pexpect.TIMEOUT, "% "]) 1 >>> x.before 'cat me.txt\r\r\nA B C\r\n' >>> x.before.split("\t") ['cat me.txt\r\r\nA B C\r\n'] Now, clearly the file contains tabs. But when I cat it through expect, and collect cat's output, those tabs have been converted to spaces. But I need the tabs! Can anyone explain this phenomenon or suggest how I can fix it? From clp2 at rebertia.com Sun Jan 15 17:17:42 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 15 Jan 2012 14:17:42 -0800 Subject: why i can get nothing? In-Reply-To: References: Message-ID: On Sun, Jan 15, 2012 at 7:40 AM, Jason Friedman wrote: >> here is my code : >> import urllib >> import lxml.html > What version of python is this? ?Based on the naked "print" I guess > 2.x, and I got: >>>> import lxml.html > Traceback (most recent call last): > ?File "", line 1, in > ImportError: No module named lxml.html lxml is a fairly popular third-party XML package for Python: http://lxml.de/ Regards, Chris From roy at panix.com Sun Jan 15 17:26:29 2012 From: roy at panix.com (Roy Smith) Date: Sun, 15 Jan 2012 17:26:29 -0500 Subject: why i can get nothing? References: Message-ID: In article , Chris Rebert wrote: > On Sun, Jan 15, 2012 at 7:40 AM, Jason Friedman wrote: > >> here is my code : > >> import urllib > >> import lxml.html > > > What version of python is this? ??Based on the naked "print" I guess > > 2.x, and I got: > > >>>> import lxml.html > > Traceback (most recent call last): > > ??File "", line 1, in > > ImportError: No module named lxml.html > > lxml is a fairly popular third-party XML package for Python: > http://lxml.de/ Fairly popular and insanely awesome! From robert at roberthelmer.com Sun Jan 15 18:03:18 2012 From: robert at roberthelmer.com (Robert Helmer) Date: Sun, 15 Jan 2012 15:03:18 -0800 Subject: why i can get nothing? In-Reply-To: References: Message-ID: On Sat, Jan 14, 2012 at 7:54 PM, contro opinion wrote: > here is my code : > import urllib > import lxml.html > down='http://download.v.163.com/dl/open/00DL0QDR0QDS0QHH.html' > file=urllib.urlopen(down). > read() > root=lxml.html.document_fromstring(file) > tnodes = root.xpath("//a/@href[contains(string(),'mp4')]") > for i,add in enumerate(tnodes): > ??? print? i,add > > why i can get nothing? The problem is the document. The links you are trying to match on are inside the script tags in the document, here's a simplified version: """ """ So the anchor elements are not part of the DOM as far as lxml is concerned, lxml does not know how to parse javascript (and even if it did it would have to execute the JS, and JS would have to modify the DOM, before you could get this via xpath) You could have lxml return just the script nodes that contain the text you care about: tnodes = root.xpath("//script[contains(.,'mp4')]") Then you will need a different tool for the rest of this, regex is not perfect but should be good enough. Probably not worth the effort to use a real javascript parser if you're just trying to scrape the mp4 links out of this, but it's an option. From steve+comp.lang.python at pearwood.info Sun Jan 15 18:04:06 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Jan 2012 23:04:06 GMT Subject: Problem while doing a cat on a tabbed file with pexpect References: Message-ID: <4f135b65$0$29987$c3e8da3$5496439d@news.astraweb.com> On Sun, 15 Jan 2012 09:51:44 -0800, Saqib Ali wrote: > I am using Solaris 10, python 2.6.2, pexpect 2.4 > > I create a file called me.txt which contains the letters "A", "B", "C" > on the same line separated by tabs. [...] > Now, clearly the file contains tabs. That is not clear at all. How do you know it contains tabs? How was the file created in the first place? Try this: text = open('me.txt', 'r').read() print '\t' in text My guess is that it will print False and that the file does not contain tabs. Check your editor used to create the file. -- Steven From cs at zip.com.au Sun Jan 15 18:40:08 2012 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 16 Jan 2012 10:40:08 +1100 Subject: Problem while doing a cat on a tabbed file with pexpect In-Reply-To: <4f135b65$0$29987$c3e8da3$5496439d@news.astraweb.com> References: <4f135b65$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20120115234008.GA28596@cskk.homeip.net> On 15Jan2012 23:04, Steven D'Aprano wrote: | On Sun, 15 Jan 2012 09:51:44 -0800, Saqib Ali wrote: | > I am using Solaris 10, python 2.6.2, pexpect 2.4 | > | > I create a file called me.txt which contains the letters "A", "B", "C" | > on the same line separated by tabs. | [...] | > Now, clearly the file contains tabs. | | That is not clear at all. How do you know it contains tabs? How was the | file created in the first place? | | Try this: | | text = open('me.txt', 'r').read() | print '\t' in text | | My guess is that it will print False and that the file does not contain | tabs. Check your editor used to create the file. I was going to post an alternative theory but on more thought I think Steven is right here. What does: od -c me.txt show you? TABs or multiple spaces? What does: ls -ld me.txt tell you about the file size? Is it 6 bytes long (three letters, two TABs, one newline)? Steven hasn't been explicit about it, but some editors will write spaces when you type a TAB. I have configured mine to do so - it makes indentation more reliable for others. If I really need a TAB character I have a special finger contortion to get one, but the actual need is rare. So first check that the file really does contain TABs. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Yes Officer, yes Officer, I will Officer. Thank you. From saqib.ali.75 at gmail.com Sun Jan 15 19:11:27 2012 From: saqib.ali.75 at gmail.com (Saqib Ali) Date: Sun, 15 Jan 2012 16:11:27 -0800 (PST) Subject: Problem while doing a cat on a tabbed file with pexpect References: Message-ID: <4008c5d1-98c5-4796-9e82-0e8835fbe42a@i25g2000vbt.googlegroups.com> Very good question. Let me explain why I'm not opening me.txt directly in python with open. The example I have posted is simplified for illustrative purpose. In reality, I'm not doing pexpect.spawn("/bin/tcsh"). I'm doing pexpect.spawn("ssh myuser at ipaddress"). Since I'm operating on a remote system, I can't simply open the file in my own python context. On Jan 15, 2:24?pm, Dennis Lee Bieber wrote: > On Sun, 15 Jan 2012 09:51:44 -0800 (PST), Saqib Ali > > wrote: > >Now, clearly the file contains tabs. But when I cat it through expect, > >and collect cat's output, those tabs have been converted to spaces. > >But I need the tabs! > > >Can anyone explain this phenomenon or suggest how I can fix it? > > ? ? ? ? My question is: > > ? ? ? ? WHY are you doing this? > > ? ? ? ? Based upon the problem discription, as given, the solution would > seem to be to just open the file IN Python -- whether you read the lines > and use split() by hand, or pass the open file to the csv module for > reading/parsing is up to you. > > -=-=-=-=-=-=- > import csv > import os > > TESTFILE = "Test.tsv" > > #create data file > fout = open(TESTFILE, "w") > for ln in [ ?"abc", > ? ? ? ? ? ? "defg", > ? ? ? ? ? ? "hijA" ?]: > ? ? fout.write("\t".join(list(ln)) + "\n") > fout.close() > > #process tab-separated data > fin = open(TESTFILE, "rb") > rdr = csv.reader(fin, dialect="excel-tab") > for rw in rdr: > ? ? print rw > > fin.close() > del rdr > os.remove(TESTFILE) > -=-=-=-=-=-=- > ['a', 'b', 'c'] > ['d', 'e', 'f', 'g'] > ['h', 'i', 'j', 'A'] > -- > ? ? ? ? Wulfraed ? ? ? ? ? ? ? ? Dennis Lee Bieber ? ? ? ? AF6VN > ? ? ? ? wlfr... at ix.netcom.com ? ?HTTP://wlfraed.home.netcom.com/ From saqib.ali.75 at gmail.com Sun Jan 15 19:14:26 2012 From: saqib.ali.75 at gmail.com (Saqib Ali) Date: Sun, 15 Jan 2012 16:14:26 -0800 (PST) Subject: Problem while doing a cat on a tabbed file with pexpect References: <4f135b65$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: The file me.txt does indeed contain tabs. I created it with vi. >>> text = open("me.txt", "r").read() >>> print "\t" in text True % od -c me.txt 0000000 A \t B \t C \n 0000006 % ls -al me.txt -rw-r--r-- 1 myUser myGroup 6 Jan 15 12:42 me.txt On Jan 15, 6:40?pm, Cameron Simpson wrote: > On 15Jan2012 23:04, Steven D'Aprano wrote: > | On Sun, 15 Jan 2012 09:51:44 -0800, Saqib Ali wrote: > | > I am using Solaris 10, python 2.6.2, pexpect 2.4 > | > > | > I create a file called me.txt which contains the letters "A", "B", "C" > | > on the same line separated by tabs. > | [...] > | > Now, clearly the file contains tabs. > | > | That is not clear at all. How do you know it contains tabs? How was the > | file created in the first place? > | > | Try this: > | > | text = open('me.txt', 'r').read() > | print '\t' in text > | > | My guess is that it will print False and that the file does not contain > | tabs. Check your editor used to create the file. > > I was going to post an alternative theory but on more thought I think > Steven is right here. > > What does: > > ? od -c me.txt > > show you? TABs or multiple spaces? > > What does: > > ? ls -ld me.txt > > tell you about the file size? Is it 6 bytes long (three letters, two > TABs, one newline)? > > Steven hasn't been explicit about it, but some editors will write spaces when > you type a TAB. I have configured mine to do so - it makes indentation more > reliable for others. If I really need a TAB character I have a special > finger contortion to get one, but the actual need is rare. > > So first check that the file really does contain TABs. > > Cheers, > -- > Cameron Simpson DoD#743http://www.cskk.ezoshosting.com/cs/ > > Yes Officer, yes Officer, I will Officer. Thank you. From vinay_sajip at yahoo.co.uk Sun Jan 15 20:03:08 2012 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sun, 15 Jan 2012 17:03:08 -0800 (PST) Subject: Two questions about logging References: <7dabf43f-3814-47b6-966a-1439f56548b5@i6g2000vbk.googlegroups.com> Message-ID: On Jan 12, 2:19?am, Matthew Pounsett wrote: > First, I'd like to be able to permit users to do more typical log > rotation, based on their OS's log rotation handler, rather than > rotating logs from inside an application. ?This is usually handled by > signalling an application with a HUP, whereupon it closes and then re- > opens all of its logs, getting new file handles (and new inodes). ?I > don't see anything in the Handler methods (or anywhere else) that > would let me tell a logger object to refresh the file handles on a log > file. ?Is there some standard way to deal with this? There's the WatchedFileHandler, which checks to see if a file's device or inode has changed (which happens when the external rotator does rotation) and if so, closes and reopens the file. (This handler is for Unix/Linux/OS X - it doesn't work on Windows). See http://docs.python.org/library/logging.handlers.html#watchedfilehandler for more information. Regards, Vinay Sajip From cs at zip.com.au Sun Jan 15 20:45:35 2012 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 16 Jan 2012 12:45:35 +1100 Subject: Problem while doing a cat on a tabbed file with pexpect In-Reply-To: References: Message-ID: <20120116014535.GA12750@cskk.homeip.net> On 15Jan2012 16:14, Saqib Ali wrote: | The file me.txt does indeed contain tabs. I created it with vi. | | >>> text = open("me.txt", "r").read() | >>> print "\t" in text | True | | % od -c me.txt | 0000000 A \t B \t C \n | 0000006 | | % ls -al me.txt | -rw-r--r-- 1 myUser myGroup 6 Jan 15 12:42 me.txt Ok, your file does indeed contain TABs. Therefre something is turning the TABs into spaces. Pexpect should be opening a pty and reading from that, and I do not expect that to expand TABs. So: 1: Using subprocess.Popen, invoke "cat me.txt" and check the result for TABs. 2: Using pexpect, run "cat me.txt" instead of "/bin/tcsh" (eliminates a layer of complexity; I don't actually expect changed behaviour) and check for TABs. On your Solaris system, read "man termios". Does it have an "expand TABs" mode switch? This is about the only thing I can think of that would produce your result - the pty terminal discipline is expanding TABs for your (unwanted!) - cat is writing TABs to the terminal and the terminal is passing expanded spaces to pexpect. Certainly terminal line disciplines do rewrite stuff, most obviously "\n" into "\r\n", but a quick glance through termios on a Linux box does not show a tab expansion mode; I do not have access to a Solaris box at present. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Maintainer's Motto: If we can't fix it, it ain't broke. From steve+comp.lang.python at pearwood.info Sun Jan 15 21:01:35 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Jan 2012 02:01:35 GMT Subject: Problem while doing a cat on a tabbed file with pexpect References: Message-ID: <4f1384ff$0$29881$c3e8da3$5496439d@news.astraweb.com> On Sun, 15 Jan 2012 09:51:44 -0800, Saqib Ali wrote: > I am using Solaris 10, python 2.6.2, pexpect 2.4 Are you sure about that? As far as I can see, pexpect's current version is 2.3 not 2.4. > I create a file called me.txt which contains the letters "A", "B", "C" > on the same line separated by tabs. > > My shell prompt is "% " > > I then do the following in the python shell: > > >>>> import pexpect >>>> x = pexpect.spawn("/bin/tcsh") Can you try another shell, just in case tcsh is converting the tabs to spaces? >>>> x.sendline("cat me.txt") > 11 What happens if you do this from the shell directly, without pexpect? It is unlikely, but perhaps the problem lies with cat rather than pexpect. You should eliminate this possibility. >>>> x.expect([pexpect.TIMEOUT, "% "]) > 1 >>>> x.before > 'cat me.txt\r\r\nA B C\r\n' Unfortunately I can't replicate the same behaviour, however my setup is different. I'm using pexpect2.3 on Linux, and I tried it using bash and sh but not tcsh. In all my tests, the tabs were returned as expected. (However, the x.expect call returned 0 instead of 1, even with the shell prompt set correctly.) -- Steven From torriem at gmail.com Sun Jan 15 21:50:46 2012 From: torriem at gmail.com (Michael Torrie) Date: Sun, 15 Jan 2012 19:50:46 -0700 Subject: PyWarts: time, datetime, and calendar modules In-Reply-To: <09e6c247-f3b1-47f2-9b8a-b6de67dc7111@r16g2000yqi.googlegroups.com> References: <15cdd8f1-35ef-43ea-a1c9-db90bc16f4ad@r16g2000yqi.googlegroups.com> <4f1254cb$0$29987$c3e8da3$5496439d@news.astraweb.com> <09e6c247-f3b1-47f2-9b8a-b6de67dc7111@r16g2000yqi.googlegroups.com> Message-ID: <4F139086.9010904@gmail.com> On 01/14/2012 10:27 PM, Rick Johnson wrote: > Face it, Guido has broken Python's cherry. She is no longer pure. > You're acting like some over- protective father. WAKE UP! Python is a > promiscuous little whore and she's on girls gone wild (Volume 4000) > shaking her little money maker. We should at least profit from the > immorality. Hmm, down goes all the credibility you had since your rebirth on this list. Back to the old ways. That said, Rick I think it's time for you to fork python. Your brilliance and foresight put Guido's to shame. No one else has the guts to stand up and say what needs to be said. If you can't fix python, no one can. From torriem at gmail.com Sun Jan 15 22:47:31 2012 From: torriem at gmail.com (Michael Torrie) Date: Sun, 15 Jan 2012 20:47:31 -0700 Subject: Problem while doing a cat on a tabbed file with pexpect In-Reply-To: <4008c5d1-98c5-4796-9e82-0e8835fbe42a@i25g2000vbt.googlegroups.com> References: <4008c5d1-98c5-4796-9e82-0e8835fbe42a@i25g2000vbt.googlegroups.com> Message-ID: <4F139DD3.9000002@gmail.com> On 01/15/2012 05:11 PM, Saqib Ali wrote: > > Very good question. Let me explain why I'm not opening me.txt directly > in python with open. > > The example I have posted is simplified for illustrative purpose. In > reality, I'm not doing pexpect.spawn("/bin/tcsh"). I'm doing > pexpect.spawn("ssh myuser at ipaddress"). Since I'm operating on a remote > system, I can't simply open the file in my own python context. There is a very nice python module called "paramiko" that you could use to, from python, programatically ssh to the remote system and cat the file (bypassing any shells) or use sftp to access it. Either way you don't need to use pexpect with it. From panmik at yandex.ru Mon Jan 16 01:03:54 2012 From: panmik at yandex.ru (_) Date: Mon, 16 Jan 2012 09:03:54 +0300 Subject: THAT WHAT NEED EXPECT FROM OPERATORS OF PYTHON. (e-mail get by the list moderator) Message-ID: <2CF22C818B82497689CEFE0212288055@asus> # THAT WHAT NEED EXPECT FROM OPERATORS OF PYTHON: Worddr = "56" # CREATE A STRING: "56" Word = ["12"] # CREATE A LIST WITH ONE SIGNED: "12" Word = Word.append("34") # APPEND TO LIST ONE MORE SIGNED: "34" Word = Word + "34" # MUST APPEND TO LIST ONE MORE SIGNED: "34" Wordpr = Word[1] # MUST SIGNED TO THE Wordpr THE SECOND SIGNED OF THE Word LIST: "34", AND IT'S ALL PARAMETRS Wordpr = Wordpr + Worddr[1] # MUST ADD TO THE STRING Wordpr: "34", A SECOND SIGNED OF STRING Worddr: "6" Word[1] = Word[1] + Worddr[1] # MUST ADD TO THE SECOND STRING LIST Word: "346", A SECOND SIGNED OF STRING Worddr: "6" -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: CORRECTION.py URL: From wuwei23 at gmail.com Mon Jan 16 01:07:31 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 15 Jan 2012 22:07:31 -0800 (PST) Subject: understanding a program project References: <4f109417$0$1387$4fafbaef@reader1.news.tin.it> Message-ID: On Jan 14, 6:29?am, Tracubik wrote: > I remember at school time there was some schema or something to create to > display the interaction of different functions / modules > > My idea was to create a model with all the methods and arrows to link > they... Do you mean call graphs? http://pycallgraph.slowchop.com/ From wuwei23 at gmail.com Mon Jan 16 01:30:24 2012 From: wuwei23 at gmail.com (alex23) Date: Sun, 15 Jan 2012 22:30:24 -0800 (PST) Subject: THAT WHAT NEED EXPECT FROM OPERATORS OF PYTHON. (e-mail get by the list moderator) References: Message-ID: On Jan 16, 4:03?pm, "_" wrote: > # THAT WHAT NEED EXPECT FROM OPERATORS OF PYTHON: > Word = Word.append("34") # APPEND TO LIST ONE MORE SIGNED: "34" list.append is an in-place operation; it doesn't return a copy of the list, so here you're setting Word to None. From steve+comp.lang.python at pearwood.info Mon Jan 16 02:01:01 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Jan 2012 07:01:01 GMT Subject: THAT WHAT NEED EXPECT FROM OPERATORS OF PYTHON. (e-mail get by the list moderator) References: Message-ID: <4f13cb2d$0$30001$c3e8da3$5496439d@news.astraweb.com> On Mon, 16 Jan 2012 09:03:54 +0300, _ wrote: > # THAT WHAT NEED EXPECT FROM OPERATORS OF PYTHON: Worddr = "56" # CREATE > A STRING: "56" Word = ["12"] # CREATE A LIST WITH ONE SIGNED: "12" Word > = Word.append("34") ... Do you have a question, or are you just dumping a lot of noise in one post? -- Steven From __peter__ at web.de Mon Jan 16 03:18:48 2012 From: __peter__ at web.de (Peter Otten) Date: Mon, 16 Jan 2012 09:18:48 +0100 Subject: Hash stability References: <4f1107b7$0$29988$c3e8da3$5496439d@news.astraweb.com> <4F1205A7.70303@modelnine.org> <4F12BC8A.9040205@modelnine.org> <4F12F9D8.5080904@modelnine.org> Message-ID: Heiko Wundram wrote: > Am 15.01.2012 13:22, schrieb Peter Otten: >> I'm curious: did you actually get false cache hits in a suds cache >> or just slower responses? > It broke the application using suds, not due to false cache hits, but > due to not getting a cache hit anymore at all. > so basically I worked around > the problem by creating an appropriate cache entry with the appropriate > name based on hash() using a local copy of xml.dtd I had around. This > took place on a development machine (32-bit), and when migrating the > application to a production machine (64-bit), the cache file wasn't used > anymore (due to the hash not being stable). Thanks for the explanation. > if the hash() output is changed. Additionally, if hash() isn't stable > between runs (the randomized hash() solution which is preferred, and > would also be my preference), suds caching becomes completely useless. > And for the results, see above. I've taken a quick look into the suds source; the good news is that you have to change a single method, reader.Reader.mangle(), to fix the problem with hash stability. However, I didn't see any code to deal with hash collisions at all. From lists at cheimes.de Mon Jan 16 03:44:05 2012 From: lists at cheimes.de (Christian Heimes) Date: Mon, 16 Jan 2012 09:44:05 +0100 Subject: Hash stability In-Reply-To: References: <4f1107b7$0$29988$c3e8da3$5496439d@news.astraweb.com> <4F1205A7.70303@modelnine.org> <4F12BC8A.9040205@modelnine.org> <4F12F9D8.5080904@modelnine.org> Message-ID: Am 16.01.2012 09:18, schrieb Peter Otten: > I've taken a quick look into the suds source; the good news is that you have > to change a single method, reader.Reader.mangle(), to fix the problem with > hash stability. > > However, I didn't see any code to deal with hash collisions at all. It smells like suds is vulnerable to cache poisoning. From modelnine at modelnine.org Mon Jan 16 04:15:17 2012 From: modelnine at modelnine.org (Heiko Wundram) Date: Mon, 16 Jan 2012 10:15:17 +0100 Subject: Hash stability In-Reply-To: References: <4f1107b7$0$29988$c3e8da3$5496439d@news.astraweb.com> <4F1205A7.70303@modelnine.org> <4F12BC8A.9040205@modelnine.org> <4F12F9D8.5080904@modelnine.org> Message-ID: <4F13EAA5.1010603@modelnine.org> Am 16.01.2012 09:44, schrieb Christian Heimes: > Am 16.01.2012 09:18, schrieb Peter Otten: >> I've taken a quick look into the suds source; the good news is that you have >> to change a single method, reader.Reader.mangle(), to fix the problem with >> hash stability. >> >> However, I didn't see any code to deal with hash collisions at all. > > It smells like suds is vulnerable to cache poisoning. That it is, yes, at least partially. Generally, this is only relevant in case you are actually caching DTDs (which is the default) and in case you are querying untrusted SOAP-servers (in which case you'll most likely/should not use caching anyway), and in case the attacker has control over the URL namespace of a DTD-serving host (because the host-part of the DTD URL is used in the cache filename, unhashed, only the actual path is hashed to form the cache index). The easier way to poison the cache is most probably through actual traffic modification, as most DTD URLs are served through plain http and thus are suspect to MitM-modifications, anyway. -- --- Heiko. From hoogendoorn.eelco at gmail.com Mon Jan 16 05:22:55 2012 From: hoogendoorn.eelco at gmail.com (Eelco) Date: Mon, 16 Jan 2012 02:22:55 -0800 (PST) Subject: NaN, Null, and Sorting References: Message-ID: <67bd5e6b-a332-4d13-aad3-8de88b218ac5@z19g2000vbe.googlegroups.com> On 13 jan, 20:04, Ethan Furman wrote: > With NaN, it is possible to get a list that will not properly sort: > > --> NaN = float('nan') > --> spam = [1, 2, NaN, 3, NaN, 4, 5, 7, NaN] > --> sorted(spam) > [1, 2, nan, 3, nan, 4, 5, 7, nan] > > I'm constructing a Null object with the semantics that if the returned > object is Null, it's actual value is unknown. > > ?From a purist point of view if it is unknown then comparison results > are also unknown since the actual value might be greater, lesser, or the > same as the value being compared against. > > ?From a practical point of view a list with Nulls scattered throughout > is a pain in the backside. > > So I am strongly leaning towards implementing the comparisons such that > Null objects are less than other objects so they will always sort together. > > Thoughts/advice/criticisms/etc? > > ~Ethan~ My suggestion would be thus: nans/nulls are unordered; sorting them is fundamentally an ill defined notion. What you want, conceptually, is a sorted list of the sortable entries, and a seperate list of the unsorted entries. Translated into code, the most pure solution would be to filter out the nanas/nulls in their own list first, and then sort the rest. If the interface demands it, you can concatenate the lists afterwards, but probably it is most convenient to keep them in seperate lists. Perhaps arbitrarily defining the ordering of nulls/nans is slightly more efficient than the above, but it should not make a big difference, and in terms of purity its no contest. From rosuav at gmail.com Mon Jan 16 05:57:59 2012 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 Jan 2012 21:57:59 +1100 Subject: NaN, Null, and Sorting In-Reply-To: <67bd5e6b-a332-4d13-aad3-8de88b218ac5@z19g2000vbe.googlegroups.com> References: <67bd5e6b-a332-4d13-aad3-8de88b218ac5@z19g2000vbe.googlegroups.com> Message-ID: On Mon, Jan 16, 2012 at 9:22 PM, Eelco wrote: > What you want, conceptually, is a > sorted list of the sortable entries, and a seperate list of the > unsorted entries. Translated into code, the most pure solution would > be to filter out the nanas/nulls in their own list first, and then > sort the rest. If the interface demands it, you can concatenate the > lists afterwards, but probably it is most convenient to keep them in > seperate lists. So... you split it into two lists, sort the two lists (one of which can't be sorted), and then concatenate them. Sounds like the quicksort algorithm. ChrisA From robert.kern at gmail.com Mon Jan 16 06:07:26 2012 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 16 Jan 2012 11:07:26 +0000 Subject: NaN, Null, and Sorting In-Reply-To: References: <67bd5e6b-a332-4d13-aad3-8de88b218ac5@z19g2000vbe.googlegroups.com> Message-ID: On 1/16/12 10:57 AM, Chris Angelico wrote: > On Mon, Jan 16, 2012 at 9:22 PM, Eelco wrote: >> What you want, conceptually, is a >> sorted list of the sortable entries, and a seperate list of the >> unsorted entries. Translated into code, the most pure solution would >> be to filter out the nanas/nulls in their own list first, and then >> sort the rest. If the interface demands it, you can concatenate the >> lists afterwards, but probably it is most convenient to keep them in >> seperate lists. > > So... you split it into two lists, sort the two lists (one of which > can't be sorted), and then concatenate them. Sounds like the quicksort > algorithm. Not at all. The "split it into two lists" steps are entirely different in what Eelco suggested and quicksort. It's misleading to attempt to describe both using the same words. -- 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 franciszhu1990 at hotmail.com Mon Jan 16 07:41:03 2012 From: franciszhu1990 at hotmail.com (Francesco Zhu) Date: Mon, 16 Jan 2012 13:41:03 +0100 Subject: Deleted System default Python on Leopard Message-ID: Hello everyone, recently I've started to be try Python on my Mac OS X 10.5.8 Leopard and I've already messed up with it... I was compiling a Python souce code but didn't succeed and so I decided to install a newer version of Python. But before that, I did a stupid thing: I deleted manually all the folders of the Leopard's system default Python 2.5.1... Before when I was using the system Python, the program namebench worked perfectly. After that I messed everything up and installed MacPython 2.5 from the site python.org, now namebench always crashes. On the problem report system of Apple it gives me these errors: http://bpaste.net/show/21904/ While this is the Console: http://bpaste.net/show/21905/ What problem can it be? Can I clean up all the Pythons and restore the system one? Thanks everyone. Regards, Francesco Zhu -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris at simplistix.co.uk Mon Jan 16 08:10:27 2012 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 16 Jan 2012 13:10:27 +0000 Subject: python loggingL filter limitation, looks intentional? Message-ID: <4F1421C3.6060806@simplistix.co.uk> Hi Vinay, It looks like this was intentional, so why was it decided that filters would only be passed messages logged to the logger they're attached to rather than the all messages that end up getting passed to logger? For example, an app and the libraries it uses log to 'some.db.driver', 'some.lib' and 'myapp'. The root logger has a number of handlers attached to it. I want to write a filter that adjusts, up or down, the level of certain messages logged based on a regex match of their message. If I understand correctly, I have to add my filter to all of the loggers above, rather than just the root logger where my handlers live? Or, alternatively, add the filter to all of the root handlers, thereby making the configuration of those handlers and/or more dependent on each other. Why is that? cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From vinay_sajip at yahoo.co.uk Mon Jan 16 10:08:25 2012 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Mon, 16 Jan 2012 15:08:25 +0000 (GMT) Subject: python loggingL filter limitation, looks intentional? In-Reply-To: <4F1421C3.6060806@simplistix.co.uk> References: <4F1421C3.6060806@simplistix.co.uk> Message-ID: <1326726505.66259.YahooMailNeo@web25803.mail.ukl.yahoo.com> Hi Chris, Filtering is intended to be for cases where integer level-based filtering is insufficient; hence it applies to individual loggers and handlers, just as the integer levels do.? You are right that you would need to add a filter to all of the loggers where you want it to apply, or to all of the handlers where you want it to apply. However, if you find your usage pattern occurring very commonly in your applications, it's easy enough to create a DelegatingHandler handler class which passes its events on to any number of handlers you like. You can then apply the filter you want to an instance of this handler, which you attach to your root logger. Regards, Vinay Sajip ----- Original Message ----- > From: Chris Withers > To: Vinay Sajip > Cc: Python List > Sent: Monday, 16 January 2012, 13:10 > Subject: python loggingL filter limitation, looks intentional? > > Hi Vinay, > > It looks like this was intentional, so why was it decided that filters would > only be passed messages logged to the logger they're attached to rather than > the all messages that end up getting passed to logger? > > For example, an app and the libraries it uses log to 'some.db.driver', > 'some.lib' and 'myapp'. > > The root logger has a number of handlers attached to it. > > I want to write a filter that adjusts, up or down, the level of certain messages > logged based on a regex match of their message. > > If I understand correctly, I have to add my filter to all of the loggers above, > rather than just the root logger where my handlers live? > > Or, alternatively, add the filter to all of the root handlers, thereby making > the configuration of those handlers and/or more dependent on each other. > > Why is that? > > cheers, > > Chris > > -- Simplistix - Content Management, Batch Processing & Python Consulting > ? ? ? ? ? ? - http://www.simplistix.co.uk > From deathweasel at gmail.com Mon Jan 16 10:10:20 2012 From: deathweasel at gmail.com (deathweaselx86) Date: Mon, 16 Jan 2012 07:10:20 -0800 (PST) Subject: Decorated class question Message-ID: <624456cd-d4f7-46ab-98e5-f2d30feab13d@34g2000yqm.googlegroups.com> Pardon me if this is a silly question. If I decorate a class, then subclass it, does my subclass feature whatever the decorator did to my superclass? Thanks in advance. From benjamin.kaplan at case.edu Mon Jan 16 11:03:02 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 16 Jan 2012 11:03:02 -0500 Subject: Deleted System default Python on Leopard In-Reply-To: References: Message-ID: On Mon, Jan 16, 2012 at 7:41 AM, Francesco Zhu wrote: > Hello everyone, > > recently I've started to be try Python on my Mac OS X 10.5.8 Leopard and > I've already messed up with it... > > I was compiling a Python souce code but didn't succeed and so I decided to > install a newer version of Python. > But before that, I did a stupid thing: I deleted manually all the folders of > the Leopard's system default Python 2.5.1... > > Before when I was using the system Python, the program namebench worked > perfectly. > After that I messed everything up and installed MacPython 2.5 from the site > python.org, now namebench always crashes. > > On the problem report system of Apple it gives me these errors: > http://bpaste.net/show/21904/ > > While this is the Console: > http://bpaste.net/show/21905/ > > What problem can it be? > Can I clean up all the Pythons and restore the system one? > > Thanks everyone. > > Regards, > Francesco Zhu For compatibility reasons, a lot of programs specify the system Python: either /usr/bin/python for the executable or /System/Library/Frameworks/Python.Framework/Versions/2.5/python for the library. If they didn't and you (for example) installed 3.2 and set it as the default Python, everything would break. You could download the Apple's Python 2.5.1 from http://opensource.apple.com/source/python/python-30.1.3/, apply the patches, and attempt to put everything back the way you found it but it's probably easiest just to reinstall Leopard from the DVD. It shouldn't wipe anything but I would suggest backing up just in case. From jeanpierreda at gmail.com Mon Jan 16 11:18:51 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Mon, 16 Jan 2012 11:18:51 -0500 Subject: Decorated class question In-Reply-To: <624456cd-d4f7-46ab-98e5-f2d30feab13d@34g2000yqm.googlegroups.com> References: <624456cd-d4f7-46ab-98e5-f2d30feab13d@34g2000yqm.googlegroups.com> Message-ID: On Mon, Jan 16, 2012 at 10:10 AM, deathweaselx86 wrote: > If I decorate a class, then subclass it, does my subclass feature > whatever the decorator did to my superclass? Yes. The following two things are completely equivalent: @foo class Bar(...): ... # and class Bar(...) ... # immediately afterward Bar = foo(Bar) -- Devin From ian.g.kelly at gmail.com Mon Jan 16 11:30:53 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 16 Jan 2012 09:30:53 -0700 Subject: Decorated class question In-Reply-To: <624456cd-d4f7-46ab-98e5-f2d30feab13d@34g2000yqm.googlegroups.com> References: <624456cd-d4f7-46ab-98e5-f2d30feab13d@34g2000yqm.googlegroups.com> Message-ID: On Mon, Jan 16, 2012 at 8:10 AM, deathweaselx86 wrote: > Pardon me if this is a silly question. > > If I decorate a class, then subclass it, does my subclass feature > whatever the decorator did to my superclass? That depends on what the decorator did. Changes made directly to the class itself, such as items added to the class dict, will be inherited. Other operations performed, such as registering the class with a framework of some sort, are not inherited and would need the decorator to be applied to the subclass as well. Cheers, Ian From nathan.alexander.rice at gmail.com Mon Jan 16 12:31:06 2012 From: nathan.alexander.rice at gmail.com (Nathan Rice) Date: Mon, 16 Jan 2012 12:31:06 -0500 Subject: Elementwise 0.120116 -//- beta release -//- Lazily compute functions, method calls and operations on all elements of an iterable (or graph). Message-ID: Elementwise provides helpful proxy objects which let you perform a series of computations on every element of an iterable or graph, in a lazy manner. Docs: http://packages.python.org/elementwise/ GitHub: https://github.com/nathan-rice/Elementwise Examples: The standard ElementwiseProxy: >>> nums = ElementwiseProxy([1, 2, 3, 4) >>> print nums.bit_length() 1, 2, 2, 3 >>> nums + 1 2, 3, 4, 5 >>> print nums * 2 2, 4, 6, 8 >>> print nums == 2 False, True, False, False >>> print ((nums + 1) * 2 + 3).apply(float) 7.0, 9.0, 11.0, 13.0 >>> print (nums.apply(float) + 0.0001).apply(round, 2) 1.0, 2.0, 3.0, 4.0 >>> print abs(nums - 3) 2, 1, 0, 1 >>> print (nums * 2 + 3) / 4 >>> print efoo2.undo(3) 1, 2, 3, 4 >>> print ((nums * 2 + 3) / 4).replicate([2, 2, 3, 3]) 1, 1, 2, 2 >>> words = ElementwiseProxy(["one", "two", "three", "four"]) >>> print (words + " little indians").upper().split(" ").apply(reversed).apply("_".join) * 2 'INDIANS_LITTLE_ONEINDIANS_LITTLE_ONE', 'INDIANS_LITTLE_TWOINDIANS_LITTLE_TWO', 'INDIANS_LITTLE_THREEINDIANS_LITTLE_THREE', 'INDIANS_LITTLE_FOURINDIANS_LITTLE_FOUR' The PairwiseProxy: >>> nums = PairwiseProxy([1, 2, 3, 4]) >>> nums + [1, 2, 3, 4] 2, 4, 6, 8 >>> nums * [2, 2, 3, 3] 2, 4, 9, 12 >>> nums == [2, 2, 3, 5] False, True, True, False >>> (nums.apply(float) / itertools.count(2) + itertools.count(1)).apply(round, args=itertools.repeat([2])) 1.5, 2.67, 3.75, 4.8 >>> abs(nums - [3, 2, 1, 1]) 2, 0, 2, 3 >>> (nums * [2, 2, 1, 5] + [3, 5, 9, 0]) / [4, 1, 2, 3] 1, 9, 6, 6 >>> ((nums * itertools.repeat(2) + itertools.repeat(3)) / itertools.repeat(4)).replicate([2, 2, 3, 3]) 1, 0, 0, 0 >>> ((nums * [2, 3, 4, 5]) > [5, 6, 7, 8]) != [True, True, False, True] True, True, True, False The RecursiveElementwiseProxy: >>> treenums = RecursiveElementwiseProxy([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) >>> treenums + 1 ((2, 3, 4), (5, 6, 7), (8, 9, 10)) >>> treenums * 2 ((2, 4, 6), (8, 10, 12), (14, 16, 18)) >>> (treenums * 2 + 1).apply(float) ((3.0, 5.0, 7.0), (9.0, 11.0, 13.0), (15.0, 17.0, 19.0)) Feedback is welcome. From chris at simplistix.co.uk Mon Jan 16 13:39:57 2012 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 16 Jan 2012 18:39:57 +0000 Subject: python loggingL filter limitation, looks intentional? In-Reply-To: <1326726505.66259.YahooMailNeo@web25803.mail.ukl.yahoo.com> References: <4F1421C3.6060806@simplistix.co.uk> <1326726505.66259.YahooMailNeo@web25803.mail.ukl.yahoo.com> Message-ID: <4F146EFD.8090102@simplistix.co.uk> Hi Vinay, On 16/01/2012 15:08, Vinay Sajip wrote: > Filtering is intended to be for cases where integer level-based filtering is insufficient; ...or where you want to manipulate log messages, which is the use case I have. > You are right that you would need to add a filter to all of the loggers where you want it to apply, or to all of the handlers where you want it to apply. Why is this? There must be some rationale for this rather than what, for me and others I've talked to, would seem more natural, ie: a filter on the root logger would get messages both logged to it and any messages propagated to it from child loggers to process. > However, if you find your usage pattern occurring very commonly in your applications, it's easy enough to create a DelegatingHandler handler class which passes its events on to any number of handlers you like. But this is just extra work when the normal built-in delegation-upwards-ending-in-root works exactly as I want. It's also the opposite of what I'd need, I'd need to plug one handler into all the specific loggers that get used (and bear in mind that many libraries log to __name__ from modules and sub-modules) this is a pretty onerous task :-( cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From vinay_sajip at yahoo.co.uk Mon Jan 16 18:21:55 2012 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Mon, 16 Jan 2012 23:21:55 +0000 (GMT) Subject: python loggingL filter limitation, looks intentional? In-Reply-To: <4F146EFD.8090102@simplistix.co.uk> References: <4F1421C3.6060806@simplistix.co.uk> <1326726505.66259.YahooMailNeo@web25803.mail.ukl.yahoo.com> <4F146EFD.8090102@simplistix.co.uk> Message-ID: <1326756115.24713.YahooMailNeo@web25806.mail.ukl.yahoo.com> > Why is this? There must be some rationale for this rather than what, for me and > others I've talked to, would seem more natural, ie: a filter on the root > logger would get messages both logged to it and any messages propagated to it > from child loggers to process. Perhaps you're right, but this can't be changed without breaking existing code, AFAICT. This hasn't come up before, so I'm not sure to what extent this is just a matter of taste. >> However, if you find your usage pattern occurring very commonly in your > applications, it's easy enough to create a DelegatingHandler handler class > which passes its events on to any number of handlers you like. ? > But this is just extra work when the normal built-in > delegation-upwards-ending-in-root works exactly as I want. It's not in general useful to filter on message content, when one factors in use of third-party libraries. Of course, if you are in control in the whole software stack you're using, or in certain very specific scenarios, it may be more useful - but in general it's most useful to filter on level and using logger names. The __name__ for loggers is useful to locate the source of events to a module, but you can have child loggers under that to log specific types of events in that module, and use the verbosity of those sub-module loggers to control output. Of course I don't know the precise reason you need things to work this way, so my suggestions and comments might appear somewhat general. > It's also the opposite of what I'd need, I'd need to plug one > handler into all the specific loggers that get used (and bear in mind that many > libraries log to __name__ from modules and sub-modules) this is a pretty onerous > task :-( I thought from an earlier comment - "rather than just the root logger where my handlers live" - that you had your handlers attached to the root logger, in which case it wouldn't be onerous at all. In place of those individual handlers attached to the root, you simply attach your DelegatingHandler to the root logger, and attach the filter and the other handlers to that DelegatingHandler instance. Regards, Vinay Sajip From vinay_sajip at yahoo.co.uk Mon Jan 16 18:56:45 2012 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Mon, 16 Jan 2012 15:56:45 -0800 (PST) Subject: python loggingL filter limitation, looks intentional? References: <4F1421C3.6060806@simplistix.co.uk> <1326726505.66259.YahooMailNeo@web25803.mail.ukl.yahoo.com> <4F146EFD.8090102@simplistix.co.uk> Message-ID: <882b16fb-2ab9-4e3a-8064-b435c300cc35@s18g2000vby.googlegroups.com> On Jan 16, 11:21?pm, Vinay Sajip wrote: > > I thought from an earlier comment - "rather than just the root logger where my handlers live" - that you had your handlers attached to the root logger, in which case it wouldn't be onerous at all. In place of those individual handlers attached to the root, you simply attach your DelegatingHandler to the root logger, and attach the filter and the other handlers to that DelegatingHandler instance. An example of using a delegating handler: https://gist.github.com/1623702 Regards, Vinay Sajip From saul.spatz at gmail.com Mon Jan 16 19:18:22 2012 From: saul.spatz at gmail.com (Saul Spatz) Date: Mon, 16 Jan 2012 16:18:22 -0800 (PST) Subject: pymysql only works under IDLE Message-ID: <11576187.1088.1326759502632.JavaMail.geo-discussion-forums@vbwl1> I've been using pymysql to connect to a database, and it has suddenly stopped working on the one machine (a virtual server) where I really need it to work. I have a function with hard-coded parameters to do the connection, and now I'm getting an error that says, "Can't connect to MySQL server on ...". The strangest thing is that while I can't connect if I run the script from the command line, or from the shell under Wing IDE, I can connect if I run the script under the IDLE shell. I noticed that the command line shell prints Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. at startup, but the IDLE shell prints Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. So, while the first lines are identical, the second lines are different. Is this a different interpreter then? Can anyone tell me what the difference is? I'm hoping that may help me figure out what's gone wrong. I'm running on Windows 7. I'll be grateful for any help you can give me. Saul From clp2 at rebertia.com Mon Jan 16 20:11:09 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 16 Jan 2012 17:11:09 -0800 Subject: pymysql only works under IDLE In-Reply-To: <11576187.1088.1326759502632.JavaMail.geo-discussion-forums@vbwl1> References: <11576187.1088.1326759502632.JavaMail.geo-discussion-forums@vbwl1> Message-ID: On Mon, Jan 16, 2012 at 4:18 PM, Saul Spatz wrote: > I've been using pymysql to connect to a database, and it has suddenly stopped working on the one machine (a virtual server) where I really need it to work. ?I have a function with hard-coded parameters to do the connection, and now I'm getting an error that says, "Can't connect to MySQL server on ...". ?The strangest thing is that while I can't connect if I run the script from the command line, or from the shell under Wing IDE, I can connect if I run the script under the IDLE shell. > > I noticed that the command line shell prints > > Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > > at startup, but the IDLE shell prints > > Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win32 > Type "copyright", "credits" or "license()" for more information. > > So, while the first lines are identical, the second lines are different. ?Is this a different interpreter then? ?Can anyone tell me what the difference is? ?I'm hoping that may help me figure out what's gone wrong. You can check the value of `sys.executable` in each to see whether they're the same, and if not, where the other one is from. Cheers, Chris -- http://rebertia.com From saul.spatz at gmail.com Mon Jan 16 22:25:36 2012 From: saul.spatz at gmail.com (Saul Spatz) Date: Mon, 16 Jan 2012 19:25:36 -0800 (PST) Subject: pymysql only works under IDLE In-Reply-To: References: <11576187.1088.1326759502632.JavaMail.geo-discussion-forums@vbwl1> Message-ID: <21298399.2044.1326770736045.JavaMail.geo-discussion-forums@yqhh6> Thanks a lot; I didn't know about sys.executable. For the record, IDLE is running pythonw.exe. I won't have a chance to test if this helps till tomorrow, unfortunately. From saul.spatz at gmail.com Mon Jan 16 22:25:36 2012 From: saul.spatz at gmail.com (Saul Spatz) Date: Mon, 16 Jan 2012 19:25:36 -0800 (PST) Subject: pymysql only works under IDLE In-Reply-To: References: <11576187.1088.1326759502632.JavaMail.geo-discussion-forums@vbwl1> Message-ID: <21298399.2044.1326770736045.JavaMail.geo-discussion-forums@yqhh6> Thanks a lot; I didn't know about sys.executable. For the record, IDLE is running pythonw.exe. I won't have a chance to test if this helps till tomorrow, unfortunately. From chris at simplistix.co.uk Tue Jan 17 01:07:19 2012 From: chris at simplistix.co.uk (Chris Withers) Date: Tue, 17 Jan 2012 06:07:19 +0000 Subject: python logging filter limitation, looks intentional? In-Reply-To: <1326756115.24713.YahooMailNeo@web25806.mail.ukl.yahoo.com> References: <4F1421C3.6060806@simplistix.co.uk> <1326726505.66259.YahooMailNeo@web25803.mail.ukl.yahoo.com> <4F146EFD.8090102@simplistix.co.uk> <1326756115.24713.YahooMailNeo@web25806.mail.ukl.yahoo.com> Message-ID: <4F151017.6020201@simplistix.co.uk> On 16/01/2012 23:21, Vinay Sajip wrote: > >> Why is this? There must be some rationale for this rather than what, for me and > >> others I've talked to, would seem more natural, ie: a filter on the root >> logger would get messages both logged to it and any messages propagated to it >> from child loggers to process. > > Perhaps you're right, but this can't be changed without breaking existing code, AFAICT. How breaking code? Configuration, maybe, but I can't see anyone being upset that filtering would begin working "the same as everything else". This just feels like a bug... >>> However, if you find your usage pattern occurring very commonly in your >> applications, it's easy enough to create a DelegatingHandler handler class >> which passes its events on to any number of handlers you like. > >> But this is just extra work when the normal built-in >> delegation-upwards-ending-in-root works exactly as I want. > > It's not in general useful to filter on message content, when one factors in use of third-party libraries. Actually, the filter I want to work on (log_nerf) is precisely for 3rd party libraries; if a library author thinks a message should be error but you think it should be debug, and vice versa, having a filter that alters the level is the only way to sort things out without hacking the 3rd party library. I've also seen this technique used successfully where the filter looks to a database for config and nerfs messages during a certain time period. > Of course, if you are in control in the whole software stack you're using, or in certain very specific scenarios, it may be more useful - but in general it's most useful to filter on level and using logger names. The __name__ for loggers is useful to locate the source of events to a module, but you can have child loggers under that to log specific types of events in that module, and use the verbosity of those sub-module loggers to control output. Again, this doesn't help if the __name__-ish loggers are in third party packages that you don't want to have to fork ;-) >> It's also the opposite of what I'd need, I'd need to plug one >> handler into all the specific loggers that get used (and bear in mind that many >> libraries log to __name__ from modules and sub-modules) this is a pretty onerous >> task :-( > > I thought from an earlier comment - "rather than just the root logger where my handlers live" - that you had your handlers attached to the root logger, in which case it wouldn't be onerous at all. In place of those individual handlers attached to the root, you simply attach your DelegatingHandler to the root logger, and attach the filter and the other handlers to that DelegatingHandler instance. Both use cases are valid, and a DelegatingHandler just feels like a hack to work around a deficiency in the framework... cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From contact at xavierho.com Tue Jan 17 01:47:39 2012 From: contact at xavierho.com (Xavier Ho) Date: Tue, 17 Jan 2012 16:47:39 +1000 Subject: Comparing None and ints Message-ID: Hello, I discovered this strange property by accident: Python 2.7.2 (default, Nov 21 2011, 17:25:27) [GCC 4.6.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> None < 0 True >>> None == 0 False >>> None > 0 False >>> int(None) Traceback (most recent call last): File "", line 1, in TypeError: int() argument must be a string or a number, not 'NoneType' What was the rationale behind this design? Specifically, (None < 0) == Trueand(None == 0) == False ? Personally I would have expected an exception on all tests above. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Jan 17 01:50:43 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Jan 2012 17:50:43 +1100 Subject: Comparing None and ints In-Reply-To: References: Message-ID: On Tue, Jan 17, 2012 at 5:47 PM, Xavier Ho wrote: > What was the rationale behind this design? ?Specifically, (None < 0) == True > and (None == 0) == False? > > Personally I would have expected an exception on all tests above. Compare with Python 3: >>> None<0 Traceback (most recent call last): File "", line 1, in None<0 TypeError: unorderable types: NoneType() < int() ChrisA From contact at xavierho.com Tue Jan 17 01:55:06 2012 From: contact at xavierho.com (Xavier Ho) Date: Tue, 17 Jan 2012 16:55:06 +1000 Subject: Comparing None and ints In-Reply-To: References: Message-ID: Good to see Python3 got rid of that confusion :] Cheers, Xav On 17 January 2012 16:50, Chris Angelico wrote: > On Tue, Jan 17, 2012 at 5:47 PM, Xavier Ho wrote: > > What was the rationale behind this design? Specifically, (None < 0) == > True > > and (None == 0) == False? > > > > Personally I would have expected an exception on all tests above. > > Compare with Python 3: > > >>> None<0 > Traceback (most recent call last): > File "", line 1, in > None<0 > TypeError: unorderable types: NoneType() < int() > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Jan 17 01:57:12 2012 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Jan 2012 17:57:12 +1100 Subject: Comparing None and ints In-Reply-To: References: Message-ID: On Tue, Jan 17, 2012 at 5:55 PM, Xavier Ho wrote: > Good to see Python3 got rid of that confusion :] Yep. Obviously you can still test for equality (they're not equal, of course), but now they're non-ordered. ChrisA From vinay_sajip at yahoo.co.uk Tue Jan 17 05:48:22 2012 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Tue, 17 Jan 2012 10:48:22 +0000 (GMT) Subject: python logging filter limitation, looks intentional? In-Reply-To: <4F151017.6020201@simplistix.co.uk> References: <4F1421C3.6060806@simplistix.co.uk> <1326726505.66259.YahooMailNeo@web25803.mail.ukl.yahoo.com> <4F146EFD.8090102@simplistix.co.uk> <1326756115.24713.YahooMailNeo@web25806.mail.ukl.yahoo.com> <4F151017.6020201@simplistix.co.uk> Message-ID: <1326797302.16852.YahooMailNeo@web25806.mail.ukl.yahoo.com> > From: Chris Withers > How breaking code? Configuration, maybe, but I can't see anyone being upset > that filtering would begin working "the same as everything else". > This just feels like a bug... Well, it means that filters that don't get called now would get called - and that's a change in behaviour. It's not a bug, because it's like that by design. I understand that you don't agree with that particular design decision, but it's out there now. What you're asking for isn't unreasonable, but not achievable without a change in behaviour. I don't want people to have to code differently for Python 3.3 and for older versions. ? > Actually, the filter I want to work on (log_nerf) is precisely for 3rd party > libraries; if a library author thinks a message should be error but you think it > should be debug, and vice versa, having a filter that alters the level is the > only way to sort things out without hacking the 3rd party library. I've also > seen this technique used successfully where the filter looks to a database for > config and nerfs messages during a certain time period. Okay,? then applying a filter on handlers is a way of achieving this. > Again, this doesn't help if the __name__-ish loggers are in third party > packages that you don't want to have to fork ;-) True, but as I said earlier, you can attach a filter to your handlers. It's rather unlikely that you would have more than half-a-dozen handlers (since handlers ~= potential audiences for log events), but even so, I can't believe it's especially onerous to set up filter configuration for those handlers - and even easier if you add a DelegatingHandler to the mix. In https://gist.github.com/1623702 I've shown a DelegatingHandler; it's quite short. ? > Both use cases are valid, and a DelegatingHandler just feels like a hack to work > around a deficiency in the framework... Rather, the approach I've taken is not to assume I'll meet everyone's needs out of the box, but that the right pieces are in place for people to use logging in useful ways in scenarios that I haven't thought of - which shortcomings might well be termed "deficiencies" according to your point of view - by deriving and overriding classes, or by composing using filters, or setting module-level flags. There are numerous examples on e.g. Stack Overflow where a small amount of customisation (e.g. a custom handler like DelegatingHandler) has been suggested to meet a specific user requirement. I don't think of these as hacks - I occasionally have to subclass stdlib classes in other areas to get the behaviour I want, and that's part and parcel of having OO at your disposal. Regards, Vinay Sajip From bv5bv5bv5 at yahoo.com Tue Jan 17 08:51:48 2012 From: bv5bv5bv5 at yahoo.com (BV) Date: Tue, 17 Jan 2012 05:51:48 -0800 (PST) Subject: THE DESCRIPTION OF THE BARRIER BETWEEN TWO SEAS !!!!!!!!!!!!!!! Message-ID: THE DESCRIPTION OF THE BARRIER BETWEEN TWO SEAS Sorry for not sending anything related to this group but it might be something new to you Oceanographers, in the wake of the scientific progress in this age, have discovered the barrier between two seas. They have found that a barrier separates two neighboring seas. The barrier moves between them, and it is called by scientists ?a front? compared to the front between two armies. By virtue of this barrier each sea retains its own characteristics which Allah (SWT) has assigned to it and which are suitable for the organisms living in that environment. Because of this barrier, the two neighboring seas mingle so slowly that the amount of water that passes from one sea to the other acquires the characteristics of the other sea while crossing the barrier which overturns the waters crossing from one sea to the other, keeping each sea with its own characteristics. The gradual progress of human knowledge about the fact of the differences between seawater masses and the existence of barriers between them : Oceanographers discovered that there were certain differences between water samples taken from various seas in 1284 AH/ 1873 AD, by the British Marine Scientific Expedition of the Challenger Voyage. It was discovered that masses of sea water vary in their composition, in respect of salinity, water temperature, density and types of marine organisms. The data were obtained from 362 oceanographic stations. The report of the expedition filled 29,500 pages in 50 volumes and took 23 years to complete. One of the great achievements of scientific exploration, the expedition also showed how little man knew about the sea. After 1933 AD another American expedition set out in the Mexican Gulf and installed hundreds of sea stations to study the characteristics of seas. It found out that a large number of stations in a certain area gave similar information about the characteristics of the water in that area, whether in respect of salinity, density, temperature, marine organisms or solubility of oxygen in water, while another group of stations in another area gave a different set of data about that area. So, oceanographers concluded that there were two distinctive seas with different characteristics, and not just limited samples as the Expedition of Challenger showed. Man installed hundreds of marine stations to study the characteristics of various seas. Scientists have found out that the differences in these characteristics distinguished one sea from another. But why do these seas not mix and become homogeneous in spite of the effect of tide and ebb that moves sea water twice a day, and causes seas to move forward and backward turbulently, besides other factors that cause sea water to be in continuous movement and turbulence, such as surface and internal waves and sea currents? The answer appeared for the first time in scientific books in 1361 AH/1942 AD. Extensive studies of marine characteristics revealed that there are water barriers separating neighboring seas and maintaining the distinctive properties of each sea with respect to density, salinity, marine life, temperature and solubility of oxygen in water. There are large waves, strong currents, and tides in the Mediterranean Sea and the Atlantic Ocean. Mediterranean Sea water enters the Atlantic by Gibraltar. But their temperature, salinity, and densities do not change, because of the barrier that separates them. After 1962 AD there was known the role of sea barriers in modifying the properties of the water masses that pass from one sea to another, to prevent one sea from overwhelming the other. So salty seas retain their own properties and boundaries by virtue of these barriers. A field study comparing the waters of Oman Gulf and those of the Arabian Gulf has shown the difference between them regarding their chemical properties, the prevalent vegetation and the barrier separating them. About a hundred years of research and study has been required to discover the fact of the existence of barriers between sea water masses and their role in making each sea retain its own properties. Hundred of researchers took part and numerous precise scientific instruments and equipment were used to achieve that. Fourteen centuries ago the Holy Qur?an revealed this fact. Allah (SWT) says: (He has let free (MARAJA) the two sees meeting together. Between them is a barrier that they do not transgress. Then which of the Blessings of your Lord will you both (Jinn and men) deny? Out of them both come out pearls and carol.? (LV: 19-22) Allah (SWT) also says: ?And He made a barrier between the two seas.) (XXVII: 61) Linguistic meanings and the commentators? sayings: Maraja (let free): IbnFaris said: ??maraja?: The consonants m, r and j form a root indicating a movement of going and coming and turbulence.? Al-Bahrayn (the two seas): Al- Asfahani said: ?Some say that the word ?bahr? (sea) is usually used to mean salt water rather than fresh water.? Ibn Manzursaid: ??Bahr? is more frequently used to describe salt water than fresh water.? If the word ?bahr? is used without qualification it means salt water; otherwise, it means the thing qualified.? The Holy Qur?an uses ?nahr?(river) to indicate abundant running fresh water, while it uses ?bahr? (sea) to indicate salt water. Allah (SWT) says: (And He has made the ships to be of service to you that they may sail through the sea by His Command; and He has made rivers (also) to be of service to you.)(XIV: 32) In the hadith, ?bahr? (sea) is also used to mean salt water. Allah?s Messenger (Peace be upon him) was asked by a man who said: ?O Allah?s Messenger! We travel by sea and carry with us a little fresh water. If we should use it forwudu (ablution) we would get thirsty. May we use seawater for wudu? Allah? Messenger (Peace be upon him) said: ?Its water is pure and its dead (animals) are lawful (to eat).?Al-Barzakh: It is the barrier. Most commentatorssuggest that it is invisible. Al-baghi: IbnManzur said: ??Al-Baghi? means transgression, exceeding the limits.? Al-Jawhari and Al-Asfahani said the same. Al-Marjan: Ibn Al-Jawzi said: ?Al-Qadi Abu Ya?li says that Al-Marjan is a kind of bar-like pearls. Al-Zajjajsaid: ?Al-Marjan is white, very white.? IbnMas?ud said: ?Al-Marjan is red beads.? Abu Hayyan said that to some people Al-Marjan is red stone. Al-Qurtubi said: ?It is said that Al-Marjan is the big pearls. The same is also said by ?Ali and Ibn ?Abbas (May Allah bestow His Mercy on them both). The small pieces of Marjan are the small pearls. It is also reported on their authority the opposite: the big pieces are called pearls and the smaller are called Marjan. Al-Dahhak and Qatadah said the same.? Al-Alusi said: ?If we take into consideration the connotation of brilliance and glitter which the Arabic word ?pearls? carries, and the connotation of movement and mixing that the word ?Marjan? carries, we can say that ?pearls? is used for big pieces and?Marjan? for small ones.? Anyhow, Marjan is a kind of ornament that is found in various colors: white and red. It may be in big or small pieces. It is bar- like stone. In the Verse it is something other than pearls, for the conjunction ?and? implies talking bout two different things. Marjan (carol), however, is found in salt seas only. The Verse shows us the minute secrets which oceanography has revealed only recently. They describe the meeting between salt seas. Following is the evidence to that: First: The Verse uses the word ?bahrayn? (two seas) without any qualification. This means that salt seas are intended here. Second: The Verses in Surat Al-Rahman show that the two seas yield pearls and ?Marjan?(carol). It has become evident that Marjan is found in salt seas only. This indicates that the Verse is referring to two salt seas. Allah (SWT) says: ?Out of them both come out pearls and carol,? i.e. out of each of them. Who knew in the past that salt seas differ in many respects in spite of their apparent similarity to the observer? (They all taste salt, look blue, have waves, contain fish, etc.) How can they differ although they meet each other? We know that when two amounts of water are mixed in a container they get homogenous. How can seas remain differentiated even in the presence of the factors of mixing, such as the ebb and flow of the sea, currents and storms? The Verse mentions the meeting of two salt seas that differ from one another. If the two seas were similar to one another, they would be one sea. However, differentiating between them in the Qur?anic utterance implies the difference between them although they are both salt. (He has let free (Maraja) the two seas meeting together) means that the two seas are mixed; they are in the state of backward and forward movements, of mixing and turbulence at the site of the meeting, as is understood from the literal meaning of?Maraja?. This is the fact that science has discovered, that is to say, the barrier is described as being zigzag or wavy and shifting in position during the various seasons because of the tide and winds. This Verse by itself implies the presence of so much mixing and merging between these seas as would deprive them of their distinctive properties. But Allah (SWT), the All-Knower, shows in the following Verse that ?between them is a barrier which they do not transgress?, i.e. In spite of this state of merging and turbulence that characterizes the seas there is a barrier between them preventing them from transgressing or exceeding their limits. This is what man has discovered as a result of the advances achieved in his sciences and instruments. It has been found that a third water mass separates the two seas and it has such properties as are different from those of each of the two seas separated by it. Yet, in spite of the presence of the barrier, the waters of the two adjacent seas mix very slowly without one sea encroaching upon the other through carrying over its own properties to it, for the barrier zone is a region for changing the water crossing from one sea to the other so that it gradually acquires the properties of the sea that is going to enter and loses the properties of the sea it has come form. Thus neither of the two seas transgresses by carrying its own properties to the other, although they mix during the process of meeting. How truthful is Allah?s Saying: (He has let free (maraja) the two seas meeting together. Between them is a barrier which they do not transgress.) Most commentators suggest that the barrier that separates the two seas referred to here is an invisible barrier created by Allah. Some commentators find it difficult to reconcile the idea of the seas being merging and the presence of a barrier at the same time, for the presence of a barrier entails the prevention of merging. So the mention of merging (maraja) entails the absence of a barrier. This apparent contradiction has been resolved by discovering the secrets of the seas. The Miraculous Aspects of the Previous Verses: We can conclude the following from the discussion above: The Holy Qur?an, which was revealed more than 14 centuries ago, includes very precise pieces of information and knowledge about marine phenomena that have been discovered only recently by means of very sophisticated equipment. An instance in this respect is the existence of water barriers between seas. Allah (SWT) says:(He has let free (maraja) the two seas meeting together. Between them is a barrier which they do not transgress.) The historical development of Oceanography shows that no precise information had been available on seas before Challenger Expedition (in 1873 AD), let alone at the time when the Holy Qur?an was being revealed 14 centuries ago to an illiterate Prophet that lived in a desert environment and never traveled by sea. Oceanography has witnessed no advances except in the last two centuries, particularly in the latter half of the twentieth century. Prior to that a sea was considered as something fearful and mysterious. Myths and superstitions were fabricated about it. Sea voyagers were only interested in their own safety and how to find the correct routes during their long journeys. Man discovered that salt seas are different only in the thirties of the twentieth century, after thousands of marine stations had been established by researchers to analyze samples of sea water to measure the differences between the degrees of temperature, salinity, density and oxygen dissolubility in the sea water recorded at all those stations, and then realize that salt seas are different. Man did not know anything about the barrier that separates between salt seas till the establishment of the aforesaid stations, and after spending a long time tracing these wavy moving barriers that change their geographical locations with the change of seasons. Man did not know that the water masses of the two seas are separated by a water barrier and are mixed at the same time till he started studying with his ships and equipment the water movement in the meeting region of the seas and analyzing the water masses in those regions. Man did not apply this rule to all seas that meet together except after vast scientific surveying, investigation and verification of this phenomenon, which occurs between each pair of adjacent seas in the world. Now then, did Allah?s Messenger (Peace be upon him) own stations and equipment for analyzing water and the ability to trace the movement of various water masses? Did he carry out a comprehensive surveying process, although he never sailed the sea and lived at a time when superstitions were prevalent, particularly in the field of seas? Were, at the time of Allah?s Messenger (Peace be upon him) such researches, instruments and studies as are available for the oceanographers of today who have discovered all these secrets by means of research and study? This knowledge, which the Qur?an came with, included a precise de******ion of the subtlest secrets at a time when humanity could never have known them, which indicates that its source is Divine, as Allah (SWT) says: (Say: ?the (Qur?an) was sent down by Him Who knows the secret (that is) in the heavens and the earth: Verily He is Oft-Forgiving, Most Merciful.) (XXV: 6) It also indicates that the one to whom the Book was sent down was a Messenger inspired. Allah (SWT) but says the Truth in the Verse: (Soon will We show Our Signs in the Universe and in their own selves, until it becomes manifest to them that this the Truth. Is it not sufficient that your Lord does witness all things?) to morehttp://rapidshare.com/files/18405467?5___1586_.html 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.usc.edu/dept/MSA/quran http://www.quranforall.org http://www.quranexplorer.com/quran http://www.prophetmuhammed.org http://www.chatislamonline.org/ar http://www.dar-us-salam.com http://youtubeislam.com From ether.joe at gmail.com Tue Jan 17 08:59:51 2012 From: ether.joe at gmail.com (Sean Wolfe) Date: Tue, 17 Jan 2012 10:59:51 -0300 Subject: THAT WHAT NEED EXPECT FROM OPERATORS OF PYTHON. (e-mail get by the list moderator) In-Reply-To: <4f13cb2d$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <4f13cb2d$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jan 16, 2012 at 4:01 AM, Steven D'Aprano wrote: > On Mon, 16 Jan 2012 09:03:54 +0300, _ wrote: > >> # THAT WHAT NEED EXPECT FROM OPERATORS OF PYTHON: Worddr = "56" # CREATE >> A STRING: "56" Word = ["12"] # CREATE A LIST WITH ONE SIGNED: "12" Word >> = Word.append("34") > ... > > > Do you have a question, or are you just dumping a lot of noise in one > post? > > I think it's a secret code. I just watched Sherlock Holmes last night so I know all about that s**t. From jerome at jolimont.fr Tue Jan 17 09:16:01 2012 From: jerome at jolimont.fr (=?UTF-8?B?SsOpcsO0bWU=?=) Date: Tue, 17 Jan 2012 15:16:01 +0100 Subject: First python project : Tuner Message-ID: <20120117151601.78e495cb@bouzin.lan> Hi all. Like others before me, I'd like to show you my first python attempt, in the hope in can get advices on how to improve my coding. I started learning python and pyGTK last november. I had had a short experience of GTK with C, but had given up as I lacked time and I found it more difficult than I expected. python makes things more easy. Yet, after starting with pyGTK, I switched to PyGObject, and lack of documentation made small things a bit hard sometimes... The project I chose as an exercise is some sort of guitar tuner. It can be found here : http://devs.jolimont.fr/tuner/ The choice of the sound backends was already discussed on this list. Next step would be to switch to a python audio library and use threads instead of processes. I added flags to avoid race conditions, perhaps with a little bit of clumsyness. This makes the code more complicated than it deserved to be. Any comment is welcome, be it about code optimization, coding style, pythonification, good practices, or simply program features and usability. Thanks. -- J?r?me From rantingrickjohnson at gmail.com Tue Jan 17 11:48:13 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 17 Jan 2012 08:48:13 -0800 (PST) Subject: First python project : Tuner References: Message-ID: <296de6ba-2929-44de-bb26-8eea343b6875@h12g2000yqg.googlegroups.com> On Jan 17, 8:16?am, J?r?me wrote: > Any comment is welcome, be it about code optimization, coding style, > pythonification, good practices, or simply program features and usability. Step one would be to show a screen shot in both English AND French language. Besides, not everyone in this community is a "card carrying" pacifist. From alex at moreati.org.uk Tue Jan 17 12:10:18 2012 From: alex at moreati.org.uk (Alex Willmer) Date: Tue, 17 Jan 2012 09:10:18 -0800 (PST) Subject: Finding x is 1, and x is 'foo' comparisons in a code base Message-ID: <6e061ae1-bb46-43bd-ad97-0aff30cc374e@m20g2000vbf.googlegroups.com> Hello, I'm looking for a way to find the occurrences of x is y comparisons in an existing code base. Except for a few special cases (e.g. x is [not] None) they're a usually mistakes, the correct test being x == y. However they happen to work most of the time on CPython (e.g. when y is a small integer or string) so they slip into production code unnoticed. PyLint and PyFlakes don't check this AFAICT. Any suggestions for such a tool, or a pointer how to add the check to an existing tool would be most welcome. Regards, Alex From jerome at jolimont.fr Tue Jan 17 12:26:14 2012 From: jerome at jolimont.fr (=?UTF-8?B?SsOpcsO0bWU=?=) Date: Tue, 17 Jan 2012 18:26:14 +0100 Subject: First python project : Tuner In-Reply-To: <296de6ba-2929-44de-bb26-8eea343b6875@h12g2000yqg.googlegroups.com> References: <296de6ba-2929-44de-bb26-8eea343b6875@h12g2000yqg.googlegroups.com> Message-ID: <20120117182614.25072938@bouzin.lan> Tue, 17 Jan 2012 08:48:13 -0800 (PST) Rick Johnson a ?crit: > On Jan 17, 8:16?am, J?r?me wrote: > > > Any comment is welcome, be it about code optimization, coding style, > > pythonification, good practices, or simply program features and usability. > > Step one would be to show a screen shot in both English AND French > language. The screenshot was a dissatisfying mix of english and french because until I18n is done (next in TODO list) all the strings are in english, but the stock buttons are localized as my system is in french. Yet the inconsistency. I didn't know it was as easy as LANGUAGE=EN ./tuner_v2_0.py to re-localize a program. Now the screenshot is english only. Anyway, I was trying to bring people's attention to the python program itself : http://devs.jolimont.fr/tuner/downloads/tuner_v2_0.py > Besides, not everyone in this community is a "card carrying" > pacifist. ? -- J?r?me From rodrick.brown at gmail.com Tue Jan 17 12:28:11 2012 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Tue, 17 Jan 2012 12:28:11 -0500 Subject: First python project : Tuner In-Reply-To: <20120117182614.25072938@bouzin.lan> References: <296de6ba-2929-44de-bb26-8eea343b6875@h12g2000yqg.googlegroups.com> <20120117182614.25072938@bouzin.lan> Message-ID: You would get more responses if you used one of those sites that displayed the code right in the browser. On Tue, Jan 17, 2012 at 12:26 PM, J?r?me wrote: > Tue, 17 Jan 2012 08:48:13 -0800 (PST) > Rick Johnson a ?crit: > > > On Jan 17, 8:16 am, J?r?me wrote: > > > > > Any comment is welcome, be it about code optimization, coding style, > > > pythonification, good practices, or simply program features and > usability. > > > > Step one would be to show a screen shot in both English AND French > > language. > > The screenshot was a dissatisfying mix of english and french because until > I18n is done (next in TODO list) all the strings are in english, but the > stock > buttons are localized as my system is in french. Yet the inconsistency. > > I didn't know it was as easy as > > LANGUAGE=EN ./tuner_v2_0.py > > to re-localize a program. Now the screenshot is english only. > > Anyway, I was trying to bring people's attention to the python program > itself : > http://devs.jolimont.fr/tuner/downloads/tuner_v2_0.py > > > Besides, not everyone in this community is a "card carrying" > > pacifist. > > ? > > -- > J?r?me > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jerome at jolimont.fr Tue Jan 17 12:48:12 2012 From: jerome at jolimont.fr (=?UTF-8?B?SsOpcsO0bWU=?=) Date: Tue, 17 Jan 2012 18:48:12 +0100 Subject: First python project : Tuner In-Reply-To: References: <296de6ba-2929-44de-bb26-8eea343b6875@h12g2000yqg.googlegroups.com> <20120117182614.25072938@bouzin.lan> Message-ID: <20120117184812.7fb59b97@bouzin.lan> Tue, 17 Jan 2012 12:28:11 -0500 Rodrick Brown a ?crit: > You would get more responses if you used one of those sites that displayed > the code right in the browser. Thanks for the tip. I thought people would rather open it in their own editor. (And I tend to avoid third-party hosting.) Here's an html rendering : http://devs.jolimont.fr/tuner/downloads/tuner_v2_0.py.html This is done with gvim. Too bad it lacks line numbering. -- J?r?me From g.starck at gmail.com Tue Jan 17 13:16:02 2012 From: g.starck at gmail.com (gst) Date: Tue, 17 Jan 2012 10:16:02 -0800 (PST) Subject: First python project : Tuner References: Message-ID: On 17 jan, 15:16, J?r?me wrote: > Hi all. > hi, just my 2 cents: you have quite lot of such test: > if self._index is 0: I think it's better to compare with equality against 0 (or other needed value) ; that is: if self._index == 0: otherwise your code looks very nice to me, though I just had a very quick look ;) regards, GS. From python at mrabarnett.plus.com Tue Jan 17 13:39:13 2012 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 17 Jan 2012 18:39:13 +0000 Subject: Finding x is 1, and x is 'foo' comparisons in a code base In-Reply-To: <6e061ae1-bb46-43bd-ad97-0aff30cc374e@m20g2000vbf.googlegroups.com> References: <6e061ae1-bb46-43bd-ad97-0aff30cc374e@m20g2000vbf.googlegroups.com> Message-ID: <4F15C051.4070002@mrabarnett.plus.com> On 17/01/2012 17:10, Alex Willmer wrote: > Hello, > > I'm looking for a way to find the occurrences of x is y comparisons in > an existing code base. Except for a few special cases (e.g. x is [not] > None) they're a usually mistakes, the correct test being x == y. > However they happen to work most of the time on CPython (e.g. when y > is a small integer or string) so they slip into production code > unnoticed. > > PyLint and PyFlakes don't check this AFAICT. Any suggestions for such > a tool, or a pointer how to add the check to an existing tool would be > most welcome. > I would search using a regex such as: \bis\b(?! +None| +not +None) in either a text editor or using a Python script. From theller at ctypes.org Tue Jan 17 13:47:53 2012 From: theller at ctypes.org (Thomas Heller) Date: Tue, 17 Jan 2012 19:47:53 +0100 Subject: Finding x is 1, and x is 'foo' comparisons in a code base In-Reply-To: <6e061ae1-bb46-43bd-ad97-0aff30cc374e@m20g2000vbf.googlegroups.com> References: <6e061ae1-bb46-43bd-ad97-0aff30cc374e@m20g2000vbf.googlegroups.com> Message-ID: <9nlu2pFb0U1@mid.individual.net> Am 17.01.2012 18:10, schrieb Alex Willmer: > Hello, > > I'm looking for a way to find the occurrences of x is y comparisons in > an existing code base. Except for a few special cases (e.g. x is [not] > None) they're a usually mistakes, the correct test being x == y. > However they happen to work most of the time on CPython (e.g. when y > is a small integer or string) so they slip into production code > unnoticed. > > PyLint and PyFlakes don't check this AFAICT. Any suggestions for such > a tool, or a pointer how to add the check to an existing tool would be > most welcome. Pychecker contains a check for this mistake. From jerome at jolimont.fr Tue Jan 17 14:00:44 2012 From: jerome at jolimont.fr (=?UTF-8?B?SsOpcsO0bWU=?=) Date: Tue, 17 Jan 2012 20:00:44 +0100 Subject: First python project : Tuner In-Reply-To: References: Message-ID: <20120117200044.1cb45023@bouzin.lan> Tue, 17 Jan 2012 10:16:02 -0800 (PST) gst a ?crit: > you have quite lot of such test: > > > if self._index is 0: > > I think it's better to compare with equality against 0 (or other > needed value) ; that is: > > if self._index == 0: Yes, I just saw that thanks to Alex Willmer's e-mail. I used to have ==, until for some strange reason I figured is was more pythonic, so I replaced all == I could with is. I shouldn't have. I appended this issue on top of my TODO list. Although I try to read as much documentation as I can to do things clean, there is still a lot of trial and error and sometimes my criterion ends up being "does it works or does it not", whithout comprehensive understanding. > otherwise your code looks very nice to me, though I just had a very > quick look ;) Thank you for the feedback. -- J?r?me From ben+python at benfinney.id.au Tue Jan 17 14:38:45 2012 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 18 Jan 2012 06:38:45 +1100 Subject: First python project : Tuner References: <296de6ba-2929-44de-bb26-8eea343b6875@h12g2000yqg.googlegroups.com> Message-ID: <87d3ai3yre.fsf@benfinney.id.au> J?r?me writes: > Anyway, I was trying to bring people's attention to the python program > itself Welcome! You have some replies now, that's good. > Rick Johnson a ?crit: > > Besides, not everyone in this community is a "card carrying" > > pacifist. > > ? You have attracted the attention of a troll. Please search for that person's past messages in the recent archives of this forum, and then decide whether it's worth continuing a dialogue with him. -- \ ?Choose mnemonic identifiers. If you can't remember what | `\ mnemonic means, you've got a problem.? ?Larry Wall | _o__) | Ben Finney From jeanmichel at sequans.com Tue Jan 17 14:59:17 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 17 Jan 2012 20:59:17 +0100 Subject: First python project : Tuner In-Reply-To: <20120117151601.78e495cb@bouzin.lan> References: <20120117151601.78e495cb@bouzin.lan> Message-ID: <4F15D315.3020606@sequans.com> J?r?me wrote: > Hi all. > > Like others before me, I'd like to show you my first python attempt, in the > hope in can get advices on how to improve my coding. > > I started learning python and pyGTK last november. I had had a short > experience of GTK with C, but had given up as I lacked time and I found it > more difficult than I expected. python makes things more easy. Yet, after > starting with pyGTK, I switched to PyGObject, and lack of documentation made > small things a bit hard sometimes... > > The project I chose as an exercise is some sort of guitar tuner. It can be > found here : > http://devs.jolimont.fr/tuner/ > > The choice of the sound backends was already discussed on this list. Next > step would be to switch to a python audio library and use threads instead of > processes. > > I added flags to avoid race conditions, perhaps with a little bit of > clumsyness. This makes the code more complicated than it deserved to be. > > Any comment is welcome, be it about code optimization, coding style, > pythonification, good practices, or simply program features and usability. > > Thanks. > > My system failed to import gi.repository But don't bother I won't install anything anyway. If it is not listed in your dependencies, maybe you should add it. You could also display the frequency of A2 (possibly 440Hz), would give a pro touch to the thing :D As for python, why don't use use 'pylint' on it. It is one good way to know about your code. It's not about correcting any error reported, but by simply looking at the messages/warnings, and asking yourself "why that rule ?" you can improve your coding style and design, maybe for the next application. JM From rantingrickjohnson at gmail.com Tue Jan 17 15:38:27 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 17 Jan 2012 12:38:27 -0800 (PST) Subject: First python project : Tuner References: <296de6ba-2929-44de-bb26-8eea343b6875@h12g2000yqg.googlegroups.com> <87d3ai3yre.fsf@benfinney.id.au> Message-ID: <9cc86927-e396-4430-88fc-eb7e11fe4eb5@u20g2000yqb.googlegroups.com> On Jan 17, 1:38?pm, Ben Finney wrote: > J?r?me writes: > > Rick Johnson a ?crit: > > > Besides, not everyone in this community is a "card carrying" > > > pacifist. > > ? > You have attracted the attention of a troll. What is worse: A wolf, or a wolf in sheep's clothing? There is no "trolling" in my reply. A nice quip, yes. Trolling, no. The fact remains that English is very important to Python. In fact, English is SO important that the great Guido van Rossum himself mentioned English explicitly in PEP8. And as we know, English is NOT his first language! GvR said: """Python coders from non-English speaking countries: please write your comments in English, unless you are 120% sure that the code will never be read by people who don't speak your language.""" GvR said: """All identifiers in the Python standard library MUST use ASCII-only identifiers, and SHOULD use English words wherever feasible (in many cases, abbreviations and technical terms are used which aren't English).""" From rosuav at gmail.com Tue Jan 17 15:46:28 2012 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 18 Jan 2012 07:46:28 +1100 Subject: First python project : Tuner In-Reply-To: <9cc86927-e396-4430-88fc-eb7e11fe4eb5@u20g2000yqb.googlegroups.com> References: <296de6ba-2929-44de-bb26-8eea343b6875@h12g2000yqg.googlegroups.com> <87d3ai3yre.fsf@benfinney.id.au> <9cc86927-e396-4430-88fc-eb7e11fe4eb5@u20g2000yqb.googlegroups.com> Message-ID: On Wed, Jan 18, 2012 at 7:38 AM, Rick Johnson wrote: > On Jan 17, 1:38?pm, Ben Finney wrote: >> You have attracted the attention of a troll. > > What is worse: A wolf, or a wolf in sheep's clothing? > > There is no "trolling" in my reply. A nice quip, yes. Trolling, no. Well, as we learn from Innistrad, worse is a wolf in shepherd's clothing. (Look up 'Gatstaf Shepherd'.) Ben didn't say there was "trolling" in your reply. He said that the OP had attracted the attention of a troll. That said, though, I would have to say that your post was trollish. ChrisA From jeff.frontz at gmail.com Tue Jan 17 19:24:21 2012 From: jeff.frontz at gmail.com (Jeff Frontz) Date: Tue, 17 Jan 2012 16:24:21 -0800 (PST) Subject: Using python to dynamically divine the contents of a CORBA (omniORB) interface Message-ID: <9cc3a404-51d7-4afa-837a-311bedfaa770@w10g2000vbg.googlegroups.com> I'm trying to write a self-maintaining test tool that can be used from the command line against a server via CORBA (omniORB). To start, I'd be happy with a tool that could describe the interface(s) that the server implements (e.g., essentially regenerating the IDL that defined the interfaces to begin with). From there, I'd grow it into something that could accept parameters, make the CORBA call, and print the results. I know that python has introspection that should make it possible to not have to write (much) code every time an argument changes or a new method is added [in the IDL]. But I don't understand enough of the python binding for omniORB (or enough python) to know how to do this easily (or whether an infrastructure already exists to do this). I've inherited some code that I'm trying to morph into my test tool. The problem is that I don't know how much is something that is stock omniORB python support and how much is homebrew. >From what I'm seeing, it looks like an omniORB CORBA interface appears in python as a class (that part seems likely standard). The methods of said interface appear as members of this class--they are each tuples with naming that appears to be the method name from the IDL prefixed with _d_. The input parameters for a given interface method are described by said method's first tuple element; the second element describes the return values. Each element is another tuple of tuples, with each describing a successive parameter. I'm hoping this reflects the implementation of omniORBpy. Assuming that it does, are there well-defined routines for interrogating/ manipulating these interface class objects? Thanks, Jeff [note: this was originally posted at stackoverflow http://stackoverflow.com/questions/8840900/using-python-to-dynamically-divine-the-contents-of-a-corba-omniorb-interface ] From rantingrickjohnson at gmail.com Tue Jan 17 20:20:32 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 17 Jan 2012 17:20:32 -0800 (PST) Subject: THAT WHAT NEED EXPECT FROM OPERATORS OF PYTHON. (e-mail get by the list moderator) References: Message-ID: <27a18eae-5b00-4f59-b86c-2034434b86c8@g27g2000yqa.googlegroups.com> On Jan 16, 12:03?am, "_" wrote: > # THAT WHAT NEED EXPECT FROM OPERATORS OF PYTHON: > Worddr = "56" # CREATE A STRING: "56" > Word = ["12"] # CREATE A LIST WITH ONE SIGNED: "12" > Word = Word.append("34") # APPEND TO LIST ONE MORE SIGNED: "34" > Word = Word + "34" # MUST APPEND TO LIST ONE MORE SIGNED: "34" > Wordpr = Word[1] # MUST SIGNED TO THE Wordpr THE SECOND SIGNED OF THE Word > LIST: "34", AND IT'S ALL PARAMETRS > Wordpr = Wordpr + Worddr[1] # MUST ADD TO THE STRING Wordpr: "34", A SECOND > SIGNED OF STRING Worddr: "6" > Word[1] = Word[1] + Worddr[1] # MUST ADD TO THE SECOND STRING LIST Word: > "346", A SECOND SIGNED OF STRING Worddr: "6" Someone needs to _underscore_ the importance of "articulate-Usenet- post-composition" to the OP. From rodrick.brown at gmail.com Wed Jan 18 00:22:20 2012 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Wed, 18 Jan 2012 00:22:20 -0500 Subject: thread example question Message-ID: Can any idea help me figure out why the following output is sequential? I'm running this example on a 4 core system. I would expect the output to look random. import _thread as thread import time class thread_counter(object): def __init__(self, thr_cnt, sleep_int): self.thr_cnt = thr_cnt self.sleep_int = sleep_int def counter(myId, count): for i in range(count): time.sleep(1) print('[{}] => {}'.format(myId, i)) def main(): for i in range(5): thread.start_new_thread(counter, (i, 5)) time.sleep(6) print('Main thread exiting..') if __name__ == '__main__': main() [0] => 0 [0] => 1 [0] => 2 [0] => 3 [0] => 4 Main thread exiting.. [1] => 0 [1] => 1 [1] => 2 [1] => 3 [1] => 4 Main thread exiting.. [2] => 0 [2] => 1 [2] => 2 [2] => 3 [2] => 4 Main thread exiting.. [3] => 0 [3] => 1 [3] => 2 [3] => 3 [3] => 4 Main thread exiting.. [4] => 0 [4] => 1 [4] => 2 [4] => 3 [4] => 4 Main thread exiting.. -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Wed Jan 18 00:27:13 2012 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 18 Jan 2012 16:27:13 +1100 Subject: thread example question In-Reply-To: References: Message-ID: <4F165831.8040300@gmail.com> On 18/01/2012 4:22 PM, Rodrick Brown wrote: > import _thread as thread > import time > > class thread_counter(object): > def __init__(self, thr_cnt, sleep_int): > self.thr_cnt = thr_cnt > self.sleep_int = sleep_int > > def counter(myId, count): > for i in range(count): > time.sleep(1) > print('[{}] => {}'.format(myId, i)) > > def main(): > for i in range(5): > thread.start_new_thread(counter, (i, 5)) I think you meant for the following 2 lines to be outside the loop (ie, to be dedented one level). Once you do that the output is as *I* expect :) Mark > time.sleep(6) > print('Main thread exiting..') > > if __name__ == '__main__': > main() > From diolu at bigfoot.com Wed Jan 18 02:16:12 2012 From: diolu at bigfoot.com (Olive) Date: Wed, 18 Jan 2012 08:16:12 +0100 Subject: sys.argv as a list of bytes Message-ID: <20120118081612.13745187@bigfoot.com> In Unix the operating system pass argument as a list of C strings. But C strings does corresponds to the bytes notions of Python3. Is it possible to have sys.argv as a list of bytes ? What happens if I pass to a program an argumpent containing funny "character", for example (with a bash shell)? python -i ./test.py $'\x01'$'\x05'$'\xFF' From __peter__ at web.de Wed Jan 18 03:05:42 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 18 Jan 2012 09:05:42 +0100 Subject: sys.argv as a list of bytes References: <20120118081612.13745187@bigfoot.com> Message-ID: Olive wrote: > In Unix the operating system pass argument as a list of C strings. But > C strings does corresponds to the bytes notions of Python3. Is it > possible to have sys.argv as a list of bytes ? What happens if I pass > to a program an argumpent containing funny "character", for example > (with a bash shell)? > > python -i ./test.py $'\x01'$'\x05'$'\xFF' Python has a special errorhandler, "surrogateescape" to deal with bytes that are not valid UTF-8. If you try to print such a string you get an error: $ python3 -c'import sys; print(repr(sys.argv[1]))' $'\x01'$'\x05'$'\xFF' '\x01\x05\udcff' $ python3 -c'import sys; print(sys.argv[1])' $'\x01'$'\x05'$'\xFF' Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'utf-8' codec can't encode character '\udcff' in position 2: surrogates not allowed It is still possible to get the original bytes: $ python3 -c'import sys; print(sys.argv[1].encode("utf-8", "surrogateescape"))' $'\x01'$'\x05'$'\xFF' b'\x01\x05\xff' From chris at simplistix.co.uk Wed Jan 18 03:48:28 2012 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 18 Jan 2012 08:48:28 +0000 Subject: MailingLogger 3.7.0 Released! Message-ID: <4F16875C.9080603@simplistix.co.uk> I'm pleased to announce a new release of Mailinglogger. Mailinglogger provides two handlers for the standard python logging framework that enable log entries to be emailed either as the entries are logged or as a summary at the end of the running process. The handlers have the following features: - customisable and dynamic subject lines for emails sent - emails sent with a configurable headers for easy filtering - flood protection to ensure the number of emails sent is not excessive - support for SMTP servers that require authentication - fully documented and tested This release fixes a long standing bug that occurred when logging unicode messages. It also provides support for sending colourised HTML emails: http://packages.python.org/mailinglogger/html.html Full docs can be found here: http://packages.python.org/mailinglogger/ For more information, please see: http://www.simplistix.co.uk/software/python/mailinglogger or http://pypi.python.org/pypi/mailinglogger cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From macsmith.us at gmail.com Wed Jan 18 04:14:37 2012 From: macsmith.us at gmail.com (Mac Smith) Date: Wed, 18 Jan 2012 14:44:37 +0530 Subject: subprocess.Popen strange bhaviour Message-ID: <4F7A2376-857C-4C5E-94B7-AC7170C16B48@gmail.com> Hi, I am using subprocess.Popen to start a movie ripping command HandBrakeCLI. My server is 64bit ubuntu server and has 8 cores. When the command starts it uses all 8 cores upto 80%-100% and works fine, but after 270 seconds the cpu usage of all the cores drops to 0% - 1%. I tried this many time this happens exactly after 270 seconds. Is there some predefined timeout?? -- Mac From steve+comp.lang.python at pearwood.info Wed Jan 18 04:23:01 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Jan 2012 09:23:01 GMT Subject: subprocess.Popen strange bhaviour References: Message-ID: <4f168f75$0$29987$c3e8da3$5496439d@news.astraweb.com> On Wed, 18 Jan 2012 14:44:37 +0530, Mac Smith wrote: > Hi, > > I am using subprocess.Popen to start a movie ripping command > HandBrakeCLI. My server is 64bit ubuntu server and has 8 cores. When the > command starts it uses all 8 cores upto 80%-100% and works fine, but > after 270 seconds the cpu usage of all the cores drops to 0% - 1%. I > tried this many time this happens exactly after 270 seconds. Is there > some predefined timeout?? I think you have misunderstood subprocess.Popen. It launches the new process (HandBrakeCLI) then what happens in that new process is independent of Python and Popen. How are you calling HandBrakeCLI? Is it ripping directly from a device or file, or is it reading from stdin? If reading from stdin, possibly it is waiting for more data from you. Or perhaps it has simply finished ripping and there's nothing else for it to do and the process ends. -- Steven From w_h_falk at yahoo.de Wed Jan 18 04:52:55 2012 From: w_h_falk at yahoo.de (Wilfried Falk) Date: Wed, 18 Jan 2012 09:52:55 +0000 (GMT) Subject: "+=" does not work correct all alogn Message-ID: <1326880375.27881.YahooMailNeo@web29007.mail.ird.yahoo.com> Hello Pythons, ? attached to this email is a pdf-file which shows, that? "+=" does not work well all along. Mybe somebody of you is able to explain my observations in this respect. I will be glad about an answer. ? Best regards Wilfried -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: BugInPython.pdf Type: application/pdf Size: 4516 bytes Desc: not available URL: From contropinion at gmail.com Wed Jan 18 04:56:52 2012 From: contropinion at gmail.com (contro opinion) Date: Wed, 18 Jan 2012 17:56:52 +0800 Subject: in the middle of web ,there is a problem,how to parse Message-ID: here is my code: import urllib import lxml.html down=" http://sc.hkex.com.hk/gb/www.hkex.com.hk/chi/market/sec_tradinfo/stockcode/eisdeqty_c.htm " file=urllib.urlopen(down).read() root=lxml.html.document_fromstring(file) data1 = root.xpath('//tr[@class="tr_normal" and .//img]') print "the row which contains img :" for u in data1: print u.text_content() data2 = root.xpath('//tr[@class="tr_normal" and not(.//img)]') print "the row which do not contain img :" for u in data2: print u.text_content() the output is :(i omit many lines ) the row which contains img : 00329 the row which do not contain img : 00001????1,000#HOF ................many lines omitted 00327????1,000#H 00328ALCO HOLDINGS2,000# i wondered why there are so many lines i can't get such as : (you can see in the web http://sc.hkex.com.hk/gb/www.hkex.com.hk/chi/market/sec_tradinfo/stockcode/eisdeqty_c.htm ) 00330???? 100#HOF00331???? 2,000#H 00332NGAI LIK IND 4,000# ...................many lines ommitted i want to know how can i get these ?? -------------- next part -------------- An HTML attachment was scrubbed... URL: From diolu at bigfoot.com Wed Jan 18 05:16:27 2012 From: diolu at bigfoot.com (Olive) Date: Wed, 18 Jan 2012 11:16:27 +0100 Subject: sys.argv as a list of bytes References: <20120118081612.13745187@bigfoot.com> Message-ID: <20120118111627.14d490ac@bigfoot.com> On Wed, 18 Jan 2012 09:05:42 +0100 Peter Otten <__peter__ at web.de> wrote: > Olive wrote: > > > In Unix the operating system pass argument as a list of C strings. > > But C strings does corresponds to the bytes notions of Python3. Is > > it possible to have sys.argv as a list of bytes ? What happens if I > > pass to a program an argumpent containing funny "character", for > > example (with a bash shell)? > > > > python -i ./test.py $'\x01'$'\x05'$'\xFF' > > Python has a special errorhandler, "surrogateescape" to deal with > bytes that are not valid UTF-8. If you try to print such a string you > get an error: > > $ python3 -c'import sys; print(repr(sys.argv[1]))' > $'\x01'$'\x05'$'\xFF' '\x01\x05\udcff' > $ python3 -c'import sys; print(sys.argv[1])' $'\x01'$'\x05'$'\xFF' > Traceback (most recent call last): > File "", line 1, in > UnicodeEncodeError: 'utf-8' codec can't encode character '\udcff' in > position 2: surrogates not allowed > > It is still possible to get the original bytes: > > $ python3 -c'import sys; print(sys.argv[1].encode("utf-8", > "surrogateescape"))' $'\x01'$'\x05'$'\xFF' b'\x01\x05\xff' > > But is it safe even if the locale is not UTF-8? I would like to be able to pass a file name to a script. I can use bytes for file names in the open function. If I keep the filename as bytes everywhere it will work reliably whatever the locale or strange character the file name may contain. Olive From ulrich.eckhardt at dominolaser.com Wed Jan 18 05:29:55 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 18 Jan 2012 11:29:55 +0100 Subject: replacing __dict__ with an OrderedDict In-Reply-To: References: Message-ID: <3ijiu8-rou.ln1@satorlaser.homedns.org> Am 06.01.2012 12:44, schrieb Peter Otten: [running unit tests in the order of their definition] > class Loader(unittest.TestLoader): > def getTestCaseNames(self, testCaseClass): > """Return a sequence of method names found within testCaseClass > sorted by co_firstlineno. > """ > def first_lineno(name): > method = getattr(testCaseClass, name) > return method.im_func.__code__.co_firstlineno > > function_names = super(Loader, self).getTestCaseNames(testCaseClass) > function_names.sort(key=first_lineno) > return function_names After using this a bit, it works great. I have up to now only found a single problem, and that is that with decorated functions it doesn't even get at the actual line number of the real code, so sorting by that number doesn't work. An example for this is "@unittest.expectedFailure(...)". I can easily ignore this though, just wanted to give this feedback Thanks again! Uli From __peter__ at web.de Wed Jan 18 09:01:38 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 18 Jan 2012 15:01:38 +0100 Subject: sys.argv as a list of bytes References: <20120118081612.13745187@bigfoot.com> <20120118111627.14d490ac@bigfoot.com> Message-ID: Olive wrote: > On Wed, 18 Jan 2012 09:05:42 +0100 > Peter Otten <__peter__ at web.de> wrote: > >> Olive wrote: >> >> > In Unix the operating system pass argument as a list of C strings. >> > But C strings does corresponds to the bytes notions of Python3. Is >> > it possible to have sys.argv as a list of bytes ? What happens if I >> > pass to a program an argumpent containing funny "character", for >> > example (with a bash shell)? >> > >> > python -i ./test.py $'\x01'$'\x05'$'\xFF' >> >> Python has a special errorhandler, "surrogateescape" to deal with >> bytes that are not valid UTF-8. If you try to print such a string you >> get an error: >> >> $ python3 -c'import sys; print(repr(sys.argv[1]))' >> $'\x01'$'\x05'$'\xFF' '\x01\x05\udcff' >> $ python3 -c'import sys; print(sys.argv[1])' $'\x01'$'\x05'$'\xFF' >> Traceback (most recent call last): >> File "", line 1, in >> UnicodeEncodeError: 'utf-8' codec can't encode character '\udcff' in >> position 2: surrogates not allowed >> >> It is still possible to get the original bytes: >> >> $ python3 -c'import sys; print(sys.argv[1].encode("utf-8", >> "surrogateescape"))' $'\x01'$'\x05'$'\xFF' b'\x01\x05\xff' >> >> > > But is it safe even if the locale is not UTF-8? I would like to be able > to pass a file name to a script. I can use bytes for file names in the > open function. If I keep the filename as bytes everywhere it will work > reliably whatever the locale or strange character the file name may > contain. I believe you need not convert back to bytes explicitly, you can open the file with open(sys.argv[i]). I don't know if there are cornercases where that won't work; maybe http://www.python.org/dev/peps/pep-0383/ can help you figure it out. From ndbecker2 at gmail.com Wed Jan 18 09:33:34 2012 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 18 Jan 2012 09:33:34 -0500 Subject: unzip function? Message-ID: python has builtin zip, but not unzip A bit of googling found my answer for my decorate/sort/undecorate problem: a, b = zip (*sorted ((c,d) for c,d in zip (x,y))) That zip (*sorted... does the unzipping. But it's less than intuitively obvious. I'm thinking unzip should be a builtin function, to match zip. From y.turgut at gmail.com Wed Jan 18 09:41:48 2012 From: y.turgut at gmail.com (Yigit Turgut) Date: Wed, 18 Jan 2012 06:41:48 -0800 (PST) Subject: Plot square wave Message-ID: <03386c82-34e2-4ecd-a0fe-d109d1956fc0@m2g2000vbc.googlegroups.com> Hi all, I am trying to generate a pseudo pwm signal, low-high transition will take place when screen goes from black to white and high-low transition when white to black. As a result I am trying to plot the signal. Here is my code; import time, pylab, numpy, scipy, pygame def _func1(): global end global white global k global t global i k = numpy.arange(4) t = numpy.arange(4) i = 0 f = open("test.txt", "w") white = True start = time.time() end = time.time() - start screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) timer = pygame.time.Clock() test = repr(time.time()) while(end<8.00): end = time.time() - start if white: screen.fill((255, 255, 255)) time.sleep(1) k[i] = 0 t[i] = end f.write(str(t[i]) + "\t" + str(k[i]) + "\n") i = i + 1 print repr(end) else: screen.fill((0, 0, 0)) time.sleep(1) k[i] = 1 t[i] = end f.write(str(t[i]) + "\t" + str(k[i]) + "\n") i = i+ 1 print repr(end) white = not white pygame.display.update() pygame.quit() if __name__ == "__main__": _func1() time,data = numpy.loadtxt('test.txt', unpack=True) print k print t print i pylab.plot(time,data) pylab.show() Problem is I get a sawtooth instead of a square wave. I know that I need to define points between 0,1,2 time integer values to achieve this. But I hope there is a python trick that will yield this time,data plot to a square wave? From alec.taylor6 at gmail.com Wed Jan 18 10:26:08 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Thu, 19 Jan 2012 02:26:08 +1100 Subject: unzip function? In-Reply-To: References: Message-ID: http://docs.python.org/library/zipfile.html ZipFile.extractall([path[, members[, pwd]]]) From alec.taylor6 at gmail.com Wed Jan 18 10:27:31 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Thu, 19 Jan 2012 02:27:31 +1100 Subject: unzip function? In-Reply-To: References: Message-ID: http://docs.python.org/library/functions.html >>> x = [1, 2, 3] >>> y = [4, 5, 6] >>> zipped = zip(x, y) >>> zipped [(1, 4), (2, 5), (3, 6)] >>> x2, y2 = zip(*zipped) >>> x == list(x2) and y == list(y2) True From steve+comp.lang.python at pearwood.info Wed Jan 18 10:27:35 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Jan 2012 15:27:35 GMT Subject: unzip function? References: Message-ID: <4f16e4e7$0$29994$c3e8da3$5496439d@news.astraweb.com> On Wed, 18 Jan 2012 09:33:34 -0500, Neal Becker wrote: > python has builtin zip, but not unzip That's because zip is (almost) its own inverse. > A bit of googling found my answer for my decorate/sort/undecorate > problem: > a, b = zip (*sorted ((c,d) for c,d in zip (x,y))) That does a lot of unnecessary work. a, b = zip(*sorted(zip(x,y))) > That zip (*sorted... > > does the unzipping. > > But it's less than intuitively obvious. *shrug* If you understand what zip does, it should be obvious. > I'm thinking unzip should be a builtin function, to match zip. Just create your own utility function. Not everything needs to be a built-in. def unzip(iterable): return zip(*iterable) Hardly seems worthwhile. -- Steven From rodrick.brown at gmail.com Wed Jan 18 10:31:02 2012 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Wed, 18 Jan 2012 10:31:02 -0500 Subject: unzip function? In-Reply-To: References: Message-ID: On Wed, Jan 18, 2012 at 10:27 AM, Alec Taylor wrote: > http://docs.python.org/library/functions.html > >>> x = [1, 2, 3] > >>> y = [4, 5, 6] > >>> zipped = zip(x, y) > >>> zipped > [(1, 4), (2, 5), (3, 6)] > >>> x2, y2 = zip(*zipped) > >>> x == list(x2) and y == list(y2) > True > Alec can you explain this behavior zip(*zipped)? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Wed Jan 18 10:37:12 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 18 Jan 2012 10:37:12 -0500 Subject: unzip function? In-Reply-To: References: Message-ID: On Wed, Jan 18, 2012 at 10:31 AM, Rodrick Brown wrote: > > > On Wed, Jan 18, 2012 at 10:27 AM, Alec Taylor > wrote: >> >> http://docs.python.org/library/functions.html >> >>> x = [1, 2, 3] >> >>> y = [4, 5, 6] >> >>> zipped = zip(x, y) >> >>> zipped >> [(1, 4), (2, 5), (3, 6)] >> >>> x2, y2 = zip(*zipped) >> >>> x == list(x2) and y == list(y2) >> True > > > Alec can you explain this behavior zip(*zipped)? Zip is its own inverse. >>> zip([1,2,3],[4,5,6]) [(1, 4), (2, 5), (3, 6)] >>> zip((1,4),(2,5),(3,6)) [(1, 2, 3), (4, 5, 6)] If you're not sure of the *zipped part, it just means treat each element of zipped as a different argument to zip. So zip(*zipped) is calling zip(zipped[0], zipped[1]... zipped[-1]) From clp2 at rebertia.com Wed Jan 18 10:38:57 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 18 Jan 2012 07:38:57 -0800 Subject: unzip function? In-Reply-To: References: Message-ID: On Wed, Jan 18, 2012 at 7:31 AM, Rodrick Brown wrote: > On Wed, Jan 18, 2012 at 10:27 AM, Alec Taylor > wrote: >> >> http://docs.python.org/library/functions.html >> >>> x = [1, 2, 3] >> >>> y = [4, 5, 6] >> >>> zipped = zip(x, y) >> >>> zipped >> [(1, 4), (2, 5), (3, 6)] >> >>> x2, y2 = zip(*zipped) >> >>> x == list(x2) and y == list(y2) >> True > > > Alec can you explain this behavior zip(*zipped)? It's just the application of the http://docs.python.org/tutorial/controlflow.html#unpacking-argument-lists feature to a zip() [http://docs.python.org/library/functions.html#zip ] call. zip(*zipped) === zip(*[(1, 4), (2, 5), (3, 6)]) === zip((1, 4), (2, 5), (3, 6)) === [(1, 2, 3), (4, 5, 6)] Cheers, Chris -- http://rebertia.com From clp2 at rebertia.com Wed Jan 18 11:00:36 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 18 Jan 2012 08:00:36 -0800 Subject: subprocess.Popen strange bhaviour In-Reply-To: <4F7A2376-857C-4C5E-94B7-AC7170C16B48@gmail.com> References: <4F7A2376-857C-4C5E-94B7-AC7170C16B48@gmail.com> Message-ID: On Wed, Jan 18, 2012 at 1:14 AM, Mac Smith wrote: > Hi, > > I am using subprocess.Popen to start a movie ripping command HandBrakeCLI. My server is 64bit ubuntu server and has 8 cores. When the command starts it uses all 8 cores upto 80%-100% and works fine, but after 270 seconds the cpu usage of all the cores drops to 0% - 1%. I tried this many time this happens exactly after 270 seconds. Is there some predefined timeout?? Please post the part of your code that uses subprocess.Popen(). Cheers, Chris From __peter__ at web.de Wed Jan 18 11:09:28 2012 From: __peter__ at web.de (Peter Otten) Date: Wed, 18 Jan 2012 17:09:28 +0100 Subject: Plot square wave References: <03386c82-34e2-4ecd-a0fe-d109d1956fc0@m2g2000vbc.googlegroups.com> Message-ID: Yigit Turgut wrote: > Problem is I get a sawtooth instead of a square wave. I know that I > need to define points between 0,1,2 time integer values to achieve > this. But I hope there is a python trick that will yield this > time,data plot to a square wave? There is no "Python trick", pylab is showing the data you provide. To get a square wave you need two y values per x value, for example import pylab time = [0, 0, 1, 1, 2, 2, 3, 3, 4, 4] data = [0, 1, 1, 0, 0, 1, 1, 0, 0, 1] pylab.plot(time, data) pylab.ylim(-.1, 1.1) # so you see the horizontal lines of the graph pylab.xlim(-.1, 4.1) pylab.show() A general advice: try the individual aspects of your script (plotting, pygame flicker, data i/o) separately to make sure you understand them well enough before putting them together in the final version of your code. From jeanpierreda at gmail.com Wed Jan 18 11:15:49 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Wed, 18 Jan 2012 11:15:49 -0500 Subject: unzip function? In-Reply-To: References: Message-ID: On Wed, Jan 18, 2012 at 10:31 AM, Rodrick Brown wrote: > Alec can you explain this behavior zip(*zipped)? Here's one way to think about it: If A is a matrix, zip(*A) returns the transpose of A. That is, the columns become rows, and the rows become columns. If you swap rows and columns, and then swap them back, you're left with the original. -- Devin From jeanpierreda at gmail.com Wed Jan 18 11:20:00 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Wed, 18 Jan 2012 11:20:00 -0500 Subject: unzip function? In-Reply-To: <4f16e4e7$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <4f16e4e7$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jan 18, 2012 at 10:27 AM, Steven D'Aprano wrote: >> That zip (*sorted... >> >> does the unzipping. >> >> But it's less than intuitively obvious. > > *shrug* > > If you understand what zip does, it should be obvious. Nobody likes to be told the thing they're confused about is trivial. It's especially bad if nobody ever actually explains what's so simple about it. Saying it's "almost its own inverse" is just restating the original question -- yes, that's what it is, but why? (I have put my own interpretation in a separate reply. ) -- Devin From arnodel at gmail.com Wed Jan 18 12:09:55 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 18 Jan 2012 17:09:55 +0000 Subject: "+=" does not work correct all alogn In-Reply-To: <1326880375.27881.YahooMailNeo@web29007.mail.ird.yahoo.com> References: <1326880375.27881.YahooMailNeo@web29007.mail.ird.yahoo.com> Message-ID: On 18 January 2012 09:52, Wilfried Falk wrote: > Hello Pythons, > > attached to this email is a pdf-file which shows, that? "+=" does not work > well all along. Mybe somebody of you is able to explain my observations in > this respect. I will be glad about an answer. I think you are more likely to get answers if you post your code in the body of your message rather than attach it in a pdf, which is quite an unusual thing to do! """ 1.) For identifier += 1 you sometimes get print(); identifier = identifier + 1 What means that there is a prior print(). I could not find out a rule for when this happens --- but it does. By replaceing identifier += 1 with identifier = identifier + 1 the malfunction (print()) allways disappears """ I can't comment on this as you don't provide any code. """ 2.) Another "mystery" is shown by the code below. There _list += [something] is not the same as _list = _list + [something]. def conc1(a, _list = []): _list = _list + [a] return _list def conc2(a, _list = []): _list += [a] return _list # Main Program for i in range(4): _list = conc1(i) print(_list) print() for i in range(4): _list = conc2(i) print(_list) In the first case the result of print(_list) is: [0] [1] [2] [3] In the second case the result of print(_list) is: [0] [0, 1] [0, 1, 2] [0, 1, 2, 3] """ This behaviour is not a bug, it is a consequence of two things: 1. The way mutable default arguments work in Python. Your misunderstanding is a very common one for Python beginners. There's a good explanation of the behaviour here: http://effbot.org/zone/default-values.htm 2. The difference between lst += [a] and lst = lst + [a] The first one mutates the list object named 'lst' by appending 'a' at its end, whereas the second one creates a new list made of the items of lst with 'a' appended at the end. So your function conc1 does not mutate _list, whereas your function conc2 does. HTH -- Arnaud From woooee at gmail.com Wed Jan 18 12:42:01 2012 From: woooee at gmail.com (woooee) Date: Wed, 18 Jan 2012 09:42:01 -0800 (PST) Subject: "+=" does not work correct all alogn References: <1326880375.27881.YahooMailNeo@web29007.mail.ird.yahoo.com> Message-ID: > def conc1(a, _list = []): > ? ? _list = _list + [a] > ? ? return _list > for i in range(4): > ? ? _list = conc1(i) ## <----- list not passed You don't pass the list to the conc1 function, so you start with the default, an empty list, each time. From nagle at animats.com Wed Jan 18 13:00:47 2012 From: nagle at animats.com (John Nagle) Date: Wed, 18 Jan 2012 10:00:47 -0800 Subject: Installing Python on CentOS 6 - a big pain Message-ID: <4f1708cc$0$1649$742ec2ed@news.sonic.net> It turns out that installing Python 2.7.2 on CentOS 6.0 is a lot of work. Here are the official CentOS install instructions: http://www.centos.org/modules/newbb/viewtopic.php?topic_id=34515&forum=41 Not only do you have to build Python from source, you have to install a lot of stuff before you can even build it. Then you have to install various Python packages from multiple sources. Python doesn't work with "yum"; you have to do it the hard way. I know how to do all this, but it takes hours. I'm bringing up a bare dedicated server remotely, which is a routine operation. Python does not "just work". I should be able to command "yum install python27". (And not clobber the Python 2.6 that comes with CentOS.) This sort of thing is why Python is losing market share. John Nagle From hniksic at xemacs.org Wed Jan 18 13:01:10 2012 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 18 Jan 2012 19:01:10 +0100 Subject: unzip function? References: Message-ID: <87aa5khoux.fsf@xemacs.org> Neal Becker writes: > python has builtin zip, but not unzip > > A bit of googling found my answer for my decorate/sort/undecorate problem: > > a, b = zip (*sorted ((c,d) for c,d in zip (x,y))) > > That zip (*sorted... > > does the unzipping. > > But it's less than intuitively obvious. > > I'm thinking unzip should be a builtin function, to match zip. "zip" and "unzip" are one and the same since zip is inverse to itself: >>> [(1, 2, 3), (4, 5, 6)] [(1, 2, 3), (4, 5, 6)] >>> zip(*_) [(1, 4), (2, 5), (3, 6)] >>> zip(*_) [(1, 2, 3), (4, 5, 6)] >>> zip(*_) [(1, 4), (2, 5), (3, 6)] What you seem to call unzip is simply zip with a different signature, taking a single argument: >>> def unzip(x): ... return zip(*x) ... >>> [(1, 2, 3), (4, 5, 6)] [(1, 2, 3), (4, 5, 6)] >>> unzip(_) [(1, 4), (2, 5), (3, 6)] >>> unzip(_) [(1, 2, 3), (4, 5, 6)] >>> unzip(_) [(1, 4), (2, 5), (3, 6)] From benjamin.kaplan at case.edu Wed Jan 18 13:23:02 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 18 Jan 2012 13:23:02 -0500 Subject: "+=" does not work correct all alogn In-Reply-To: <1326880375.27881.YahooMailNeo@web29007.mail.ird.yahoo.com> References: <1326880375.27881.YahooMailNeo@web29007.mail.ird.yahoo.com> Message-ID: On Wed, Jan 18, 2012 at 4:52 AM, Wilfried Falk wrote: > Hello Pythons, > > attached to this email is a pdf-file which shows, that? "+=" does not work > well all along. Mybe somebody of you is able to explain my observations in > this respect. I will be glad about an answer. > > Best regards > Wilfried > Please do not send attachments to the list. Besides the fact that it's annoying and there's no reason to do it, the list is also available as a Usenet group and I'm pretty sure the gateway doesn't keep attachments. Also, it makes it more difficult for us to respond to you. Common courtesy on this (and many other) groups is to quote the relevant text that we're responding to. It makes it easier for people to follow the conversation, especially when threads get bigger. >Hello Pythons, >my Python is a download of your Python3.2.2 Windows x86 MSI Installer. What I want to >report is, that "+=" does not work correct all along. >1.) For identifier += 1 you sometimes get print(); identifier = identifier + 1 >What means that there is a prior print(). I could not find out a rule for when this happens --- but it >does. By replaceing identifier += 1 with identifier = identifier + 1 the malfunction (print()) allways >disappears. If this was an actual bug in Python, a lot of other people would have noticed it. Since you're the only one with the problem, it probably has something to do with your code and not with Python. Please post an example showing the problem. >2.) Another "mystery" is shown by the code below. There _list += [something] is not the same >as _list = _list + [something]. > >def conc1(a, _list = []): > _list = _list + [a] > return _list >def conc2(a, _list = []): > _list += [a] > return _list ># Main Program >for i in range(4): > _list = conc1(i) > print(_list) >print() >for i in range(4): > _list = conc2(i) > print(_list) >In the first case the result of print(_list) is: >[0] >[1] >[2] >[3] >In the second case the result of print(_list) is: >[0] >[0, 1] >[0, 1, 2] >[0, 1, 2, 3]. a += b and a = a + b are not the same thing. In Python, a += b is the same thing as a = a.__iadd_(b) while a = a + b is a = a.__add__(b). Like in many other languages, += on objects is an in place operation- it mutates the original object (except in cases of immutable objects like ints). On the other hand, a + b creates a new object with the value of a + b. So in the case of conc1, you're generating a new list each time and leaving the original list (stored in conc1.func_defaults[0] but you shouldn't touch that) alone. In conc2, you're modifying the list so the changed list is shared between calls of the function. From nagle at animats.com Wed Jan 18 13:24:09 2012 From: nagle at animats.com (John Nagle) Date: Wed, 18 Jan 2012 10:24:09 -0800 Subject: Please don't use "setuptools", the "rotten .egg" install system. Message-ID: <4f170e46$0$1659$742ec2ed@news.sonic.net> Please don't use "setuptools", the so-called "easy" installation system in your packages. It just makes things more complicated, adds dependencies, and needs too many weird options if things aren't exactly where it wants them. Since "setuptools" is non-standard, it has to be installed before installing other things. In particular, if you're using somepython setup.py install don't require setuptools. Setuptools isn't doing anything for anybody at that point. "egg" files are usually more trouble than they're worth. John Nagle From benjamin.kaplan at case.edu Wed Jan 18 13:30:00 2012 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 18 Jan 2012 13:30:00 -0500 Subject: Installing Python on CentOS 6 - a big pain In-Reply-To: <4f1708cc$0$1649$742ec2ed@news.sonic.net> References: <4f1708cc$0$1649$742ec2ed@news.sonic.net> Message-ID: On Wed, Jan 18, 2012 at 1:00 PM, John Nagle wrote: > ?It turns out that installing Python 2.7.2 on CentOS 6.0 is a lot of work. > ?Here are the official CentOS install instructions: > > http://www.centos.org/modules/newbb/viewtopic.php?topic_id=34515&forum=41 > > Not only do you have to build Python from source, you have to install > a lot of stuff before you can even build it. ?Then you have to install > various Python packages from multiple sources. ?Python doesn't work > with "yum"; you have to do it the hard way. > > I know how to do all this, but it takes hours. ?I'm bringing up > a bare dedicated server remotely, which is a routine operation. > > ? Python does not "just work". ?I should be able to command > "yum install python27". ?(And not clobber the Python 2.6 that > comes with CentOS.) > > ? This sort of thing is why Python is losing market share. > > > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?John Nagle > -- What does this have to do with Python? It's CentOS (and Red Hat's) decision not to provide a package for Python 2.7. It's not feasible for the Python community to provide a repository for each of the 200+ Linux distributions. The instructions for building Python are exactly the same as to build any other large project and there is absolutely nothing that we can do about that- you can't compile a program without a compiler and you can't link to other programs without the development headers. You'll have the exact same problems if you want to install gcc 4.6.2 unless some 3rd party has decided to build the rpm for you. From afylot at gmail.com Wed Jan 18 14:58:52 2012 From: afylot at gmail.com (simona bellavista) Date: Wed, 18 Jan 2012 11:58:52 -0800 (PST) Subject: scientific notation in legend (pylab) References: Message-ID: <36fed49d-b37d-48ae-a46c-182cee760e90@l1g2000vbc.googlegroups.com> thank you, I am trying to learn python, but I am having a hard to find a good introduction to it. On Jan 15, 3:27?am, Jason Friedman wrote: > > Not sure why legend annotations makes the problem different, but > perhaps this is a start: From goldtech at worldpost.com Wed Jan 18 15:06:04 2012 From: goldtech at worldpost.com (goldtech) Date: Wed, 18 Jan 2012 12:06:04 -0800 (PST) Subject: from PyQt4 import QtWebKit ImportError: DLL load failed Message-ID: <8bbe7c1c-4fc1-499d-afa9-c4cec6727330@v14g2000yqh.googlegroups.com> Hi, Using WinXP I installed PyQt from http://www.riverbankcomputing.co.uk/software/pyqt/download installation file: PyQt-Py2.7-x86-gpl-4.9-1 then tried: Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> from PyQt4 import QtWebKit Traceback (most recent call last): File "", line 1, in from PyQt4 import QtWebKit ImportError: DLL load failed: The specified procedure could not be found. >>> This is a common problem when I google it but I don't see a clear procedure for a fix. Any help appreciated. From user at example.net Wed Jan 18 15:16:49 2012 From: user at example.net (J.O. Aho) Date: Wed, 18 Jan 2012 21:16:49 +0100 Subject: Installing Python on CentOS 6 - a big pain In-Reply-To: <4f1708cc$0$1649$742ec2ed@news.sonic.net> References: <4f1708cc$0$1649$742ec2ed@news.sonic.net> Message-ID: <9nonliFk9lU1@mid.individual.net> John Nagle wrote: > It turns out that installing Python 2.7.2 on CentOS 6.0 is a lot of work. Here > are the official CentOS install instructions: > > http://www.centos.org/modules/newbb/viewtopic.php?topic_id=34515&forum=41 Don't see any official about the post, it's just another forum member who posts what he did to install a later version of Python than the default 2.6 that comes with RedHat EL (and those comes with CentOS). > Not only do you have to build Python from source, you have to install > a lot of stuff before you can even build it. To build a car, you need a lot of parts, and you need to build the engine too. If you are building something yourself, you need header files and gcc, no matter if it's python or something else you want, you need those things and lucky you that you don't have something like ms-windows, then you don't have a package manager which will install most of the things you need, you would need to hunt down everything yourself (I know ms-win has already compiled versions, but we are talking about compiling yourself). > Then you have to install > various Python packages from multiple sources. Python doesn't work > with "yum"; you have to do it the hard way. That's the life when you don't want to use what you are given for free, I'm sure someone would put up a repo for you if you paid them to compile python and all the modules for it. > I know how to do all this, but it takes hours. I'm bringing up > a bare dedicated server remotely, which is a routine operation. If you build your own RPMs, you can do that on your desktop machine, no need to do it on the underpowered VPS or really, you should have picked a distribution which gives you python 2.7 by default instead, just visit distrowatch.com and you can find at least one within two minutes. > Python does not "just work". I should be able to command > "yum install python27". (And not clobber the Python 2.6 that > comes with CentOS.) > > This sort of thing is why Python is losing market share. It's not Python developers fault that some distributions choose to stay with older versions of Python instead of switching to 3.2 at once, or that ms-win don't have python at all. If you want CentOS to have a newer python by default, then contact RedHat, but before they listen to you, you may need to get some RedHat licenses. -- //Aho From rantingrickjohnson at gmail.com Wed Jan 18 15:26:05 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 18 Jan 2012 12:26:05 -0800 (PST) Subject: Please don't use "setuptools", the "rotten .egg" install system. References: <4f170e46$0$1659$742ec2ed@news.sonic.net> Message-ID: <395a9e16-6dd3-4738-9f2a-9a7c356da383@34g2000yqm.googlegroups.com> On Jan 18, 12:24?pm, John Nagle wrote: > ? ?Please don't use "setuptools", the so-called "easy" > installation system in your packages. ?It just makes things > more complicated, adds dependencies, and needs too many weird > options if things aren't exactly where it wants them. ?Since > "setuptools" is non-standard, it has to be installed before > installing other things. > > In particular, if you're using > > ? ? ? ? somepython setup.py install > > don't require setuptools. ?Setuptools isn't doing anything > for anybody at that point. > > "egg" files are usually more trouble than they're worth. BIG PLUS ONE ON THIS! +1 From chris at simplistix.co.uk Wed Jan 18 16:02:33 2012 From: chris at simplistix.co.uk (Chris Withers) Date: Wed, 18 Jan 2012 21:02:33 +0000 Subject: python logging filter limitation, looks intentional? In-Reply-To: <1326797302.16852.YahooMailNeo@web25806.mail.ukl.yahoo.com> References: <4F1421C3.6060806@simplistix.co.uk> <1326726505.66259.YahooMailNeo@web25803.mail.ukl.yahoo.com> <4F146EFD.8090102@simplistix.co.uk> <1326756115.24713.YahooMailNeo@web25806.mail.ukl.yahoo.com> <4F151017.6020201@simplistix.co.uk> <1326797302.16852.YahooMailNeo@web25806.mail.ukl.yahoo.com> Message-ID: <4F173369.9010501@simplistix.co.uk> On 17/01/2012 10:48, Vinay Sajip wrote: >> From: Chris Withers > >> How breaking code? Configuration, maybe, but I can't see anyone being upset >> that filtering would begin working "the same as everything else". >> This just feels like a bug... > > Well, it means that filters that don't get called now would get called - and that's a change in behaviour. How about an option that defaults to "backwards compatibility mode" for Python 2.7, flipped the other way in 3.3? > It's not a bug, because it's like that by design. I understand that you don't agree with that particular design decision, but it's out there now. What you're asking for isn't unreasonable, but not achievable without a change in behaviour. See above ;-) > I don't want people to have to code differently for Python 3.3 and for older versions. I must stress again, we're talking about a configuration change, not a code change, given the massive changes people are going to have to make between 2 and 3 anyway, I don't think that's unreasonable... > True, but as I said earlier, you can attach a filter to your handlers. It's rather unlikely that you would have more than half-a-dozen handlers (since handlers ~= potential audiences for log events), Yeah, just feels a bit icky... >> Both use cases are valid, and a DelegatingHandler just feels like a hack to work >> around a deficiency in the framework... > > Rather, the approach I've taken is not to assume I'll meet everyone's needs out of the box, but that the right pieces are in place for people to use logging in useful ways in scenarios that I haven't thought of - which shortcomings might well be termed "deficiencies" according to your point of view - by deriving and overriding classes, or by composing using filters, or setting module-level flags. A module-level flag would be ideal :-) cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From malaclypse2 at gmail.com Wed Jan 18 16:28:12 2012 From: malaclypse2 at gmail.com (Jerry Hill) Date: Wed, 18 Jan 2012 16:28:12 -0500 Subject: Please don't use "setuptools", the "rotten .egg" install system. In-Reply-To: <4f170e46$0$1659$742ec2ed@news.sonic.net> References: <4f170e46$0$1659$742ec2ed@news.sonic.net> Message-ID: On Wed, Jan 18, 2012 at 1:24 PM, John Nagle wrote: > Please don't use "setuptools", the so-called "easy" > installation system in your packages. It just makes things > more complicated, adds dependencies, and needs too many weird > options if things aren't exactly where it wants them. Since > "setuptools" is non-standard, it has to be installed before > installing other things. > Please don't use any projects that are built with "setuptools" or "easy" installation systems. Problem solved. -- Jerry -------------- next part -------------- An HTML attachment was scrubbed... URL: From bthate at gmail.com Wed Jan 18 17:33:02 2012 From: bthate at gmail.com (Bart Thate) Date: Wed, 18 Jan 2012 14:33:02 -0800 (PST) Subject: GOZERBOT 1.0 RELEASED Message-ID: <15040551.3564.1326925982864.JavaMail.geo-discussion-forums@yqia35> I am proud ! Version 1.0 of GOZERBOT is here in the world. 7 years of evolutionary code development. The eagle has landed, the egg is layed See http://gozerbot.org - WELCOME TO GOZERBOT ? GOZERBOT v1.0.1 FINAL documentation WELCOME TO GOZERBOT?. I am pleased to present to you version 1.0 of GOZERBOT, a IRC and Jabber(XMPP) bot. This is the final and last release of GOZERBOT, new development will continue with the JSONBOT... From steve+comp.lang.python at pearwood.info Wed Jan 18 18:20:44 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Jan 2012 23:20:44 GMT Subject: unzip function? References: <4f16e4e7$0$29994$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f1753cc$0$29987$c3e8da3$5496439d@news.astraweb.com> On Wed, 18 Jan 2012 11:20:00 -0500, Devin Jeanpierre wrote: > On Wed, Jan 18, 2012 at 10:27 AM, Steven D'Aprano > wrote: >>> That zip (*sorted... >>> >>> does the unzipping. >>> >>> But it's less than intuitively obvious. >> >> *shrug* >> >> If you understand what zip does, it should be obvious. > > Nobody likes to be told the thing they're confused about is trivial. Nobody likes to be told to brush their teeth, eat their vegetables or clean their room. Then they grow up and learn that life is full of things that you do because you have to, not because you want to. Learning that some things that they are confused about are trivial is one of those things. > It's especially bad if nobody ever actually explains what's so simple > about it. Saying it's "almost its own inverse" is just restating the > original question -- yes, that's what it is, but why? (I have put my own > interpretation in a separate reply. ) Because that's the nature of the Universe. That's just the way the zip operation works. It is a little more complicated, but no more mysterious, than the idea that you don't need separate reverse() and unreverse() methods. If you reverse a list, and then reverse it again, you get back the original order. The only complication is that you can't just pass the result of zip back to zip directly, you have to use the unpack operator * to split the result "one sequence of N subsequences" into N separate arguments. But apart from that complication, if you zip a bunch of sequences, then zip it again, you get back the original order. You describe that as taking the transpose of a matrix, which is correct, but that just puts a name to it, it doesn't explain *why* taking the transpose twice gives you the original matrix. If you have a function that zips up items from multiple sequences, it takes the first item from each sequence and puts them together, then does the same thing with the second item from each sequence, the third item, and so forth: zip([a1, a2, a3, ...], [b1, b2, b3, ...], [c1, c2, c3, ...], ...) => [(a1, b1, c1, ...), (a2, b2, c2, ...), (a3, b3, c3, ...), ...] If you take that resulting list-of-sequences, expand it to separate arguments, and pass them to zip again: zip((a1, b1, c1, ...), (a2, b2, c2, ...), (a3, b3, c3, ...), ...) the zip function will zip the items up exactly in the same way, giving: [(a1, a2, a3, ...), (b1, b2, b3, ...), (c1, c2, c3, ...), ...] which naturally reverses the process. (Except that it returns a list of tuples instead of a list of lists.) -- Steven From steve+comp.lang.python at pearwood.info Wed Jan 18 18:32:35 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Jan 2012 23:32:35 GMT Subject: Installing Python on CentOS 6 - a big pain References: <4f1708cc$0$1649$742ec2ed@news.sonic.net> Message-ID: <4f175693$0$29987$c3e8da3$5496439d@news.astraweb.com> On Wed, 18 Jan 2012 10:00:47 -0800, John Nagle wrote: > This sort of thing is why Python is losing market share. Only on Planet Nagle. Do you have any evidence that Python actually *is* losing market share, or are you just trolling? -- Steven From marduk at letterboxes.org Wed Jan 18 19:03:44 2012 From: marduk at letterboxes.org (Albert W. Hopkins) Date: Wed, 18 Jan 2012 19:03:44 -0500 Subject: Installing Python on CentOS 6 - a big pain In-Reply-To: <4f1708cc$0$1649$742ec2ed@news.sonic.net> References: <4f1708cc$0$1649$742ec2ed@news.sonic.net> Message-ID: <1326931424.122821.3.camel@stretch.local> On Wed, 2012-01-18 at 10:00 -0800, John Nagle wrote: > Python does not "just work". I should be able to command > "yum install python27". (And not clobber the Python 2.6 that > comes with CentOS.) > > This sort of thing is why Python is losing market share. > > Or ? and this is the more likely scenario ? it could be that this has nothing to do with the Python language per s? and you are just playing the whiny snot-nosed kid. From tjreedy at udel.edu Wed Jan 18 19:50:29 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 18 Jan 2012 19:50:29 -0500 Subject: python logging filter limitation, looks intentional? In-Reply-To: <4F173369.9010501@simplistix.co.uk> References: <4F1421C3.6060806@simplistix.co.uk> <1326726505.66259.YahooMailNeo@web25803.mail.ukl.yahoo.com> <4F146EFD.8090102@simplistix.co.uk> <1326756115.24713.YahooMailNeo@web25806.mail.ukl.yahoo.com> <4F151017.6020201@simplistix.co.uk> <1326797302.16852.YahooMailNeo@web25806.mail.ukl.yahoo.com> <4F173369.9010501@simplistix.co.uk> Message-ID: On 1/18/2012 4:02 PM, Chris Withers wrote: > On 17/01/2012 10:48, Vinay Sajip wrote: > How about an option that defaults to "backwards compatibility mode" for > Python 2.7, flipped the other way in 3.3? 2.7 only gets bug fixes, and this does not seem to be one. >> It's not a bug, because it's like that by design. I understand that >> you don't agree with that particular design decision, but it's out >> there now. What you're asking for isn't unreasonable, but not >> achievable without a change in behaviour. > > See above ;-) > >> I don't want people to have to code differently for Python 3.3 and for >> older versions. This is not a general policy, else we would never add new features ;-) Do you plan to keep logging feature-frozen forever, or just for another release? (I actually think is a good idea to fix bugs, tests, and docs first.) -- Terry Jan Reedy From wuwei23 at gmail.com Wed Jan 18 22:10:43 2012 From: wuwei23 at gmail.com (alex23) Date: Wed, 18 Jan 2012 19:10:43 -0800 (PST) Subject: Installing Python on CentOS 6 - a big pain References: <4f1708cc$0$1649$742ec2ed@news.sonic.net> Message-ID: On Jan 19, 4:00?am, John Nagle wrote: > ? ?It turns out that installing Python 2.7.2 on CentOS 6.0 is a lot of > work. There must have been some radical changes between Centos 5 & 6, then, as building Python 2.7 from scratch took all of 10 minutes. > ?Here are the official CentOS install instructions: The person who posted that has the forum designation "Newbie". Those aren't the official anything. > Not only do you have to build Python from source, you have to install > a lot of stuff before you can even build it. ?Then you have to install > various Python packages from multiple sources. ?Python doesn't work > with "yum"; you have to do it the hard way. > > I know how to do all this, but it takes hours. So you're of course building an rpm as you go to prevent the need for you or anyone else having to do this again, right? You're not some selfish asshole who expects "The Python Community" to do everything for him, are you? > Python does not "just work". ?I should be able to command > "yum install python27". ?(And not clobber the Python 2.6 that > comes with CentOS.) If only someone had just recently boasted about being able to do just this and had built an rpm to prove it... > ? ? This sort of thing is why Python is losing market share. If Python is losing anything it's from the endless FUD spouted by yourself and others. From jason at powerpull.net Wed Jan 18 22:21:50 2012 From: jason at powerpull.net (Jason Friedman) Date: Wed, 18 Jan 2012 20:21:50 -0700 Subject: scientific notation in legend (pylab) In-Reply-To: <36fed49d-b37d-48ae-a46c-182cee760e90@l1g2000vbc.googlegroups.com> References: <36fed49d-b37d-48ae-a46c-182cee760e90@l1g2000vbc.googlegroups.com> Message-ID: > thank you, I am trying to learn python, but I am having a hard to find > a good introduction to it. Try this: http://docs.python.org/py3k/tutorial/ From steve+comp.lang.python at pearwood.info Wed Jan 18 23:36:01 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Jan 2012 04:36:01 GMT Subject: Installing Python on CentOS 6 - a big pain References: <4f1708cc$0$1649$742ec2ed@news.sonic.net> Message-ID: <4f179db1$0$14012$c3e8da3$76491128@news.astraweb.com> On Wed, 18 Jan 2012 19:10:43 -0800, alex23 wrote: > On Jan 19, 4:00?am, John Nagle wrote: >> ? ?It turns out that installing Python 2.7.2 on CentOS 6.0 is a lot >> ? ?of >> work. > > There must have been some radical changes between Centos 5 & 6, then, as > building Python 2.7 from scratch took all of 10 minutes. Reading between the lines, I guess that John has set up his Centos boxes without development tools. I've known sys admins like that: in an effort to "increase security" they take away dev tools so that anybody breaking in can't install anything underhanded, at least in theory. With all the tools installed, it's a matter of a few minutes effort to build from scratch: download the tar ball extract the contents of the file cd into the source directory run ./configure run make optionally run make test run sudo make altinstall As a total n00b who'd never used make before, it took me 25 minutes effort on my first attempt, including reading the entire README file (twice!). Now I have the whole process down to about 30 seconds effort, and six minutes elapsed time, on my laptop. But obviously you can't build from source without a compiler. So under those circumstances, it would be very difficult to build from source, as you need to install make, gcc, and who knows what other tools, and fight with the cryptic error messages generated until eventually it all Just Works. I hate to imagine how much effort would be involved. And I can't fathom why John imagines that this is Python's fault. -- Steven From nobody at nowhere.com Thu Jan 19 00:05:32 2012 From: nobody at nowhere.com (Nobody) Date: Thu, 19 Jan 2012 05:05:32 +0000 Subject: sys.argv as a list of bytes References: <20120118081612.13745187@bigfoot.com> <20120118111627.14d490ac@bigfoot.com> Message-ID: On Wed, 18 Jan 2012 09:05:42 +0100, Peter Otten wrote: >> Python has a special errorhandler, "surrogateescape" to deal with >> bytes that are not valid UTF-8. On Wed, 18 Jan 2012 11:16:27 +0100, Olive wrote: > But is it safe even if the locale is not UTF-8? Yes. Peter's reference to UTF-8 is misleading. The surrogateescape mechanism is used to represent anything which cannot be decoded according to the locale's encoding. E.g. in the "C" locale, any byte >= 128 will be encoded as a surrogate. On Wed, 18 Jan 2012 09:05:42 +0100, Peter Otten wrote: > It is still possible to get the original bytes: > > python3 -c'import sys; print(sys.argv[1].encode("utf-8", "surrogateescape"))' Except, it isn't. Because the Python dev's can't make up their mind which encoding sys.argv uses, or even document it. AFAICT: On Windows, there never was a bytes version of sys.argv to start with (the OS supplies the command line using wide strings). On Mac OS X, the command line is always decoded using UTF-8. On Unix, the command line is decoded using mbstowcs(). There isn't a Python function to query which encoding this used (if there even _is_ a corresponding Python encoding). Except on Windows (where OS APIs take wide string parameters), if a library function needs to pass a Unicode string to an API function, it will normally decode it using sys.getfilesystemencoding(), which isn't guaranteed to be the encoding which was used to fabricate sys.argv in the first place. In short: if you need to write "system" scripts on Unix, and you need them to work reliably, you need to stick with Python 2.x. From huayanghao at gmail.com Thu Jan 19 00:55:21 2012 From: huayanghao at gmail.com (Hua Yanghao) Date: Thu, 19 Jan 2012 13:55:21 +0800 Subject: Python Descriptor as Instance Attribute Message-ID: Hi all, Currently descriptors only work as class attribute, and doesn't work as a descriptor when it is an instance attribute. e.g. if we have descriptor class DescriptorTest, class Dummy(object): d = DescriptorTest() class Dummy2(object): def __init__(self): self.d = DescriptorTest() The instance of Dummy2 does not invoke the descriptor protocols on "d". Whereas Dummy() instances all share the same descriptor "d". Yes I know d.__get__() have an "instance" parameter which can be used to store per-instance values, but sometimes it is just not enough (or it is that I do not know a better approach exists). Suppose the below scenario, I want to model a "Register". A register is consist of some fields, which have different number of bits. e.g. a 32 bit register divided into 3 field, bit[0] to bit[7] is called M, bit[8] to bit[15] is called N, and bit[16] to bit[31] is called Z. I want to model a register that, when instantiated as "reg", reg.M/N/Z can directly reference each field, calling a descriptor protocol to verify and return the values. Yes, I know I can use metaclass to create a different class for different registers, but that's not seems to be a very smart approach here, as I want all register instances be of type "Register". But the default python protocol will not run descriptor protocols if a descriptor is an instance attribute. I'm sure I should not be the only one that facing this issue and I googled around and found a solution to redefine the __setattr__ and __getattribute__ to look up the descriptor protocols first: 107 def __getattribute__(self, name): 108 value = object.__getattribute__(self, name) 109 if hasattr(value, '__get__'): 110 value = value.__get__(self, self.__class__) 111 return value 112 113 def __setattr__(self, name, value): 114 try: 115 obj = object.__getattribute__(self, name) 116 except AttributeError: 117 pass 118 else: 119 if hasattr(obj, '__set__'): 120 return obj.__set__(self, value) 121 return object.__setattr__(self, name, value) This works like a charm and each instance of "Register" now invoke the descriptors properly. I just do not understand, why such behavior is not a default in python. Or, is there a better design pattern here? Thanks & Best Regards, Hua Yanghao From lagenar at gmail.com Thu Jan 19 02:01:52 2012 From: lagenar at gmail.com (Lucas Moauro) Date: Thu, 19 Jan 2012 04:01:52 -0300 Subject: Make never ends when compiling from source Message-ID: I'm trying to install Python 2.7 from source on Centos 6.0. When running make after first running ./configure successfully on the source directory, it performs the checks done by the configure step again in a loop, i.e: the checks are done infinitely many times, so the compiling process never starts. Does anyone know the cause of this behaviour and how to solve it? - Lucas -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Thu Jan 19 02:07:21 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 19 Jan 2012 00:07:21 -0700 Subject: Python Descriptor as Instance Attribute In-Reply-To: References: Message-ID: On Wed, Jan 18, 2012 at 10:55 PM, Hua Yanghao wrote: > I just do not understand, why such behavior is not a default in python. > Or, is there a better design pattern here? The behavior is by design. First, keeping object behavior in the class definition simplifies the implementation and also makes instance checks more meaningful. To borrow your Register example, if the "M" descriptor is defined by some instances rather than by the class, then knowing that the object "reg" is an instance of Register does not tell me anything about whether "reg.M" is a valid attribute or an error. As a result, I'll need to guard virtually every access of "reg.M" with a try-except construct just in case "reg" is the wrong kind of register. Second, the separation of class from instance also helps you keep object behavior separate from object data. Consider the following class: class ObjectHolder(object): def __init__(self, obj): self.obj = obj Don't worry about what this class might be useful for. Just know that it's meant to hold and provide unrestricted access to arbitrary Python objects: >>> holder = ObjectHolder(42) >>> print(holder.obj) 42 >>> holder.obj = range(5) >>> print(holder.obj) [0, 1, 2, 3, 4] Since the class is meant to hold arbitrary objects, it's even valid that somebody might want to store a descriptor object there: >>> holder.obj = property(lambda x: x.foo) >>> print(holder.obj) Now suppose that Python invoked the descriptor protocol for descriptors stored in instance attributes: >>> holder = ObjectHolder(None) >>> holder.obj = property(lambda x: x.foo) >>> print(holder.obj) Traceback (most recent call last): File "", line 1, in AttributeError: 'ObjectHolder' object has no attribute 'foo' In this case, the ObjectHolder would fail to simply hold the property object as data. The mere act of assigning the property object, a descriptor, to an instance attribute would *change the behavior* of the ObjectHolder. Instead of treating "holder.obj" as a simple data attribute, it would start invoking the descriptor protocol on accesses to "holder.obj" and ultimately redirect them to the non-existent and meaningless "holder.foo" attribute, which is certainly not what the author of the class intended. For the above reasons, I would probably implement your Register class as a set of related class sharing a common metaclass. The solution you came up with is probably fine to solve your specific problem, though. Cheers, Ian From lagenar at gmail.com Thu Jan 19 02:14:43 2012 From: lagenar at gmail.com (Lucas Moauro) Date: Thu, 19 Jan 2012 04:14:43 -0300 Subject: Make never ends when compiling from source In-Reply-To: References: Message-ID: Just found that the issue was that the clock was not set properly on the server. 2012/1/19 Lucas Moauro > I'm trying to install Python 2.7 from source on Centos 6.0. When running > make after first running ./configure successfully on the source directory, > it performs the checks done by the configure step again in a loop, i.e: the > checks are done infinitely many times, so the compiling process never > starts. > > Does anyone know the cause of this behaviour and how to solve it? > > - Lucas > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lele at metapensiero.it Thu Jan 19 03:56:57 2012 From: lele at metapensiero.it (Lele Gaifax) Date: Thu, 19 Jan 2012 09:56:57 +0100 Subject: Please don't use "setuptools", the "rotten .egg" install system. References: <4f170e46$0$1659$742ec2ed@news.sonic.net> Message-ID: <87ehuwqdd2.fsf@metapensiero.it> John Nagle writes: > "egg" files are usually more trouble than they're worth. I find it really funny you say so, just after another thread where you proved yourself unable to come up with a working Python environment lacking an already packaged RPM of version 2.7... I know "egg" are not standard, but these days are still the only way to install Python-related stuff that includes precompiled stuff, be it a Python module implemented in C, or a Pyjamas application, or simply .mo files containing gettext translations... *without* forcing the recipient to install all the needed "compiler chains". I really hope the distribute2 toolset will provide such nice capability. ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From shilparani9030 at gmail.com Thu Jan 19 04:32:27 2012 From: shilparani9030 at gmail.com (SHILPA) Date: Thu, 19 Jan 2012 01:32:27 -0800 (PST) Subject: HOT ACTRESS ROMANTIC PHOTOS & VIDEOS Message-ID: NIPPU MOVIE LATEST HOT STILLS http://actressgallery-kalyani.blogspot.com/2011/11/nippu-movie-stills.html KAJAL AGARWAL IN BUSINESSMAN MOVIE http://actressgallery-kalyani.blogspot.com/2012/01/kajal-agarwal-in-business-man.html LAKSHMI RAI LATEST STILLS http://actressgallery-kalyani.blogspot.com/2012/01/laksmi-rai-stills.html RITU KAUR LATEST PHOTO STILLS http://actressgallery-kalyani.blogspot.com/2012/01/ritu-kaur-stills.html SRIKANTH DEVARA MOVIE GALLERY http://actressgallery-kalyani.blogspot.com/2011/12/devaraya-movie-stills.html O MANASA MOVIE STILLS http://actressgallery-kalyani.blogspot.com/2011/12/o-manasa-movie-stills.html KULLUMANALI MOVIE STILLS http://actressgallery-kalyani.blogspot.com/2011/12/kullu-manali-movie-stills.html BUSINESSMAN MOVIE STILLS http://actressgallery-kalyani.blogspot.com/2011/12/businessman-movie-stills.html HOT ACTRESS BIKINI STILLS IN 2012 CALENDAR http://actressgallery-kalyani.blogspot.com/2011/12/2012-actress-calendar-wallpapers.html SAMANTHA SOUTHSCOPE HOT PHOTOS http://actressgallery-kalyani.blogspot.com/2011/12/samantha-at-south-scope-magazine.html DEEPIKA PADUKONE SPICY WALLPAPERS http://actressgallery-kalyani.blogspot.com/2011/12/deepika-padukone.html KATRINA KAIF LATEST HOT WALLPAPERS http://actressgallery-kalyani.blogspot.com/2011/12/katrina-kaif-wallpapers.html LOVE FAILURE MOVIE STILLS http://actressgallery-kalyani.blogspot.com/2011/12/love-failure-movie-stills.html 4FRIENDS MOVIE STILLS http://actressgallery-kalyani.blogspot.com/2011/12/4-friends-movie-stills.html NANDEESWARUDU MOVIE STILLS http://actressgallery-kalyani.blogspot.com/2011/12/nandeeswarudu-movie-stills.html HARI PRIYA HOT PHOTO STILLS http://actressgallery-kalyani.blogspot.com/2011/12/haripariya-actress.html SHRUTI HASSAN HOT IN 3 MOVIE http://actressgallery-kalyani.blogspot.com/2011/11/shruti-hassan-in-3-movie.html PANJA MOVIE LATEST STILLS http://actressgallery-kalyani.blogspot.com/2011/11/panja-movie-stills.html NIPPU MOVIE WORKING STILLS http://actressgallery-kalyani.blogspot.com/2011/11/nippu-movie-stills.html FOR FAST UPDATES IN FILM INDUSTRY KATRINA KAIF RARE PHOTOS http://allyouwants.blogspot.com/2011/12/katrina-kaif.html KAJAL AGARWAL LATEST STILLS http://allyouwants.blogspot.com/2011/03/kajal-latest-stills.html PRIYANKA CHOPRA LATEST HOT PHOTOSHOOT http://allyouwants.blogspot.com/2011/08/priyanka-chopra.html TAMIL ACTRESS HOT PHOTOS&VIDEOS http://allyouwants.blogspot.com/2011/08/tamil-actress.html FOR ONLY HOT GUYS SEE THIS SOUJANYA HOT PHOTO STILLS http://hotactress-kalyani.blogspot.com/2012/01/soujanya-hot.html LATEST HOT KATRINA KAIF PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/katrina-kaif-hot.html ANUSHKA LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/anushka-hot.html PRIYANKA TIWARI HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/12/priyanka-tiwari-hot.html TAMANNA LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/08/tamanna-hot.html PARUL HOT PHOTO STILLS http://hotactress-kalyani.blogspot.com/2011/12/parul-hot.html ADITI AGARWAL NEW ROMANTIC STILLS http://hotactress-kalyani.blogspot.com/2011/12/aditi-agarwal-hot.html PAYAL GHOSH HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/11/payal-ghosh-hot.html RAGINI DWIVEDI HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/12/ragini-dwivedi.html PARVATHI MELTON LATEST HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/11/parvathi-melton-hot.html SARAH JANE DIAS HOT PHOTOS http://hotactress-kalyani.blogspot.com/2011/11/sarah-jane-dias-hot.html KAJAL AGARWAL HOT SAREE STILLS http://hotactress-kalyani.blogspot.com/2011/11/kajal-agarwal-hot-in-saree.html POONAM KAUR HOT ROMANTIC STILLS http://hotactress-kalyani.blogspot.com/2011/11/poonam-kaur-hot.html From rosuav at gmail.com Thu Jan 19 04:43:23 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Jan 2012 20:43:23 +1100 Subject: Installing Python on CentOS 6 - a big pain In-Reply-To: <4f179db1$0$14012$c3e8da3$76491128@news.astraweb.com> References: <4f1708cc$0$1649$742ec2ed@news.sonic.net> <4f179db1$0$14012$c3e8da3$76491128@news.astraweb.com> Message-ID: On Thu, Jan 19, 2012 at 3:36 PM, Steven D'Aprano wrote: > With all the tools installed, it's a matter of a few minutes effort to > build from scratch: > > run ./configure > run make > run sudo make altinstall > > As a total n00b who'd never used make before, it took me 25 minutes > effort on my first attempt, including reading the entire README file > (twice!). Now I have the whole process down to about 30 seconds effort, > and six minutes elapsed time, on my laptop. The first time I built a Python 3, I didn't know about 'make altinstall', and managed to make something of a mess of my system (the default Python is 2.6.6 on Ubuntu, IIRC, and there are system scripts that don't work on Py3). But now, it's pretty easy, as yesterday can attest: I did a fresh install of Debian, starting at about 11AM, and by mid-afternoon everything was built and deployed. Most of that time was spent cloning about 8-10 source repositories (including one local one of "work stuff") and building stuff from source, and not one of the programs gave me any trouble. Python 3 was among them. Now, granted, this was Debian and I can't speak for Centos. But it would surprise me greatly if your package manager can't provide build essentials. ChrisA From wxjmfauth at gmail.com Thu Jan 19 05:40:44 2012 From: wxjmfauth at gmail.com (jmfauth) Date: Thu, 19 Jan 2012 02:40:44 -0800 (PST) Subject: sys.argv as a list of bytes References: <20120118081612.13745187@bigfoot.com> <20120118111627.14d490ac@bigfoot.com> Message-ID: > > In short: if you need to write "system" scripts on Unix, and you need them > to work reliably, you need to stick with Python 2.x. I think, understanding the coding of the characters helps a bit. I can not figure out how the example below could not be done on other systems. D:\tmp>chcp Page de codes active?: 1252 D:\tmp>c:\python32\python.exe sysarg.py a b ? ? \u0430 \u03b1 z arg: 1 unicode name: LATIN SMALL LETTER A arg: 2 unicode name: LATIN SMALL LETTER B arg: 3 unicode name: LATIN SMALL LETTER E WITH ACUTE arg: 4 unicode name: EURO SIGN arg: 5 unicode name: CYRILLIC SMALL LETTER A arg: 6 unicode name: GREEK SMALL LETTER ALPHA arg: 7 unicode name: LATIN SMALL LETTER Z jmf From jerome at jolimont.fr Thu Jan 19 05:44:55 2012 From: jerome at jolimont.fr (=?UTF-8?B?SsOpcsO0bWU=?=) Date: Thu, 19 Jan 2012 11:44:55 +0100 Subject: First python project : Tuner In-Reply-To: <20120117151601.78e495cb@bouzin.lan> References: <20120117151601.78e495cb@bouzin.lan> Message-ID: <20120119114455.3839bc29@bouzin.lan> Tue, 17 Jan 2012 15:16:01 +0100 J?r?me a ?crit: > Hi all. > > Like others before me, I'd like to show you my first python attempt, in the > hope in can get advices on how to improve my coding. Hi. Thank you for your useful advices. - I tried to clarify the dependencies of my program by adding "PyGObject (python-gi)." I believe PyGObject is the name, but python-gi being the name of the debian package (and possibly other distros' package, I didn't check), I assumed it would be more helpful. - Frequency is now displayed on the main window under each key (it was already displayed in the selector widget) - Pylint helped me improve a bit. Mostly conventions. And it still yields what I believe are false-positives. I didn't try to configure it not to. Thanks for telling me about Pylint. This tool is helpful. - I also corrected the "is" misuse as "==". - Most importantly, new 2.1 version comes with an absolutely pure french-free english-only screenshot, for your convenience. http://devs.jolimont.fr/tuner/ http://devs.jolimont.fr/tuner/downloads/tuner_v2_1.py.html -- J?r?me From steve+comp.lang.python at pearwood.info Thu Jan 19 05:47:35 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Jan 2012 10:47:35 GMT Subject: Installing Python on CentOS 6 - a big pain References: <4f1708cc$0$1649$742ec2ed@news.sonic.net> <4f179db1$0$14012$c3e8da3$76491128@news.astraweb.com> Message-ID: <4f17f4c7$0$29987$c3e8da3$5496439d@news.astraweb.com> On Thu, 19 Jan 2012 20:43:23 +1100, Chris Angelico wrote: > On Thu, Jan 19, 2012 at 3:36 PM, Steven D'Aprano > wrote: >> With all the tools installed, it's a matter of a few minutes effort to >> build from scratch: [...] > Now, granted, this was Debian and I can't speak for Centos. But it would > surprise me greatly if your package manager can't provide build > essentials. I daresay any decent package manager would be able to provide the complete tool chain for building Python from source. But I have no idea what tools are needed -- gcc and make, obviously, but what else? Maybe it really is as simple as "yum install gcc make", but I suspect that it won't be. "yum install gcc make yacc bison elephant weasel fox cow spam ham cheese chalk aardvark" perhaps. (I may have made one or two of those up.) Best of all, if the BOFH who built your system deliberately removed the package manager, what are you going to do then? :) But really, we're all just guessing here. Unless John Nagle decides to tell us, we have *no idea* why he found it so difficult to build from source. "No compiler tools" is just my guess. -- Steven From rosuav at gmail.com Thu Jan 19 06:05:53 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Jan 2012 22:05:53 +1100 Subject: Installing Python on CentOS 6 - a big pain In-Reply-To: <4f17f4c7$0$29987$c3e8da3$5496439d@news.astraweb.com> References: <4f1708cc$0$1649$742ec2ed@news.sonic.net> <4f179db1$0$14012$c3e8da3$76491128@news.astraweb.com> <4f17f4c7$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Jan 19, 2012 at 9:47 PM, Steven D'Aprano wrote: > I daresay any decent package manager would be able to provide the > complete tool chain for building Python from source. But I have no idea > what tools are needed -- gcc and make, obviously, but what else? Maybe it > really is as simple as "yum install gcc make", but I suspect that it > won't be. "yum install gcc make yacc bison elephant weasel fox cow spam > ham cheese chalk aardvark" perhaps. (I may have made one or two of those > up.) What I do is apt-get the most obvious things (g++/gcc and make, in this case), then run configure and see if it bombs, then run make and see if it bombs, and whenever there's a "command not found", attempt to apt-get that command as a package name. It usually works. Generally, if my boss (not as familiar with the commands as I, and prefers GUI tools where possible) asks me to set down exactly what I needed to do to get XYZ going, the notes end up looking pretty prohibitive, but it doesn't take long to guess your way through things. ChrisA From enalicho at gmail.com Thu Jan 19 06:08:28 2012 From: enalicho at gmail.com (Noah Hall) Date: Thu, 19 Jan 2012 11:08:28 +0000 Subject: Installing Python on CentOS 6 - a big pain In-Reply-To: <4f17f4c7$0$29987$c3e8da3$5496439d@news.astraweb.com> References: <4f1708cc$0$1649$742ec2ed@news.sonic.net> <4f179db1$0$14012$c3e8da3$76491128@news.astraweb.com> <4f17f4c7$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Jan 19, 2012 at 10:47 AM, Steven D'Aprano wrote: > On Thu, 19 Jan 2012 20:43:23 +1100, Chris Angelico wrote: > >> On Thu, Jan 19, 2012 at 3:36 PM, Steven D'Aprano >> wrote: >>> With all the tools installed, it's a matter of a few minutes effort to >>> build from scratch: > > [...] >> Now, granted, this was Debian and I can't speak for Centos. But it would >> surprise me greatly if your package manager can't provide build >> essentials. > > I daresay any decent package manager would be able to provide the > complete tool chain for building Python from source. But I have no idea > what tools are needed -- gcc and make, obviously, but what else? Maybe it > really is as simple as "yum install gcc make", but I suspect that it > won't be. "yum install gcc make yacc bison elephant weasel fox cow spam > ham cheese chalk aardvark" perhaps. (I may have made one or two of those > up.) I am fairly certain nobody would be silly enough to make a package called "gcc". "make", maybe, but not gcc. I mean, that's not even a real word! yum groupinstall "Development Tools" will probably do what the OP needs unless 6 no longer has it. From lists at cheimes.de Thu Jan 19 06:16:49 2012 From: lists at cheimes.de (Christian Heimes) Date: Thu, 19 Jan 2012 12:16:49 +0100 Subject: Installing Python on CentOS 6 - a big pain In-Reply-To: References: <4f1708cc$0$1649$742ec2ed@news.sonic.net> <4f179db1$0$14012$c3e8da3$76491128@news.astraweb.com> <4f17f4c7$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 19.01.2012 12:05, schrieb Chris Angelico: > What I do is apt-get the most obvious things (g++/gcc and make, in > this case), then run configure and see if it bombs, then run make and > see if it bombs, and whenever there's a "command not found", attempt > to apt-get that command as a package name. It usually works. Much easier: $ apt-get build-dep python In general the 'build-essential' package provides almost every part of the build chain (compilers, make, autotools, yacc & friends): $ apt-get install build-essential Christian From rosuav at gmail.com Thu Jan 19 06:27:33 2012 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Jan 2012 22:27:33 +1100 Subject: Installing Python on CentOS 6 - a big pain In-Reply-To: References: <4f1708cc$0$1649$742ec2ed@news.sonic.net> <4f179db1$0$14012$c3e8da3$76491128@news.astraweb.com> <4f17f4c7$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Jan 19, 2012 at 10:16 PM, Christian Heimes wrote: > Much easier: > > $ apt-get build-dep python In the specific case where that's available, it's fine. I've not gotten into the habit of trusting it, though, largely because a lot of what I compile _isn't_ in the package manager - otherwise I'd just apt-get the thing and save the trouble. (Although, more and more, I'm finding that I want to update to a version that isn't in Debian's repo - eg SciTE has had a LOT of new features since the version in repository - so I end up compiling from source still.) ChrisA From andrea.crotti.0 at gmail.com Thu Jan 19 08:12:22 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Thu, 19 Jan 2012 13:12:22 +0000 Subject: multiversion flag and auto requiring import hook Message-ID: <4F1816B6.4060708@gmail.com> I'm using the multiversion flag in setuptools (-m) to be able to run many different projects, without modifying the global environment. Then thanks to pkg_resources magic and setuptools I can get automatically everything loaded. Now the problem is that we want to be able to run tests. The best way would be to use python setup.py test, which would make everything needed for the tests available. The problem is that it's very slow to run and harder to integrate in Eclipse, so I created an import hook, that tries to do a pkg_resources.require first. The test runner should do something like with AutoRequire(): # run tests But now I'm fighting with nose and plugins, and I'm not sure this approach is really correct... Anyone has a better idea?? Here is the import hook for the auto_import... --8<---------------cut here---------------start------------->8--- class AutoRequireImport(object): """This require import automatically requires with pkg_resources all the modules that need to be imported. """ def find_module(self, module_name, package=None): #TODO: try to filter to only the important modules mod_parent = module_name.split('.')[0] try: find_module(mod_parent) except ImportError: try: pkg_resources.require(module_name) except pkg_resources.DistributionNotFound: logger.error("not able to require the module %s, you need to run a related project or develop the egg with dev_main" % mod_parent) #TODO: raise the right error to be catched from somewhere else? else: logger.info("%s required correctly" % mod_parent) class AutoRequire(object): """Context manager to enable and disable the auto-require import hook """ def __init__(self): self.ar = AutoRequireImport() def __enter__(self): logger.debug("enable the auto require import hook") sys.meta_path.append(self.ar) return self def __exit__(self, type, value, traceback): logger.debug("disable the auto require import hook") sys.meta_path.remove(self.ar) --8<---------------cut here---------------end--------------->8--- From andrea.crotti.0 at gmail.com Thu Jan 19 08:32:18 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Thu, 19 Jan 2012 13:32:18 +0000 Subject: multiversion flag and auto requiring import hook In-Reply-To: <4F1816B6.4060708@gmail.com> References: <4F1816B6.4060708@gmail.com> Message-ID: <4F181B62.8010508@gmail.com> ... Actually the main problem which I've been banging my head quite a few days alreays is this: --8<---------------cut here---------------start------------->8--- ERROR: Failure: AttributeError ('module' object has no attribute 'walk') ---------------------------------------------------------------------- Traceback (most recent call last): File "c:\python25\lib\site-packages\nose-0.10.3n1-py2.5-win32.egg\nose\loader. py", line 364, in loadTestsFromName addr.filename, addr.module) File "c:\python25\lib\site-packages\nose-0.10.3n1-py2.5-win32.egg\nose\importe r.py", line 39, in importFromPath return self.importFromDir(dir_path, fqname) File "c:\python25\lib\site-packages\nose-0.10.3n1-py2.5-win32.egg\nose\importe r.py", line 85, in importFromDir mod = load_module(part_fqname, fh, filename, desc) File "h:\git_projs\Psi\psi.devsonly\psi\devsonly\test\test_walk.py", line 3, i n import psi.devsonly.walk as w AttributeError: 'module' object has no attribute 'walk' --8<---------------cut here---------------end--------------->8--- On Windows using nosetests works perfectly, but using a very simple wrapper of nose as the following: --8<---------------cut here---------------start------------->8--- def egg_runner(self, eggpath): """Run all the tests in the given egg """ conf = Config() conf.verbosity = 3 ep = EclipseFriendlyPlugin() # how do I make sure the plugin is actually loaded and doing something? plugins = [ep] # and with this the verbosity should be set correctly # should use addplugins instead if they are not "default" plugins TestProgram(argv=argv[:1], config=conf, defaultTest=eggpath, plugins=plugins) --8<---------------cut here---------------end--------------->8--- Gives the above output, while on Linux they both work perfectly. I thought this was related to the AutoRequire hook, but I get the same problem even if I disable it.. Anyone ever saw something similar? Thanks From jeanpierreda at gmail.com Thu Jan 19 10:56:00 2012 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 19 Jan 2012 10:56:00 -0500 Subject: unzip function? In-Reply-To: <4f1753cc$0$29987$c3e8da3$5496439d@news.astraweb.com> References: <4f16e4e7$0$29994$c3e8da3$5496439d@news.astraweb.com> <4f1753cc$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jan 18, 2012 at 6:20 PM, Steven D'Aprano wrote: > On Wed, 18 Jan 2012 11:20:00 -0500, Devin Jeanpierre wrote: > Nobody likes to be told to brush their teeth, eat their vegetables or > clean their room. Then they grow up and learn that life is full of things > that you do because you have to, not because you want to. I don't tell my coworkers to brush their teeth, clean their room, and eat their vegetables. You aren't his daddy. Also, DBAD principle always applies. "I'm just telling you the truth" is the defense of bullies. It's not about telling the truth, it's about helping people. Or at least, I assume it is. > That's just the way the zip operation works. If you can't specifically explain it, who are you to tell others it's trivial? > Because that's the nature of the Universe. If I asked why 1*-1 has to be -1, and not 1, you could just say "that's the nature of the universe", but that's just dodging the question. Statements like these are theorems that can be proven. The fact that they have been proven in the past does not magically make them obvious. (You might think so now, but I distinctly remember a lot of confusion in grade school when negative numbers were first introduced. For me that confusion was never properly resolved until much later.) The proof itself is the explanation, together with the explanations for why the definitions make sense, and why each step in the proof makes sense, recursively until the person who doesn't know why this should be true is satisfied, or until the person is lost [in which case, need to do something more bottom-up; you can't teach somebody integration if they don't get multiplication]. If possible, intuitive analogies should be used. (Math is specifically designed around intuition as much as feasible.) In the case of 1*-1 = -1, the explanation is that the definition of "1" is that 1 * x = x, even if x is -1 [*] (this can be worded less algebraically, since whoever asks you this is probably 7 years old). Then one might ask, "well, why is that?", and then we must result to the intuitive explanation of what "one" is, and how we extend that to negative numbers (e.g. "take one step back" versus "one step forward"; "one backward step", etc.). The point is that of _course_ it's the nature of the universe. Every mathematical theorem follows from the definitions. That doesn't mean it's simple, and that doesn't mean it can't be explained. As a matter of fact it can be explained: I gave the explanation that made me "get it". I'm sure there are other ways of wording the idea, but "that's just the way the universe is" doesn't do anything for anyone except make one confused person feel a little worse. > The only complication is that you can't just pass the result of zip back > to zip directly, you have to use the unpack operator * to split the > result "one sequence of N subsequences" into N separate arguments. > > But apart from that complication, if you zip a bunch of sequences, then > zip it again, you get back the original order. You describe that as > taking the transpose of a matrix, which is correct, but that just puts a > name to it, it doesn't explain *why* taking the transpose twice gives you > the original matrix. I did more than just say "nyer it's the transpose", I explained what a transpose is and why it is that transpose is its own inverse. I think you're right in thinking my explanation was too short, though. Short version I already stated: the reason taking the transpose twice results in the original matrix is because exchanges rows and columns -- the columns of the transpose are the rows of the original. Exchanging twice leaves you with the original (the comparison with reverse is appropriate). Call the transpose of A t(*A). Each row of t(*t(*A)) is a column of t(*A), and each column of t(*A) is a row of A. so clearly every row of t(*t(*A)) is a row of A. I assert that there are also the same number of rows by the definition of the transpose (it only swaps, doesn't delete), so t(*t(*A)) is the same as A! [All the rows are the same, and there are the same number of rows <--> they are the same] At this point I have to explain that t = zip. We could do this by definition (ignoring that Python uses no such words), or we could do this by explaining how the docs for zip describe transpose, or we could say "compare it with transpose on several example matrices. The second option turns out to pan out better than expected: here is how Python defines zip: This function returns a list of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables. This is how wikipedia defines the transpose: Formally, the (i,j) element of A-Transpose is the (j,i) element of A. Wikipedia adds the "j" to explain that the elements in the rows are in the same order as the respective column in the original matrix. This is also implied in the zip definition, but not made explicitly clear. I assert that these are equivalent for matrices based on the above [zip includes an additional sentence addressing non-matrices], and based on perhaps a few manual experiments to verify that order is kept by zip(). The only issue left now is that you can pass things that aren't matrices into zip. zip has its own way of turning them into matrices, which results in information being cut out -- specifically, if we have a nested-sequence that doesn't really look like a rectangle (some rows are longer than others), it cuts it short to force it into the shape of a rectangle, treats this nested list as a matrix, returns the transpose of the matrix. So zip(*x) is really only almost its own inverse -- it's precisely its own inverse for matrices. -- Devin From rantingrickjohnson at gmail.com Thu Jan 19 11:32:35 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 19 Jan 2012 08:32:35 -0800 (PST) Subject: First python project : Tuner References: <20120117151601.78e495cb@bouzin.lan> Message-ID: <9eaa8919-fa16-4684-923f-ab0baab2e0e0@m2g2000vbc.googlegroups.com> On Jan 19, 4:44?am, J?r?me wrote: > - Most importantly, new 2.1 version comes with an absolutely pure french-free > ? english-only screenshot, for your convenience. Thanks for this update. However, i need to stress that while the English language is fundamental to writing Python code, we are not advocating doing away with French (or any other language) either. As long as you have an English screenshot you have met the expectations of this community. Feel free to add as many screen-shots in as many languages as required to serve your base. From nagle at animats.com Thu Jan 19 12:05:28 2012 From: nagle at animats.com (John Nagle) Date: Thu, 19 Jan 2012 09:05:28 -0800 Subject: Please don't use "setuptools", the "rotten .egg" install system. In-Reply-To: References: <4f170e46$0$1659$742ec2ed@news.sonic.net> Message-ID: <4f184d54$0$1714$742ec2ed@news.sonic.net> On 1/19/2012 12:56 AM, Lele Gaifax wrote: > John Nagle writes: > >> "egg" files are usually more trouble than they're worth. > > I find it really funny you say so, just after another thread where you > proved yourself unable to come up with a working Python environment > lacking an already packaged RPM of version 2.7... I can do it, I just have better things to do than system administration. The fact that Python doesn't "just work" is part of why it's losing market share. > I know "egg" are not standard, but these days are still the only way to > install Python-related stuff that includes precompiled stuff, be it a > Python module implemented in C, or a Pyjamas application, or simply > .mo files containing gettext translations... *without* forcing the > recipient to install all the needed "compiler chains". > > I really hope the distribute2 toolset will provide such nice capability. > > ciao, lele. If it can be built with "python setup.py build", go that way. A "setup.py" script, invoked with the correct Python, reliably knows which Python it is supposed to update. "egg" files usually have trouble with that. Prebuilt systems should use the installer for the distro, and work with yum, apt-get, or the Windows installer as appropriate. It does seem to be necessary to install the development tools on a Linux system just to get various Python packages to install. Major packages are still all over the place. PyPy is just a directory of links, not a repository like CPAN. Python sort of slips through the cracks. Nobody is doing the work to make PyPy handle these problems, and Python isn't important enough for MySQL, etc. to support the connector for the language. (They support Perl, C, Java, etc., but not Python.) John Nagle From andrea.crotti.0 at gmail.com Thu Jan 19 12:11:11 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Thu, 19 Jan 2012 17:11:11 +0000 Subject: importing and nose Message-ID: <4F184EAF.5080603@gmail.com> I'm writing some code to analyse pstats statistics, and I'm trying to have some working unit tests. Suppose I have in the test directory another directory 'profiling', which contains 'x.py', and 'b.py'. Now running the following code in a script works perfectly, class TestStatParser(unittest.TestCase): def setUp(self): self.temp_file = tempfile.mktemp() prof_path = path.join(path.dirname(__file__), 'profiling') sys.path.append(prof_path) import x profile.run('x.f1()', filename=self.temp_file) But running it within nose I get the following exec cmd in globals, locals File "", line 1, in NameError: name 'x' is not defined Which doesn't make sense to me, because the import doesn't actually fails, so how can x not be defined??? Any clue? From andrea.crotti.0 at gmail.com Thu Jan 19 12:21:54 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Thu, 19 Jan 2012 17:21:54 +0000 Subject: Please don't use "setuptools", the "rotten .egg" install system. In-Reply-To: <4f184d54$0$1714$742ec2ed@news.sonic.net> References: <4f170e46$0$1659$742ec2ed@news.sonic.net> <4f184d54$0$1714$742ec2ed@news.sonic.net> Message-ID: <4F185132.8010607@gmail.com> On 01/19/2012 05:05 PM, John Nagle wrote: > I can do it, I just have better things to do than system > administration. The fact that Python doesn't "just work" is > part of why it's losing market share. > Maybe in your home is losing market (if you're so sure post some sources). > If it can be built with "python setup.py build", go that way. > A "setup.py" script, invoked with the correct Python, reliably > knows which Python it is supposed to update. "egg" files > usually have trouble with that. > > Prebuilt systems should use the installer for the distro, and > work with yum, apt-get, or the Windows installer as appropriate. > > It does seem to be necessary to install the development tools > on a Linux system just to get various Python packages to install. > Major packages are still all over the place. > PyPy is just a directory of links, not a repository like CPAN. > > Python sort of slips through the cracks. Nobody is doing > the work to make PyPy handle these problems, and Python isn't > important enough for MySQL, etc. to support the connector for > the language. (They support Perl, C, Java, etc., but not > Python.) > > John Nagle An egg includes a python and OS version actually, and you're perfectly free to use your favourite distro-installer system. Someone cares if MySQL doesn't officially support Python when there are already perfectly working connectors? Most hardware vendors don't support Linux and Linux drivers often work way better than the Windows-equivalent (just to make an example). From __peter__ at web.de Thu Jan 19 12:36:27 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 19 Jan 2012 18:36:27 +0100 Subject: importing and nose References: <4F184EAF.5080603@gmail.com> Message-ID: Andrea Crotti wrote: > I'm writing some code to analyse pstats statistics, and I'm trying to > have some working unit tests. > Suppose I have in the test directory another directory 'profiling', > which contains 'x.py', and 'b.py'. > > Now running the following code in a script works perfectly, I don't believe you. > class TestStatParser(unittest.TestCase): > > def setUp(self): > self.temp_file = tempfile.mktemp() > prof_path = path.join(path.dirname(__file__), 'profiling') > sys.path.append(prof_path) > import x > profile.run('x.f1()', filename=self.temp_file) > > > But running it within nose I get the following > > exec cmd in globals, locals > File "", line 1, in > NameError: name 'x' is not defined > > > Which doesn't make sense to me, because the import doesn't actually > fails, so > how can x not be defined??? > > Any clue? profile.run() doesn't have access to the setUp() method's local namespace, it looks into the global (module) namespace. A stripped-down example: >>> import profile >>> def demo(): ... def foo(): print "local" ... profile.run("foo()") ... >>> demo() Traceback (most recent call last): File "", line 1, in File "", line 3, in demo File "/usr/lib/python2.6/profile.py", line 70, in run prof = prof.run(statement) File "/usr/lib/python2.6/profile.py", line 456, in run return self.runctx(cmd, dict, dict) File "/usr/lib/python2.6/profile.py", line 462, in runctx exec cmd in globals, locals File "", line 1, in NameError: name 'foo' is not defined >>> def foo(): ... print "global" ... >>> demo() global 4 function calls in 0.000 CPU seconds [snip] From andrea.crotti.0 at gmail.com Thu Jan 19 12:49:57 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Thu, 19 Jan 2012 17:49:57 +0000 Subject: importing and nose In-Reply-To: References: <4F184EAF.5080603@gmail.com> Message-ID: <4F1857C5.3040305@gmail.com> On 01/19/2012 05:36 PM, Peter Otten wrote: > > I don't believe you. Quite sure it does: [andrea at precision test]$ cat simple.py import profile from os import path import sys prof_path = path.join(path.dirname(__file__), 'profiling') sys.path.append(prof_path) import x profile.run('x.f1()') [andrea at precision test]$ cat simple.py import profile from os import path import sys prof_path = path.join(path.dirname(__file__), 'profiling') sys.path.append(prof_path) import x profile.run('x.f1()') [andrea at precision test]$ python2 simple.py 2005 function calls in 0.057 seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 1001 0.007 0.000 0.007 0.000 :0(range) 1 0.007 0.007 0.007 0.007 :0(setprofile) 1 0.000 0.000 0.050 0.050 :1() 1000 0.037 0.000 0.043 0.000 b.py:1(f2) 0 0.000 0.000 profile:0(profiler) 1 0.000 0.000 0.057 0.057 profile:0(x.f1()) 1 0.007 0.007 0.050 0.050 x.py:4(f1) But in general you're perfectly right, I forgot about this profile "issue", calling profile.runctx('x.f1()', locals=locals(), globals=globals()) works, even if maybe I don't even need to pass so much, but the x location would be enough.. Why does the simple example works then? From __peter__ at web.de Thu Jan 19 13:09:52 2012 From: __peter__ at web.de (Peter Otten) Date: Thu, 19 Jan 2012 19:09:52 +0100 Subject: importing and nose References: <4F184EAF.5080603@gmail.com> <4F1857C5.3040305@gmail.com> Message-ID: Andrea Crotti wrote: > On 01/19/2012 05:36 PM, Peter Otten wrote: >> >> I don't believe you. > > Quite sure it does: > > [andrea at precision test]$ cat simple.py > import profile > from os import path > import sys > > prof_path = path.join(path.dirname(__file__), 'profiling') > sys.path.append(prof_path) > import x > > > profile.run('x.f1()') > [andrea at precision test]$ cat simple.py > import profile > from os import path > import sys > > prof_path = path.join(path.dirname(__file__), 'profiling') > sys.path.append(prof_path) > import x > > > profile.run('x.f1()') > [andrea at precision test]$ python2 simple.py > 2005 function calls in 0.057 seconds > > Ordered by: standard name > > ncalls tottime percall cumtime percall filename:lineno(function) > 1001 0.007 0.000 0.007 0.000 :0(range) > 1 0.007 0.007 0.007 0.007 :0(setprofile) > 1 0.000 0.000 0.050 0.050 :1() > 1000 0.037 0.000 0.043 0.000 b.py:1(f2) > 0 0.000 0.000 profile:0(profiler) > 1 0.000 0.000 0.057 0.057 profile:0(x.f1()) > 1 0.007 0.007 0.050 0.050 x.py:4(f1) > > > > But in general you're perfectly right, I forgot about this profile > "issue", calling > profile.runctx('x.f1()', locals=locals(), globals=globals()) > works, even if maybe I don't even need to pass so much, but the x location > would be enough.. > > Why does the simple example works then? Because x is in __main__'s global namespace. And that is used as the default: def run(self, cmd): import __main__ dict = __main__.__dict__ return self.runctx(cmd, dict, dict) From diolu at bigfoot.com Thu Jan 19 13:19:50 2012 From: diolu at bigfoot.com (Olive) Date: Thu, 19 Jan 2012 19:19:50 +0100 Subject: "+=" does not work correct all alogn References: Message-ID: <20120119191950.7b908eee@bigfoot.com> On Wed, 18 Jan 2012 09:52:55 +0000 (GMT) Wilfried Falk wrote: > Hello Pythons, > ? > attached to this email is a pdf-file which shows, that? "+=" does not > work well all along. Mybe somebody of you is able to explain my > observations in this respect. I will be glad about an answer. Best > regards Wilfried I am not sure I understand your first question. For the second this is explained here: http://docs.python.org/tutorial/controlflow.html#default-argument-values In the first case, you create a new list from the empty list at each call. In the second case, you modify the argument in place and it is not reevaluated between calls. Olive From michael at stroeder.com Thu Jan 19 14:45:09 2012 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Thu, 19 Jan 2012 20:45:09 +0100 Subject: ANN: python-ldap 2.4.7 Message-ID: Find a new release of python-ldap: http://pypi.python.org/pypi/python-ldap/2.4.4 python-ldap provides an object-oriented API to access LDAP directory servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for that purpose. Additionally it contains modules for other LDAP-related stuff (e.g. processing LDIF, LDAPURLs and LDAPv3 schema). Project's web site: http://www.python-ldap.org/ Ciao, Michael. ---------------------------------------------------------------- Released 2.4.7 2012-12-19 Changes since 2.4.6: Lib/ * Separate classes for request/response controls for RFC 3829 * Fixed ldap.schema.subentry.SubSchema.attribute_types() to also eliminate double attribute types in MAY clause of DIT content rule Modules/ * Fixed memory leak (thanks to David Malcolm) ---------------------------------------------------------------- Released 2.4.6 2011-11-27 Changes since 2.4.5: Lib/ * ldap.controls.ppolicy: Another fix for decoding the password policy response control From jabba.laci at gmail.com Thu Jan 19 15:45:38 2012 From: jabba.laci at gmail.com (Jabba Laci) Date: Thu, 19 Jan 2012 21:45:38 +0100 Subject: verify the return value of a function Message-ID: Hi, In a unit test, I want to verify that a function returns a cookielib.LWPCookieJar object. What is the correct way of doing that? 1) First I tried to figure out its type with type(return_value) but it is 2) return_value.__class__ .__name__ gives 'LWPCookieJar', which is bettter 3) isinstance(return_value, cookielib.LWPCookieJar) seems to be the best way, however somewhere I read that using isinstance is discouraged Thanks, Laszlo From clp2 at rebertia.com Thu Jan 19 16:13:22 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 19 Jan 2012 13:13:22 -0800 Subject: verify the return value of a function In-Reply-To: References: Message-ID: On Thu, Jan 19, 2012 at 12:45 PM, Jabba Laci wrote: > Hi, > > In a unit test, I want to verify that a function returns a > cookielib.LWPCookieJar object. What is the correct way of doing that? > 3) isinstance(return_value, cookielib.LWPCookieJar) seems to be the > best way, however somewhere I read that using isinstance is > discouraged Explicit typechecking is often discouraged in favor of duck typing. However, if you want to do explicit typechecking (as one might in unit tests), then isinstance() is absolutely the technique to use. The alternative would be to check for the specific attributes of LWPCookieJar that you're relying upon (using hasattr() or similar), but that's probably overkill here. Cheers, Chris -- http://rebertia.com From benedict.verheyen at gmail.com Fri Jan 20 03:42:24 2012 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Fri, 20 Jan 2012 09:42:24 +0100 Subject: Wrong directory encoding when building a windows setup from Linux Message-ID: Hi, I have a suite of scripts that I develop on Debian Linux, python version 2.7.1 but the resulting server where the scripts are deployed to is Windows based. I struggled making my setup.py file include data I need for my testing suite, but in the end i succeeded by making a MANIFEST.in file containing "graft data" where data is the name of the directory containing my test data. Building an installable for Windows is easily done via python setup.py bdist_wininst So far so good; The data contains directories with non ascii characters like ?, ? and so on. Checking the build/lib/mypackage/data reveals that the names are still correct on Linux. However, on Windows, the directory names aren't correct any more, the special chars are replaced with other weird chars. If I extract the .exe file on Windows using 7 zip, I can see that the directories in there are already wrong. How can I fix this? Is there a way to specify what encoding the directory names are using and how do I specify this in the setup.py script? Thanks, Regards, Benedict From ulrich.eckhardt at dominolaser.com Fri Jan 20 04:15:54 2012 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Fri, 20 Jan 2012 10:15:54 +0100 Subject: verify the return value of a function In-Reply-To: References: Message-ID: Am 19.01.2012 21:45, schrieb Jabba Laci: > In a unit test, I want to verify that a function returns a > cookielib.LWPCookieJar object. What is the correct way of doing that? > > 1) First I tried to figure out its type with type(return_value) but it > is I'm not sure where the problem here is and where exactly you are seeing this. This might even indicate a problem with how the returned type is constructed. Anyhow: >>> x = 1 >>> type(x) >>> type(x) is int True So checking for an exact type should work using type(). > 2) return_value.__class__ .__name__ gives 'LWPCookieJar', which is bettter It doesn't cover namespaces though. Also, you should compare that to cookielib.LWPCookieJar.__name__, not 'LWPCookieJar'. What is the "LWP", btw? > 3) isinstance(return_value, cookielib.LWPCookieJar) seems to be the > best way, however somewhere I read that using isinstance is > discouraged. Never trust any such claim that doesn't give a justification. In your case, that would be the right thing to do, IMHO. Promising to return an LWPCookieJar is fulfilled when the returnvalue is of that type or a class derived from that, which variant 1 doesn't cover. Uli From benedict.verheyen at gmail.com Fri Jan 20 04:39:33 2012 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Fri, 20 Jan 2012 10:39:33 +0100 Subject: Installing Python on CentOS 6 - a big pain In-Reply-To: <4f179db1$0$14012$c3e8da3$76491128@news.astraweb.com> References: <4f1708cc$0$1649$742ec2ed@news.sonic.net> <4f179db1$0$14012$c3e8da3$76491128@news.astraweb.com> Message-ID: On 19/01/2012 5:36, Steven D'Aprano wrote: > On Wed, 18 Jan 2012 19:10:43 -0800, alex23 wrote: > > > download the tar ball > extract the contents of the file > cd into the source directory > run ./configure > run make > optionally run make test > run sudo make altinstall > > As a total n00b who'd never used make before, it took me 25 minutes > effort on my first attempt, including reading the entire README file > (twice!). Now I have the whole process down to about 30 seconds effort, > and six minutes elapsed time, on my laptop. > My first attempt to compile it on Debian took some extra steps, as Python didn't find the ncurses and and readline libs. But it was still easy to figure out how to build and install (locally) all the necessary packages. I leave the system installed python alone, and install the python version I built in $HOME/usr/local so I can later use this in a virtualenv. These are part of my notes from a while back so version might not be up to date anymore. 1. Compile zlib tar xzvf zlib-1.2.5.tar.gz cd zlib-1.2.5 ./configure --64 --prefix=$HOME/usr/local make make install 2. Compile readline tar xzvf readline-6.1.tar.gz ./configure --enable-shared --prefix=$HOME/usr/local make make install 3. Compile ncurses tar xzvf ncurses-5.7 ./configure --with-shared --enable-termcap --prefix=$HOME/usr/local make make install 4. Install Python from source tar xzvf Python-2.7.2.gz cd Python-2.7.2 export LDFLAGS="-L$HOME/usr/local" ./configure --enable-shared --prefix=$HOME/usr/local make make install If i need to install a new version of Python, as I happen to have done today, I only need to do step 4. Which is maybe 5 minutes of work. Cheers, Benedict From as at sci.fi Fri Jan 20 05:13:30 2012 From: as at sci.fi (Anssi Saari) Date: Fri, 20 Jan 2012 12:13:30 +0200 Subject: First python project : Tuner References: <20120117151601.78e495cb@bouzin.lan> Message-ID: J?r?me writes: > - I tried to clarify the dependencies of my program by adding > "PyGObject (python-gi)." > I believe PyGObject is the name, but python-gi being the name of the debian > package (and possibly other distros' package, I didn't check), I assumed it > would be more helpful. You might mention that Debian Stable (Squeeze) doesn't have a new enough PyGObject to run your code. There's no package python-gi and the version of python-gobject is 2.21.4+is.2.21.3-1. From jeanmichel at sequans.com Fri Jan 20 05:13:59 2012 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 20 Jan 2012 11:13:59 +0100 Subject: verify the return value of a function In-Reply-To: References: Message-ID: <4F193E67.70700@sequans.com> Jabba Laci wrote: > Hi, > > In a unit test, I want to verify that a function returns a > cookielib.LWPCookieJar object. What is the correct way of doing that? > > 1) First I tried to figure out its type with type(return_value) but it > is > > 2) return_value.__class__ .__name__ gives 'LWPCookieJar', which is bettter > > 3) isinstance(return_value, cookielib.LWPCookieJar) seems to be the > best way, however somewhere I read that using isinstance is > discouraged > > Thanks, > > Laszlo > isinstance is fine, if you could find the source where it is discouraged... Could be a consequence of some specific context. However, checking types in OOP is in general a failure. Unitary tests are possibly an exception. JM From as at sci.fi Fri Jan 20 06:42:32 2012 From: as at sci.fi (Anssi Saari) Date: Fri, 20 Jan 2012 13:42:32 +0200 Subject: Installing Python on CentOS 6 - a big pain References: <4f1708cc$0$1649$742ec2ed@news.sonic.net> <4f179db1$0$14012$c3e8da3$76491128@news.astraweb.com> Message-ID: Benedict Verheyen writes: > If i need to install a new version of Python, as I happen to have done today, > I only need to do step 4. Which is maybe 5 minutes of work. I don't really understand why you compile these common libraries (zlib, ncurses, readline) yourself instead of using the relevant libraries provided by your Debian system? Is it just that you didn't *know* Debian puts parts needed for compilation in separate packages so you'd need to install those first? From jasonkeddie at hotmail.com Fri Jan 20 08:52:33 2012 From: jasonkeddie at hotmail.com (jasonkeddie at hotmail.com) Date: Fri, 20 Jan 2012 05:52:33 -0800 (PST) Subject: C++ and Embedded Python Message-ID: Is there a method to allow a pointer to an object in local memory to be shared with embedded Python within a C++ executable? The reason I require this is I have a C++ instance of a class that has data memers that are themeselves pointers to other object types. It is a fairly complicated object. In an ideal world I would just pass this pointer into an instance of the Python interpreter. This would allow the python program access and change some properties of this object instance, then pass it back to the calling C++ program. I would use this same system to pass messages between the C++ (calling program) and the embedded Python interpreter. I have looked at using shared memory, which will work until you require embedded pointers within your object as you cannot dynamically allocate memory in a shared space. Any help is much appreciated. From mwilson at the-wire.com Fri Jan 20 08:53:13 2012 From: mwilson at the-wire.com (Mel Wilson) Date: Fri, 20 Jan 2012 08:53:13 -0500 Subject: verify the return value of a function References: Message-ID: Jean-Michel Pichavant wrote: > isinstance is fine, if you could find the source where it is > discouraged... Could be a consequence of some specific context. > However, checking types in OOP is in general a failure. Unitary tests > are possibly an exception. I think it's discouraged when people try to write big overloaded functions that check the types of the arguments to decide what they should be doing. In diagnostics and tests like the OP's there should be no problem. Mel. From roy at panix.com Fri Jan 20 09:24:04 2012 From: roy at panix.com (Roy Smith) Date: Fri, 20 Jan 2012 09:24:04 -0500 Subject: verify the return value of a function References: Message-ID: In article , Jabba Laci wrote: > Hi, > > In a unit test, I want to verify that a function returns a > cookielib.LWPCookieJar object. What is the correct way of doing that? jar = my_function_being_tested() self.assertIsInstance(jar, cookielib.LWPCookieJar) That works in 2.7. If you're using something older than 2.7, you'll need to do: self.assertTrue(isinstance(jar, cookielib.LWPCookieJar) Alternatively, just download the 2.7 version of unittest and use that (it works fine with 2.6, not sure about earlier than that). > 3) isinstance(return_value, cookielib.LWPCookieJar) seems to be the > best way, however somewhere I read that using isinstance is > discouraged Where did you read that, and in what context? Compared to type(), isinstance() is an improvement because it correctly handles subclasses. If you want a LWPCookieJar, you should be happy to have somebody give you a subclass of LWPCookieJar (assuming they correctly implemented the interface). Thus says the Church of Most Corpulent Staticness and Type Bondage. On the other hand, there are some (adherents of the Most Holy and Loquacious Church of Duck Typing) who would say that testing for class at all is a sin, and what you want to do is test that the object being tested has the methods and attributes you expect. Me, I'm somewhere in between. I believe that pinching it and seeing what the quack sounds like is usually the right thing to do. On the other hand, if you want to demand to see its Certificate of Duckiness, you have a right to do that too. From skip at montanaro.dyndns.org Fri Jan 20 09:42:16 2012 From: skip at montanaro.dyndns.org (Skip Montanaro) Date: Fri, 20 Jan 2012 08:42:16 -0600 (CST) Subject: subprocess module and long-lived subprocesses Message-ID: <20120120144217.26BE026FC934@montanaro.dyndns.org> I'm converting some os.popen calls to use subprocess.Popen. I had previously been ignoring stdout and stderr when using os.popen. The primary motivation to switch to subprocess.Popen now is that I now want to check stderr, so would have to make code changes to use os.popen[34] anyway. Might as well go whole hog and switch to the new API. The library documentation doesn't talk a lot about long-lived subprocesses other than the possibility of deadlock when using Popen.wait(). Ideally, I would write to the subprocess's stdin, check for output on stdout and stderr, then lather, rinse, repeat. Is it safe to assume that if the stdout and/or stderr pipes have nothing for me the reads on those file objects (I'm using PIPE for all three std* files) will return immediately with an empty string for output? They won't block, will they? Will a broken pipe IOError get raised as for os.popen() or do I have to call Popen.poll() even in error situations? Thanks, -- Skip Montanaro - skip at pobox.com - http://www.smontanaro.net/ From steve+comp.lang.python at pearwood.info Fri Jan 20 10:07:28 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Jan 2012 15:07:28 GMT Subject: verify the return value of a function References: Message-ID: <4f198330$0$29987$c3e8da3$5496439d@news.astraweb.com> On Fri, 20 Jan 2012 08:53:13 -0500, Mel Wilson wrote: > Jean-Michel Pichavant wrote: > >> isinstance is fine, if you could find the source where it is >> discouraged... Could be a consequence of some specific context. >> However, checking types in OOP is in general a failure. Unitary tests >> are possibly an exception. > > I think it's discouraged when people try to write big overloaded > functions that check the types of the arguments to decide what they > should be doing. I don't agree with that. Writing polymorphic functions using isinstance is a perfectly reasonable thing to do. E.g. from the standard library's decimal module: class Decimal(object): """Floating point class for decimal arithmetic.""" # We're immutable, so use __new__ not __init__ def __new__(cls, value="0", context=None): self = object.__new__(cls) # From a string # REs insist on real strings, so we can too. if isinstance(value, str): ... # From an integer if isinstance(value, int): ... # From another decimal if isinstance(value, Decimal): ... # From an internal working value if isinstance(value, _WorkRep): ... # tuple/list conversion (possibly from as_tuple()) if isinstance(value, (list,tuple)): ... if isinstance(value, float): ... raise TypeError("Cannot convert %r to Decimal" % value) What should be avoided, when possible, is over-reliance on isinstance checks instead of protocol or interface checks. For example, don't check for a list if your function doesn't *need* a list but would be happy with a tuple or some other sequence. Worse than isinstance is testing for an exact type: if type(x) is list # worse than isinstance(x, list) although of course, there are times where you need to break the rules. > In diagnostics and tests like the OP's there should be > no problem. Agreed. -- Steven From mcfletch at vrplumber.com Fri Jan 20 10:28:57 2012 From: mcfletch at vrplumber.com (Mike C. Fletcher) Date: Fri, 20 Jan 2012 10:28:57 -0500 Subject: subprocess module and long-lived subprocesses In-Reply-To: <20120120144217.26BE026FC934@montanaro.dyndns.org> References: <20120120144217.26BE026FC934@montanaro.dyndns.org> Message-ID: <4F198839.2090806@vrplumber.com> On 12-01-20 09:42 AM, skip at pobox.com wrote: > I'm converting some os.popen calls to use subprocess.Popen. I had > previously been ignoring stdout and stderr when using os.popen. The primary > motivation to switch to subprocess.Popen now is that I now want to check > stderr, so would have to make code changes to use os.popen[34] anyway. > Might as well go whole hog and switch to the new API. > > The library documentation doesn't talk a lot about long-lived subprocesses > other than the possibility of deadlock when using Popen.wait(). Ideally, I > would write to the subprocess's stdin, check for output on stdout and > stderr, then lather, rinse, repeat. Is it safe to assume that if the stdout > and/or stderr pipes have nothing for me the reads on those file objects (I'm > using PIPE for all three std* files) will return immediately with an empty > string for output? They won't block, will they? Will a broken pipe IOError > get raised as for os.popen() or do I have to call Popen.poll() even in error > situations? > > Thanks, > Definitely *will* block, you have to explicitly set them non-blocking to have non-blocking behaviour: def set_nb( fh ): """Set non-blocking flag on given file handle""" if isinstance( fh, int ) or hasattr( fh, 'fileno' ): flags = fcntl.fcntl(fh, fcntl.F_GETFL) fcntl.fcntl(fh, fcntl.F_SETFL, flags| os.O_NONBLOCK) on each of the 3 buffers, then you need to attempt read/write on each of them periodically, catching the EWOULDBLOCK errors, to prevent deadlocks where the buffers have filled up (e.g. because the subprocess is printing out errors on stderr, or because it is generating output, or because for some reason the process isn't reading your input fast enough). I think everyone winds up with their own wrapper around subprocess after they use it for more than a short period... HTH, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From ian.g.kelly at gmail.com Fri Jan 20 10:30:22 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 20 Jan 2012 08:30:22 -0700 Subject: verify the return value of a function In-Reply-To: References: Message-ID: On Fri, Jan 20, 2012 at 2:15 AM, Ulrich Eckhardt < ulrich.eckhardt at dominolaser.com> wrote: > Am 19.01.2012 21:45, schrieb Jabba Laci: > > In a unit test, I want to verify that a function returns a >> cookielib.LWPCookieJar object. What is the correct way of doing that? >> >> 1) First I tried to figure out its type with type(return_value) but it >> is >> > > I'm not sure where the problem here is and where exactly you are seeing > this. This might even indicate a problem with how the returned type is > constructed. > This just means that LWPCookieJar is an old-style class: >>> class Foo: pass ... >>> type(Foo()) >>> Foo().__class__ So for type checks here the __class__ attribute should be used, not the type function. isinstance is better for instance checks though in either case. Cheers, Ian -------------- next part -------------- An HTML attachment was scrubbed... URL: From hugol at fastmail.net Fri Jan 20 10:35:56 2012 From: hugol at fastmail.net (=?ISO-8859-1?Q?Hugo=20L=E9veill=E9?=) Date: Fri, 20 Jan 2012 10:35:56 -0500 Subject: Changing interpolation Message-ID: <1327073756.11445.140661025890269@webmail.messagingengine.com> Another quick question this morning Does anyone have the syntax to change keyframe interpolation of a curve ? For exemple, I am trying to change the curve of the translate of a camera using this and it does not do much nuke.selectedNode().knobs()['translate'].animations()[0].changeInterpolation( nuke.selectedNode().knobs()['translate'].animations()[0].keys() , nuke.CONSTANT) -- Hugo L?veill? TD Compositing, Vision Globale hugol at fastmail.net From andrea.crotti.0 at gmail.com Fri Jan 20 10:44:17 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Fri, 20 Jan 2012 15:44:17 +0000 Subject: Is a with on open always necessary? Message-ID: <4F198BD1.4040301@gmail.com> I normally didn't bother too much when reading from files, and for example I always did a content = open(filename).readlines() But now I have the doubt that it's not a good idea, does the file handler stays open until the interpreter quits? So maybe doing a with open(filename) as f: contents = f.readlines() is always a better idea?? From justin.simms at gmail.com Fri Jan 20 10:49:31 2012 From: justin.simms at gmail.com (Justin Simms) Date: Fri, 20 Jan 2012 10:49:31 -0500 Subject: Is a with on open always necessary? In-Reply-To: <4F198BD1.4040301@gmail.com> References: <4F198BD1.4040301@gmail.com> Message-ID: As I understand it, with gives you a cleaner way of doing the following steps: 1) pre processing 2) actual work 3) post processing, where the __enter__ and __exit__ methods are used to take care of 1 and 3. So with is not always necessary, but it is the preferred was to do things like file processing, since the file object and other already have the context manager protocol in place (which is when the object being used in the with expression has implementations of __with__ and __exit__) . I have just learned about it myself , so hopefully if I am not accurate someone more experienced can provide you with more detail. On Fri, Jan 20, 2012 at 10:44 AM, Andrea Crotti wrote: > I normally didn't bother too much when reading from files, and for example > I always did a > > content = open(filename).readlines() > > But now I have the doubt that it's not a good idea, does the file handler > stays > open until the interpreter quits? > > So maybe doing a > > with open(filename) as f: > contents = f.readlines() > > is always a better idea?? > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at gmail.com Fri Jan 20 10:56:26 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 20 Jan 2012 15:56:26 +0000 Subject: Is a with on open always necessary? In-Reply-To: <4F198BD1.4040301@gmail.com> References: <4F198BD1.4040301@gmail.com> Message-ID: On 20 January 2012 15:44, Andrea Crotti wrote: > I normally didn't bother too much when reading from files, and for example > I always did a > > content = open(filename).readlines() > > But now I have the doubt that it's not a good idea, does the file handler > stays > open until the interpreter quits? IIRC it stays open until garbage collected (it's closed in the file object's __del__ method). When the file object is collected is an implementation detail, although in CPython it will happen straight away because it uses reference counting. > So maybe doing a > > with open(filename) as f: > ? ? contents = f.readlines() That's what I do, unless I'm in an interactive session. -- Arnaud From clp2 at rebertia.com Fri Jan 20 11:16:31 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 20 Jan 2012 08:16:31 -0800 Subject: Changing interpolation In-Reply-To: <1327073756.11445.140661025890269@webmail.messagingengine.com> References: <1327073756.11445.140661025890269@webmail.messagingengine.com> Message-ID: On Fri, Jan 20, 2012 at 7:35 AM, Hugo L?veill? wrote: > Another quick question this morning > > Does anyone have the syntax to change keyframe interpolation of a curve > ? > > For exemple, I am trying to change the curve of the translate of a > camera using this and it does not do much > > nuke.selectedNode().knobs()['translate'].animations()[0].changeInterpolation( > nuke.selectedNode().knobs()['translate'].animations()[0].keys() , > nuke.CONSTANT) This is in apparently in reference to http://www.thefoundry.co.uk/products/nuke/ ? When asking questions about 3rd-party libs, it's best to clarify up front which one you're talking about. Cheers, Chris From torriem at gmail.com Fri Jan 20 11:20:03 2012 From: torriem at gmail.com (Michael Torrie) Date: Fri, 20 Jan 2012 09:20:03 -0700 Subject: Please don't use "setuptools", the "rotten .egg" install system. In-Reply-To: <4f184d54$0$1714$742ec2ed@news.sonic.net> References: <4f170e46$0$1659$742ec2ed@news.sonic.net> <4f184d54$0$1714$742ec2ed@news.sonic.net> Message-ID: <4F199433.2030000@gmail.com> On 01/19/2012 10:05 AM, John Nagle wrote: > I can do it, I just have better things to do than system > administration. The fact that Python doesn't "just work" is > part of why it's losing market share. Yes you keep saying that. Of course you are complaining on the wrong list. You should be bugging Red Hat about the Python 2.7 thing (after all you pay them for support, right?). Whining about it here is just silly. > Python sort of slips through the cracks. Nobody is doing > the work to make PyPy handle these problems, and Python isn't > important enough for MySQL, etc. to support the connector for > the language. (They support Perl, C, Java, etc., but not > Python.) Supporting C is all they need to do in this case. Python works just fine with C libraries. I have used python with MySQL a fair amount in my previous job. The DB-API interface worked quite well and I found PostgreSQL and MySQL drivers that worked quite nicely. I'm not sure what you think is missing. Maybe you are whining about Python not shipping with the MySQL connector directly. Again, though this is a problem best solved at the distribution level as Python cannot possibly ship binary MySQL libraries for every variation of OS and MySQL client library version. I know the propensity of people on this list is to support and defend Python from any criticism, but in this case such defense seems justified. From rcarlson.cs at gmail.com Fri Jan 20 11:38:17 2012 From: rcarlson.cs at gmail.com (Richard Carlson) Date: Fri, 20 Jan 2012 10:38:17 -0600 Subject: Extending PyGTK widgets with Glade Message-ID: I'm working on a program using PyGTK and Glade. I create a glade XML file using Glade Designer and then load widgets like this: class MyDialog: def __init__(self): self.dialog = gtk.glade.XML(self.GLADEFILE).get_widget ("dialog.xml") I think it would be better if I extended the Dialog class, but I can't figure out how to do it. I'd like to do something like this: class MyDialog(gtk.Dialog): def __init__(self): self = gtk.glade.XML(self.GLADEFILE).get_widget("example_dialog") Can someone point me in the right direction? Thanks, Richard From stefan_ml at behnel.de Fri Jan 20 12:17:50 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 20 Jan 2012 18:17:50 +0100 Subject: C++ and Embedded Python In-Reply-To: References: Message-ID: jasonkeddie at hotmail.com, 20.01.2012 14:52: > Is there a method to allow a pointer to an object in local memory to > be shared with embedded Python within a C++ executable? > > The reason I require this is I have a C++ instance of a class that has > data memers that are themeselves pointers to other object types. It is > a fairly complicated object. > In an ideal world I would just pass this pointer into an instance of > the Python interpreter. This would allow the python program access and > change some properties of this object instance, then pass it back to > the calling C++ program. I would use this same system to pass messages > between the C++ (calling program) and the embedded Python interpreter. > > I have looked at using shared memory, which will work until you > require embedded pointers within your object as you cannot dynamically > allocate memory in a shared space. Do I understand correctly that you only have one instance of a Python runtime, embedded in a C++ program? If that's the case, I don't see the problem. Just create an extension type to model your API towards the C++ objects and pass data back and forth. Cython will make that easy. I specifically do not see why you would care about shared memory here. If both parts of the application (i.e. Python code and C++ code) are in the same process, they will usually be able to access the same memory without any special setup. If I misunderstood your intention, please provide more details, including the steps you undertook so far and a specific description of what didn't work. You may also want to provide some hints on what kind of data you want to exchange and what both sides will do with it. Stefan From rustompmody at gmail.com Fri Jan 20 12:32:25 2012 From: rustompmody at gmail.com (rusi) Date: Fri, 20 Jan 2012 09:32:25 -0800 (PST) Subject: Installing Python on CentOS 6 - a big pain References: <4f1708cc$0$1649$742ec2ed@news.sonic.net> <4f179db1$0$14012$c3e8da3$76491128@news.astraweb.com> Message-ID: On Jan 20, 2:39?pm, Benedict Verheyen wrote: > On 19/01/2012 5:36, Steven D'Aprano wrote: > > > > > > > > > On Wed, 18 Jan 2012 19:10:43 -0800, alex23 wrote: > > > > > download the tar ball > > extract the contents of the file > > cd into the source directory > > run ./configure > > run make > > optionally run make test > > run sudo make altinstall > > > As a total n00b who'd never used make before, it took me 25 minutes > > effort on my first attempt, including reading the entire README file > > (twice!). Now I have the whole process down to about 30 seconds effort, > > and six minutes elapsed time, on my laptop. > > > > My first attempt to compile it on Debian took some extra steps, > as Python didn't find the ncurses and and readline libs. > But it was still easy to figure out how to build and install (locally) all > the necessary packages. > I leave the system installed python alone, and install the python version > I built in $HOME/usr/local so I can later use this in a virtualenv. > > These are part of my notes from a while back so version might not be > up to date anymore. > > 1. Compile zlib > tar xzvf zlib-1.2.5.tar.gz > cd zlib-1.2.5 > ./configure --64 --prefix=$HOME/usr/local > make > make install > > 2. Compile readline > tar xzvf readline-6.1.tar.gz > ./configure --enable-shared --prefix=$HOME/usr/local > make > make install > > 3. Compile ncurses > tar xzvf ?ncurses-5.7 > ./configure --with-shared --enable-termcap --prefix=$HOME/usr/local > make > make install If you apt-get the foll libncurses5-dev libreadline6-dev zlib1g-dev the first three steps should not be necessary. In general apt-get build-dep python2.7 will list out (a superset of) what python2.7 needs. > > 4. Install Python from source > tar xzvf Python-2.7.2.gz > cd Python-2.7.2 > export LDFLAGS="-L$HOME/usr/local" > ./configure --enable-shared --prefix=$HOME/usr/local > make > make install > > If i need to install a new version of Python, as I happen to have done today, > I only need to do step 4. Which is maybe 5 minutes of work. > > Cheers, > Benedict From skip at pobox.com Fri Jan 20 13:45:25 2012 From: skip at pobox.com (skip at pobox.com) Date: Fri, 20 Jan 2012 12:45:25 -0600 (CST) Subject: subprocess module and long-lived subprocesses Message-ID: <20120120184525.E4B9D26FE032@montanaro.dyndns.org> (Apologies for the non-threaded reply. My subscription to the list is currently set to no-mail and I can't get to gmane.org, so have no clean way to reply...) Mike Fletcher wrote: > Definitely *will* block, you have to explicitly set them non-blocking to > have non-blocking behaviour: ... > .... I think everyone winds up with their own wrapper around subprocess > after they use it for more than a short period... Thanks, that saves me much head scratching. Skip From tamannas.rahman at gmail.com Fri Jan 20 13:49:03 2012 From: tamannas.rahman at gmail.com (Tamanna Sultana) Date: Fri, 20 Jan 2012 10:49:03 -0800 (PST) Subject: can some one help me with my code. thanks Message-ID: can some one help me?? > I would like to create a function that, given a bin, which is a list > (example below), generates averages for the numbers separated by a > string 'end'. I am expecting to have 4 averages from the above bin, > since there are 4 sets of numbers separated by 4 'end' strings > ['2598.95165', '2541.220308', '221068.0401', 'end', '4834.581952', > '1056.394859', '3010.609563', '2421.437603', '4619.861889', > '746.040504', '268.3881793', '379.3934898', '1252.527752', > '11459.88522', '4862.167506', '506.924289', '634.6737389', > '496.4679199', '17941.59143', '919.4998935', '7247.610974', > '1166.053214', '47360.91508', '855.2426137', '4020.444585', > '4469.896904', '2615.874982', '19862.92009', '2379.619573', > '1203.268956', '4399.589212', '6838.825864', '1848.407564', > '3527.198403', '33976.85042', '818.8722263', '634.6652078', > '469.2685928', '4864.830004', '5103.222941', '1011.239929', > '829.9915382', '8571.237936', '3301.953656', '14594.47385', > '25688.83822', '4024.393045', '4163.775185', '1775.894366', > '3682.012227', '3371.092883', '6651.509488', '7906.092773', > '7297.133447', 'end', '4566.874299', 'end', '4255.700077', > '1857.648393', '11289.48095', '2070.981805', '1817.505094', > '1892.256615', '1757.0048', '59458.46328', '778.5755201', '54987.32423', > '2245.172711', '722.2619663', '5116.616632', '3427.865861', > '17973.07118', '14398.74281', '66313.92115', '11585.24151', > '45294.03043', '6524.744077', '25958.80015', '593.3786209', > '2899.040703', '85577.21342', '153576.2633', '5852.008444', > '563.0265409', '70796.45356', '565.2123689', '6560.030116', > '2668.934414', '418.666014', '5216.392132', '760.894589', '8072.957639', > '346.5905371', 'end'] > > If you can give me some lead to fix the code I wrote below that will be great: > def average(bin): num=[] total = 0.0 count=0 for number in bin: while True: if number!='end': number=float(number) total += float(number) count+=1 avg = total/count if number=='end': break num.append(avg) return num > > Thnx From vinay_sajip at yahoo.co.uk Fri Jan 20 14:17:36 2012 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Fri, 20 Jan 2012 11:17:36 -0800 (PST) Subject: python logging filter limitation, looks intentional? References: <4F1421C3.6060806@simplistix.co.uk> <1326726505.66259.YahooMailNeo@web25803.mail.ukl.yahoo.com> <4F146EFD.8090102@simplistix.co.uk> <1326756115.24713.YahooMailNeo@web25806.mail.ukl.yahoo.com> <4F151017.6020201@simplistix.co.uk> <1326797302.16852.YahooMailNeo@web25806.mail.ukl.yahoo.com> <4F173369.9010501@simplistix.co.uk> Message-ID: <3e4f47f7-ab4c-4a7e-a8ab-a280202c235a@v14g2000vbc.googlegroups.com> On Jan 19, 12:50?am, Terry Reedy wrote: > > >> I don't want people to have to code differently for Python 3.3 and for > >> older versions. > > This is not a general policy, else we would never add new features ;-) > Do you plan to keep logging feature-frozen forever, or just for another > release? (I actually think is a good idea to fix bugs, tests, and docs > first.) Logging isn't by any means feature-frozen - new features are being added all the time, including non-trivial additions made in 2.7 and 3.2, and some more changes planned for 3.3 and already checked in. My comment was about the specific change proposed, which if implemented could lead to existing working third party code failing after a Python version upgrade. The proposed change isn't a new feature, it's a request for an existing feature to work differently. Apart from the behavioural change, there is also a performance implication which needs to be considered. All in all, I'm not sure there is a lot of demand for this proposed change, and I have already suggested a workable approach to Chris which should meet his needs without any need for a behavioural change in the standard library. Regards, Vinay Sajip From vincent.vandevyvre at swing.be Fri Jan 20 14:30:20 2012 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Fri, 20 Jan 2012 20:30:20 +0100 Subject: can some one help me with my code. thanks In-Reply-To: References: Message-ID: <4F19C0CC.3080708@swing.be> An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Fri Jan 20 14:46:24 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 20 Jan 2012 14:46:24 -0500 Subject: can some one help me with my code. thanks In-Reply-To: References: Message-ID: On 1/20/2012 1:49 PM, Tamanna Sultana wrote: > > can some one help me?? >> I would like to create a function that, given a bin, which is a list >> (example below), generates averages for the numbers separated by a >> string 'end'. I am expecting to have 4 averages from the above bin, >> since there are 4 sets of numbers separated by 4 'end' strings [Posting your overly long set of data lines with a '>' quote at the beginning of each line was a nuisance. Reposted with few lines. I will let you compare your code to mine.] bin = ['2598.95165', '2541.220308', '221068.0401', 'end', '4834.581952', '1056.394859', '3010.609563', '2421.437603', '4619.861889', '3682.012227', '3371.092883', '6651.509488', '7906.092773', '7297.133447', 'end', '4566.874299', 'end', '4255.700077', '1857.648393', '11289.48095', '2070.981805', '1817.505094', '563.0265409', '70796.45356', '565.2123689', '6560.030116', '2668.934414', '418.666014', '5216.392132', '760.894589', '8072.957639', '346.5905371', 'end'] def average(bin): num=[] total = 0.0 count=0 for number in bin: if number!='end': total += float(number) count+=1 else: num.append(total/count) total = 0.0 count= 0 return num print(average(bin)) >>> [75402.73735266666, 4485.0726684, 4566.874299, 7817.36494866] -- Terry Jan Reedy From tjreedy at udel.edu Fri Jan 20 15:09:31 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 20 Jan 2012 15:09:31 -0500 Subject: python logging filter limitation, looks intentional? In-Reply-To: <3e4f47f7-ab4c-4a7e-a8ab-a280202c235a@v14g2000vbc.googlegroups.com> References: <4F1421C3.6060806@simplistix.co.uk> <1326726505.66259.YahooMailNeo@web25803.mail.ukl.yahoo.com> <4F146EFD.8090102@simplistix.co.uk> <1326756115.24713.YahooMailNeo@web25806.mail.ukl.yahoo.com> <4F151017.6020201@simplistix.co.uk> <1326797302.16852.YahooMailNeo@web25806.mail.ukl.yahoo.com> <4F173369.9010501@simplistix.co.uk> <3e4f47f7-ab4c-4a7e-a8ab-a280202c235a@v14g2000vbc.googlegroups.com> Message-ID: On 1/20/2012 2:17 PM, Vinay Sajip wrote: > On Jan 19, 12:50 am, Terry Reedy wrote: >> >>>> I don't want people to have to code differently for Python 3.3 and for >>>> older versions. >> >> This is not a general policy, else we would never add new features ;-) >> Do you plan to keep logging feature-frozen forever, or just for another >> release? (I actually think is a good idea to fix bugs, tests, and docs >> first.) > > Logging isn't by any means feature-frozen - new features are being > added all the time, including non-trivial additions made in 2.7 and > 3.2, and some more changes planned for 3.3 and already checked in. My > comment was about the specific change proposed, which if implemented > could lead to existing working third party code failing after a Python > version upgrade. The proposed change isn't a new feature, it's a > request for an existing feature to work differently. Thank you for the clarification. I had not gotten that the request was for a change, which has a much higher bar to pass than feature additions. I was thinking of 'code differently' as in if sys.version.split()[0] >= '3.3': else: but that is not a 'have to' as long as the workaround still works. -- Terry Jan Reedy From python.list at tim.thechases.com Fri Jan 20 15:17:47 2012 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 20 Jan 2012 14:17:47 -0600 Subject: can some one help me with my code. thanks In-Reply-To: References: Message-ID: <4F19CBEB.7090200@tim.thechases.com> On 01/20/12 13:46, Terry Reedy wrote: > def average(bin): > num=[] > total = 0.0 > count=0 > for number in bin: > if number!='end': > total += float(number) > count+=1 > else: > num.append(total/count) > total = 0.0 > count= 0 > return num print(average(['end'])) ka-blooie! :-) would be worth noting what should happen in the event of an empty bin. -tkc From awilliam at whitemice.org Fri Jan 20 15:38:11 2012 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Fri, 20 Jan 2012 15:38:11 -0500 Subject: etree/lxml/XSLT and dynamic stylesheet variables Message-ID: <1327091891.5020.12.camel@linux-dauq.site> I'm using etree to perform XSLT transforms, such as - from lxml import etree source = etree.parse(self.rfile) xslt = etree.fromstring(self._xslt) transform = etree.XSLT(xslt) result = transform(source) according to the docs at I can pass a dictionary of parameters to transform, such as - result = transform(doc_root, **{'non-python-identifier': '5'}) Can I pass a dictionary-like object? That doesn't seem to be working. I need to perform dynamic lookup of variables for the stylesheet. I've subclassed dictionary and overloaded [], get, has_key, and in to perform the required lookups; these work in testing. But passing the object to transform doesn't work. If that isn't possible is there an alternate XSLT implementation for python that would allow calling back for variable values? -- System & Network Administrator [ LPI & NCLA ] OpenGroupware Developer Adam Tauno Williams From tjreedy at udel.edu Fri Jan 20 15:42:45 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 20 Jan 2012 15:42:45 -0500 Subject: verify the return value of a function In-Reply-To: <4f198330$0$29987$c3e8da3$5496439d@news.astraweb.com> References: <4f198330$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 1/20/2012 10:07 AM, Steven D'Aprano wrote: > What should be avoided, when possible, is over-reliance on isinstance > checks instead of protocol or interface checks. For example, don't check > for a list if your function doesn't *need* a list but would be happy with > a tuple or some other sequence. In other words, do not use isinstance to artificially limit the input domain of a function. The generic or polymorphic nature of (builtin) operators and functions is a major feature of Python. On the other hand, the output range of a function is typically much more limited as to type. Complete testing requires testing the specified output type. For instance, sorted(iterable) is documented as producing a sorted list, so 'type(output) is list' is an appropriate test. -- Terry Jan Reedy From y.turgut at gmail.com Fri Jan 20 15:47:47 2012 From: y.turgut at gmail.com (Yigit Turgut) Date: Fri, 20 Jan 2012 12:47:47 -0800 (PST) Subject: Weird Loop Behaviour Message-ID: <23de2ba8-dccc-404c-92f3-da0023c12646@t2g2000yqk.googlegroups.com> Hi, In the following code, I am trying to run "black" screen for 3 seconds and respectively 2 seconds "white" screen. Black routine takes 3 seconds and white 2 seconds, 2 x black + white = 8 seconds which should be the expected value but when I run it I get black-white-black- white instead of black-white-black. Couldn't figure out what is wrong thus sharing the code as well ; white = False while(end<8.00): end = time.time() - start if white: screen.fill((255, 255, 255)) time.sleep(2) else: screen.fill((0, 0, 0)) time.sleep(3) white = not white pygame.display.update() pygame.quit() From python at mrabarnett.plus.com Fri Jan 20 16:10:29 2012 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 20 Jan 2012 21:10:29 +0000 Subject: Weird Loop Behaviour In-Reply-To: <23de2ba8-dccc-404c-92f3-da0023c12646@t2g2000yqk.googlegroups.com> References: <23de2ba8-dccc-404c-92f3-da0023c12646@t2g2000yqk.googlegroups.com> Message-ID: <4F19D845.5040609@mrabarnett.plus.com> On 20/01/2012 20:47, Yigit Turgut wrote: > Hi, > > In the following code, I am trying to run "black" screen for 3 seconds > and respectively 2 seconds "white" screen. Black routine takes 3 > seconds and white 2 seconds, 2 x black + white = 8 seconds which > should be the expected value but when I run it I get black-white-black- > white instead of black-white-black. Couldn't figure out what is > wrong thus sharing the code as well ; > > white = False > while(end<8.00): > end = time.time() - start > if white: > screen.fill((255, 255, 255)) > time.sleep(2) > else: > screen.fill((0, 0, 0)) > time.sleep(3) > white = not white > pygame.display.update() > pygame.quit() Could it be because you're setting 'end' after testing it? It might be simpler as: while time.time() - start < 8: Also, should it really be sleeping before updating the display? I would've thought that it should be sleeping _after_ updating the display. From emile at fenx.com Fri Jan 20 16:20:21 2012 From: emile at fenx.com (Emile van Sebille) Date: Fri, 20 Jan 2012 13:20:21 -0800 Subject: Weird Loop Behaviour In-Reply-To: <23de2ba8-dccc-404c-92f3-da0023c12646@t2g2000yqk.googlegroups.com> References: <23de2ba8-dccc-404c-92f3-da0023c12646@t2g2000yqk.googlegroups.com> Message-ID: On 1/20/2012 12:47 PM Yigit Turgut said... > Hi, > > In the following code, I am trying to run "black" screen for 3 seconds > and respectively 2 seconds "white" screen. Black routine takes 3 > seconds and white 2 seconds, 2 x black + white = 8 seconds which > should be the expected value but when I run it I get black-white-black- > white instead of black-white-black. Couldn't figure out what is > wrong thus sharing the code as well ; > > white = False > while(end<8.00): > end = time.time() - start you're setting end's value before the display happens, so while tests the values 0,3,5 before getting after the fourth pass 8. Move this after to white = note white and I suspect you'll be OK. HTH, Emile > if white: > screen.fill((255, 255, 255)) > time.sleep(2) > else: > screen.fill((0, 0, 0)) > time.sleep(3) > white = not white > pygame.display.update() > pygame.quit() From awilliam at whitemice.org Fri Jan 20 16:21:04 2012 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Fri, 20 Jan 2012 16:21:04 -0500 Subject: Extending PyGTK widgets with Glade In-Reply-To: References: Message-ID: <20120120162104.Horde.HeOWVZeICrNPGdrAscCwiPA@aleph.wmmi.net> Quoting Richard Carlson : > I'm working on a program using PyGTK and Glade. I create a glade XML file > using Glade Designer and then load widgets like this: > class MyDialog: > def __init__(self): > self.dialog = gtk.glade.XML(self.GLADEFILE).get_widget > ("dialog.xml") > I think it would be better if I extended the Dialog class, but I can't > figure out how to do it. I'd like to do something like this: > class MyDialog(gtk.Dialog): > def __init__(self): > self = gtk.glade.XML(self.GLADEFILE).get_widget("example_dialog") > > Can someone point me in the right direction? There is some documentation about this around somewhere; but I don't recall offhand. In any case you will probably get a good answer if you ask on the pygtk maillist. Content on that list is pretty good. From tjreedy at udel.edu Fri Jan 20 16:26:45 2012 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 20 Jan 2012 16:26:45 -0500 Subject: can some one help me with my code. thanks In-Reply-To: References: Message-ID: On 1/20/2012 2:46 PM, Terry Reedy wrote: > On 1/20/2012 1:49 PM, Tamanna Sultana wrote: >> >> can some one help me?? >>> I would like to create a function that, given a bin, which is a list >>> (example below), generates averages for the numbers separated by a >>> string 'end'. I am expecting to have 4 averages from the above bin, >>> since there are 4 sets of numbers separated by 4 'end' strings > > [Posting your overly long set of data lines with a '>' quote at the > beginning of each line was a nuisance. Reposted with few lines. I will > let you compare your code to mine.] > > bin = ['2598.95165', '2541.220308', '221068.0401', 'end', '4834.581952', > '1056.394859', '3010.609563', '2421.437603', '4619.861889', > '3682.012227', '3371.092883', '6651.509488', '7906.092773', > '7297.133447', 'end', '4566.874299', 'end', '4255.700077', > '1857.648393', '11289.48095', '2070.981805', '1817.505094', > '563.0265409', '70796.45356', '565.2123689', '6560.030116', > '2668.934414', '418.666014', '5216.392132', '760.894589', '8072.957639', > '346.5905371', 'end'] > > def average(bin): > num=[] > total = 0.0 > count=0 > for number in bin: > if number!='end': > total += float(number) > count+=1 > else: > num.append(total/count) > total = 0.0 > count= 0 > return num > > print(average(bin)) > > >>> > [75402.73735266666, 4485.0726684, 4566.874299, 7817.36494866] U're welcome. But do notice Tim's comment. In non-toy situations, you have to decide how to handle empty collections (return float('nan')?), or whether to just let whatever happens happen. If you control the input format, a list of lists would be easier than an end marker. But sometimes one is handed data and asked to process it as is. Also note (this is a more advanced topic) that average() could be turned into a generator function by replacing 'num.append(total/count)' with 'yield total/count' and removing the initialization and return of num. -- Terry Jan Reedy From arnodel at gmail.com Fri Jan 20 18:10:44 2012 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 20 Jan 2012 23:10:44 +0000 Subject: Weird Loop Behaviour In-Reply-To: <23de2ba8-dccc-404c-92f3-da0023c12646@t2g2000yqk.googlegroups.com> References: <23de2ba8-dccc-404c-92f3-da0023c12646@t2g2000yqk.googlegroups.com> Message-ID: On 20 January 2012 20:47, Yigit Turgut wrote: > Hi, > > In the following code, I am trying to run "black" screen for 3 seconds > and respectively 2 seconds "white" screen. Black routine takes 3 > seconds and white 2 seconds, 2 x black + white = 8 seconds which > should be the expected value but when I run it I get black-white-black- > white ? instead of black-white-black. Couldn't figure out what is > wrong thus sharing the code as well ; > > white = False > ? ? while(end<8.00): > ? ? ?end = time.time() - start > ? ? ?if white: > ? ? ? screen.fill((255, 255, 255)) > ? ? ? ?time.sleep(2) > ? ? ?else: > ? ? ? ?screen.fill((0, 0, 0)) > ? ? ? ?time.sleep(3) > ? ? ?white = not white > ? ? ?pygame.display.update() > ? ? pygame.quit() This is cryptic. You'd be better off with something like black = 0, 0, 0 white = 255, 255, 255 for color, wait in (black, 3), (white, 2), (black, 3): screen.fill(color) pygame.display.update() time.sleep(wait) pygame.quit() -- Arnaud From rantingrickjohnson at gmail.com Fri Jan 20 19:21:30 2012 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 20 Jan 2012 16:21:30 -0800 (PST) Subject: can some one help me with my code. thanks References: Message-ID: <38c1fdd1-6bd1-4e4c-b0c7-ea47f75c9e86@b23g2000yqn.googlegroups.com> On Jan 20, 12:49?pm, Tamanna Sultana wrote: > > If you can give me some lead to fix the code I wrote below that will be great: Your variable names need a bit more thought > def average(bin): What is a "bin"? Maybe you shoulc have called this a "lst" eh? > ? ? num=[] Why would you call a list of numbers (that's plural BTW) the singular name "num"? Not to mention that even "numbers" is the wrong identifier. Use "averages" instead. Heck, even "buffer" would have been a better choice that "num". > ? ? total = 0.0 > ? ? count = 0 > ? ? for number in bin: Not every "item" in the lst is a number so we should use the generic "item" identifier here. > ? ? ? ? while True: What the hell is a loop doing here??? > ? ? ? ? ? ? if number!='end': > ? ? ? ? ? ? ? ? number=float(number) > ? ? ? ? ? ? ? ? total += float(number) > ? ? ? ? ? ? ? ? count+=1 > ? ? ? ? ? ? ? ? avg = total/count > ? ? ? ? ? ? if number=='end': > ? ? ? ? ? ? ? ? ? ? break This block of logic is ugly. Try this instead... > ? ? ? ? ? ? if number == 'end': > break > ? ? ? ? ? ? number=float(number) > ? ? ? ? ? ? total += float(number) > ? ? ? ? ? ? count+=1 > ? ? ? ? ? ? avg = total/count ...but that whole loop thing is nonsense anyway. I would reconsider this code completely. Here is an outline: for item in lst if item equals "end": compute the current average from buffers else: increment the running total increment the count. From roy at panix.com Fri Jan 20 19:22:19 2012 From: roy at panix.com (Roy Smith) Date: Fri, 20 Jan 2012 19:22:19 -0500 Subject: Is a with on open always necessary? References: <4F198BD1.4040301@gmail.com> Message-ID: In article , Arnaud Delobelle wrote: > > So maybe doing a > > > > with open(filename) as f: > > ?? ?? contents = f.readlines() > > That's what I do, unless I'm in an interactive session. >From the resource management point of view, there's no doubt that's the right thing to be doing. That being said, I don't bother most of the time and I can't think of a time when I've been bitten by it. From nobody at nowhere.com Fri Jan 20 19:35:45 2012 From: nobody at nowhere.com (Nobody) Date: Sat, 21 Jan 2012 00:35:45 +0000 Subject: subprocess module and long-lived subprocesses References: Message-ID: On Fri, 20 Jan 2012 08:42:16 -0600, skip wrote: > The library documentation doesn't talk a lot about long-lived subprocesses > other than the possibility of deadlock when using Popen.wait(). Ideally, I > would write to the subprocess's stdin, check for output on stdout and > stderr, then lather, rinse, repeat. Is it safe to assume that if the stdout > and/or stderr pipes have nothing for me the reads on those file objects (I'm > using PIPE for all three std* files) will return immediately with an empty > string for output? They won't block, will they? They will. You need to use either threads, select() or non-blocking I/O in order to avoid deadlock. See the definitions of subprocess._communicate() (there's one version for Windows which uses threads and another for Unix using select()). > Will a broken pipe IOError get raised as for os.popen() IOError(EPIPE) will be raised if you write to the stdin pipe when there are no readers. > or do I have to call Popen.poll() even in error situations? Once you're finished with the process, you should close .stdin then consume all output from .stdout and .stderr until both report EOF, then call .wait(). That should cover any possible child behaviour (e.g. if the child explicitly close()s its stdin, getting EPIPE doesn't mean that you can forget about the process or that .wait() won't deadlock). From steve+comp.lang.python at pearwood.info Fri Jan 20 19:48:08 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Jan 2012 00:48:08 GMT Subject: Is a with on open always necessary? References: Message-ID: <4f1a0b47$0$29987$c3e8da3$5496439d@news.astraweb.com> On Fri, 20 Jan 2012 15:44:17 +0000, Andrea Crotti wrote: > I normally didn't bother too much when reading from files, and for > example I always did a > > content = open(filename).readlines() > > But now I have the doubt that it's not a good idea, does the file > handler stays open until the interpreter quits? The file will stay open until: 1) you explicitly close it; 2) the reference to the open file goes out of scope and is garbage collected; or 3) the Python environment shuts down whichever happens first. In the case of #2, the timing is a matter of implementation detail. CPython and PyPy currently close the file immediately the last reference to it goes out of scope (but that's not a promise of the language, so it could change in the future); Jython and IronPython will eventually close the file, but it may take a long time. Except for the quickest and dirtiest scripts, I recommend always using either the "with file as" idiom, or explicitly closing the file. -- Steven From rfflrccrd at gmail.com Fri Jan 20 19:50:24 2012 From: rfflrccrd at gmail.com (Raffaele Ricciardi) Date: Sat, 21 Jan 2012 00:50:24 +0000 Subject: Please don't use "setuptools", the "rotten .egg" install system. In-Reply-To: <4f170e46$0$1659$742ec2ed@news.sonic.net> References: <4f170e46$0$1659$742ec2ed@news.sonic.net> Message-ID: <9nugavFr37U1@mid.individual.net> In order to build and run Mercurial on Linux, I needed Python with docutils. I've just installed Python from source and later setuptools. As a non-Pythonista, my impression has been that the procedure of installing setuptools and then using them is quite straightforward, but it's not advertised enough to newcomers. From joncle at googlemail.com Fri Jan 20 20:30:49 2012 From: joncle at googlemail.com (Jon Clements) Date: Fri, 20 Jan 2012 17:30:49 -0800 (PST) Subject: can some one help me with my code. thanks References: Message-ID: On Jan 20, 9:26?pm, Terry Reedy wrote: > On 1/20/2012 2:46 PM, Terry Reedy wrote: > > > > > > > > > > > On 1/20/2012 1:49 PM, Tamanna Sultana wrote: > > >> can some one help me?? > >>> I would like to create a function that, given a bin, which is a list > >>> (example below), generates averages for the numbers separated by a > >>> string 'end'. I am expecting to have 4 averages from the above bin, > >>> since there are 4 sets of numbers separated by 4 'end' strings > > > [Posting your overly long set of data lines with a '>' quote at the > > beginning of each line was a nuisance. Reposted with few lines. I will > > let you compare your code to mine.] > > > bin = ['2598.95165', '2541.220308', '221068.0401', 'end', '4834.581952', > > '1056.394859', '3010.609563', '2421.437603', '4619.861889', > > '3682.012227', '3371.092883', '6651.509488', '7906.092773', > > '7297.133447', 'end', '4566.874299', 'end', '4255.700077', > > '1857.648393', '11289.48095', '2070.981805', '1817.505094', > > '563.0265409', '70796.45356', '565.2123689', '6560.030116', > > '2668.934414', '418.666014', '5216.392132', '760.894589', '8072.957639', > > '346.5905371', 'end'] > > > def average(bin): > > num=[] > > total = 0.0 > > count=0 > > for number in bin: > > if number!='end': > > total += float(number) > > count+=1 > > else: > > num.append(total/count) > > total = 0.0 > > count= 0 > > return num > > > print(average(bin)) > > > [75402.73735266666, 4485.0726684, 4566.874299, 7817.36494866] > > U're welcome. But do notice Tim's comment. In non-toy situations, you > have to decide how to handle empty collections (return float('nan')?), > or whether to just let whatever happens happen. > > If you control the input format, a list of lists would be easier than an > end marker. But sometimes one is handed data and asked to process it as is. > > Also note (this is a more advanced topic) that average() could be turned > into a generator function by replacing 'num.append(total/count)' with > 'yield total/count' and removing the initialization and return of num. > > -- > Terry Jan Reedy Not directing this at you Terry, and you and Tim have made fine points -- this just appears to me to be the best point at which to respond to a thread. To the OP - you have great answers, and, please note this just happens to be the way I would do this. I would separate the parsing of the data, and the calculation code out. I've whipped this up rather quickly, so it might have a few flaws but... from itertools import groupby def partition(iterable, sep=lambda L: L == 'end', factory=float): for key, vals in groupby(iterable, sep): if not key: yield map(factory, vals) # And a pure cheat, but useful if more complex calculations are required etc... (Plus covers NaN) import numpy as np print map(np.mean, partition(bin)) What you've got will work though, so wouldn't worry too much and this is just my 2p, Jon. From steve+comp.lang.python at pearwood.info Fri Jan 20 21:23:19 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Jan 2012 02:23:19 GMT Subject: can some one help me with my code. thanks References: <38c1fdd1-6bd1-4e4c-b0c7-ea47f75c9e86@b23g2000yqn.googlegroups.com> Message-ID: <4f1a2197$0$29987$c3e8da3$5496439d@news.astraweb.com> On Fri, 20 Jan 2012 16:21:30 -0800, Rick Johnson wrote: > On Jan 20, 12:49?pm, Tamanna Sultana wrote: >> > If you can give me some lead to fix the code I wrote below that will >> > be great: > > Your variable names need a bit more thought > >> def average(bin): > > What is a "bin"? Maybe you shoulc have called this a "lst" eh? What's a 'lst'? It's not even a real word, and it looks like 1st. "Bin" is a standard English world. You know, like "rubbish bin" or "recycling bin". It is also a standard term used in statistics as a noun, a verb, and adjective, e.g.: http://stackoverflow.com/questions/5581023/r-graphing-binned-data -- Steven From awilliam at whitemice.org Fri Jan 20 21:34:27 2012 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Fri, 20 Jan 2012 21:34:27 -0500 Subject: LibreOffice with Python In-Reply-To: References: <87aa5v8a3r.fsf@benfinney.id.au> Message-ID: <1327113267.9973.3.camel@workstation.wmmi.net> On Tue, 2012-01-10 at 19:04 -0500, Terry Reedy wrote: > On 1/10/2012 5:29 PM, Ben Finney wrote: > > LibreOffice supports scripting with several languages, including Python > > > So that page says. But it only tells how to attach a Python script once > writen, not how to write one that will do anything. Are there any links > for that? +1 PyUNO, and UNO in general, needs way more press and for some of the people who use it to do a bit of BLOGing. Getting up over the initial learning curve is rough; I know it has pushed me back from a couple of attempts. > > Extensions can also be written in Python, using the UNO runtime API > > . -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part URL: From sam at samiconductor.com Fri Jan 20 22:46:24 2012 From: sam at samiconductor.com (Sam Simmons) Date: Fri, 20 Jan 2012 19:46:24 -0800 (PST) Subject: Masking a dist package with a copy in my own package Message-ID: <20992811.215.1327117584953.JavaMail.geo-discussion-forums@yqcz12> Hey all, I'm using twisted in a project and have run into a class that's in version 11.1 but not 8.2 in OSX. I was thinking to get it working for mac users I could just extract the 11.1 twisted package and through it under my package. e.g. project/ __init__.py twisted/ __init__.py ... When running anything, it imports from the local 11.1 twisted, but zope throws a warning: /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/zope/__init__.py:1: UserWarning: Module twisted was already imported from /path/to/project/twisted/__init__.pyc, but /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python is being added to sys.path __import__('pkg_resources').declare_namespace(__name__) Is there an elegant way to give mac users vers 11.1 other than copying in package and possibly renaming it? Thanks! From rosuav at gmail.com Fri Jan 20 23:03:18 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Jan 2012 15:03:18 +1100 Subject: can some one help me with my code. thanks In-Reply-To: <4f1a2197$0$29987$c3e8da3$5496439d@news.astraweb.com> References: <38c1fdd1-6bd1-4e4c-b0c7-ea47f75c9e86@b23g2000yqn.googlegroups.com> <4f1a2197$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jan 21, 2012 at 1:23 PM, Steven D'Aprano wrote: > On Fri, 20 Jan 2012 16:21:30 -0800, Rick Johnson wrote: >> Your variable names need a bit more thought >> >>> def average(bin): >> >> What is a "bin"? Maybe you shoulc have called this a "lst" eh? > > "Bin" is a standard English world. You know, like "rubbish bin" or > "recycling bin". Or my first thought: stock location. Inventory software often doesn't care whether your physical stock is organized by shelf, box, warehouse, planet, or secret-space-on-Firefly-class-ship; just number each location, and that's the bin number. (And no, that isn't like "PIN number".) It's then quite logical to want various stats to be per-bin, which would lead exactly to the OP's problem - including the odd notation of input data, all too likely in a real-world scenario. ChrisA From stefan_ml at behnel.de Fri Jan 20 23:56:32 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 21 Jan 2012 05:56:32 +0100 Subject: etree/lxml/XSLT and dynamic stylesheet variables In-Reply-To: <1327091891.5020.12.camel@linux-dauq.site> References: <1327091891.5020.12.camel@linux-dauq.site> Message-ID: Adam Tauno Williams, 20.01.2012 21:38: > I'm using etree to perform XSLT transforms, such as - > > from lxml import etree > source = etree.parse(self.rfile) > xslt = etree.fromstring(self._xslt) > transform = etree.XSLT(xslt) > result = transform(source) > > according to the docs at > I can pass a > dictionary of parameters to transform, such as - > > result = transform(doc_root, **{'non-python-identifier': '5'}) > > Can I pass a dictionary-like object? That doesn't seem to be working. Yes it does, Python copies it into a plain dict at call time. > I need to perform dynamic lookup of variables for the stylesheet. Different story. > I've subclassed dictionary and overloaded [], get, has_key, and in to > perform the required lookups; these work in testing. But passing the > object to transform doesn't work. You should make the lookup explicit in your XSLT code using an XPath function. See here: http://lxml.de/extensions.html Stefan From steve+comp.lang.python at pearwood.info Sat Jan 21 05:07:04 2012 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Jan 2012 10:07:04 GMT Subject: Tab-completion in tutorial Message-ID: <4f1a8e48$0$29987$c3e8da3$5496439d@news.astraweb.com> I'm reading the part of the tutorial that talks about tab-completion, and I think the docs are wrong. http://docs.python.org/tutorial/interactive.html#key-bindings The "more capable startup file" example given claims: # Add auto-completion and a stored history file of commands to your Python # interactive interpreter. Requires Python 2.0+, readline. Autocomplete is # bound to the Esc key by default (you can change it - see readline docs). but I have tried it, and it doesn't seem to actually bind autocomplete to anything. Is this a documentation bug, or am I doing something wrong? -- Steven From lie.1296 at gmail.com Sat Jan 21 06:38:44 2012 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 21 Jan 2012 22:38:44 +1100 Subject: Is a with on open always necessary? In-Reply-To: <4F198BD1.4040301@gmail.com> References: <4F198BD1.4040301@gmail.com> Message-ID: On 01/21/2012 02:44 AM, Andrea Crotti wrote: > I normally didn't bother too much when reading from files, and for example > I always did a > > content = open(filename).readlines() > > But now I have the doubt that it's not a good idea, does the file > handler stays > open until the interpreter quits? It is not necessary most of the time, and most likely is not necessary for short-lived programs. The file handler stays open until the file object is garbage collected, in CPython which uses reference counting the file handler is closed when the last reference to the file object is deleted or goes out of context; in python implementations that uses garbage collection method, this is indeterministic. It is only strictly necessary for programs that opens thousands of files in a short while, since the operating system may limit of the number of active file handlers you can have. However, it is considered best practice to close file handlers; making it a habit will avoid problems when you least expect it. From __peter__ at web.de Sat Jan 21 08:25:13 2012 From: __peter__ at web.de (Peter Otten) Date: Sat, 21 Jan 2012 14:25:13 +0100 Subject: Tab-completion in tutorial References: <4f1a8e48$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I'm reading the part of the tutorial that talks about tab-completion, and > I think the docs are wrong. > > http://docs.python.org/tutorial/interactive.html#key-bindings > > The "more capable startup file" example given claims: > > # Add auto-completion and a stored history file of commands to your Python > # interactive interpreter. Requires Python 2.0+, readline. Autocomplete is > # bound to the Esc key by default (you can change it - see readline docs). > > but I have tried it, and it doesn't seem to actually bind autocomplete to > anything. > > Is this a documentation bug, or am I doing something wrong? I've just tried it on Kubuntu's konsole. I see strange reactions: After typing "imp" I have to hit ESC three times before "ort" is added, and afterwards a character is swallowed. However, I can get the expected behaviour after binding the key explicitly with >>> import readline >>> readline.parse_and_bind("esc: complete") I'm not sure whether Python is to blame or Ubuntu; it may be an interference with konsole's key bindings. From andrea.crotti.0 at gmail.com Sat Jan 21 08:47:00 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Sat, 21 Jan 2012 13:47:00 +0000 Subject: while True or while 1 Message-ID: <4F1AC1D4.2080402@gmail.com> I see sometimes in other people code "while 1" instead of "while True". I think using True is more pythonic, but I wanted to check if there is any difference in practice. So I tried to do the following, and the result is surprising. For what I can see it looks like the interpreter can optimize away the 1 boolean conversion while it doesn't with the True, the opposite of what I supposed. Anyone can explain me why is that, or maybe is my conclusion wrong? def f1(): while 1: pass def f2(): while True: pass In [10]: dis.dis(f) 2 0 SETUP_LOOP 3 (to 6) 3 >> 3 JUMP_ABSOLUTE 3 >> 6 LOAD_CONST 0 (None) 9 RETURN_VALUE In [9]: dis.dis(f1) 2 0 SETUP_LOOP 10 (to 13) >> 3 LOAD_GLOBAL 0 (True) 6 POP_JUMP_IF_FALSE 12 3 9 JUMP_ABSOLUTE 3 >> 12 POP_BLOCK >> 13 LOAD_CONST 0 (None) 16 RETURN_VALUE From andrea.crotti.0 at gmail.com Sat Jan 21 09:29:12 2012 From: andrea.crotti.0 at gmail.com (Andrea Crotti) Date: Sat, 21 Jan 2012 14:29:12 +0000 Subject: while True or while 1 In-Reply-To: <4F1AC1D4.2080402@gmail.com> References: <4F1AC1D4.2080402@gmail.com> Message-ID: <4F1ACBB8.5060306@gmail.com> Actually there was the same question here (sorry should have looked before) http://stackoverflow.com/questions/3815359/while-1-vs-for-whiletrue-why-is-there-a-difference And I think the main reason is that 1 is a constant while True is not such and can be reassigned. From tinnews at isbd.co.uk Sat Jan 21 09:58:39 2012 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Sat, 21 Jan 2012 14:58:39 +0000 Subject: What's the very simplest way to run some Python from a button on a web page? Message-ID: I want to run a server side python script when a button on a web page is clicked. This is on a LAMP server - apache2 on xubuntu 11.10. I know I *could* run it as a CGI script but I don't want to change the web page at all when the button is clicked (I'll see the effect elsewhere on the screen anyway) so normal CGI isn't ideal. It's easy to show a button:- ; Can I get away with something clever for 'something' that will somehow hook through to a server side script? Alternatively, seeing as both client and server are on the same system, this *could* be done on the client side by breaking out of the browser sandbox - is there any easy way to do this? I'm just looking for the crudest, simplest possible way of doing this, it's only for my own convenience to fire up a utility I want to use when viewing certain of my local HTML pages. These pages aren't visible from the outside world so security isn't a big issue. -- Chris Green From rosuav at gmail.com Sat Jan 21 09:59:01 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 22 Jan 2012 01:59:01 +1100 Subject: while True or while 1 In-Reply-To: <4F1AC1D4.2080402@gmail.com> References: <4F1AC1D4.2080402@gmail.com> Message-ID: On Sun, Jan 22, 2012 at 12:47 AM, Andrea Crotti wrote: > So I tried to do the following, and the result is surprising. ?For what > I can see it looks like the interpreter can optimize away the 1 boolean > conversion while it doesn't with the True, the opposite of what I > supposed. > > Anyone can explain me why is that, or maybe is my conclusion wrong? In Python 3, they compile to the same code, because 'True' is a keyword. In Python 2, you can reassign True to be 0. ChrisA From matteo at matteolandi.net Sat Jan 21 10:24:09 2012 From: matteo at matteolandi.net (Matteo Landi) Date: Sat, 21 Jan 2012 16:24:09 +0100 Subject: while True or while 1 In-Reply-To: <4F1AC1D4.2080402@gmail.com> References: <4F1AC1D4.2080402@gmail.com> Message-ID: <20120121152117.GA5361@MARble> Probably because of the fact it is possible to set True equal to False and consequently then invalidate loop logic as presented below: True = False while True: ... On the other hand `1' will always be evaluated as a constant. Don't know, just guessing. Matteo On Jan/21, Andrea Crotti wrote: > I see sometimes in other people code "while 1" instead of "while True". > I think using True is more pythonic, but I wanted to check if there is > any difference in practice. > > So I tried to do the following, and the result is surprising. For what > I can see it looks like the interpreter can optimize away the 1 boolean > conversion while it doesn't with the True, the opposite of what I > supposed. > > Anyone can explain me why is that, or maybe is my conclusion wrong? > > def f1(): > while 1: > pass > > def f2(): > while True: > pass > > In [10]: dis.dis(f) > 2 0 SETUP_LOOP 3 (to 6) > > 3 >> 3 JUMP_ABSOLUTE 3 > >> 6 LOAD_CONST 0 (None) > 9 RETURN_VALUE > > In [9]: dis.dis(f1) > 2 0 SETUP_LOOP 10 (to 13) > >> 3 LOAD_GLOBAL 0 (True) > 6 POP_JUMP_IF_FALSE 12 > > 3 9 JUMP_ABSOLUTE 3 > >> 12 POP_BLOCK > >> 13 LOAD_CONST 0 (None) > 16 RETURN_VALUE > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.matteolandi.net From awilliam at whitemice.org Sat Jan 21 13:07:21 2012 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Sat, 21 Jan 2012 13:07:21 -0500 Subject: etree/lxml/XSLT and dynamic stylesheet variables In-Reply-To: References: <1327091891.5020.12.camel@linux-dauq.site> Message-ID: <1327169241.9973.7.camel@workstation.wmmi.net> On Sat, 2012-01-21 at 05:56 +0100, Stefan Behnel wrote: > Adam Tauno Williams, 20.01.2012 21:38: > > I'm using etree to perform XSLT transforms, such as - > > from lxml import etree > > source = etree.parse(self.rfile) > > xslt = etree.fromstring(self._xslt) > > transform = etree.XSLT(xslt) > > result = transform(source) > > according to the docs at > > I can pass a > > dictionary of parameters to transform, such as - > > result = transform(doc_root, **{'non-python-identifier': '5'}) > > Can I pass a dictionary-like object? That doesn't seem to be working. > Yes it does, Python copies it into a plain dict at call time. Ah, I wondered if that was happening. In which case is supresses all the magic of my dict subclass. > > I need to perform dynamic lookup of variables for the stylesheet. > Different story. > > I've subclassed dictionary and overloaded [], get, has_key, and in to > > perform the required lookups; these work in testing. But passing the > > object to transform doesn't work > You should make the lookup explicit in your XSLT code using an XPath > function. See here: > http://lxml.de/extensions.html Perfect thanks; this provides everything I need. A stupid test case / example for anyone interested: from lxml import etree class MyExt: def __init__(self, languages): self._languages = languages def languagelookup(self, _, arg): language = self._languages.get(arg) if not language: return 'undefined' return language extensions = etree.Extension( MyExt(languages={ 'ES': 'Spanish', 'EL': 'Greek', 'DE': 'German', 'EN': 'English' } ), ( 'languagelookup', ), ns='847fe241-df88-45c6-b4a7' ) text = ''' 109 OP Revolt Of The Masses Jose Ortega y Gasset 1930 ES 108 P Meditations Marcus Aurelius EL 1930 425 OP The Communist Manifesto Karl Marx Friedrich Engels DE 1914 507 POT The Cathedral & The Bazaar Eric S. Raymond 199 ''' source = etree.fromstring(text) style =''' ," "," " ''' xslt = etree.XSLT(etree.XML(style), extensions=extensions) print xslt(source) -- Adam Tauno Williams System Administrator, OpenGroupware Developer, LPI / CNA Fingerprint 8C08 209A FBE3 C41A DD2F A270 2D17 8FA4 D95E D383 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part URL: From ian.g.kelly at gmail.com Sat Jan 21 13:44:08 2012 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 21 Jan 2012 11:44:08 -0700 Subject: What's the very simplest way to run some Python from a button on a web page? In-Reply-To: References: Message-ID: On Sat, Jan 21, 2012 at 7:58 AM, wrote: > I want to run a server side python script when a button on a web page > is clicked. This is on a LAMP server - apache2 on xubuntu 11.10. > > I know I *could* run it as a CGI script but I don't want to change the > web page at all when the button is clicked (I'll see the effect > elsewhere on the screen anyway) so normal CGI isn't ideal. > > It's easy to show a button:- > > ; > > Can I get away with something clever for 'something' that will somehow > hook through to a server side script? > Yes, use AJAX to make an asynchronous request. There are several AJAX toolkits out there that will make this simple. -------------- next part -------------- An HTML attachment was scrubbed... URL: From max at alcyone.com Sat Jan 21 16:13:14 2012 From: max at alcyone.com (Erik Max Francis) Date: Sat, 21 Jan 2012 13:13:14 -0800 Subject: while True or while 1 In-Reply-To: References: <4F1AC1D4.2080402@gmail.com> Message-ID: Chris Angelico wrote: > On Sun, Jan 22, 2012 at 12:47 AM, Andrea Crotti > wrote: >> So I tried to do the following, and the result is surprising. For what >> I can see it looks like the interpreter can optimize away the 1 boolean >> conversion while it doesn't with the True, the opposite of what I >> supposed. >> >> Anyone can explain me why is that, or maybe is my conclusion wrong? > > In Python 3, they compile to the same code, because 'True' is a > keyword. In Python 2, you can reassign True to be 0. Why this should concern anyone, I don't know; someone who's rebound `True` or `False` to evaluate to something other than true and false, respectively, is only doing so to be difficult (or very foolish). One of the principles of Python programming is that We're All Adults Here, so this kind of defensive programming is really superfluous. In other words, yes, it's quite reasonable to assume that (even in Python 2) `True` is bound to something which is, in fact, true. The real reason people still use the `while 1` construct, I would imagine, is just inertia or habit, rather than a conscious, defensive decision. If it's the latter, it's a case of being _way_ too defensive. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Jabber erikmaxfrancis Ambition can creep as well as soar. -- Edmund Burke From max at alcyone.com Sat Jan 21 16:14:24 2012 From: max at alcyone.com (Erik Max Francis) Date: Sat, 21 Jan 2012 13:14:24 -0800 Subject: while True or while 1 In-Reply-To: References: Message-ID: Andrea Crotti wrote: > I see sometimes in other people code "while 1" instead of "while True". > I think using True is more pythonic, but I wanted to check if there is > any difference in practice. No (with the exception of `True` and `False` being rebinable in Python 2). The idiomatic `while 1` notation comes from back in the pre-Boolean days. In any reasonably modern implementation, `while True` is more self-documenting. I would imagine the primary reason people still do it, any after-the-fact rationalizations aside, is simply habit. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Jabber erikmaxfrancis Ambition can creep as well as soar. -- Edmund Burke From rosuav at gmail.com Sat Jan 21 17:13:23 2012 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 22 Jan 2012 09:13:23 +1100 Subject: while True or while 1 In-Reply-To: References: <4F1AC1D4.2080402@gmail.com> Message-ID: On Sun, Jan 22, 2012 at 8:13 AM, Erik Max Francis wrote: > Why this should concern anyone, I don't know; someone who's rebound `True` > or `False` to evaluate to something other than true and false, respectively, > is only doing so to be difficult (or very foolish). ?One of the principles > of Python programming is that We're All Adults Here, so this kind of > defensive programming is really superfluous. ?In other words, yes, it's > quite reasonable to assume that (even in Python 2) `True` is bound to > something which is, in fact, true. Yes, but there's no special code in the compiler to handle True - it's just a name like any other. It finds a token that looks like a name, so it puts a name lookup into the bytecode. > The real reason people still use the `while 1` construct, I would imagine, > is just inertia or habit, rather than a conscious, defensive decision. ?If > it's the latter, it's a case of being _way_ too defensive. Ehh, 'while 1' is shorter too. I reckon some people are just lazy :) Or have come from C where 'while (1)' is the normal thing to do. According to the Eliza Effect, supporting 'while 1' is a Good Thing. ChrisA From spiercyanna at aol.com Sat Jan 21 20:14:56 2012 From: spiercyanna at aol.com (spiercyanna at aol.com) Date: Sat, 21 Jan 2012 20:14:56 -0500 (EST) Subject: No subject Message-ID: <8CEA6BA22299F24-12FC-12453@webmail-m075.sysops.aol.com> http://project.fadinghorse.com/lib/ezpdf/fonts/qegi.html From sam at samiconductor.com Sat Jan 21 21:28:02 2012 From: sam at samiconductor.com (Sam Simmons) Date: Sat, 21 Jan 2012 18:28:02 -0800 (PST) Subject: Masking a dist package with a copy in my own package In-Reply-To: <20992811.215.1327117584953.JavaMail.geo-discussion-forums@yqcz12> References: <20992811.215.1327117584953.JavaMail.geo-discussion-forums@yqcz12> Message-ID: <14122265.730.1327199282065.JavaMail.geo-discussion-forums@yqbc11> I just installed 2.7... should have done this a while ago. pip finally works! Thanks! From th982a at googlemail.com Sat Jan 21 22:04:08 2012 From: th982a at googlemail.com (Tamer Higazi) Date: Sun, 22 Jan 2012 04:04:08 +0100 Subject: access address from object and vice versa Message-ID: <4F1B7CA8.80702@googlemail.com> Hi people! I have asked myself the following thing. How do I access the address of an object and later get the object from that address ?! I am heavily interisted. thank you Tamer From clp2 at rebertia.com Sat Jan 21 22:36:32 2012 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 21 Jan 2012 19:36:32 -0800 Subject: access address from object and vice versa In-Reply-To: <4F1B7CA8.80702@googlemail.com> References: <4F1B7CA8.80702@googlemail.com> Message-ID: On Sat, Jan 21, 2012 at 7:04 PM, Tamer Higazi wrote: > Hi people! > I have asked myself the following thing. > > How do I access the address of an object id(obj) happens to do that in CPython, but it's a mere implementation detail. > and later get the object from > that address ?! Not possible. > I am heavily interisted. Why? Cheers, Chris From timr at probo.com Sat Jan 21 23:36:07 2012 From: timr at probo.com (Tim Roberts) Date: Sat, 21 Jan 2012 20:36:07 -0800 Subject: What's the very simplest way to run some Python from a button on a web page? References: Message-ID: tinnews at isbd.co.uk wrote: > >I want to run a server side python script when a button on a web page >is clicked. This is on a LAMP server - apache2 on xubuntu 11.10. > >I know I *could* run it as a CGI script but I don't want to change the >web page at all when the button is clicked (I'll see the effect >elsewhere on the screen anyway) so normal CGI isn't ideal. It seems what you're after is AJAX. If you are using a Javascript framework like jQuery, it's easy to fire off an asynchronous request back to your server that leaves the existing page alone. If you aren't, then I think the easiest method is to use an invisible