From albert at spenarnc.xs4all.nl Mon Apr 8 10:50:26 2013 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 08 Apr 2013 14:50:26 GMT Subject: The usage of -m option of python References: Message-ID: <5162d932$0$6060$e4fe514c@dreader36.news.xs4all.nl> In article , Terry Reedy wrote: >On 3/18/2013 5:17 PM, Peng Yu wrote: >> Hi, >> >> I don't quite understand how -m option is used. And it is difficult to >> search for -m in google. Could anybody provide me with an example on >> how to use this option? > >python -m test >at a command line runs the regression tests in the test package >python -m test -v test_difflib >runs test.test_difflib in verbose mode. I get for both : "/usr/bin/python: test is a package and cannot be directly executed." What gives? (Official stable Debian distribution. Python 2.7) >-- >Terry Jan Reedy > Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From tjreedy at udel.edu Mon Apr 8 14:47:31 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Mon, 08 Apr 2013 14:47:31 -0400 Subject: The usage of -m option of python In-Reply-To: <5162d932$0$6060$e4fe514c@dreader36.news.xs4all.nl> References: <5162d932$0$6060$e4fe514c@dreader36.news.xs4all.nl> Message-ID: On 4/8/2013 10:50 AM, Albert van der Horst wrote: > In article , > Terry Reedy wrote: >> On 3/18/2013 5:17 PM, Peng Yu wrote: >>> Hi, >>> >>> I don't quite understand how -m option is used. And it is difficult to >>> search for -m in google. Could anybody provide me with an example on >>> how to use this option? >> >> python -m test >> at a command line runs the regression tests in the test package >> python -m test -v test_difflib >> runs test.test_difflib in verbose mode. > > I get for both : > "/usr/bin/python: test is a package and cannot be directly executed." > > What gives? > > (Official stable Debian distribution. Python 2.7) For me, 3.3 is default Python. Look in the 2.7 doc for 'test' and I believe it will tell you that you need to write 'test.regrtest'. tjr From michael.herrmann at getautoma.com Thu Apr 4 03:05:30 2013 From: michael.herrmann at getautoma.com (Michael Herrmann) Date: Thu, 4 Apr 2013 00:05:30 -0700 (PDT) Subject: Help me pick an API design (OO vs functional) In-Reply-To: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> References: <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> Message-ID: Hi everyone, we just released the new version of our GUI automation tool with the improved API: http://www.getautoma.com/blog/Automa-1-5-1-window-switching. Thank you again for your help. Best regards, Michael On Monday, March 25, 2013 8:29:23 PM UTC+1, Michael Herrmann wrote: > Hello everyone, > > > > my name is Michael, I'm the lead developer of a Python GUI automation library for Windows called Automa: http://www.getautoma.com. We want to add some features to our library but are unsure how to best expose them via our API. It would be extremely helpful for us if you could let us know which API design feels "right" to you. > > > > Our API already offers very simple commands for automating the GUI of a Windows computer. For example: > > > > from automa.api import * > > start("Notepad") > > write("Hello World!") > > press(CTRL + 's') > > write("test.txt", into="File name") > > click("Save") > > click("Close") > > > > When you execute this script, Automa starts Notepad and simulates key strokes, mouse movements and clicks to perform the required commands. At the moment, each action is performed in the currently active window. > > > > We do not (yet) have a functionality that allows you to explicitly switch to a specific window. Such a functionality would for instance make it possible to open two Notepad windows using the start(...) command, and copy text between them. > > > > One API design would be to have our start(...) function return a "Window" (say) object, whose methods allow you to do the same operations as the global functions write(...), press(...), click(...) etc., but in the respective window. In this design, the example of operating two Notepad windows could be written as > > > > notepad_1 = start("Notepad") > > notepad_2 = start("Notepad") > > notepad_1.write("Hello World!") > > notepad_1.press(CTRL + 'a', CTRL + 'c') > > notepad_2.press(CTRL + 'v') > > > > The problem with this design is that it effectively duplicates our API: We want to keep our "global" functions because they are so easy to read. If we add methods to a new "Window" class that do more or less the same, we feel that we are violating Python's principle that "There should be one - and preferably only one - obvious way to do it." > > > > An alternative design would be to make the window switching an explicit action. One way of doing this would be to add a new global function, say "switch_to" or "activate", that takes a single parameter that identifies the window to be switched to. We could still have start(...) return a Window object, that could then be passed to our function: > > > > notepad_1 = start("Notepad") > > notepad_2 = start("Notepad") > > switch_to(notepad_1) > > write("Hello World!") > > press(CTRL + 'a', CTRL + 'c') > > switch_to(notepad_2) > > press(CTRL + 'v') > > > > Maybe our Window objects could also be used as context managers: > > > > notepad_1 = start("Notepad") > > notepad_2 = start("Notepad") > > with notepad_1: > > write("Hello World!") > > press(CTRL + 'a', CTRL + 'c') > > with notepad_2: > > press(CTRL + 'v') > > > > As a final idea, switching could also be done as a method of the Window class: > > > > notepad_1 = start("Notepad") > > notepad_2 = start("Notepad") > > notepad_1.activate() > > write("Hello World!") > > press(CTRL + 'a', CTRL + 'c') > > notepad_2.activate() > > press(CTRL + 'v') > > > > It would be extremely helpful for us if you could let me know which way of using the API you would prefer. If you opt for an explicit version, how would you call the respective method? "activate" / "switch_to" / "focus" or something else? > > > > Thank you so much! > > > > Best wishes, > > Michael From rustompmody at gmail.com Mon Apr 1 01:33:45 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 31 Mar 2013 22:33:45 -0700 (PDT) Subject: Performance of int/long in Python 3 References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> <0b6be19c-ff11-4e24-a7dc-fec0af411393@kw7g2000pbb.googlegroups.com> <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> Message-ID: <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> On Mar 31, 5:55?pm, Mark Lawrence wrote: > I'm feeling very sorry for this horse, it's been flogged so often it's > down to bare bones. While I am now joining the camp of those fed up with jmf's whining, I do wonder if we are shooting the messenger? >From a recent Roy mysqldb-unicode thread: > My unicode-fu is a bit weak. Are we looking at a Python problem, a > MySQLdb problem, or a problem with the underlying MySQL server? We've > certainly inserted utf-8 data before without any problems. It's > possible this is the first time we've tried to handle a character > outside the BMP. : : > OK, that leads to the next question. Is there anyway I can (in Python > 2.7) detect when a string is not entirely in the BMP? If I could find > all the non-BMP characters, I could replace them with U+FFFD > (REPLACEMENT CHARACTER) and life would be good (enough). Steven's: > But it means that if you're one of the 99.9% of users who mostly use > characters in the BMP, ? And from http://www.tlg.uci.edu/~opoudjis/unicode/unicode_astral.html > The informal name for the supplementary planes of Unicode is "astral planes", since > (especially in the late '90s) their use seemed to be as remote as > the theosophical "great beyond". ? > As of this writing for instance, Dreamweaver MX for MacOSX (which I am currently using > to prepare this) will let you paste BMP text into its WYSIWYG window; but pasting > Supplementary Plane text there will make it crash. So I really wonder: Is python losing more by supporting SMP with performance hit on BMP? The problem as I see it is that a choice that is sufficiently skew is no more a straightforward choice. An example will illustrate: I can choose to drive or not -- a choice. Statistics tell me that on average there are 3 fatalities every day; I am very concerned that I could get killed so I choose not to drive. Which neglects that there are a couple of million safe-drives at the same time as the '3 fatalities' [What if anything this has to do with jmf's rants I dont know because I dont know if anyone (including jmf) knows what he is ranting about. ] From ian.g.kelly at gmail.com Mon Apr 1 01:52:52 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 31 Mar 2013 23:52:52 -0600 Subject: Performance of int/long in Python 3 In-Reply-To: <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> <0b6be19c-ff11-4e24-a7dc-fec0af411393@kw7g2000pbb.googlegroups.com> <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> Message-ID: On Sun, Mar 31, 2013 at 11:33 PM, rusi wrote: > > So I really wonder: Is python losing more by supporting SMP with > performance hit on BMP? I don't believe so. Although performance is undeniably worse for some benchmarks, it is also better for some others. Nobody has yet demonstrated an actual, real-world program that is affected negatively by the Unicode change. All of jmf's complaints amount to cherry-picking data and leaping to conclusions. From rosuav at gmail.com Mon Apr 1 01:57:51 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Apr 2013 16:57:51 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> <0b6be19c-ff11-4e24-a7dc-fec0af411393@kw7g2000pbb.googlegroups.com> <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> Message-ID: On Mon, Apr 1, 2013 at 4:33 PM, rusi wrote: > So I really wonder: Is python losing more by supporting SMP with > performance hit on BMP? If your strings fit entirely within the BMP, then you should see no penalty compared to previous versions of Python. If they happen to fit inside ASCII, then there may well be significant improvements. But regardless, what you gain is the ability to work with *any* string, regardless of its content, without worrying about it. You can count characters regardless of their content. Imagine if a tuple of integers behaved differently if some of those integers flipped to being long ints: x = (1, 2, 4, 8, 1<<30, 1<<300, 1<<10) Wouldn't you be surprised if len(x) returned 8? I certainly would be. And that's what a narrow build of Python does with Unicode. Unicode strings are approximately comparable to tuples of integers. In fact, they can be interchanged fairly readily: string = "Treble clef: \U0001D11E" array = tuple(map(ord,string)) assert(len(array) == 14) out_string = ''.join(map(chr,array)) assert(out_string == string) This doesn't work in Python 2.6 on Windows, partly because of surrogates, but also because chr() isn't designed for Unicode strings. There's probably a solution to the second, but not really to the first. The tuple of ords should match the way the characters are laid out to a human. ChrisA From steve+comp.lang.python at pearwood.info Mon Apr 1 04:14:16 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Apr 2013 08:14:16 GMT Subject: Performance of int/long in Python 3 References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> <0b6be19c-ff11-4e24-a7dc-fec0af411393@kw7g2000pbb.googlegroups.com> <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> Message-ID: <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> On Sun, 31 Mar 2013 22:33:45 -0700, rusi wrote: > On Mar 31, 5:55?pm, Mark Lawrence wrote: > > > >> I'm feeling very sorry for this horse, it's been flogged so often it's >> down to bare bones. > > While I am now joining the camp of those fed up with jmf's whining, I do > wonder if we are shooting the messenger? No. The trouble is that the messenger is shouting that the Unicode world is ending on December 21st 2012, and hasn't noticed that was over three months ago and the world didn't end. [...] >> OK, that leads to the next question. Is there anyway I can (in Python >> 2.7) detect when a string is not entirely in the BMP? If I could find >> all the non-BMP characters, I could replace them with U+FFFD >> (REPLACEMENT CHARACTER) and life would be good (enough). Of course you can do this, but you should not. If your input data includes character C, you should deal with character C and not just throw it away unnecessarily. That would be rude, and in Python 3.3 it should be unnecessary. Although, since the person you are quoting is stuck in Python 2.7, it may be less bad than having to deal with potentially broken Unicode strings. > Steven's: >> But it means that if you're one of the 99.9% of users who mostly use >> characters in the BMP, ? Yes. "Mostly" does not mean exclusively, and given (say) a billion computer users, that leaves about a million users who have significant need for non-BMP characters. If you don't agree with my estimate, feel free to invent your own :-) > And from http://www.tlg.uci.edu/~opoudjis/unicode/unicode_astral.html >> The informal name for the supplementary planes of Unicode is "astral >> planes", since (especially in the late '90s) their use seemed to be as >> remote as the theosophical "great beyond". ? That was nearly two decades ago. Two decades ago, the idea that the entire computing world could standardize on a single character set, instead of having to deal with dozens of different "code pages", seemed as likely as people landing on the Moon seemed in 1940. Today, the entire computing world has standardized on such a system, "code pages" (encodings) are mostly only needed for legacy data and shitty applications, but most implementations don't support the entire Unicode range. A couple of programming languages, including Pike and Python, support Unicode fully and correctly. Pike has never had the same high-profile as Python, but now that Python can support the entire Unicode range without broken surrogate support, maybe users of other languages will start to demand the same. > So I really wonder: Is python losing more by supporting SMP with > performance hit on BMP? No. As many people have demonstrated, both with code snippets and whole- program benchmarks, Python 3.3 is *as fast* or *faster* than Python 3.2 narrow builds. In practice, Python 3.3 saves enough memory by using sensible string implementations that real world software is faster in Python 3.3 than in 3.2. > The problem as I see it is that a choice that is sufficiently skew is no > more a straightforward choice. An example will illustrate: > > I can choose to drive or not -- a choice. Statistics tell me that on > average there are 3 fatalities every day; I am very concerned that I > could get killed so I choose not to drive. Which neglects that there are > a couple of million safe-drives at the same time as the '3 fatalities' Clear as mud. What does this have to do with supporting Unicode? -- Steven From roy at panix.com Mon Apr 1 08:15:53 2013 From: roy at panix.com (Roy Smith) Date: Mon, 01 Apr 2013 08:15:53 -0400 Subject: Performance of int/long in Python 3 References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> <0b6be19c-ff11-4e24-a7dc-fec0af411393@kw7g2000pbb.googlegroups.com> <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <515941d8$0$29967$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > [...] > >> OK, that leads to the next question. Is there anyway I can (in Python > >> 2.7) detect when a string is not entirely in the BMP? If I could find > >> all the non-BMP characters, I could replace them with U+FFFD > >> (REPLACEMENT CHARACTER) and life would be good (enough). > > Of course you can do this, but you should not. If your input data > includes character C, you should deal with character C and not just throw > it away unnecessarily. That would be rude, and in Python 3.3 it should be > unnecessary. The import job isn't done yet, but so far we've processed 116 million records and had to clean up four of them. I can live with that. Sometimes practicality trumps correctness. It turns out, the problem is that the version of MySQL we're using doesn't support non-BMP characters. Newer versions do (but you have to declare the column to use the utf8bm4 character set). I could upgrade to a newer MySQL version, but it's just not worth it. Actually, I did try spinning up a 5.5 instance (one of the nice things of being in the cloud) and experimented with that, but couldn't get it to work there either. I'll admit that I didn't invest a huge amount of effort to make that work before just writing this: def bmp_filter(self, s): """Filter a unicode string to remove all non-BMP (basic multilingual plane) characters. All such characters are replaced with U+FFFD (Unicode REPLACEMENT CHARACTER). """ if all(ord(c) <= 0xffff for c in s): return s else: self.logger.warning("making %r BMP-clean", s) bmp_chars = [(c if ord(c) <= 0xffff else u'\ufffd') for c in s] return ''.join(bmp_chars) From rustompmody at gmail.com Mon Apr 1 09:11:50 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 1 Apr 2013 06:11:50 -0700 (PDT) Subject: Performance of int/long in Python 3 References: <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> <0b6be19c-ff11-4e24-a7dc-fec0af411393@kw7g2000pbb.googlegroups.com> <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2bfc9e3f-cddc-4c65-a9b9-fc9794f57d86@9g2000pba.googlegroups.com> On Apr 1, 5:15?pm, Roy Smith wrote: > In article <515941d8$0$29967$c3e8da3$54964... at news.astraweb.com>, > ?Steven D'Aprano wrote: > > > [...] > > >> OK, that leads to the next question. ?Is there anyway I can (in Python > > >> 2.7) detect when a string is not entirely in the BMP? ?If I could find > > >> all the non-BMP characters, I could replace them with U+FFFD > > >> (REPLACEMENT CHARACTER) and life would be good (enough). > > > Of course you can do this, but you should not. If your input data > > includes character C, you should deal with character C and not just throw > > it away unnecessarily. That would be rude, and in Python 3.3 it should be > > unnecessary. > > The import job isn't done yet, but so far we've processed 116 million > records and had to clean up four of them. ?I can live with that. > Sometimes practicality trumps correctness. That works out to 0.000003%. Of course I assume it is US only data. Still its good to know how skew the distribution is. From steve+comp.lang.python at pearwood.info Mon Apr 1 13:02:35 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Apr 2013 17:02:35 GMT Subject: Performance of int/long in Python 3 References: <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> <0b6be19c-ff11-4e24-a7dc-fec0af411393@kw7g2000pbb.googlegroups.com> <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <2bfc9e3f-cddc-4c65-a9b9-fc9794f57d86@9g2000pba.googlegroups.com> Message-ID: <5159bdab$0$29967$c3e8da3$5496439d@news.astraweb.com> On Mon, 01 Apr 2013 06:11:50 -0700, rusi wrote: > On Apr 1, 5:15?pm, Roy Smith wrote: >> The import job isn't done yet, but so far we've processed 116 million >> records and had to clean up four of them. ?I can live with that. >> Sometimes practicality trumps correctness. > > That works out to 0.000003%. Of course I assume it is US only data. > Still its good to know how skew the distribution is. If the data included Japanese names, or used Emoji, it would be much closer to 100% than 0.000003%. -- Steven From steve+comp.lang.python at pearwood.info Mon Apr 1 13:07:02 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Apr 2013 17:07:02 GMT Subject: Performance of int/long in Python 3 References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> <0b6be19c-ff11-4e24-a7dc-fec0af411393@kw7g2000pbb.googlegroups.com> <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> On Mon, 01 Apr 2013 08:15:53 -0400, Roy Smith wrote: > In article <515941d8$0$29967$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> [...] >> >> OK, that leads to the next question. Is there anyway I can (in >> >> Python 2.7) detect when a string is not entirely in the BMP? If I >> >> could find all the non-BMP characters, I could replace them with >> >> U+FFFD (REPLACEMENT CHARACTER) and life would be good (enough). >> >> Of course you can do this, but you should not. If your input data >> includes character C, you should deal with character C and not just >> throw it away unnecessarily. That would be rude, and in Python 3.3 it >> should be unnecessary. > > The import job isn't done yet, but so far we've processed 116 million > records and had to clean up four of them. I can live with that. > Sometimes practicality trumps correctness. Well, true. It has to be said that few programming languages (and databases) make it easy to do the right thing. On the other hand, you're a programmer. Your job is to write correct code, not easy code. > It turns out, the problem is that the version of MySQL we're using Well there you go. Why don't you use a real database? http://www.postgresql.org/docs/9.2/static/multibyte.html :-) Postgresql has supported non-broken UTF-8 since at least version 8.1. > doesn't support non-BMP characters. Newer versions do (but you have to > declare the column to use the utf8bm4 character set). I could upgrade > to a newer MySQL version, but it's just not worth it. My brain just broke. So-called "UTF-8" in MySQL only includes up to a maximum of three-byte characters. There has *never* been a time where UTF-8 excluded four-byte characters. What were the developers thinking, arbitrarily cutting out support for 50% of UTF-8? > Actually, I did try spinning up a 5.5 instance (one of the nice things > of being in the cloud) and experimented with that, but couldn't get it > to work there either. I'll admit that I didn't invest a huge amount of > effort to make that work before just writing this: > > def bmp_filter(self, s): > """Filter a unicode string to remove all non-BMP (basic > multilingual plane) characters. All such characters are > replaced with U+FFFD (Unicode REPLACEMENT CHARACTER). > > """ I expect that in 5-10 years, applications that remove or mangle non-BMP characters will be considered as unacceptable as applications that mangle BMP characters. Or for that matter, applications that cannot handle names with apostrophes. Hell, if your customer base is in Asia, chances are that mangling non-BMP characters is *already* considered unacceptable. -- Steven From rosuav at gmail.com Mon Apr 1 13:20:30 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Apr 2013 04:20:30 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> <0b6be19c-ff11-4e24-a7dc-fec0af411393@kw7g2000pbb.googlegroups.com> <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Apr 2, 2013 at 4:07 AM, Steven D'Aprano wrote: > On Mon, 01 Apr 2013 08:15:53 -0400, Roy Smith wrote: >> It turns out, the problem is that the version of MySQL we're using > > Well there you go. Why don't you use a real database? > > http://www.postgresql.org/docs/9.2/static/multibyte.html > > :-) > > Postgresql has supported non-broken UTF-8 since at least version 8.1. Not only that, but I *rely* on PostgreSQL to test-or-reject stuff that comes from untrustworthy languages, like PHP. If it's malformed in any way, it won't get past the database. >> doesn't support non-BMP characters. Newer versions do (but you have to >> declare the column to use the utf8bm4 character set). I could upgrade >> to a newer MySQL version, but it's just not worth it. > > My brain just broke. So-called "UTF-8" in MySQL only includes up to a > maximum of three-byte characters. There has *never* been a time where > UTF-8 excluded four-byte characters. What were the developers thinking, > arbitrarily cutting out support for 50% of UTF-8? Steven, you punctuated that wrongly. What, were the developers *thinking*? Arbitrarily etc? It really is brain-breaking. I could understand a naive UTF-8 codec being too permissive (allowing over-long encodings, allowing codepoints above what's allocated (eg FA 80 80 80 80, which would notionally represent U+2000000), etc), but why should it arbitrarily stop short? There must have been some internal limitation - that, perhaps, collation was defined only within the BMP. ChrisA From python at mrabarnett.plus.com Mon Apr 1 13:53:44 2013 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 01 Apr 2013 18:53:44 +0100 Subject: Performance of int/long in Python 3 In-Reply-To: <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> References: <5153a12d$0$29998$c3e8da3$5496439d@news.astraweb.com> <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> <0b6be19c-ff11-4e24-a7dc-fec0af411393@kw7g2000pbb.googlegroups.com> <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5159C9A8.5040302@mrabarnett.plus.com> On 01/04/2013 18:07, Steven D'Aprano wrote: > On Mon, 01 Apr 2013 08:15:53 -0400, Roy Smith wrote: > >> In article <515941d8$0$29967$c3e8da3$5496439d at news.astraweb.com>, >> Steven D'Aprano wrote: >> >>> [...] >>> >> OK, that leads to the next question. Is there anyway I can (in >>> >> Python 2.7) detect when a string is not entirely in the BMP? If I >>> >> could find all the non-BMP characters, I could replace them with >>> >> U+FFFD (REPLACEMENT CHARACTER) and life would be good (enough). >>> >>> Of course you can do this, but you should not. If your input data >>> includes character C, you should deal with character C and not just >>> throw it away unnecessarily. That would be rude, and in Python 3.3 it >>> should be unnecessary. >> >> The import job isn't done yet, but so far we've processed 116 million >> records and had to clean up four of them. I can live with that. >> Sometimes practicality trumps correctness. > > Well, true. It has to be said that few programming languages (and > databases) make it easy to do the right thing. On the other hand, you're > a programmer. Your job is to write correct code, not easy code. > > >> It turns out, the problem is that the version of MySQL we're using > > Well there you go. Why don't you use a real database? > > http://www.postgresql.org/docs/9.2/static/multibyte.html > > :-) > > Postgresql has supported non-broken UTF-8 since at least version 8.1. > > >> doesn't support non-BMP characters. Newer versions do (but you have to >> declare the column to use the utf8bm4 character set). I could upgrade >> to a newer MySQL version, but it's just not worth it. > > My brain just broke. So-called "UTF-8" in MySQL only includes up to a > maximum of three-byte characters. There has *never* been a time where > UTF-8 excluded four-byte characters. What were the developers thinking, > arbitrarily cutting out support for 50% of UTF-8? > [snip] 50%? The BMP is one of 17 planes, so wouldn't that be 94%? From wxjmfauth at gmail.com Mon Apr 1 15:15:25 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Mon, 1 Apr 2013 12:15:25 -0700 (PDT) Subject: Performance of int/long in Python 3 References: <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> <0b6be19c-ff11-4e24-a7dc-fec0af411393@kw7g2000pbb.googlegroups.com> <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> --------- I'm not whining or and I'm not complaining (and never did). I always exposed facts. I'm not especially interested in Python, I'm interested in Unicode. Usualy when I posted examples, there are confirmed. What I see is this (std "download-abled" Python's on Windows 7 (and other Windows/platforms/machines): Py32 >>> import timeit >>> timeit.repeat("'a' * 1000 + '?'") [0.7005365263669056, 0.6810694766790423, 0.6811978680727229] >>> timeit.repeat("'a' * 1000 + 'z'") [0.7105829560031083, 0.6904999426964764, 0.6938637184431968] Py33 import timeit timeit.repeat("'a' * 1000 + '?'") [1.1484035160337613, 1.1233738895227505, 1.1215708962703874] timeit.repeat("'a' * 1000 + 'z'") [0.6640958193635527, 0.6469043692851528, 0.6458961423900007] I have systematically such a behaviour, in 99.99999% of my tests. When there is something better, it is usually because something else (3.2/3.3) has been modified. I have my idea where this is coming from. Question: When it is claimed, that this has been tested, do you mean stringbench.py as proposed many times by Terry? (Thanks for an answer). jmf From rosuav at gmail.com Mon Apr 1 15:28:53 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Apr 2013 06:28:53 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> References: <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> <0b6be19c-ff11-4e24-a7dc-fec0af411393@kw7g2000pbb.googlegroups.com> <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> Message-ID: On Tue, Apr 2, 2013 at 6:15 AM, jmfauth wrote: > Py32 >>>> import timeit >>>> timeit.repeat("'a' * 1000 + '?'") > [0.7005365263669056, 0.6810694766790423, 0.6811978680727229] >>>> timeit.repeat("'a' * 1000 + 'z'") > [0.7105829560031083, 0.6904999426964764, 0.6938637184431968] > > Py33 > import timeit > timeit.repeat("'a' * 1000 + '?'") > [1.1484035160337613, 1.1233738895227505, 1.1215708962703874] > timeit.repeat("'a' * 1000 + 'z'") > [0.6640958193635527, 0.6469043692851528, 0.6458961423900007] This is what's called a microbenchmark. Can you show me any instance in production code where an operation like this is done repeatedly, in a time-critical place? It's a contrived example, and it's usually possible to find regressions in any system if you fiddle enough with the example. Do you have, for instance, a web server that can handle 1000 tps on 3.2 and only 600 tps on 3.3, all other things being equal? ChrisA From breamoreboy at yahoo.co.uk Mon Apr 1 15:54:26 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 01 Apr 2013 20:54:26 +0100 Subject: Performance of int/long in Python 3 In-Reply-To: <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> References: <5153d313$0$29984$c3e8da3$5496439d@news.astraweb.com> <0b6be19c-ff11-4e24-a7dc-fec0af411393@kw7g2000pbb.googlegroups.com> <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> Message-ID: On 01/04/2013 20:15, jmfauth wrote: > --------- > > > I'm not whining or and I'm not complaining (and never did). > I always exposed facts. The only fact I'm aware of is an edge case that is being addressed on the Python bug tracker, sorry I'm too lazy to look up the number again. > > I'm not especially interested in Python, I'm interested in > Unicode. So why do you keep harping on about the same old edge case? > > Usualy when I posted examples, there are confirmed. The only thing you've ever posted are the same old boring micro benchmarks. You never, ever comment on the memory savings that are IIRC extremely popular with the Django folks amongst others. Neither do you comment on the fact that the unicode implementation in Python 3.3 is correct. I can only assume that you prefer a fast but buggy implementation to a correct but slow one. Except that in many cases the 3.3 implementation is actually faster, so you conveniently ignore this. > > > What I see is this (std "download-abled" Python's on Windows 7 (and > other > Windows/platforms/machines): > > Py32 >>>> import timeit >>>> timeit.repeat("'a' * 1000 + '?'") > [0.7005365263669056, 0.6810694766790423, 0.6811978680727229] >>>> timeit.repeat("'a' * 1000 + 'z'") > [0.7105829560031083, 0.6904999426964764, 0.6938637184431968] > > Py33 > import timeit > timeit.repeat("'a' * 1000 + '?'") > [1.1484035160337613, 1.1233738895227505, 1.1215708962703874] > timeit.repeat("'a' * 1000 + 'z'") > [0.6640958193635527, 0.6469043692851528, 0.6458961423900007] > > I have systematically such a behaviour, in 99.99999% of my tests. Always run on your micro benchmarks, never anything else. > When there is something better, it is usually because something else > (3.2/3.3) has been modified. > > I have my idea where this is coming from. I know where this is coming from as it's been stated umpteen times on numerous threads. As usual you simply ignore any facts that you feel like, particularly with respect to any real world use cases. > > Question: When it is claimed, that this has been tested, > do you mean stringbench.py as proposed many times by Terry? > (Thanks for an answer). I find it amusing that you ask for an answer but refuse point blank to provide answers yourself. I suspect that you've bitten off more than you can chew. > > jmf > -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From wxjmfauth at gmail.com Mon Apr 1 16:28:10 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Mon, 1 Apr 2013 13:28:10 -0700 (PDT) Subject: Performance of int/long in Python 3 References: <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> Message-ID: On 1 avr, 21:28, Chris Angelico wrote: > On Tue, Apr 2, 2013 at 6:15 AM, jmfauth wrote: > > Py32 > >>>> import timeit > >>>> timeit.repeat("'a' * 1000 + '?'") > > [0.7005365263669056, 0.6810694766790423, 0.6811978680727229] > >>>> timeit.repeat("'a' * 1000 + 'z'") > > [0.7105829560031083, 0.6904999426964764, 0.6938637184431968] > > > Py33 > > import timeit > > timeit.repeat("'a' * 1000 + '?'") > > [1.1484035160337613, 1.1233738895227505, 1.1215708962703874] > > timeit.repeat("'a' * 1000 + 'z'") > > [0.6640958193635527, 0.6469043692851528, 0.6458961423900007] > > This is what's called a microbenchmark. Can you show me any instance > in production code where an operation like this is done repeatedly, in > a time-critical place? It's a contrived example, and it's usually > possible to find regressions in any system if you fiddle enough with > the example. Do you have, for instance, a web server that can handle > 1000 tps on 3.2 and only 600 tps on 3.3, all other things being equal? > > ChrisA ----- Of course this is an example, as many I gave. Examples you may find in apps. Can you point and give at least a bunch of examples, showing there is no regression, at least to contradict me. The only one I succeed to see (in month), is the one given by Steven, a status quo. I will happily accept them. The only think I read is "this is faster", "it has been tested", ... jmf From rosuav at gmail.com Mon Apr 1 16:35:41 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Apr 2013 07:35:41 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> Message-ID: On Tue, Apr 2, 2013 at 7:28 AM, jmfauth wrote: > Of course this is an example, as many I gave. Examples you may find in > apps. > Show me an *entire app* that suffers. Show me one. ChrisA From breamoreboy at yahoo.co.uk Mon Apr 1 17:38:24 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 01 Apr 2013 22:38:24 +0100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> Message-ID: On 01/04/2013 21:35, Chris Angelico wrote: > On Tue, Apr 2, 2013 at 7:28 AM, jmfauth wrote: >> Of course this is an example, as many I gave. Examples you may find in >> apps. >> > > Show me an *entire app* that suffers. > > Show me one. > > ChrisA > Please don't hold your breath. -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From breamoreboy at yahoo.co.uk Mon Apr 1 17:43:13 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 01 Apr 2013 22:43:13 +0100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> Message-ID: On 01/04/2013 21:28, jmfauth wrote: > On 1 avr, 21:28, Chris Angelico wrote: >> On Tue, Apr 2, 2013 at 6:15 AM, jmfauth wrote: >>> Py32 >>>>>> import timeit >>>>>> timeit.repeat("'a' * 1000 + '?'") >>> [0.7005365263669056, 0.6810694766790423, 0.6811978680727229] >>>>>> timeit.repeat("'a' * 1000 + 'z'") >>> [0.7105829560031083, 0.6904999426964764, 0.6938637184431968] >> >>> Py33 >>> import timeit >>> timeit.repeat("'a' * 1000 + '?'") >>> [1.1484035160337613, 1.1233738895227505, 1.1215708962703874] >>> timeit.repeat("'a' * 1000 + 'z'") >>> [0.6640958193635527, 0.6469043692851528, 0.6458961423900007] >> >> This is what's called a microbenchmark. Can you show me any instance >> in production code where an operation like this is done repeatedly, in >> a time-critical place? It's a contrived example, and it's usually >> possible to find regressions in any system if you fiddle enough with >> the example. Do you have, for instance, a web server that can handle >> 1000 tps on 3.2 and only 600 tps on 3.3, all other things being equal? >> >> ChrisA > > ----- > > Of course this is an example, as many I gave. Examples you may find in > apps. You've given many examples of the same type of micro benchmark, not many examples of different types of benchmark. > > Can you point and give at least a bunch of examples, showing > there is no regression, at least to contradict me. The only > one I succeed to see (in month), is the one given by Steven, a status > quo. Once again you deliberately choose to ignore the memory saving and correctness to concentrate on the performance slowdown in some cases. > > I will happily accept them. The only think I read is "this is faster", > "it has been tested", ... > I do not believe that you will ever accept any facts unless you yourself provide them. > jmf > -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From nhodgson at iinet.net.au Mon Apr 1 19:43:59 2013 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Tue, 02 Apr 2013 10:43:59 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> Message-ID: Mark Lawrence: > You've given many examples of the same type of micro benchmark, not many > examples of different types of benchmark. Trying to work out what jmfauth is on about I found what appears to be a performance regression with '<' string comparisons on Windows 64-bit. Its around 30% slower on a 25 character string that differs in the last character and 70-100% on a 100 character string that differs at the end. Can someone else please try this to see if its reproducible? Linux doesn't show this problem. >c:\python32\python -u "charwidth.py" 3.2 (r32:88445, Feb 20 2011, 21:30:00) [MSC v.1500 64 bit (AMD64)] a=['C:/Users/Neil/Documents/b','C:/Users/Neil/Documents/z']176 [0.7116295577956576, 0.7055591343157613, 0.7203483026429418] a=['C:/Users/Neil/Documents/?','C:/Users/Neil/Documents/?']176 [0.7664397841378787, 0.7199902325464409, 0.713719289812504] a=['C:/Users/Neil/Documents/b','C:/Users/Neil/Documents/?']176 [0.7341851791817691, 0.6994205901833599, 0.7106807593741005] a=['C:/Users/Neil/Documents/?','C:/Users/Neil/Documents/?']180 [0.7346812372666784, 0.6995411113377914, 0.7064768417728411] >c:\python33\python -u "charwidth.py" 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit (AMD64)] a=['C:/Users/Neil/Documents/b','C:/Users/Neil/Documents/z']108 [0.9913326076446045, 0.9455845241056282, 0.9459076605341776] a=['C:/Users/Neil/Documents/?','C:/Users/Neil/Documents/?']192 [1.0472289217234318, 1.0362342484091207, 1.0197109728048384] a=['C:/Users/Neil/Documents/b','C:/Users/Neil/Documents/?']192 [1.0439643704533834, 0.9878581050301687, 0.9949265834034335] a=['C:/Users/Neil/Documents/?','C:/Users/Neil/Documents/?']312 [1.0987483965446412, 1.0130257167690004, 1.024832248526499] Here is the code: # encoding:utf-8 import os, sys, timeit print(sys.version) examples = [ "a=['$b','$z']", "a=['$?','$?']", "a=['$b','$?']", "a=['$\U00020000','$\U00020001']"] baseDir = "C:/Users/Neil/Documents/" #~ baseDir = "C:/Users/Neil/Documents/Visual Studio 2012/Projects/Sigma/QtReimplementation/HLFKBase/Win32/x64/Debug" for t in examples: t = t.replace("$", baseDir) # Using os.write as simple way get UTF-8 to stdout os.write(sys.stdout.fileno(), t.encode("utf-8")) print(sys.getsizeof(t)) print(timeit.repeat("a[0] < a[1]",t,number=5000000)) print() For a more significant performance difference try replacing the baseDir setting with (may be wrapped): baseDir = "C:/Users/Neil/Documents/Visual Studio 2012/Projects/Sigma/QtReimplementation/HLFKBase/Win32/x64/Debug" Neil From wxjmfauth at gmail.com Tue Apr 2 03:24:21 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Tue, 2 Apr 2013 00:24:21 -0700 (PDT) Subject: Performance of int/long in Python 3 References: <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> Message-ID: On 2 avr, 01:43, Neil Hodgson wrote: > Mark Lawrence: > > > You've given many examples of the same type of micro benchmark, not many > > examples of different types of benchmark. > > ? ? Trying to work out what jmfauth is on about I found what appears to > be a performance regression with '<' string comparisons on Windows > 64-bit. Its around 30% slower on a 25 character string that differs in > the last character and 70-100% on a 100 character string that differs at > the end. > > ? ? Can someone else please try this to see if its reproducible? Linux > doesn't show this problem. > > ?>c:\python32\python -u "charwidth.py" > 3.2 (r32:88445, Feb 20 2011, 21:30:00) [MSC v.1500 64 bit (AMD64)] > a=['C:/Users/Neil/Documents/b','C:/Users/Neil/Documents/z']176 > [0.7116295577956576, 0.7055591343157613, 0.7203483026429418] > > a=['C:/Users/Neil/Documents/?','C:/Users/Neil/Documents/?']176 > [0.7664397841378787, 0.7199902325464409, 0.713719289812504] > > a=['C:/Users/Neil/Documents/b','C:/Users/Neil/Documents/?']176 > [0.7341851791817691, 0.6994205901833599, 0.7106807593741005] > > a=['C:/Users/Neil/Documents/?','C:/Users/Neil/Documents/?']180 > [0.7346812372666784, 0.6995411113377914, 0.7064768417728411] > > ?>c:\python33\python -u "charwidth.py" > 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit > (AMD64)] > a=['C:/Users/Neil/Documents/b','C:/Users/Neil/Documents/z']108 > [0.9913326076446045, 0.9455845241056282, 0.9459076605341776] > > a=['C:/Users/Neil/Documents/?','C:/Users/Neil/Documents/?']192 > [1.0472289217234318, 1.0362342484091207, 1.0197109728048384] > > a=['C:/Users/Neil/Documents/b','C:/Users/Neil/Documents/?']192 > [1.0439643704533834, 0.9878581050301687, 0.9949265834034335] > > a=['C:/Users/Neil/Documents/?','C:/Users/Neil/Documents/?']312 > [1.0987483965446412, 1.0130257167690004, 1.024832248526499] > > ? ? Here is the code: > > # encoding:utf-8 > import os, sys, timeit > print(sys.version) > examples = [ > "a=['$b','$z']", > "a=['$?','$?']", > "a=['$b','$?']", > "a=['$\U00020000','$\U00020001']"] > baseDir = "C:/Users/Neil/Documents/" > #~ baseDir = "C:/Users/Neil/Documents/Visual Studio > 2012/Projects/Sigma/QtReimplementation/HLFKBase/Win32/x64/Debug" > for t in examples: > ? ? ?t = t.replace("$", baseDir) > ? ? ?# Using os.write as simple way get UTF-8 to stdout > ? ? ?os.write(sys.stdout.fileno(), t.encode("utf-8")) > ? ? ?print(sys.getsizeof(t)) > ? ? ?print(timeit.repeat("a[0] < a[1]",t,number=5000000)) > ? ? ?print() > > ? ? For a more significant performance difference try replacing the > baseDir setting with (may be wrapped): > baseDir = "C:/Users/Neil/Documents/Visual Studio > 2012/Projects/Sigma/QtReimplementation/HLFKBase/Win32/x64/Debug" > > ? ? Neil -------- Hi, >c:\python32\pythonw -u "charwidth.py" 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] a=['D:\jm\jmpy\py3app\stringbenchb','D:\jm\jmpy\py3app \stringbenchz']168 [0.8343414906182101, 0.8336184057396241, 0.8330473419738562] a=['D:\jm\jmpy\py3app\stringbench??','D:\jm\jmpy\py3app \stringbench??']168 [0.818378092261062, 0.8180854713107406, 0.8192279926793571] a=['D:\jm\jmpy\py3app\stringbenchb','D:\jm\jmpy\py3app \stringbench??']168 [0.8131353330542339, 0.8126985677326912, 0.8122744051977042] a=['D:\jm\jmpy\py3app\stringbench????','D:\jm\jmpy\py3app \stringbench????']172 [0.8271094603211102, 0.82704053883214, 0.8265781741004083] >Exit code: 0 >c:\Python33\pythonw -u "charwidth.py" 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] a=['D:\jm\jmpy\py3app\stringbenchb','D:\jm\jmpy\py3app \stringbenchz']94 [1.3840254166697845, 1.3933888932429768, 1.391664674507438] a=['D:\jm\jmpy\py3app\stringbench??','D:\jm\jmpy\py3app \stringbench??']176 [1.6217970707185678, 1.6279369907932706, 1.6207041728220117] a=['D:\jm\jmpy\py3app\stringbenchb','D:\jm\jmpy\py3app \stringbench??']176 [1.5150522562729396, 1.5130369919353992, 1.5121890607025037] a=['D:\jm\jmpy\py3app\stringbench????','D:\jm\jmpy\py3app \stringbench????']316 [1.6135375194801664, 1.6117739170366434, 1.6134331526540109] >Exit code: 0 - win7 32-bits - The file is in utf-8 - Do not be afraid by this output, it is just a copy/paste for your excellent editor, the coding output pane is configured to use the locale coding. - Of course and as expected, similar behaviour from a console. (Which btw show, how good is you application). ========== Something different. >From a previous msg, on this thread. --- > Sure. And over a different set of samples, it is less compact. If you > write a lot of Latin-1, Python will use one byte per character, while > UTF-8 will use two bytes per character. I think you mean writing a lot of Latin-1 characters outside ASCII. However, even people writing texts in, say, French will find that only a small proportion of their text is outside ASCII and so the cost of UTF-8 is correspondingly small. The counter-problem is that a French document that needs to include one mathematical symbol (or emoji) outside Latin-1 will double in size as a Python string. --- I already explained this. It is, how to say, a miss-understanding of Unicode. What's count, is not the amount of non-ascii chars you have in a stream. Relevant is the fact that every char is handled with the "same algorithm", in that case utf-8. Unicode takes you from the "char" up to the unicode transformated form. Then it is a question of implementation. This is exactly what you are doing in Scintilla (maybe without realizing this deeply). An editor may reflect very well the example a gave. You enter thousand ascii chars, then - boum - as you enter a non ascii char, your editor (assuming is uses a mechanism like the FSR), has to internally reencode everything! jmf From rosuav at gmail.com Tue Apr 2 04:03:17 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Apr 2013 19:03:17 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> Message-ID: On Tue, Apr 2, 2013 at 6:24 PM, jmfauth wrote: > An editor may reflect very well the example a gave. You enter > thousand ascii chars, then - boum - as you enter a non ascii > char, your editor (assuming is uses a mechanism like the FSR), > has to internally reencode everything! That assumes that the editor stores the entire buffer as a single Python string. Frankly, I think this unlikely; the nature of insertions and deletions makes this impractical. (I've known editors that do function this way. They're utterly unusable on large files.) ChrisA From steve+comp.lang.python at pearwood.info Tue Apr 2 04:35:30 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Apr 2013 08:35:30 GMT Subject: Performance of int/long in Python 3 References: <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> Message-ID: <515a9851$0$29891$c3e8da3$5496439d@news.astraweb.com> On Tue, 02 Apr 2013 19:03:17 +1100, Chris Angelico wrote: > On Tue, Apr 2, 2013 at 6:24 PM, jmfauth wrote: >> An editor may reflect very well the example a gave. You enter thousand >> ascii chars, then - boum - as you enter a non ascii char, your editor >> (assuming is uses a mechanism like the FSR), has to internally reencode >> everything! > > That assumes that the editor stores the entire buffer as a single Python > string. Frankly, I think this unlikely; the nature of insertions and > deletions makes this impractical. (I've known editors that do function > this way. They're utterly unusable on large files.) Nevertheless, for *some* size of text block (a word? line? paragraph?) an implementation may need to re-encode the block as characters are inserted or deleted. So what? Who cares if it takes 0.00002 second to insert a character instead of 0.00001 second? That's still a hundred times faster than you can type. -- Steven From wxjmfauth at gmail.com Tue Apr 2 05:24:09 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Tue, 2 Apr 2013 02:24:09 -0700 (PDT) Subject: Performance of int/long in Python 3 References: <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <515a9851$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2 avr, 10:35, Steven D'Aprano wrote: > On Tue, 02 Apr 2013 19:03:17 +1100, Chris Angelico wrote: > > So what? Who cares if it takes 0.00002 second to insert a character > instead of 0.00001 second? That's still a hundred times faster than you > can type. > --------- This not the problem. The interesting point is that they are good and "less good" Unicode implementations. jmf From breamoreboy at yahoo.co.uk Tue Apr 2 05:43:48 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 02 Apr 2013 10:43:48 +0100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <515a9851$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 02/04/2013 10:24, jmfauth wrote: > On 2 avr, 10:35, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> On Tue, 02 Apr 2013 19:03:17 +1100, Chris Angelico wrote: >> >> So what? Who cares if it takes 0.00002 second to insert a character >> instead of 0.00001 second? That's still a hundred times faster than you >> can type. >> > --------- > > This not the problem. The interesting point is that they > are good and "less good" Unicode implementations. > > jmf > The interesting point is that the Python 3.3 unicode implementation is correct, that of most other languages is buggy. Or have I fallen victim to the vicious propaganda of the various Pythonistas who frequent this list? -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From square.steve at gmail.com Tue Apr 2 06:58:11 2013 From: square.steve at gmail.com (Steve Simmons) Date: Tue, 02 Apr 2013 11:58:11 +0100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <515a9851$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: <515AB9C3.2000304@gmail.com> On 02/04/2013 10:43, Mark Lawrence wrote: > On 02/04/2013 10:24, jmfauth wrote: >> On 2 avr, 10:35, Steven D'Aprano > +comp.lang.pyt... at pearwood.info> wrote: >>> On Tue, 02 Apr 2013 19:03:17 +1100, Chris Angelico wrote: >>> >>> So what? Who cares if it takes 0.00002 second to insert a character >>> instead of 0.00001 second? That's still a hundred times faster than you >>> can type. >>> >> --------- >> >> This not the problem. The interesting point is that they >> are good and "less good" Unicode implementations. >> >> jmf >> > > The interesting point is that the Python 3.3 unicode implementation is > correct, that of most other languages is buggy. Or have I fallen > victim to the vicious propaganda of the various Pythonistas who > frequent this list? > Mark, Thanks for asking this question. It seems to me that jmf *might* be moving towards a vindicated position. There is some interest now in duplicating, understanding and (hopefully!) extending his test results, which can only be a Good Thing - whatever the outcome and wherever the facepalm might land. However, as you rightly point out, there is only value in following this through if the functionality is (at least near) 100% correct. I am sure there are some that will disagree but in most cases, functionality is the primary requirement and poor performance can be managed initially and fixed in due time. Steve From breamoreboy at yahoo.co.uk Tue Apr 2 10:12:44 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 02 Apr 2013 15:12:44 +0100 Subject: Performance of int/long in Python 3 In-Reply-To: <515AB9C3.2000304@gmail.com> References: <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <515a9851$0$29891$c3e8da3$5496439d@news.astraweb.com> <515AB9C3.2000304@gmail.com> Message-ID: On 02/04/2013 11:58, Steve Simmons wrote: > > On 02/04/2013 10:43, Mark Lawrence wrote: >> On 02/04/2013 10:24, jmfauth wrote: >>> On 2 avr, 10:35, Steven D'Aprano >> +comp.lang.pyt... at pearwood.info> wrote: >>>> On Tue, 02 Apr 2013 19:03:17 +1100, Chris Angelico wrote: >>>> >>>> So what? Who cares if it takes 0.00002 second to insert a character >>>> instead of 0.00001 second? That's still a hundred times faster than you >>>> can type. >>>> >>> --------- >>> >>> This not the problem. The interesting point is that they >>> are good and "less good" Unicode implementations. >>> >>> jmf >>> >> >> The interesting point is that the Python 3.3 unicode implementation is >> correct, that of most other languages is buggy. Or have I fallen >> victim to the vicious propaganda of the various Pythonistas who >> frequent this list? >> > Mark, > > Thanks for asking this question. > > It seems to me that jmf *might* be moving towards a vindicated > position. There is some interest now in duplicating, understanding and > (hopefully!) extending his test results, which can only be a Good Thing > - whatever the outcome and wherever the facepalm might land. > The position that is already documented in PEP393, how so? > However, as you rightly point out, there is only value in following this > through if the functionality is (at least near) 100% correct. I am sure > there are some that will disagree but in most cases, functionality is > the primary requirement and poor performance can be managed initially > and fixed in due time. I've already raised an issue about performance and Neil Hodgson has raised a new one. To balance this out perhaps we should have counter issues asking for the amount of memory being used to be increased to old levels and the earlier buggier behaviour of Python to be reintroduced? Swings and roundabouts? > > Steve -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From square.steve at gmail.com Tue Apr 2 11:03:30 2013 From: square.steve at gmail.com (Steve Simmons) Date: Tue, 02 Apr 2013 16:03:30 +0100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <515a9851$0$29891$c3e8da3$5496439d@news.astraweb.com> <515AB9C3.2000304@gmail.com> Message-ID: <515AF342.60605@gmail.com> On 02/04/2013 15:12, Mark Lawrence wrote: > I've already raised an issue about performance and Neil Hodgson has > raised a new one. Recognised in a separate post > To balance this out perhaps we should have counter issues asking for > the amount of memory being used to be increased to old levels and the > earlier buggier behaviour of Python to be reintroduced? Swings and > roundabouts? I don't think I came anywhere near suggesting that we should regress correct functionality or memory usage improvements. I just don't believe that we can't have good performance alongside it. Steve S From ethan at stoneleaf.us Tue Apr 2 11:17:12 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 02 Apr 2013 08:17:12 -0700 Subject: Performance of int/long in Python 3 In-Reply-To: <515AF342.60605@gmail.com> References: <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <515a9851$0$29891$c3e8da3$5496439d@news.astraweb.com> <515AB9C3.2000304@gmail.com> <515AF342.60605@gmail.com> Message-ID: <515AF678.5050002@stoneleaf.us> On 04/02/2013 08:03 AM, Steve Simmons wrote: > On 02/04/2013 15:12, Mark Lawrence wrote: >> I've already raised an issue about performance and Neil Hodgson has raised a new one. > Recognised in a separate post > >> To balance this out perhaps we should have counter issues asking for the amount of memory being used to be increased >> to old levels and the earlier buggier behaviour of Python to be reintroduced? Swings and roundabouts? > > I don't think I came anywhere near suggesting that we should regress correct functionality or memory usage > improvements. I just don't believe that we can't have good performance alongside it. It's always a trade-off between time and memory. However, as it happens, there are plenty of instances where the new FSR is faster -- and this in real world code, not useless micro-benchmarks. Simmons (too many Steves!), I know you're new so don't have all the history with jmf that many of us do, but consider that the original post was about numbers, had nothing to do with characters or unicode *in any way*, and yet jmf still felt the need to bring unicode up. -- ~Ethan~ From rustompmody at gmail.com Tue Apr 2 12:57:09 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 2 Apr 2013 09:57:09 -0700 (PDT) Subject: Performance of int/long in Python 3 References: <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <515a9851$0$29891$c3e8da3$5496439d@news.astraweb.com> <515AB9C3.2000304@gmail.com> <515AF342.60605@gmail.com> Message-ID: <757f2dad-c073-487f-ac40-310e54083eef@kw7g2000pbb.googlegroups.com> On Apr 2, 8:17?pm, Ethan Furman wrote: > Simmons (too many Steves!), I know you're new so don't have all the history with jmf that many > of us do, but consider that the original post was about numbers, had nothing to do with > characters or unicode *in any way*, and yet jmf still felt the need to bring unicode up. Just for reference, here is the starting para of Chris' original mail that started this thread. > The Python 3 merge of int and long has effectively penalized > small-number arithmetic by removing an optimization. As we've seen > from PEP 393 strings (jmf aside), there can be huge benefits from > having a single type with multiple representations internally. Is > there value in making the int type have a machine-word optimization in > the same way? ie it mentions numbers, strings, PEP 393 *AND jmf.* So while it is true that jmf has been butting in with trollish behavior into completely unrelated threads with his unicode rants, that cannot be said for this thread. From wxjmfauth at gmail.com Tue Apr 2 14:22:29 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Tue, 2 Apr 2013 11:22:29 -0700 (PDT) Subject: Performance of int/long in Python 3 References: <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <515a9851$0$29891$c3e8da3$5496439d@news.astraweb.com> <515AB9C3.2000304@gmail.com> <515AF342.60605@gmail.com> <757f2dad-c073-487f-ac40-310e54083eef@kw7g2000pbb.googlegroups.com> Message-ID: On 2 avr, 18:57, rusi wrote: > On Apr 2, 8:17?pm, Ethan Furman wrote: > > > Simmons (too many Steves!), I know you're new so don't have all the history with jmf that many > > of us do, but consider that the original post was about numbers, had nothing to do with > > characters or unicode *in any way*, and yet jmf still felt the need to bring unicode up. > > Just for reference, here is the starting para of Chris' original mail > that started this thread. > > > The Python 3 merge of int and long has effectively penalized > > small-number arithmetic by removing an optimization. As we've seen > > from PEP 393 strings (jmf aside), there can be huge benefits from > > having a single type with multiple representations internally. Is > > there value in making the int type have a machine-word optimization in > > the same way? > > ie it mentions numbers, strings, PEP 393 *AND jmf.* ?So while it is > true that jmf has been butting in with trollish behavior into > completely unrelated threads with his unicode rants, that cannot be > said for this thread. ----- That's because you did not understand the analogy, int/long <-> FSR. One another illustration, >>> def AddOne(i): ... if 0 < i <= 100: ... return i + 10 + 10 + 10 - 10 - 10 - 10 + 1 ... elif 100 < i <= 1000: ... return i + 100 + 100 + 100 + 100 - 100 - 100 - 100 - 100 + 1 ... else: ... return i + 1 ... Do it work? yes. Is is "correct"? this can be discussed. Now replace i by a char, a representent of each "subset" of the FSR, select a method where this FST behave badly and take a look of what happen. >>> timeit.repeat("'a' * 1000 + 'z'") [0.6532032148133153, 0.6407248807756699, 0.6407264561239894] >>> timeit.repeat("'a' * 1000 + '9'") [0.6429508479509245, 0.6242782443215589, 0.6240490311410927] >>> >>> timeit.repeat("'a' * 1000 + '?'") [1.095694927496563, 1.0696347279235603, 1.0687741939041082] >>> timeit.repeat("'a' * 1000 + '?'") [1.0796421281222877, 1.0348612767961853, 1.035325216876231] >>> timeit.repeat("'a' * 1000 + '\u2345'") [1.0855414137412112, 1.0694677410017164, 1.0688096392412945] >>> >>> timeit.repeat("'?' * 1000 + '\U00010001'") [1.237314015362017, 1.2226262553064657, 1.21994619397816] >>> timeit.repeat("'?' * 1000 + '\U00010002'") [1.245773635836997, 1.2303978424029651, 1.2258257877430765] Where does it come from? Simple, the FSR breaks the simple rules used in all coding schemes (unicode or not). 1) a unique set of chars 2) the "same" algorithm for all chars. And again that's why utf-8 is working very smoothly. The "corporates" which understood this very well and wanted to incorporate, let say, the used characters of the French language had only the choice to create new coding schemes (eg mac-roman, cp1252). In unicode, the "latin-1" range is real plague. After years of experience, I'm still fascinated to see the corporates has solved this issue easily and the "free software" is still relying on latin-1. I never succeed to find an explanation. Even, the TeX folks, when they shifted to the Cork encoding in 199?, were aware of this and consequently provides special package(s). No offense, this is in my mind why "corporate software" will always be "corporate software" and "hobbyist software" will always stay at the level of "hobbyist software". A French windows user, understanding nothing in the coding of characters, assuming he is aware of its existence (!), has certainly no problem. Fascinating how it is possible to use Python to teach, to illustrate, to explain the coding of the characters. No? jmf From rustompmody at gmail.com Tue Apr 2 14:50:10 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 2 Apr 2013 11:50:10 -0700 (PDT) Subject: Performance of int/long in Python 3 References: <515a9851$0$29891$c3e8da3$5496439d@news.astraweb.com> <515AB9C3.2000304@gmail.com> <515AF342.60605@gmail.com> <757f2dad-c073-487f-ac40-310e54083eef@kw7g2000pbb.googlegroups.com> Message-ID: <0db48970-c682-4881-8276-c8cae5d26640@kk11g2000pbb.googlegroups.com> On Apr 2, 11:22?pm, jmfauth wrote: > On 2 avr, 18:57, rusi wrote: > > > > > > > > > > > On Apr 2, 8:17?pm, Ethan Furman wrote: > > > > Simmons (too many Steves!), I know you're new so don't have all the history with jmf that many > > > of us do, but consider that the original post was about numbers, had nothing to do with > > > characters or unicode *in any way*, and yet jmf still felt the need to bring unicode up. > > > Just for reference, here is the starting para of Chris' original mail > > that started this thread. > > > > The Python 3 merge of int and long has effectively penalized > > > small-number arithmetic by removing an optimization. As we've seen > > > from PEP 393 strings (jmf aside), there can be huge benefits from > > > having a single type with multiple representations internally. Is > > > there value in making the int type have a machine-word optimization in > > > the same way? > > > ie it mentions numbers, strings, PEP 393 *AND jmf.* ?So while it is > > true that jmf has been butting in with trollish behavior into > > completely unrelated threads with his unicode rants, that cannot be > > said for this thread. > > ----- > > That's because you did not understand the analogy, int/long <-> FSR. > > One another illustration, > > >>> def AddOne(i): > > ... ? ? if 0 < i <= 100: > ... ? ? ? ? return i + 10 + 10 + 10 - 10 - 10 - 10 + 1 > ... ? ? elif 100 < i <= 1000: > ... ? ? ? ? return i + 100 + 100 + 100 ?+ 100 - 100 - 100 - 100 - 100 > + 1 > ... ? ? else: > ... ? ? ? ? return i + 1 > ... > > Do it work? yes. > Is is "correct"? this can be discussed. > > Now replace i by a char, a representent of each "subset" > of the FSR, select a method where this FST behave badly > and take a look of what happen. > > >>> timeit.repeat("'a' * 1000 + 'z'") > > [0.6532032148133153, 0.6407248807756699, 0.6407264561239894]>>> timeit.repeat("'a' * 1000 + '9'") > > [0.6429508479509245, 0.6242782443215589, 0.6240490311410927] > > > > >>> timeit.repeat("'a' * 1000 + '?'") > > [1.095694927496563, 1.0696347279235603, 1.0687741939041082]>>> timeit.repeat("'a' * 1000 + '?'") > > [1.0796421281222877, 1.0348612767961853, 1.035325216876231]>>> timeit.repeat("'a' * 1000 + '\u2345'") > > [1.0855414137412112, 1.0694677410017164, 1.0688096392412945] > > > > >>> timeit.repeat("'?' * 1000 + '\U00010001'") > > [1.237314015362017, 1.2226262553064657, 1.21994619397816]>>> timeit.repeat("'?' * 1000 + '\U00010002'") > > [1.245773635836997, 1.2303978424029651, 1.2258257877430765] > > Where does it come from? Simple, the FSR breaks the > simple rules used in all coding schemes (unicode or not). > 1) a unique set of chars > 2) the "same" algorithm for all chars. Can you give me a source for this requirement? Numbers are after all numbers. SO we should use the same code/ algorithms/machine-instructions for floating-point and integers? > > And again that's why utf-8 is working very smoothly. How wonderful. Heres a suggestion. Code up the UTF-8 and any of the python string reps in C and profile them. Please come back and tell us if UTF-8 outperforms any of the python representations for strings on any operation (except straight copy). > > The "corporates" which understood this very well and > wanted to incorporate, let say, the used characters > of the French language had only the choice to > create new coding schemes (eg mac-roman, cp1252). > > In unicode, the "latin-1" range is real plague. > > After years of experience, I'm still fascinated to see > the corporates has solved this issue easily and the "free > software" is still relying on latin-1. > I never succeed to find an explanation. > > Even, the TeX folks, when they shifted to the Cork > encoding in 199?, were aware of this and consequently > provides special package(s). > > No offense, this is in my mind why "corporate software" > will always be "corporate software" and "hobbyist software" > will always stay at the level of "hobbyist software". > > A French windows user, understanding nothing in the > coding of characters, assuming he is aware of its > existence (!), has certainly no problem. > > Fascinating how it is possible to use Python to teach, > to illustrate, to explain the coding of the characters. No? > > jmf You troll with eclat and elan! From lele at metapensiero.it Tue Apr 2 18:52:22 2013 From: lele at metapensiero.it (Lele Gaifax) Date: Wed, 03 Apr 2013 00:52:22 +0200 Subject: Performance of int/long in Python 3 References: <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <515a9851$0$29891$c3e8da3$5496439d@news.astraweb.com> <515AB9C3.2000304@gmail.com> <515AF342.60605@gmail.com> <757f2dad-c073-487f-ac40-310e54083eef@kw7g2000pbb.googlegroups.com> Message-ID: <87hajoczq1.fsf@nautilus.nautilus> jmfauth writes: > Now replace i by a char, a representent of each "subset" > of the FSR, select a method where this FST behave badly > and take a look of what happen. You insist in cherry-picking a single "method where this FST behave badly", even when it is so obviously a corner case (IMHO it is not reasonably a common case when you have relatively big chunks of ASCII characters where you are adding one single non-ASCII char...) Anyway, these are my results on the opposite case, where you have a big chunk of non-ASCII characters and a single ASCII char added: Python 2.7.3 (default, Jan 2 2013, 13:56:14) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import timeit >>> timeit.repeat("'?' * 1000 + 'z'") [0.2817099094390869, 0.2811391353607178, 0.2811310291290283] >>> timeit.repeat("u'?' * 1000 + u'\U00010001'") [0.549591064453125, 0.5502040386199951, 0.5490291118621826] >>> timeit.repeat("u'\U00010001' * 1000 + u'?'") [0.3823568820953369, 0.3823089599609375, 0.3820679187774658] >>> timeit.repeat("u'\U00010002' * 1000 + 'a'") [0.45046305656433105, 0.45000195503234863, 0.44980502128601074] Python 3.3.0 (default, Mar 18 2013, 12:00:52) [GCC 4.7.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import timeit >>> timeit.repeat("'?' * 1000 + 'z'") [0.23264244200254325, 0.23299441300332546, 0.2325888039995334] >>> timeit.repeat("'?' * 1000 + '\U00010001'") [0.3760241370036965, 0.37552819900156464, 0.3755163860041648] >>> timeit.repeat("'\U00010001' * 1000 + '?'") [0.28259182300098473, 0.2825558360054856, 0.2824251129932236] >>> timeit.repeat("'\U00010002' * 1000 + 'a'") [0.28227063300437294, 0.2815949220021139, 0.2829978369991295] IIUC, while it may be true that Py3 is slightly slower than Py2 when the string operation involves an internal representation change (all your examples, and the second operation above), in the much more common case it is considerably faster. This, and the fact that Py3 actually handles the whole Unicode space without glitches, make it a better environment in my eyes. Kudos to the core team! Just my 0.45-0.28 cents, 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 rustompmody at gmail.com Tue Apr 2 09:42:06 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 2 Apr 2013 06:42:06 -0700 (PDT) Subject: Performance of int/long in Python 3 References: <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <515a9851$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: <71e7d5fe-c214-4c19-a0bf-8aa34ae5020d@mz7g2000pbb.googlegroups.com> On Apr 2, 3:58?pm, Steve Simmons wrote: > On 02/04/2013 10:43, Mark Lawrence wrote: > > > > > > > > > On 02/04/2013 10:24, jmfauth wrote: > >> On 2 avr, 10:35, Steven D'Aprano >> +comp.lang.pyt... at pearwood.info> wrote: > >>> On Tue, 02 Apr 2013 19:03:17 +1100, Chris Angelico wrote: > > >>> So what? Who cares if it takes 0.00002 second to insert a character > >>> instead of 0.00001 second? That's still a hundred times faster than you > >>> can type. > > >> --------- > > >> This not the problem. The interesting point is that they > >> are good and "less good" Unicode implementations. > > >> jmf > > > The interesting point is that the Python 3.3 unicode implementation is > > correct, that of most other languages is buggy. Or have I fallen > > victim to the vicious propaganda of the various Pythonistas who > > frequent this list? > > Mark, > > Thanks for asking this question. > > It seems to me that jmf *might* be moving towards a vindicated > position. ?There is some interest now in duplicating, understanding and > (hopefully!) extending his test results, which can only be a Good Thing > - whatever the outcome and wherever the facepalm might land. Whew! Very reassuring to hear some sanity in this discussion at long last! From steve+comp.lang.python at pearwood.info Tue Apr 2 10:03:12 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Apr 2013 14:03:12 GMT Subject: Performance of int/long in Python 3 References: <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <515a9851$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: <515ae520$0$29967$c3e8da3$5496439d@news.astraweb.com> On Tue, 02 Apr 2013 11:58:11 +0100, Steve Simmons wrote: > It seems to me that jmf *might* be moving towards a vindicated position. > There is some interest now in duplicating, understanding and > (hopefully!) extending his test results, which can only be a Good Thing > - whatever the outcome and wherever the facepalm might land. Some interest "now"? Oh please. http://mail.python.org/pipermail/python-list/2012-September/629810.html Mark Lawrence even created a bug report to track this, also back in September. http://bugs.python.org/issue16061 I'm sure you didn't intend to be insulting, but some of us *have* taken JMF seriously, at least at first. His repeated overblown claims of how Python is destroying Unicode, his lack of acknowledgement that other people have seen string handling *speed up* not slow down, and his refusal to assist in diagnosing this performance regression except to repeatedly quote the same artificial micro-benchmarks over and over again have lost him whatever credibility he started with. This feature is a *memory optimization*, not a speed optimization, and yet as a side-effect of saving memory, it also saves time. Real-world benchmarks of actual applications demonstrate this. One or two trivial slowdowns of artificial micro-benchmarks simply are not important, even if they are genuine. I believe they are genuine, but likely operating system and hardware dependent. -- Steven From square.steve at gmail.com Tue Apr 2 10:39:10 2013 From: square.steve at gmail.com (Steve Simmons) Date: Tue, 02 Apr 2013 15:39:10 +0100 Subject: Performance of int/long in Python 3 In-Reply-To: <515ae520$0$29967$c3e8da3$5496439d@news.astraweb.com> References: <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <515a9851$0$29891$c3e8da3$5496439d@news.astraweb.com> <515ae520$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <515AED8E.8060709@gmail.com> On 02/04/2013 15:03, Steven D'Aprano wrote: > On Tue, 02 Apr 2013 11:58:11 +0100, Steve Simmons wrote: > >> It seems to me that jmf *might* be moving towards a vindicated position. >> There is some interest now in duplicating, understanding and >> (hopefully!) extending his test results, which can only be a Good Thing >> - whatever the outcome and wherever the facepalm might land. > Some interest "now"? Oh please. > > http://mail.python.org/pipermail/python-list/2012-September/629810.html > > Mark Lawrence even created a bug report to track this, also back in > September. > > http://bugs.python.org/issue16061 > > I'm sure you didn't intend to be insulting, but some of us *have* taken > JMF seriously, at least at first. His repeated overblown claims of how > Python is destroying Unicode, his lack of acknowledgement that other > people have seen string handling *speed up* not slow down, and his > refusal to assist in diagnosing this performance regression except to > repeatedly quote the same artificial micro-benchmarks over and over again > have lost him whatever credibility he started with. > > This feature is a *memory optimization*, not a speed optimization, and > yet as a side-effect of saving memory, it also saves time. Real-world > benchmarks of actual applications demonstrate this. One or two trivial > slowdowns of artificial micro-benchmarks simply are not important, even > if they are genuine. I believe they are genuine, but likely operating > system and hardware dependent. > > First off, no insult intended and I haven't been part of this list long enough to be fully immersed in the history of this so I'm sure there are events of which I am unaware. However, it seems to me that, for whatever reason, JMF has reached the end of his capacity (time, capability, patience, ...) to extend his benchmarks into a more credible test set - i.e. one that demonstrates an acceptably 'real life' profile with a marked drop in performance. As a community we have choices. We can brand him a Troll - and some of his behaviour may mandate that - or we can put some additional energy into drawing this 'disagreement' to a more amicable and constructive conclusion. My post was primarily aimed at recognising the work that people like Mark, Neil and others have done to move the problem forward and was intended to help shift the focus to a more productive approach. Again, my apologies if it was ill timed or ill-directed. Steve Simmons From breamoreboy at yahoo.co.uk Tue Apr 2 11:02:09 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 02 Apr 2013 16:02:09 +0100 Subject: Performance of int/long in Python 3 In-Reply-To: <515AED8E.8060709@gmail.com> References: <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <515a9851$0$29891$c3e8da3$5496439d@news.astraweb.com> <515ae520$0$29967$c3e8da3$5496439d@news.astraweb.com> <515AED8E.8060709@gmail.com> Message-ID: On 02/04/2013 15:39, Steve Simmons wrote: > > My post was primarily aimed at recognising the work that people like > Mark, Neil and others have done to move the problem forward and was > intended to help shift the focus to a more productive approach. Again, > my apologies if it was ill timed or ill-directed. > > Steve Simmons > I must point out that I only raised issue 16061 based on data provided by Steven D'Aprano and Serhiy Storchaka. -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From ethan at stoneleaf.us Tue Apr 2 11:09:18 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 02 Apr 2013 08:09:18 -0700 Subject: Performance of int/long in Python 3 In-Reply-To: <515AED8E.8060709@gmail.com> References: <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <515a9851$0$29891$c3e8da3$5496439d@news.astraweb.com> <515ae520$0$29967$c3e8da3$5496439d@news.astraweb.com> <515AED8E.8060709@gmail.com> Message-ID: <515AF49E.8060105@stoneleaf.us> On 04/02/2013 07:39 AM, Steve Simmons wrote: > > On 02/04/2013 15:03, Steven D'Aprano wrote: >> On Tue, 02 Apr 2013 11:58:11 +0100, Steve Simmons wrote: >> >>> It seems to me that jmf *might* be moving towards a vindicated position. >>> There is some interest now in duplicating, understanding and >>> (hopefully!) extending his test results, which can only be a Good Thing >>> - whatever the outcome and wherever the facepalm might land. >> Some interest "now"? Oh please. >> >> http://mail.python.org/pipermail/python-list/2012-September/629810.html >> >> Mark Lawrence even created a bug report to track this, also back in >> September. >> >> http://bugs.python.org/issue16061 >> >> I'm sure you didn't intend to be insulting, but some of us *have* taken >> JMF seriously, at least at first. His repeated overblown claims of how >> Python is destroying Unicode, his lack of acknowledgement that other >> people have seen string handling *speed up* not slow down, and his >> refusal to assist in diagnosing this performance regression except to >> repeatedly quote the same artificial micro-benchmarks over and over again >> have lost him whatever credibility he started with. >> >> This feature is a *memory optimization*, not a speed optimization, and >> yet as a side-effect of saving memory, it also saves time. Real-world >> benchmarks of actual applications demonstrate this. One or two trivial >> slowdowns of artificial micro-benchmarks simply are not important, even >> if they are genuine. I believe they are genuine, but likely operating >> system and hardware dependent. >> >> > First off, no insult intended and I haven't been part of this list long enough to be fully immersed in the history of > this so I'm sure there are events of which I am unaware. Yes, that would be his months of trollish behavior on this subject. > However, it seems to me that, for whatever reason, JMF has reached the end of his capacity His capacity, maybe; his time? Not by a long shot. I am positive we will continue to see his uncooperative, bratty* behavior continue ad nauseum. -- ~Ethan~ *I was going to say childish, but I know plenty of better behaved children. From wxjmfauth at gmail.com Tue Apr 2 11:12:32 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Tue, 2 Apr 2013 08:12:32 -0700 (PDT) Subject: Performance of int/long in Python 3 References: <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <515a9851$0$29891$c3e8da3$5496439d@news.astraweb.com> <515ae520$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7f0f6502-6368-4d58-b248-36653e2b3cfa@w21g2000vbp.googlegroups.com> On 2 avr, 16:03, Steven D'Aprano wrote: > On Tue, 02 Apr 2013 11:58:11 +0100, Steve Simmons wrote: > > I'm sure you didn't intend to be insulting, but some of us *have* taken > JMF seriously, at least at first. His repeated overblown claims of how > Python is destroying Unicode ... Sorrry I never claimed this, I'm just seeing on how Python is becoming less Unicode friendly. > > This feature is a *memory optimization*, not a speed optimization, I totaly agree, and utf-8 is doing that with a great art. (see Neil Hodgson comment). (Do not interpret this as if i'm saying "Python should use utf-8, as I'have read). jmf From breamoreboy at yahoo.co.uk Tue Apr 2 11:43:44 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 02 Apr 2013 16:43:44 +0100 Subject: Performance of int/long in Python 3 In-Reply-To: <7f0f6502-6368-4d58-b248-36653e2b3cfa@w21g2000vbp.googlegroups.com> References: <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <515a9851$0$29891$c3e8da3$5496439d@news.astraweb.com> <515ae520$0$29967$c3e8da3$5496439d@news.astraweb.com> <7f0f6502-6368-4d58-b248-36653e2b3cfa@w21g2000vbp.googlegroups.com> Message-ID: On 02/04/2013 16:12, jmfauth wrote: > > Sorrry I never claimed this, I'm just seeing on how Python is becoming > less Unicode friendly. Please explain this. I see no justification for this comment. How can an implementation that fixes bugs be less Unicode friendly than its earlier, buggier equivalents? > > jmf > -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From rustompmody at gmail.com Tue Apr 2 13:08:50 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 2 Apr 2013 10:08:50 -0700 (PDT) Subject: Performance of int/long in Python 3 References: <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <515a9851$0$29891$c3e8da3$5496439d@news.astraweb.com> <515ae520$0$29967$c3e8da3$5496439d@news.astraweb.com> <7f0f6502-6368-4d58-b248-36653e2b3cfa@w21g2000vbp.googlegroups.com> Message-ID: <7a5330a7-f837-4e50-a148-73b5d2010aeb@5g2000pbs.googlegroups.com> On Apr 2, 8:12?pm, jmfauth wrote: > > Sorrry I never claimed this, I'm just seeing on how Python is becoming > less Unicode friendly. jmf: I suggest you try to use less emotionally loaded and more precise language if you want people to pay heed to your technical observations/ contributions. In particular, while you say unicode, your examples always (as far as I remember) refer to BMP. Also words like 'friendly' are so emotionally charged that people stop being friendly :-) So may I suggest that you rephrase your complaint as "I am seeing python is becoming poorly performant on BMP-chars at the expense of correct support for the whole (6.0?) charset" (assuming thats what you want to say) In any case PLEASE note that 'performant' and 'correct' are different for most practical purposes. If you dont respect this semantics, people are unlikely to pay heed to your complaints. From tjreedy at udel.edu Tue Apr 2 17:33:54 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Tue, 02 Apr 2013 17:33:54 -0400 Subject: Performance of int/long in Python 3 In-Reply-To: <7f0f6502-6368-4d58-b248-36653e2b3cfa@w21g2000vbp.googlegroups.com> References: <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <515a9851$0$29891$c3e8da3$5496439d@news.astraweb.com> <515ae520$0$29967$c3e8da3$5496439d@news.astraweb.com> <7f0f6502-6368-4d58-b248-36653e2b3cfa@w21g2000vbp.googlegroups.com> Message-ID: On 4/2/2013 11:12 AM, jmfauth wrote: > On 2 avr, 16:03, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> I'm sure you didn't intend to be insulting, but some of us *have* taken >> JMF seriously, at least at first. His repeated overblown claims of how >> Python is destroying Unicode ... ... = 'usability in Python" or some variation on that. > Sorrry I never claimed this, I'm just seeing on how Python is becoming > less Unicode friendly. Let us see what Jim has claimed, starting in 2012 August. http://mail.python.org/pipermail/python-list/2012-August/628826.html "Devs are developing sophisticed tools based on a non working basis." http://mail.python.org/pipermail/python-list/2012-August/629514.html "This "Flexible String Representation" fails." http://mail.python.org/pipermail/python-list/2012-August/629554.html "This flexible representation is working absurdly." Reader can decide whether 'non-working', 'fails', 'working absurdly' are closer to 'destroying Unicode usability or just 'less friendly'. On speed: http://mail.python.org/pipermail/python-list/2012-August/628781.html "Python 3.3 is "slower" than Python 3.2." http://mail.python.org/pipermail/python-list/2012-August/628762.html "I can open IDLE with Py 3.2 ou Py 3.3 and compare strings manipulations. Py 3.3 is always slower. Period." False. Period. Here is my followup at the time. python.org/pipermail/python-list/2012-August/628779.html "You have not tried enough tests ;-). On my Win7-64 system: from timeit import timeit print(timeit(" 'a'*10000 ")) 3.3.0b2: .5 3.2.3: .8 print(timeit("c in a", "c = '?'; a = 'a'*10000")) 3.3: .05 (independent of len(a)!) 3.2: 5.8 100 times slower! Increase len(a) and the ratio can be made as high as one wants! print(timeit("a.encode()", "a = 'a'*1000")) 3.2: 1.5 3.3: .26" If one runs stringbency.ph with its 40 or so tests, 3.2 is sometimes faster and 3.3 is sometimes faster. http://mail.python.org/pipermail/python-list/2012-September/630736.html On to September: "http://mail.python.org/pipermail/python-list/2012-September/630736.html" "Avoid Py3.3" In other words, ignore all the benefits and reject because a couple of selected microbenchmarks show a slowdown. http://mail.python.org/pipermail/python-list/2012-September/631730.html "Py 3.3 succeeded to somehow kill unicode" I will stop here and let Jim explain how 'kill unicode' is different from 'destroy unicode'. -- Terry Jan Reedy From joshua.landau.ws at gmail.com Tue Apr 2 18:40:01 2013 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Tue, 2 Apr 2013 23:40:01 +0100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <515a9851$0$29891$c3e8da3$5496439d@news.astraweb.com> <515ae520$0$29967$c3e8da3$5496439d@news.astraweb.com> <7f0f6502-6368-4d58-b248-36653e2b3cfa@w21g2000vbp.googlegroups.com> Message-ID: The initial post posited: "The Python 3 merge of int and long has effectively penalized small-number arithmetic by removing an optimization. As we've seen from PEP 393 strings (jmf aside), there can be huge benefits from having a single type with multiple representations internally. Is there value in making the int type have a machine-word optimization in the same way?" Thanks to the fervent response jmf has gotten, the point above has been mostly abandoned May I request that next time such an obvious diversion (aka. jmf) occurs, responses happen in a different thread? -------------- next part -------------- An HTML attachment was scrubbed... URL: From wxjmfauth at gmail.com Tue Apr 2 05:20:09 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Tue, 2 Apr 2013 02:20:09 -0700 (PDT) Subject: Performance of int/long in Python 3 References: <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> Message-ID: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> On 2 avr, 10:03, Chris Angelico wrote: > On Tue, Apr 2, 2013 at 6:24 PM, jmfauth wrote: > > An editor may reflect very well the example a gave. You enter > > thousand ascii chars, then - boum - as you enter a non ascii > > char, your editor (assuming is uses a mechanism like the FSR), > > has to internally reencode everything! > > That assumes that the editor stores the entire buffer as a single > Python string. Frankly, I think this unlikely; the nature of > insertions and deletions makes this impractical. (I've known editors > that do function this way. They're utterly unusable on large files.) > > ChrisA -------- No, no, no, no, ... as we say in French (this is a kindly form). The length of a string may have its importance. This bad behaviour may happen on every char. The most complicated chars are the chars with diacritics and ligatured [1, 2] chars, eg chars used in Arabic script [2]. It is somehow funny to see, the FSR "fails" precisely on problems Unicode will solve/handle, eg normalization or sorting [3]. No really a problem for those you are endorsing the good work Unicode does [5]. [1] A point which was not, in my mind, very well understood when I read the PEP393 discussion. [2] Take a unicode "TeX" compliant engine and toy with the decomposed form of these chars. A very good way, to understand what can be really a char, when you wish to process text "seriously". [3] I only test and tested these "chars" blindly with the help of the doc I have. Btw, when I test complicated "Arabic chars", I noticed, Py33 "crashes", it does not really crash, it get stucked in some king of infinite loop (or is it due to "timeit"?). [4] Am I the only one who test this kind of stuff? [5] Unicode is a fascinating construction. jmf From ian.g.kelly at gmail.com Tue Apr 2 15:44:48 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 2 Apr 2013 13:44:48 -0600 Subject: Performance of int/long in Python 3 In-Reply-To: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> References: <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> Message-ID: On Tue, Apr 2, 2013 at 3:20 AM, jmfauth wrote: > It is somehow funny to see, the FSR "fails" precisely > on problems Unicode will solve/handle, eg normalization or > sorting [3]. Neither of these problems have anything to do with the FSR. Can you give us an example of normalization or sorting where Python 3.3 fails and Python 3.2 does not? > [3] I only test and tested these "chars" blindly with the help > of the doc I have. Btw, when I test complicated "Arabic chars", > I noticed, Py33 "crashes", it does not really crash, it get stucked > in some king of infinite loop (or is it due to "timeit"?). Without knowing what the actual test that you ran was, we have no way of answering that. Unless you give us more detail, my assumption would be that the number of repetitions that you passed to timeit was excessively large for the particular test case. > [4] Am I the only one who test this kind of stuff? No, you're just the only one who considers it important. Micro-benchmarks like the ones you have been reporting are *useful* when it comes to determining what operations can be better optimized, but they are not *important* in and of themselves. What is important is that actual, real-world programs are not significantly slowed by these kinds of optimizations. Until you can demonstrate that real programs are adversely affected by PEP 393, there is not in my opinion any regression that is worth worrying over. From nhodgson at iinet.net.au Tue Apr 2 23:31:03 2013 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Wed, 03 Apr 2013 14:31:03 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> Message-ID: <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> Ian Kelly: > Micro-benchmarks like the ones you have been reporting are *useful* > when it comes to determining what operations can be better optimized, > but they are not *important* in and of themselves. What is important > is that actual, real-world programs are not significantly slowed by > these kinds of optimizations. Until you can demonstrate that real > programs are adversely affected by PEP 393, there is not in my opinion > any regression that is worth worrying over. The problem with only responding to issues with real-world programs is that real-world programs are complex and their performance issues often difficult to diagnose. See, for example, scons which is written in Python and which has not been able to overcome performance problems over several years. (http://www.electric-cloud.com/blog/2010/07/21/a-second-look-at-scons-performance/) Bottom-up performance work has advantages in that a narrow focus area can be more easily analyzed and tested and can produce widely applicable benefits. The choice of comparison for the script wasn't arbitrary. Comparison is one of the main building blocks of higher-level code. Sorting, for example, depends strongly on comparison performance with a decrease in comparison speed multiplied when applied to sorting. Its unfortunate that stringbench.py does not contain any comparison or sorting tests. Sorting a million string list (all the file paths on a particular computer) went from 0.4 seconds with Python 3.2 to 0.78 with 3.3 so we're out of the 'not noticeable by humans' range. Perhaps this is still a 'micro-benchmark' - I'd just like to avoid adding email access to get this over the threshold. Here's some code. Replace the "if 1" with "if 0" on subsequent runs to avoid the costly file system walk. import os, time from os.path import join, getsize paths = [] if 1: for root, dirs, files in os.walk('c:\\'): for name in files: paths.append(join(root, name)) with open("filelist.txt", "w") as f: f.write("\n".join(paths)) else: with open("filelist.txt", "r") as f: paths = f.read().split("\n") print(len(paths)) timeStart = time.time() paths.sort() timeEnd = time.time() print("Time taken=", timeEnd - timeStart) Neil From rustompmody at gmail.com Tue Apr 2 23:53:21 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 2 Apr 2013 20:53:21 -0700 (PDT) Subject: Performance of int/long in Python 3 References: <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> Message-ID: <5f8ed721-7c89-4ffd-8f2b-21979cc3386a@kk11g2000pbb.googlegroups.com> On Apr 3, 8:31?am, Neil Hodgson wrote: > ? ? Sorting a million string list (all the file paths on a particular > computer) went from 0.4 seconds with Python 3.2 to 0.78 with 3.3 so > we're out of the 'not noticeable by humans' range. Perhaps this is still > a 'micro-benchmark' - I'd just like to avoid adding email access to get > this over the threshold. What does that last statement mean? From nhodgson at iinet.net.au Wed Apr 3 00:03:21 2013 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Wed, 03 Apr 2013 15:03:21 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: <5f8ed721-7c89-4ffd-8f2b-21979cc3386a@kk11g2000pbb.googlegroups.com> References: <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <5f8ed721-7c89-4ffd-8f2b-21979cc3386a@kk11g2000pbb.googlegroups.com> Message-ID: rusi wrote: > ... >> a 'micro-benchmark' - I'd just like to avoid adding email access to get >> this over the threshold. > > What does that last statement mean? Its a reference to a comment by Jamie Zawinski (relatively famous developer of Netscape Navigator and other things): "Every program attempts to expand until it can read mail. Those programs which cannot so expand are replaced by ones which can." One of the games played in bug reporting and avoidance is to deny that the report is a real problem. A short script is dismissed as unrepresentative of actual programs. Once it can read email though, it has to be a real program. Neil From rustompmody at gmail.com Wed Apr 3 01:11:25 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 2 Apr 2013 22:11:25 -0700 (PDT) Subject: Performance of int/long in Python 3 References: <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <5f8ed721-7c89-4ffd-8f2b-21979cc3386a@kk11g2000pbb.googlegroups.com> Message-ID: <91e33518-4265-4c71-bc8d-49ef3b5cfe92@la7g2000pbc.googlegroups.com> On Apr 3, 9:03?am, Neil Hodgson wrote: > rusi wrote: > > ... > >> a 'micro-benchmark' - I'd just like to avoid adding email access to get > >> this over the threshold. > > > What does that last statement mean? > > ? ? Its a reference to a comment by Jamie Zawinski (relatively famous > developer of Netscape Navigator and other things): And Xemacs (which is famous in the free sw world for other things!) > > ? ? "Every program attempts to expand until it can read mail. Those > programs which cannot so expand are replaced by ones which can." :-) Ok got it From rosuav at gmail.com Wed Apr 3 02:22:26 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 3 Apr 2013 17:22:26 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <5f8ed721-7c89-4ffd-8f2b-21979cc3386a@kk11g2000pbb.googlegroups.com> Message-ID: On Wed, Apr 3, 2013 at 3:03 PM, Neil Hodgson wrote: > rusi wrote: > "Every program attempts to expand until it can read mail. Those programs > which cannot so expand are replaced by ones which can." In my personal experience, it's calculators. I put command-line calculators into *everything*... often in the form of more general executors, and thus restricted to admins, but it's still a calculator. For some reason, the ability to type "calc 1+2" and get back 3 is very satisfying to me. You know, in case I ever forget what one plus two makes. ChrisA From roy at panix.com Wed Apr 3 09:28:00 2013 From: roy at panix.com (Roy Smith) Date: Wed, 03 Apr 2013 09:28:00 -0400 Subject: Performance of int/long in Python 3 References: <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <5f8ed721-7c89-4ffd-8f2b-21979cc3386a@kk11g2000pbb.googlegroups.com> Message-ID: In article , Chris Angelico wrote: > On Wed, Apr 3, 2013 at 3:03 PM, Neil Hodgson wrote: > > rusi wrote: > > "Every program attempts to expand until it can read mail. Those programs > > which cannot so expand are replaced by ones which can." > > In my personal experience, it's calculators. I put command-line > calculators into *everything*... often in the form of more general > executors, and thus restricted to admins, but it's still a calculator. > > For some reason, the ability to type "calc 1+2" and get back 3 is very > satisfying to me. You know, in case I ever forget what one plus two > makes. I discovered recently that Spotlight (the OSX built-in search engine) can do this. From rosuav at gmail.com Wed Apr 3 09:38:07 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 4 Apr 2013 00:38:07 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <5f8ed721-7c89-4ffd-8f2b-21979cc3386a@kk11g2000pbb.googlegroups.com> Message-ID: On Thu, Apr 4, 2013 at 12:28 AM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> On Wed, Apr 3, 2013 at 3:03 PM, Neil Hodgson wrote: >> > rusi wrote: >> > "Every program attempts to expand until it can read mail. Those programs >> > which cannot so expand are replaced by ones which can." >> >> In my personal experience, it's calculators. I put command-line >> calculators into *everything*... often in the form of more general >> executors, and thus restricted to admins, but it's still a calculator. >> >> For some reason, the ability to type "calc 1+2" and get back 3 is very >> satisfying to me. You know, in case I ever forget what one plus two >> makes. > > I discovered recently that Spotlight (the OSX built-in search engine) > can do this. Good feature, not surprising. Google Search has had that feature for a while, and it just "feels right" to be able to look up information the same way regardless of its source. ChrisA From roy at panix.com Wed Apr 3 00:10:36 2013 From: roy at panix.com (Roy Smith) Date: Wed, 03 Apr 2013 00:10:36 -0400 Subject: Performance of int/long in Python 3 References: <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <5f8ed721-7c89-4ffd-8f2b-21979cc3386a@kk11g2000pbb.googlegroups.com> Message-ID: In article <5f8ed721-7c89-4ffd-8f2b-21979cc3386a at kk11g2000pbb.googlegroups.com>, rusi wrote: > On Apr 3, 8:31?am, Neil Hodgson wrote: > > > ? ? Sorting a million string list (all the file paths on a particular > > computer) went from 0.4 seconds with Python 3.2 to 0.78 with 3.3 so > > we're out of the 'not noticeable by humans' range. On the other hand, how long did it take you to do the directory tree walk required to find those million paths? I'll bet a long longer than 0.78 seconds, so this gets lost in the noise. Still, it is unfortunate if sort performance got hurt significantly. My mind was blown a while ago when I discovered that python could sort a file of strings faster than the unix command-line sort utility. That's pretty impressive. From nhodgson at iinet.net.au Wed Apr 3 04:15:22 2013 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Wed, 03 Apr 2013 19:15:22 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <5f8ed721-7c89-4ffd-8f2b-21979cc3386a@kk11g2000pbb.googlegroups.com> Message-ID: <1f2dnfPBhY54eMbMnZ2dnUVZ_oSdnZ2d@westnet.com.au> Roy Smith: > On the other hand, how long did it take you to do the directory tree > walk required to find those million paths? I'll bet a long longer than > 0.78 seconds, so this gets lost in the noise. About 2 minutes. But that's just getting an example data set. Other data sets may be loaded more quickly from databases or files or be created by processing. Reading the example data from a file takes around the same time as sorting. Neil From roy at panix.com Wed Apr 3 09:25:06 2013 From: roy at panix.com (Roy Smith) Date: Wed, 03 Apr 2013 09:25:06 -0400 Subject: Performance of int/long in Python 3 References: <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <5f8ed721-7c89-4ffd-8f2b-21979cc3386a@kk11g2000pbb.googlegroups.com> <1f2dnfPBhY54eMbMnZ2dnUVZ_oSdnZ2d@westnet.com.au> Message-ID: In article <1f2dnfPBhY54eMbMnZ2dnUVZ_oSdnZ2d at westnet.com.au>, Neil Hodgson wrote: > Roy Smith: > > > On the other hand, how long did it take you to do the directory tree > > walk required to find those million paths? I'll bet a long longer than > > 0.78 seconds, so this gets lost in the noise. > > About 2 minutes. But that's just getting an example data set. Other > data sets may be loaded more quickly from databases or files or be > created by processing. Reading the example data from a file takes around > the same time as sorting. Fair enough. In fact, given that reading the file from disk is O(n) and sorting it is O(n log n), at some point, the sort will totally swamp the input time. Your original example just happened to be one of the unusual cases where the sort time is not the rate limiting factor in the overall process. I remember reading somewhere that more CPU cycles in the entire history of computing have been spend doing sorting than anything else. From rosuav at gmail.com Wed Apr 3 09:34:08 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 4 Apr 2013 00:34:08 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <5f8ed721-7c89-4ffd-8f2b-21979cc3386a@kk11g2000pbb.googlegroups.com> <1f2dnfPBhY54eMbMnZ2dnUVZ_oSdnZ2d@westnet.com.au> Message-ID: On Thu, Apr 4, 2013 at 12:25 AM, Roy Smith wrote: > > Fair enough. In fact, given that reading the file from disk is O(n) and > sorting it is O(n log n), at some point, the sort will totally swamp the > input time. But given the much larger fixed cost of disk access, that might take an awful lot of strings... ChrisA From steve+comp.lang.python at pearwood.info Wed Apr 3 01:32:11 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Apr 2013 05:32:11 GMT Subject: Performance of int/long in Python 3 References: <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> Message-ID: <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Apr 2013 14:31:03 +1100, Neil Hodgson wrote: > Sorting a million string list (all the file paths on a particular > computer) went from 0.4 seconds with Python 3.2 to 0.78 with 3.3 so > we're out of the 'not noticeable by humans' range. Perhaps this is still > a 'micro-benchmark' - I'd just like to avoid adding email access to get > this over the threshold. I cannot confirm this performance regression. On my laptop (Debian Linux, not Windows), I can sort a million file names in approximately 1.2 seconds in both Python 3.2 and 3.3. There is no meaningful difference in speed between the two versions. -- Steven From tjreedy at udel.edu Wed Apr 3 02:19:46 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Wed, 03 Apr 2013 02:19:46 -0400 Subject: Performance of int/long in Python 3 In-Reply-To: <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> References: <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/3/2013 1:32 AM, Steven D'Aprano wrote: > On Wed, 03 Apr 2013 14:31:03 +1100, Neil Hodgson wrote: > >> Sorting a million string list (all the file paths on a particular >> computer) went from 0.4 seconds with Python 3.2 to 0.78 with 3.3 so >> we're out of the 'not noticeable by humans' range. Perhaps this is still >> a 'micro-benchmark' - I'd just like to avoid adding email access to get >> this over the threshold. What system *and* what compiler and compiler options. Unless 3.2 and 3.3 are both compiler with the same compiler and settings, we do not know the source of the difference. > I cannot confirm this performance regression. On my laptop (Debian Linux, > not Windows), I can sort a million file names in approximately 1.2 > seconds in both Python 3.2 and 3.3. There is no meaningful difference in > speed between the two versions. I am guessing that Neil's undisclosed system (that I can see) is Windows, since other benchmarks have been more different on Windows than on *nix. Given that we *know* that the 3.2 and 3.3 distribution are compiled with different compilers and run with different C runtimes, it is possible that some of the difference is from that and not from python at all. tjr From rosuav at gmail.com Wed Apr 3 02:25:37 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 3 Apr 2013 17:25:37 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> References: <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 3, 2013 at 4:32 PM, Steven D'Aprano wrote: > On Wed, 03 Apr 2013 14:31:03 +1100, Neil Hodgson wrote: > >> Sorting a million string list (all the file paths on a particular >> computer) went from 0.4 seconds with Python 3.2 to 0.78 with 3.3 so >> we're out of the 'not noticeable by humans' range. Perhaps this is still >> a 'micro-benchmark' - I'd just like to avoid adding email access to get >> this over the threshold. > > I cannot confirm this performance regression. On my laptop (Debian Linux, > not Windows), I can sort a million file names in approximately 1.2 > seconds in both Python 3.2 and 3.3. There is no meaningful difference in > speed between the two versions. I'd be curious to know the sorts of characters used. Given that it's probably a narrow-vs-wide Python difference we're talking here, the actual distribution of codepoints may well make a difference. ChrisA From nhodgson at iinet.net.au Wed Apr 3 02:27:14 2013 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Wed, 03 Apr 2013 17:27:14 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: Terry Jan Reedy: > What system *and* what compiler and compiler options. Unless 3.2 and 3.3 > are both compiler with the same compiler and settings, we do not know > the source of the difference. The version signatures are: 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] The machine is running Windows 8 64-bit (the Python installations are 32-bit though) and the processor is an i3 2350M running at 2.3 GHz. Neil From nhodgson at iinet.net.au Wed Apr 3 02:29:42 2013 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Wed, 03 Apr 2013 17:29:42 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico: > I'd be curious to know the sorts of characters used. Given that it's > probably a narrow-vs-wide Python difference we're talking here, the > actual distribution of codepoints may well make a difference. I was going to upload it but then I thought of potential client -confidentiality problems and the need to audit a list that long. Neil From rosuav at gmail.com Wed Apr 3 02:52:21 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 3 Apr 2013 17:52:21 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 3, 2013 at 5:29 PM, Neil Hodgson wrote: > Chris Angelico: > > >> I'd be curious to know the sorts of characters used. Given that it's >> probably a narrow-vs-wide Python difference we're talking here, the >> actual distribution of codepoints may well make a difference. > > > I was going to upload it but then I thought of potential client > -confidentiality problems and the need to audit a list that long. Hmm. I was about to say "Can you just do a quick collections.Counter() of the string widths in 3.3, as an easy way of seeing which ones use BMP or higher characters", but I can't find a simple way to query a string's width. Can't see it as a method of the string object, nor in the string or sys modules. It ought to be easy enough at the C level - just look up the two bits representing 'kind' - but I've not found it exposed to Python. Is there anything? ChrisA From ian.g.kelly at gmail.com Wed Apr 3 03:06:33 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 3 Apr 2013 01:06:33 -0600 Subject: Performance of int/long in Python 3 In-Reply-To: References: <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 3, 2013 at 12:52 AM, Chris Angelico wrote: > Hmm. I was about to say "Can you just do a quick collections.Counter() > of the string widths in 3.3, as an easy way of seeing which ones use > BMP or higher characters", but I can't find a simple way to query a > string's width. Can't see it as a method of the string object, nor in > the string or sys modules. It ought to be easy enough at the C level - > just look up the two bits representing 'kind' - but I've not found it > exposed to Python. Is there anything? 4 if max(map(ord, s)) > 0xffff else 2 if max(map(ord, s)) > 0xff else 1 From rosuav at gmail.com Wed Apr 3 03:24:25 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 3 Apr 2013 18:24:25 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 3, 2013 at 6:06 PM, Ian Kelly wrote: > On Wed, Apr 3, 2013 at 12:52 AM, Chris Angelico wrote: >> Hmm. I was about to say "Can you just do a quick collections.Counter() >> of the string widths in 3.3, as an easy way of seeing which ones use >> BMP or higher characters", but I can't find a simple way to query a >> string's width. Can't see it as a method of the string object, nor in >> the string or sys modules. It ought to be easy enough at the C level - >> just look up the two bits representing 'kind' - but I've not found it >> exposed to Python. Is there anything? > > 4 if max(map(ord, s)) > 0xffff else 2 if max(map(ord, s)) > 0xff else 1 Yeah, that's iterating over the whole string (twice, if it isn't width 4). The system already knows what the size is, I was hoping for an uber-quick inspection of the string header. ChrisA From nhodgson at iinet.net.au Wed Apr 3 03:37:00 2013 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Wed, 03 Apr 2013 18:37:00 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: Reran the programs taking a bit more care with the encoding of the file. This had no effect on the speeds. There are only a small amount of paths that don't fit into ASCII: ASCII 1076101 Latin1 218 BMP 113 Astral 0 # encoding:utf-8 import codecs, os, time from os.path import join, getsize with codecs.open("filelist.txt", "r", "utf-8") as f: paths = f.read().split("\n") bucket = [0,0,0,0] for p in paths: b = 0 maxChar = max([ord(ch) for ch in p]) if maxChar >= 65536: b = 3 elif maxChar >= 256: b = 2 elif maxChar >= 128: b = 1 bucket[b] = bucket[b] + 1 print("ASCII", bucket[0]) print("Latin1", bucket[1]) print("BMP", bucket[2]) print("Astral", bucket[3]) Neil From rustompmody at gmail.com Wed Apr 3 04:07:07 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 3 Apr 2013 01:07:07 -0700 (PDT) Subject: Performance of int/long in Python 3 References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Apr 3, 12:37?pm, Neil Hodgson wrote: > ? ? Reran the programs taking a bit more care with the encoding of the > file. This had no effect on the speeds. There are only a small amount of > paths that don't fit into ASCII: > > ASCII 1076101 > Latin1 218 > BMP 113 > Astral 0 > > # encoding:utf-8 > import codecs, os, time > from os.path import join, getsize > with codecs.open("filelist.txt", "r", "utf-8") as f: > ? ? ?paths = f.read().split("\n") > bucket = [0,0,0,0] > for p in paths: > ? ? ?b = 0 > ? ? ?maxChar = max([ord(ch) for ch in p]) > ? ? ?if maxChar >= 65536: > ? ? ? ? ?b = 3 > ? ? ?elif maxChar >= 256: > ? ? ? ? ?b = 2 > ? ? ?elif maxChar >= 128: > ? ? ? ? ?b = 1 > ? ? ?bucket[b] = bucket[b] + 1 > print("ASCII", bucket[0]) > print("Latin1", bucket[1]) > print("BMP", bucket[2]) > print("Astral", bucket[3]) > > ? ? Neil Can you please try one more experiment Neil? Knock off all non-ASCII strings (paths) from your dataset and try again. [It should take little more than converting your above code to a filter: if b == 0: print if b > 0: ignore ] From nhodgson at iinet.net.au Wed Apr 3 04:22:32 2013 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Wed, 03 Apr 2013 19:22:32 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: rusi: > Can you please try one more experiment Neil? > Knock off all non-ASCII strings (paths) from your dataset and try > again. Results are the same 0.40 (well, 0.001 less but I don't think the timer is that accurate) for Python 3.2 and 0.78 for Python 3.3. Neil From davea at davea.name Wed Apr 3 06:20:37 2013 From: davea at davea.name (Dave Angel) Date: Wed, 03 Apr 2013 06:20:37 -0400 Subject: Performance of int/long in Python 3 In-Reply-To: References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: <515C0275.9030006@davea.name> On 04/03/2013 04:22 AM, Neil Hodgson wrote: > rusi: > >> Can you please try one more experiment Neil? >> Knock off all non-ASCII strings (paths) from your dataset and try >> again. > > Results are the same 0.40 (well, 0.001 less but I don't think the > timer is that accurate) for Python 3.2 and 0.78 for Python 3.3. > > Neil That would seem to imply that the speed regression on your data is NOT caused by the differing size encodings. Perhaps it is the difference in MSC compiler version, or other changes made between 3.2 and 3.3 Of course, I can't then explain why Steven didn't get the same results. Perhaps the difference between 32bit Python and 64 on Windows? Or perhaps you have significantly more (or significantly fewer) "collisions" than Steven did. Before I saw this message, I was thinking of suggesting that you supply a key= parameter to sort, specifying as a key the Unicode character 65536 higher than the one supplied. That way all the keys to be sorted would be 32 bits in size. If this made the timings change noticeably, it could be a big clue. -- DaveA From nhodgson at iinet.net.au Wed Apr 3 07:05:55 2013 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Wed, 03 Apr 2013 22:05:55 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: Dave Angel: > That would seem to imply that the speed regression on your data is NOT > caused by the differing size encodings. Perhaps it is the difference in > MSC compiler version, or other changes made between 3.2 and 3.3 Its not caused by there actually being different size encodings but that the code is checking encoding size 2-4 times for each character. Back in 3.2 the comparison loop looked like: while (len1 > 0 && len2 > 0) { Py_UNICODE c1, c2; c1 = *s1++; c2 = *s2++; if (c1 != c2) return (c1 < c2) ? -1 : 1; len1--; len2--; } For 3.3 this has changed to for (i = 0; i < len1 && i < len2; ++i) { Py_UCS4 c1, c2; c1 = PyUnicode_READ(kind1, data1, i); c2 = PyUnicode_READ(kind2, data2, i); if (c1 != c2) return (c1 < c2) ? -1 : 1; } with PyUnicode_READ being #define PyUnicode_READ(kind, data, index) \ ((Py_UCS4) \ ((kind) == PyUnicode_1BYTE_KIND ? \ ((const Py_UCS1 *)(data))[(index)] : \ ((kind) == PyUnicode_2BYTE_KIND ? \ ((const Py_UCS2 *)(data))[(index)] : \ ((const Py_UCS4 *)(data))[(index)] \ ) \ )) There are either 1 or 2 kind checks in each call to PyUnicode_READ and 2 calls to PyUnicode_READ inside the loop. A compiler may decide to move the kind checks out of the loop and specialize the loop but MSVC 2010 appears to not do so. The assembler (32-bit build) for each PyUnicode_READ looks like mov ecx, DWORD PTR _kind1$[ebp] cmp ecx, 1 jne SHORT $LN17 at unicode_co@2 lea ecx, DWORD PTR [ebx+eax] movzx edx, BYTE PTR [ecx+edx] jmp SHORT $LN16 at unicode_co@2 $LN17 at unicode_co@2: cmp ecx, 2 jne SHORT $LN15 at unicode_co@2 movzx edx, WORD PTR [ebx+edi] jmp SHORT $LN16 at unicode_co@2 $LN15 at unicode_co@2: mov edx, DWORD PTR [ebx+esi] $LN16 at unicode_co@2: The kind1/kind2 variables aren't even going into registers and at least one test+branch and a jump are executed for every character. Two tests for 2 and 4 byte kinds. len1 and len2 don't get to go into registers either. Here's the full assembler output for unicode_compare: ; COMDAT _unicode_compare _TEXT SEGMENT _kind2$ = -20 ; size = 4 _kind1$ = -16 ; size = 4 _len2$ = -12 ; size = 4 _len1$ = -8 ; size = 4 _data2$ = -4 ; size = 4 _unicode_compare PROC ; COMDAT ; _str1$ = ecx ; _str2$ = eax ; 10417: { push ebp mov ebp, esp sub esp, 20 ; 00000014H push ebx push esi mov esi, eax ; 10418: int kind1, kind2; ; 10419: void *data1, *data2; ; 10420: Py_ssize_t len1, len2, i; ; 10421: ; 10422: kind1 = PyUnicode_KIND(str1); mov eax, DWORD PTR [ecx+16] mov edx, eax shr edx, 2 and edx, 7 push edi mov DWORD PTR _kind1$[ebp], edx ; 10423: kind2 = PyUnicode_KIND(str2); mov edx, DWORD PTR [esi+16] mov edi, edx shr edi, 2 and edi, 7 mov DWORD PTR _kind2$[ebp], edi ; 10424: data1 = PyUnicode_DATA(str1); test al, 32 ; 00000020H je SHORT $LN9 at unicode_co@2 test al, 64 ; 00000040H je SHORT $LN7 at unicode_co@2 lea ebx, DWORD PTR [ecx+24] jmp SHORT $LN10 at unicode_co@2 $LN7 at unicode_co@2: lea ebx, DWORD PTR [ecx+36] jmp SHORT $LN10 at unicode_co@2 $LN9 at unicode_co@2: mov ebx, DWORD PTR [ecx+36] $LN10 at unicode_co@2: ; 10425: data2 = PyUnicode_DATA(str2); test dl, 32 ; 00000020H je SHORT $LN13 at unicode_co@2 test dl, 64 ; 00000040H je SHORT $LN11 at unicode_co@2 lea edx, DWORD PTR [esi+24] jmp SHORT $LN30 at unicode_co@2 $LN11 at unicode_co@2: lea eax, DWORD PTR [esi+36] mov DWORD PTR _data2$[ebp], eax mov edx, eax jmp SHORT $LN14 at unicode_co@2 $LN13 at unicode_co@2: mov edx, DWORD PTR [esi+36] $LN30 at unicode_co@2: mov DWORD PTR _data2$[ebp], edx $LN14 at unicode_co@2: ; 10426: len1 = PyUnicode_GET_LENGTH(str1); mov edi, DWORD PTR [ecx+8] ; 10427: len2 = PyUnicode_GET_LENGTH(str2); mov ecx, DWORD PTR [esi+8] ; 10428: ; 10429: for (i = 0; i < len1 && i < len2; ++i) { xor eax, eax mov DWORD PTR _len1$[ebp], edi mov DWORD PTR _len2$[ebp], ecx test edi, edi jle SHORT $LN2 at unicode_co@2 ; 10426: len1 = PyUnicode_GET_LENGTH(str1); mov esi, edx mov edi, edx ; 10428: ; 10429: for (i = 0; i < len1 && i < len2; ++i) { sub ebx, edx jmp SHORT $LN4 at unicode_co@2 $LL28 at unicode_co@2: mov edx, DWORD PTR _data2$[ebp] $LN4 at unicode_co@2: cmp eax, ecx jge SHORT $LN29 at unicode_co@2 ; 10430: Py_UCS4 c1, c2; ; 10431: c1 = PyUnicode_READ(kind1, data1, i); mov ecx, DWORD PTR _kind1$[ebp] cmp ecx, 1 jne SHORT $LN17 at unicode_co@2 lea ecx, DWORD PTR [ebx+eax] movzx edx, BYTE PTR [ecx+edx] jmp SHORT $LN16 at unicode_co@2 $LN17 at unicode_co@2: cmp ecx, 2 jne SHORT $LN15 at unicode_co@2 movzx edx, WORD PTR [ebx+edi] jmp SHORT $LN16 at unicode_co@2 $LN15 at unicode_co@2: mov edx, DWORD PTR [ebx+esi] $LN16 at unicode_co@2: ; 10432: c2 = PyUnicode_READ(kind2, data2, i); mov ecx, DWORD PTR _kind2$[ebp] cmp ecx, 1 jne SHORT $LN21 at unicode_co@2 mov ecx, DWORD PTR _data2$[ebp] movzx ecx, BYTE PTR [eax+ecx] jmp SHORT $LN20 at unicode_co@2 $LN21 at unicode_co@2: cmp ecx, 2 jne SHORT $LN19 at unicode_co@2 movzx ecx, WORD PTR [edi] jmp SHORT $LN20 at unicode_co@2 $LN19 at unicode_co@2: mov ecx, DWORD PTR [esi] $LN20 at unicode_co@2: ; 10433: ; 10434: if (c1 != c2) cmp edx, ecx jne SHORT $LN31 at unicode_co@2 mov ecx, DWORD PTR _len2$[ebp] inc eax add edi, 2 add esi, 4 cmp eax, DWORD PTR _len1$[ebp] jl SHORT $LL28 at unicode_co@2 $LN29 at unicode_co@2: mov edi, DWORD PTR _len1$[ebp] $LN2 at unicode_co@2: ; 10436: } ; 10437: ; 10438: return (len1 < len2) ? -1 : (len1 != len2); cmp edi, ecx jge SHORT $LN23 at unicode_co@2 pop edi pop esi or eax, -1 pop ebx ; 10439: } mov esp, ebp pop ebp ret 0 $LN31 at unicode_co@2: ; 10435: return (c1 < c2) ? -1 : 1; sbb eax, eax pop edi and eax, -2 ; fffffffeH pop esi inc eax pop ebx ; 10439: } mov esp, ebp pop ebp ret 0 $LN23 at unicode_co@2: ; 10436: } ; 10437: ; 10438: return (len1 < len2) ? -1 : (len1 != len2); xor eax, eax cmp edi, ecx pop edi pop esi setne al pop ebx ; 10439: } mov esp, ebp pop ebp ret 0 _unicode_compare ENDP Neil From davea at davea.name Wed Apr 3 07:52:42 2013 From: davea at davea.name (Dave Angel) Date: Wed, 03 Apr 2013 07:52:42 -0400 Subject: Performance of int/long in Python 3 In-Reply-To: References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: <515C180A.4030302@davea.name> On 04/03/2013 07:05 AM, Neil Hodgson wrote: > Dave Angel: > >> That would seem to imply that the speed regression on your data is NOT >> caused by the differing size encodings. Perhaps it is the difference in >> MSC compiler version, or other changes made between 3.2 and 3.3 > > Its not caused by there actually being different size encodings but > that the code is checking encoding size 2-4 times for each character. > > Back in 3.2 the comparison loop looked like: > > while (len1 > 0 && len2 > 0) { > Py_UNICODE c1, c2; > > c1 = *s1++; > c2 = *s2++; > > if (c1 != c2) > return (c1 < c2) ? -1 : 1; > > len1--; len2--; > } > > For 3.3 this has changed to > > for (i = 0; i < len1 && i < len2; ++i) { > Py_UCS4 c1, c2; > c1 = PyUnicode_READ(kind1, data1, i); > c2 = PyUnicode_READ(kind2, data2, i); > > if (c1 != c2) > return (c1 < c2) ? -1 : 1; > } > > with PyUnicode_READ being > > #define PyUnicode_READ(kind, data, index) \ > ((Py_UCS4) \ > ((kind) == PyUnicode_1BYTE_KIND ? \ > ((const Py_UCS1 *)(data))[(index)] : \ > ((kind) == PyUnicode_2BYTE_KIND ? \ > ((const Py_UCS2 *)(data))[(index)] : \ > ((const Py_UCS4 *)(data))[(index)] \ > ) \ > )) > > There are either 1 or 2 kind checks in each call to PyUnicode_READ > and 2 calls to PyUnicode_READ inside the loop. A compiler may decide to > move the kind checks out of the loop and specialize the loop but MSVC > 2010 appears to not do so. I don't know how good MSC's template logic is, but it seems this would be a good case for an explicit template, typed on the 'kind's values. Or are all C++ features disabled when compiling Python? Failing that, just code up 9 cases, and do a switch on the kinds. I'm also puzzled. I thought that the sort algorithm used a hash of all the items to be sorted, and only reverted to a raw comparison of the original values when the hash collided. Is that not the case? Or is the code you post here only used when the hash collides? The assembler (32-bit build) for each > PyUnicode_READ looks like > > mov ecx, DWORD PTR _kind1$[ebp] > cmp ecx, 1 > jne SHORT $LN17 at unicode_co@2 > lea ecx, DWORD PTR [ebx+eax] > movzx edx, BYTE PTR [ecx+edx] > jmp SHORT $LN16 at unicode_co@2 > $LN17 at unicode_co@2: > cmp ecx, 2 > jne SHORT $LN15 at unicode_co@2 > movzx edx, WORD PTR [ebx+edi] > jmp SHORT $LN16 at unicode_co@2 > $LN15 at unicode_co@2: > mov edx, DWORD PTR [ebx+esi] > $LN16 at unicode_co@2: It appears that the compiler is keeping the three pointers in three separate registers (eax, esi and edi) even though those are 3 aliases for the same pointer. This is preventing it from putting other values in those registers. It'd probably do better if the C code manipulated the pointers, rather than using an index i each time. But if it did, perhaps gcc would generate worse code. If I were coding the assembler by hand (Intel only), I'd be able to avoid the multiple cmp operations, simply by comparing first to 2, then doing a jne and a ja. I dunno whether the compiler would notice if I coded the equivalent in C. (make both comparisons to 2, one for less, and one for more) > > The kind1/kind2 variables aren't even going into registers and at > least one test+branch and a jump are executed for every character. Two > tests for 2 and 4 byte kinds. len1 and len2 don't get to go into > registers either. > > Here's the full assembler output for unicode_compare: > > ; COMDAT _unicode_compare > _TEXT SEGMENT > _kind2$ = -20 ; size = 4 > _kind1$ = -16 ; size = 4 > _len2$ = -12 ; size = 4 > _len1$ = -8 ; size = 4 > _data2$ = -4 ; size = 4 > _unicode_compare PROC ; COMDAT > ; _str1$ = ecx > ; _str2$ = eax > > ; 10417: { > > push ebp > mov ebp, esp > sub esp, 20 ; 00000014H > push ebx > push esi > mov esi, eax > > ; 10418: int kind1, kind2; > ; 10419: void *data1, *data2; > ; 10420: Py_ssize_t len1, len2, i; > ; 10421: > ; 10422: kind1 = PyUnicode_KIND(str1); > > mov eax, DWORD PTR [ecx+16] > mov edx, eax > shr edx, 2 > and edx, 7 > push edi > mov DWORD PTR _kind1$[ebp], edx > > ; 10423: kind2 = PyUnicode_KIND(str2); > > mov edx, DWORD PTR [esi+16] > mov edi, edx > shr edi, 2 > and edi, 7 > mov DWORD PTR _kind2$[ebp], edi > > ; 10424: data1 = PyUnicode_DATA(str1); > > test al, 32 ; 00000020H > je SHORT $LN9 at unicode_co@2 > test al, 64 ; 00000040H > je SHORT $LN7 at unicode_co@2 > lea ebx, DWORD PTR [ecx+24] > jmp SHORT $LN10 at unicode_co@2 > $LN7 at unicode_co@2: > lea ebx, DWORD PTR [ecx+36] > jmp SHORT $LN10 at unicode_co@2 > $LN9 at unicode_co@2: > mov ebx, DWORD PTR [ecx+36] > $LN10 at unicode_co@2: > > ; 10425: data2 = PyUnicode_DATA(str2); > > test dl, 32 ; 00000020H > je SHORT $LN13 at unicode_co@2 > test dl, 64 ; 00000040H > je SHORT $LN11 at unicode_co@2 > lea edx, DWORD PTR [esi+24] > jmp SHORT $LN30 at unicode_co@2 > $LN11 at unicode_co@2: > lea eax, DWORD PTR [esi+36] > mov DWORD PTR _data2$[ebp], eax > mov edx, eax > jmp SHORT $LN14 at unicode_co@2 > $LN13 at unicode_co@2: > mov edx, DWORD PTR [esi+36] > $LN30 at unicode_co@2: > mov DWORD PTR _data2$[ebp], edx > $LN14 at unicode_co@2: > > ; 10426: len1 = PyUnicode_GET_LENGTH(str1); > > mov edi, DWORD PTR [ecx+8] > > ; 10427: len2 = PyUnicode_GET_LENGTH(str2); > > mov ecx, DWORD PTR [esi+8] > > ; 10428: > ; 10429: for (i = 0; i < len1 && i < len2; ++i) { > > xor eax, eax > mov DWORD PTR _len1$[ebp], edi > mov DWORD PTR _len2$[ebp], ecx > test edi, edi > jle SHORT $LN2 at unicode_co@2 > > ; 10426: len1 = PyUnicode_GET_LENGTH(str1); > > mov esi, edx > mov edi, edx > > ; 10428: > ; 10429: for (i = 0; i < len1 && i < len2; ++i) { > > sub ebx, edx > jmp SHORT $LN4 at unicode_co@2 > $LL28 at unicode_co@2: > mov edx, DWORD PTR _data2$[ebp] > $LN4 at unicode_co@2: > cmp eax, ecx > jge SHORT $LN29 at unicode_co@2 > > ; 10430: Py_UCS4 c1, c2; > ; 10431: c1 = PyUnicode_READ(kind1, data1, i); > > mov ecx, DWORD PTR _kind1$[ebp] > cmp ecx, 1 > jne SHORT $LN17 at unicode_co@2 > lea ecx, DWORD PTR [ebx+eax] > movzx edx, BYTE PTR [ecx+edx] > jmp SHORT $LN16 at unicode_co@2 > $LN17 at unicode_co@2: > cmp ecx, 2 > jne SHORT $LN15 at unicode_co@2 > movzx edx, WORD PTR [ebx+edi] > jmp SHORT $LN16 at unicode_co@2 > $LN15 at unicode_co@2: > mov edx, DWORD PTR [ebx+esi] > $LN16 at unicode_co@2: > > ; 10432: c2 = PyUnicode_READ(kind2, data2, i); > > mov ecx, DWORD PTR _kind2$[ebp] > cmp ecx, 1 > jne SHORT $LN21 at unicode_co@2 > mov ecx, DWORD PTR _data2$[ebp] > movzx ecx, BYTE PTR [eax+ecx] > jmp SHORT $LN20 at unicode_co@2 > $LN21 at unicode_co@2: > cmp ecx, 2 > jne SHORT $LN19 at unicode_co@2 > movzx ecx, WORD PTR [edi] > jmp SHORT $LN20 at unicode_co@2 > $LN19 at unicode_co@2: > mov ecx, DWORD PTR [esi] > $LN20 at unicode_co@2: > > ; 10433: > ; 10434: if (c1 != c2) > > cmp edx, ecx > jne SHORT $LN31 at unicode_co@2 > mov ecx, DWORD PTR _len2$[ebp] > inc eax > add edi, 2 > add esi, 4 > cmp eax, DWORD PTR _len1$[ebp] > jl SHORT $LL28 at unicode_co@2 > $LN29 at unicode_co@2: > mov edi, DWORD PTR _len1$[ebp] > $LN2 at unicode_co@2: > > ; 10436: } > ; 10437: > ; 10438: return (len1 < len2) ? -1 : (len1 != len2); > > cmp edi, ecx > jge SHORT $LN23 at unicode_co@2 > pop edi > pop esi > or eax, -1 > pop ebx > > ; 10439: } > > mov esp, ebp > pop ebp > ret 0 > $LN31 at unicode_co@2: > > ; 10435: return (c1 < c2) ? -1 : 1; > > sbb eax, eax > pop edi > and eax, -2 ; fffffffeH > pop esi > inc eax > pop ebx > > ; 10439: } > > mov esp, ebp > pop ebp > ret 0 > $LN23 at unicode_co@2: > > ; 10436: } > ; 10437: > ; 10438: return (len1 < len2) ? -1 : (len1 != len2); > > xor eax, eax > cmp edi, ecx > pop edi > pop esi > setne al > pop ebx > > ; 10439: } > > mov esp, ebp > pop ebp > ret 0 > _unicode_compare ENDP > > Neil -- DaveA From ian.g.kelly at gmail.com Wed Apr 3 12:30:45 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 3 Apr 2013 10:30:45 -0600 Subject: Performance of int/long in Python 3 In-Reply-To: <515C180A.4030302@davea.name> References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515C180A.4030302@davea.name> Message-ID: On Wed, Apr 3, 2013 at 5:52 AM, Dave Angel wrote: > I'm also puzzled. I thought that the sort algorithm used a hash of all the > items to be sorted, and only reverted to a raw comparison of the original > values when the hash collided. Is that not the case? Or is the code you > post here only used when the hash collides? I think you are mistaken, because I don't see how that could work. If the hashes of two items are different then you can assume they are not equal, but sorting requires a partial ordering comparison, not simply an equality comparison. You cannot determine which item is less or greater than the other from the hash values alone. From davea at davea.name Wed Apr 3 13:51:26 2013 From: davea at davea.name (Dave Angel) Date: Wed, 03 Apr 2013 13:51:26 -0400 Subject: Performance of int/long in Python 3 In-Reply-To: References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515C180A.4030302@davea.name> Message-ID: <515C6C1E.5050307@davea.name> On 04/03/2013 12:30 PM, Ian Kelly wrote: > On Wed, Apr 3, 2013 at 5:52 AM, Dave Angel wrote: >> I'm also puzzled. I thought that the sort algorithm used a hash of all the >> items to be sorted, and only reverted to a raw comparison of the original >> values when the hash collided. Is that not the case? Or is the code you >> post here only used when the hash collides? > > I think you are mistaken, because I don't see how that could work. If > the hashes of two items are different then you can assume they are not > equal, but sorting requires a partial ordering comparison, not simply > an equality comparison. You cannot determine which item is less or > greater than the other from the hash values alone. > You are of course correct. The particular data that Neil had provided might well have had many duplicates, but that won't be the typical case, so there's not much point in doing an unordered hash. I guess I was confusing it with the key= argument for modifying sort order, where the key function might replace a slow-to-compare data type with something faster. -- DaveA From steve+comp.lang.python at pearwood.info Wed Apr 3 10:43:26 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Apr 2013 14:43:26 GMT Subject: Sorting [was Re: Performance of int/long in Python 3] References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: <515c400e$0$29966$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Apr 2013 07:52:42 -0400, Dave Angel wrote: > I thought that the sort algorithm used a hash of all > the items to be sorted, and only reverted to a raw comparison of the > original values when the hash collided. Is that not the case? Or is > the code you post here only used when the hash collides? Sorting does not require that the elements being sorted are hashable. If I have understood the implementation here: http://hg.python.org/releasing/3.3.1/file/2ab2a09901f9/Objects/listobject.c sorting in Python only requires that objects implement the less-than comparison. py> class Funny: ... def __init__(self, x): ... self.x = x ... def __lt__(self, other): ... return self.x < other.x ... def __gt__(self, x): ... raise AttributeError ... __le__ = __ge__ = __eq__ = __ne__ = __gt__ ... py> L = [Funny(i) for i in range(10)] py> random.shuffle(L) py> [f.x for f in L] [8, 5, 7, 0, 9, 2, 3, 6, 1, 4] py> [f.x for f in sorted(L)] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] but if I change Funny.__lt__ to also raise, sorting fails. I seem to recall that "sort relies only on < operator" is a language promise, but I can't seem to find it documented anywhere official. -- Steven From roy at panix.com Wed Apr 3 11:00:10 2013 From: roy at panix.com (Roy Smith) Date: Wed, 03 Apr 2013 11:00:10 -0400 Subject: Sorting [was Re: Performance of int/long in Python 3] References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515c400e$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <515c400e$0$29966$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > I seem to recall that "sort relies only on < operator" is a language > promise, but I can't seem to find it documented anywhere official. That's pretty typical for sort implementations in all languages. Except for those which rely on "less than and equal to" :-) From nhodgson at iinet.net.au Wed Apr 3 18:58:09 2013 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Thu, 04 Apr 2013 09:58:09 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: Neil Hodgson, replying to self: > The assembler (32-bit build) for each > PyUnicode_READ looks like Don't have 64-bit MSVC 2010 set up but the code from 64-bit MSVC 2012 is better since there are an extra 8 registers in 64-bit mode: ; 10431: c1 = PyUnicode_READ(kind1, data1, i); cmp rsi, 1 jne SHORT $LN17 at unicode_co lea rax, QWORD PTR [r9+rcx] movzx r8d, BYTE PTR [rax+rbx] jmp SHORT $LN16 at unicode_co $LN17 at unicode_co: cmp rsi, 2 jne SHORT $LN15 at unicode_co movzx r8d, WORD PTR [r9+r11] jmp SHORT $LN16 at unicode_co $LN15 at unicode_co: mov r8d, DWORD PTR [r9+r10] $LN16 at unicode_co: All the variables used in the loop are now in registers but the tests and branches are the same. This lines up with 64-bit being better than 32-bit on Windows but not as good as Python 3.2 or Unix. Neil From steve+comp.lang.python at pearwood.info Wed Apr 3 03:53:51 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Apr 2013 07:53:51 GMT Subject: Performance of int/long in Python 3 References: <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Apr 2013 18:24:25 +1100, Chris Angelico wrote: > On Wed, Apr 3, 2013 at 6:06 PM, Ian Kelly wrote: >> On Wed, Apr 3, 2013 at 12:52 AM, Chris Angelico >> wrote: >>> Hmm. I was about to say "Can you just do a quick collections.Counter() >>> of the string widths in 3.3, as an easy way of seeing which ones use >>> BMP or higher characters", but I can't find a simple way to query a >>> string's width. Can't see it as a method of the string object, nor in >>> the string or sys modules. It ought to be easy enough at the C level - >>> just look up the two bits representing 'kind' - but I've not found it >>> exposed to Python. Is there anything? >> >> 4 if max(map(ord, s)) > 0xffff else 2 if max(map(ord, s)) > 0xff else 1 > > Yeah, that's iterating over the whole string (twice, if it isn't width > 4). Then don't write it as a one-liner :-P n = max(map(ord, s)) 4 if n > 0xffff else 2 if n > 0xff else 1 Here's another way: (sys.getsizeof(s) - sys.getsizeof(''))/len(s) should work. There's probably also a way to do it using ctypes. > The system already knows what the size is, I was hoping for an > uber-quick inspection of the string header. I'm not sure that I would want strings to have a method reporting this, but it might be nice to have a function in the inspect module to do so. -- Steven From rosuav at gmail.com Wed Apr 3 04:02:12 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 3 Apr 2013 19:02:12 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> References: <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 3, 2013 at 6:53 PM, Steven D'Aprano wrote: > Here's another way: > > > (sys.getsizeof(s) - sys.getsizeof(''))/len(s) > > should work. Hmm, I had been under the impression that there was a certain "base length" below which strings all had the same size. Yes, that also works; though again, it's something that can be directly queried, at the C level. > There's probably also a way to do it using ctypes. > >> The system already knows what the size is, I was hoping for an >> uber-quick inspection of the string header. > > I'm not sure that I would want strings to have a method reporting this, > but it might be nice to have a function in the inspect module to do so. Yeah, that's why I also looked in 'sys'; 'inspect' might well be a good place for it, too. But it seems such a function doesn't exist, which is what I was asking. ChrisA From wxjmfauth at gmail.com Wed Apr 3 04:08:54 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Wed, 3 Apr 2013 01:08:54 -0700 (PDT) Subject: Performance of int/long in Python 3 References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: -------- This FSR is wrong by design. A naive way to embrace Unicode. jmf From breamoreboy at yahoo.co.uk Wed Apr 3 07:27:58 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 03 Apr 2013 12:27:58 +0100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 03/04/2013 09:08, jmfauth wrote: > -------- > > This FSR is wrong by design. A naive way to embrace Unicode. > > jmf > The hole you're digging for yourself is getting bigger and bigger and I'm loving it :) -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From roy at panix.com Wed Apr 3 09:43:06 2013 From: roy at panix.com (Roy Smith) Date: Wed, 03 Apr 2013 09:43:06 -0400 Subject: Performance of int/long in Python 3 References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <515be00e$0$29891$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > On Wed, 03 Apr 2013 18:24:25 +1100, Chris Angelico wrote: > > > On Wed, Apr 3, 2013 at 6:06 PM, Ian Kelly wrote: > >> On Wed, Apr 3, 2013 at 12:52 AM, Chris Angelico > >> wrote: > >>> Hmm. I was about to say "Can you just do a quick collections.Counter() > >>> of the string widths in 3.3, as an easy way of seeing which ones use > >>> BMP or higher characters", but I can't find a simple way to query a > >>> string's width. Can't see it as a method of the string object, nor in > >>> the string or sys modules. It ought to be easy enough at the C level - > >>> just look up the two bits representing 'kind' - but I've not found it > >>> exposed to Python. Is there anything? > >> > >> 4 if max(map(ord, s)) > 0xffff else 2 if max(map(ord, s)) > 0xff else 1 > > > > Yeah, that's iterating over the whole string (twice, if it isn't width > > 4). > > Then don't write it as a one-liner :-P > > n = max(map(ord, s)) > 4 if n > 0xffff else 2 if n > 0xff else 1 This has to inspect the entire string, no? I posted (essentially) this a few days ago: if all(ord(c) <= 0xffff for c in s): return "it's all bmp" else: return "it's got astral crap in it" I'm reasonably sure all() is smart enough to stop at the first False value. > (sys.getsizeof(s) - sys.getsizeof(''))/len(s) > I wouldn't trust getsizeof() to return exactly what you're looking for. From rosuav at gmail.com Wed Apr 3 10:17:28 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 4 Apr 2013 01:17:28 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Apr 4, 2013 at 12:43 AM, Roy Smith wrote: > This has to inspect the entire string, no? I posted (essentially) this > a few days ago: > > if all(ord(c) <= 0xffff for c in s): > return "it's all bmp" > else: > return "it's got astral crap in it" > > I'm reasonably sure all() is smart enough to stop at the first False > value. Probably, but it still has to scan the body of the string. It'd not be too bad if it's all astral, but if it's all BMP, it has to scan the whole string. In the max() case, it has to scan the whole string anyway, as there's no other way to determine the maximum. I'm thinking here of this function: http://pike.lysator.liu.se/generated/manual/modref/ex/7.2_3A_3A/String/width.html It's implemented as a simple lookup into the header. (Pike strings, like PEP 393 strings, are stored in the most compact way possible - 1, 2, or 4 bytes per character - with a conceptually similar header structure.) Is this something that would be worth having available? Should I post an issue about it? ChrisA more for self-ref than anyone else's: source of Pike's String.width(): http://pike-git.lysator.liu.se/gitweb.cgi?p=pike.git;a=blob;f=src/builtin.cmod;hb=HEAD#l1077 From steve+comp.lang.python at pearwood.info Wed Apr 3 11:02:37 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Apr 2013 15:02:37 GMT Subject: Performance of int/long in Python 3 References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: <515c448c$0$29966$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Apr 2013 09:43:06 -0400, Roy Smith wrote: [...] >> n = max(map(ord, s)) >> 4 if n > 0xffff else 2 if n > 0xff else 1 > > This has to inspect the entire string, no? Correct. A more efficient implementation would be: def char_size(s): for n in map(ord, s): if n > 0xFFFF: return 4 if n > 0xFF: return 2 return 1 > I posted (essentially) this a few days ago: > > if all(ord(c) <= 0xffff for c in s): > return "it's all bmp" > else: > return "it's got astral crap in it" It's not "astral crap". People use it, and they'll use it more in the future. Just because you don't, doesn't give you leave to make disparaging remarks about it. Honestly, it's really painful to see how history repeats itself: "Bah humbug, why do we need to support the SMP astral crap? The Unicode BMP is more than enough for everybody." "Bah humbug, why do we need to support Unicode crap? Latin1 is more than enough for everybody." "Bah humbug, why do we need to support Latin1 crap? ASCII is more than enough for everybody." "Bah humbug, why do we need to support ASCII crap? Uppercase A-Z is more than enough for everybody." Seriously. Go back long enough, to the telegraph days, and you have people arguing that there was no need for upper and lower case letters. > I'm reasonably sure all() is smart enough to stop at the first False > value. Yes, all() and any() are guaranteed to be short-circuit functions. They will stop as soon as they see a False or a True value respectively. -- Steven From ian.g.kelly at gmail.com Wed Apr 3 12:38:20 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 3 Apr 2013 10:38:20 -0600 Subject: Performance of int/long in Python 3 In-Reply-To: <515c448c$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> <515c448c$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 3, 2013 at 9:02 AM, Steven D'Aprano wrote: > On Wed, 03 Apr 2013 09:43:06 -0400, Roy Smith wrote: > > [...] >>> n = max(map(ord, s)) >>> 4 if n > 0xffff else 2 if n > 0xff else 1 >> >> This has to inspect the entire string, no? > > Correct. A more efficient implementation would be: > > def char_size(s): > for n in map(ord, s): > if n > 0xFFFF: return 4 > if n > 0xFF: return 2 > return 1 That's an incorrect implementation, as it would return 2 at the first non-Latin-1 BMP character, even if there were SMP characters later in the string. It's only safe to short-circuit return 4, not 2 or 1. From steve+comp.lang.python at pearwood.info Wed Apr 3 13:43:51 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Apr 2013 17:43:51 GMT Subject: Performance of int/long in Python 3 References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> <515c448c$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <515c6a57$0$29966$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Apr 2013 10:38:20 -0600, Ian Kelly wrote: > On Wed, Apr 3, 2013 at 9:02 AM, Steven D'Aprano > wrote: >> On Wed, 03 Apr 2013 09:43:06 -0400, Roy Smith wrote: >> >> [...] >>>> n = max(map(ord, s)) >>>> 4 if n > 0xffff else 2 if n > 0xff else 1 >>> >>> This has to inspect the entire string, no? >> >> Correct. A more efficient implementation would be: >> >> def char_size(s): >> for n in map(ord, s): >> if n > 0xFFFF: return 4 >> if n > 0xFF: return 2 >> return 1 > > That's an incorrect implementation, as it would return 2 at the first > non-Latin-1 BMP character, even if there were SMP characters later in > the string. It's only safe to short-circuit return 4, not 2 or 1. Doh! I mean, well done sir, you have successfully passed my little test! -- Steven From rosuav at gmail.com Wed Apr 3 17:55:43 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 4 Apr 2013 08:55:43 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: <515c6a57$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> <515c448c$0$29966$c3e8da3$5496439d@news.astraweb.com> <515c6a57$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Apr 4, 2013 at 4:43 AM, Steven D'Aprano wrote: > On Wed, 03 Apr 2013 10:38:20 -0600, Ian Kelly wrote: > >> On Wed, Apr 3, 2013 at 9:02 AM, Steven D'Aprano >> wrote: >>> On Wed, 03 Apr 2013 09:43:06 -0400, Roy Smith wrote: >>> >>> [...] >>>>> n = max(map(ord, s)) >>>>> 4 if n > 0xffff else 2 if n > 0xff else 1 >>>> >>>> This has to inspect the entire string, no? >>> >>> Correct. A more efficient implementation would be: >>> >>> def char_size(s): >>> for n in map(ord, s): >>> if n > 0xFFFF: return 4 >>> if n > 0xFF: return 2 >>> return 1 >> >> That's an incorrect implementation, as it would return 2 at the first >> non-Latin-1 BMP character, even if there were SMP characters later in >> the string. It's only safe to short-circuit return 4, not 2 or 1. > > > Doh! > > I mean, well done sir, you have successfully passed my little test! Try this: def str_width(s): width=1 for ch in map(ord,s): if ch > 0xFFFF: return 4 if cn > 0xFF: width=2 return width ChrisA From breamoreboy at yahoo.co.uk Wed Apr 3 18:39:19 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 03 Apr 2013 23:39:19 +0100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> <515c448c$0$29966$c3e8da3$5496439d@news.astraweb.com> <515c6a57$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 03/04/2013 22:55, Chris Angelico wrote: > On Thu, Apr 4, 2013 at 4:43 AM, Steven D'Aprano > wrote: >> On Wed, 03 Apr 2013 10:38:20 -0600, Ian Kelly wrote: >> >>> On Wed, Apr 3, 2013 at 9:02 AM, Steven D'Aprano >>> wrote: >>>> On Wed, 03 Apr 2013 09:43:06 -0400, Roy Smith wrote: >>>> >>>> [...] >>>>>> n = max(map(ord, s)) >>>>>> 4 if n > 0xffff else 2 if n > 0xff else 1 >>>>> >>>>> This has to inspect the entire string, no? >>>> >>>> Correct. A more efficient implementation would be: >>>> >>>> def char_size(s): >>>> for n in map(ord, s): >>>> if n > 0xFFFF: return 4 >>>> if n > 0xFF: return 2 >>>> return 1 >>> >>> That's an incorrect implementation, as it would return 2 at the first >>> non-Latin-1 BMP character, even if there were SMP characters later in >>> the string. It's only safe to short-circuit return 4, not 2 or 1. >> >> >> Doh! >> >> I mean, well done sir, you have successfully passed my little test! > > Try this: > > def str_width(s): > width=1 > for ch in map(ord,s): > if ch > 0xFFFF: return 4 > if cn > 0xFF: width=2 > return width > > ChrisA > Given the quality of some code posted here recently this patch can't be accepted until there are some unit tests :) -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From roy at panix.com Wed Apr 3 20:49:15 2013 From: roy at panix.com (Roy Smith) Date: Wed, 03 Apr 2013 20:49:15 -0400 Subject: Performance of int/long in Python 3 References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> <515c448c$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <515c448c$0$29966$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > On Wed, 03 Apr 2013 09:43:06 -0400, Roy Smith wrote: > > [...] > >> n = max(map(ord, s)) > >> 4 if n > 0xffff else 2 if n > 0xff else 1 > > > > This has to inspect the entire string, no? > > Correct. A more efficient implementation would be: > > def char_size(s): > for n in map(ord, s): > if n > 0xFFFF: return 4 > if n > 0xFF: return 2 > return 1 > > > > > I posted (essentially) this a few days ago: > > > > if all(ord(c) <= 0xffff for c in s): > > return "it's all bmp" > > else: > > return "it's got astral crap in it" > > > It's not "astral crap". People use it, and they'll use it more in the > future. Just because you don't, doesn't give you leave to make > disparaging remarks about it. > > Honestly, it's really painful to see how history repeats itself: > > "Bah humbug, why do we need to support the SMP astral crap? The Unicode > BMP is more than enough for everybody." Come on, guys. It was a joke. I'm the guy who was complaining that my database doesn't support non-BMP, remember? From steve+comp.lang.python at pearwood.info Wed Apr 3 11:07:25 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Apr 2013 15:07:25 GMT Subject: Performance of int/long in Python 3 References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: <515c45ad$0$29966$c3e8da3$5496439d@news.astraweb.com> On Thu, 04 Apr 2013 01:17:28 +1100, Chris Angelico wrote: > Probably, but it still has to scan the body of the string. It'd not be > too bad if it's all astral, but if it's all BMP, it has to scan the > whole string. In the max() case, it has to scan the whole string anyway, > as there's no other way to determine the maximum. I'm thinking here of > this function: > > http://pike.lysator.liu.se/generated/manual/modref/ex/7.2_3A_3A/String/ width.html > > It's implemented as a simple lookup into the header. (Pike strings, like > PEP 393 strings, are stored in the most compact way possible - 1, 2, or > 4 bytes per character - with a conceptually similar header structure.) > Is this something that would be worth having available? Should I post an > issue about it? I'm not really sure why I would want to know, apart from pure intellectual curiosity, but sure, post a feature request. Be sure to mention that Pike supports this feature. -- Steven From rosuav at gmail.com Wed Apr 3 17:57:19 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 4 Apr 2013 08:57:19 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: <515c45ad$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> <515c45ad$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Apr 4, 2013 at 2:07 AM, Steven D'Aprano wrote: > On Thu, 04 Apr 2013 01:17:28 +1100, Chris Angelico wrote: > >> Probably, but it still has to scan the body of the string. It'd not be >> too bad if it's all astral, but if it's all BMP, it has to scan the >> whole string. In the max() case, it has to scan the whole string anyway, >> as there's no other way to determine the maximum. I'm thinking here of >> this function: >> >> http://pike.lysator.liu.se/generated/manual/modref/ex/7.2_3A_3A/String/ > width.html >> >> It's implemented as a simple lookup into the header. (Pike strings, like >> PEP 393 strings, are stored in the most compact way possible - 1, 2, or >> 4 bytes per character - with a conceptually similar header structure.) >> Is this something that would be worth having available? Should I post an >> issue about it? > > I'm not really sure why I would want to know, apart from pure > intellectual curiosity, but sure, post a feature request. Be sure to > mention that Pike supports this feature. http://bugs.python.org/issue17629 opened. ChrisA From storchaka at gmail.com Sat Apr 6 05:09:43 2013 From: storchaka at gmail.com (Serhiy Storchaka) Date: Sat, 06 Apr 2013 12:09:43 +0300 Subject: Performance of int/long in Python 3 In-Reply-To: References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> <515c45ad$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: 04.04.13 00:57, Chris Angelico ???????(??): > On Thu, Apr 4, 2013 at 2:07 AM, Steven D'Aprano > wrote: >> On Thu, 04 Apr 2013 01:17:28 +1100, Chris Angelico wrote: >> >>> Probably, but it still has to scan the body of the string. It'd not be >>> too bad if it's all astral, but if it's all BMP, it has to scan the >>> whole string. In the max() case, it has to scan the whole string anyway, >>> as there's no other way to determine the maximum. I'm thinking here of >>> this function: >>> >>> http://pike.lysator.liu.se/generated/manual/modref/ex/7.2_3A_3A/String/ >> width.html >>> >>> It's implemented as a simple lookup into the header. (Pike strings, like >>> PEP 393 strings, are stored in the most compact way possible - 1, 2, or >>> 4 bytes per character - with a conceptually similar header structure.) >>> Is this something that would be worth having available? Should I post an >>> issue about it? >> >> I'm not really sure why I would want to know, apart from pure >> intellectual curiosity, but sure, post a feature request. Be sure to >> mention that Pike supports this feature. > > http://bugs.python.org/issue17629 opened. See also the discussion at http://comments.gmane.org/gmane.comp.python.ideas/15640 . I agree with rejection. This is an implementation detail and different Python implementations (including future CPython versions) can have different internal string implementations. From rosuav at gmail.com Sat Apr 6 17:24:59 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 7 Apr 2013 07:24:59 +1000 Subject: Performance of int/long in Python 3 In-Reply-To: References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> <515c45ad$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Apr 6, 2013 at 8:09 PM, Serhiy Storchaka wrote: > 04.04.13 00:57, Chris Angelico ???????(??): >> http://bugs.python.org/issue17629 opened. > > > See also the discussion at > http://comments.gmane.org/gmane.comp.python.ideas/15640 . I agree with > rejection. This is an implementation detail and different Python > implementations (including future CPython versions) can have different > internal string implementations. I really don't see why this means that there can't be a function in sys, or something. I mean, other Pythons aren't expected to return the exact same values from sys.getsizeof, are they? But clearly the weight of opinion is against me, so fine, I don't care that much. ChrisA From ethan at stoneleaf.us Sat Apr 6 17:58:23 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 06 Apr 2013 14:58:23 -0700 Subject: Performance of int/long in Python 3 In-Reply-To: References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> <515c45ad$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51609A7F.7040707@stoneleaf.us> On 04/06/2013 02:24 PM, Chris Angelico wrote: > On Sat, Apr 6, 2013 at 8:09 PM, Serhiy Storchaka wrote: >> 04.04.13 00:57, Chris Angelico ???????(??): >>> http://bugs.python.org/issue17629 opened. >> >> >> See also the discussion at >> http://comments.gmane.org/gmane.comp.python.ideas/15640 . I agree with >> rejection. This is an implementation detail and different Python >> implementations (including future CPython versions) can have different >> internal string implementations. > > I really don't see why this means that there can't be a function in > sys, or something. I mean, other Pythons aren't expected to return the > exact same values from sys.getsizeof, are they? What it boils down to is: - it can easily be done by hand now - it's a very uncommon need ergo: - it's not worth the time and on-going effort required -- ~Ethan~ From steve+comp.lang.python at pearwood.info Sat Apr 6 21:29:15 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Apr 2013 01:29:15 GMT Subject: Performance of int/long in Python 3 References: <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> <515c45ad$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5160cbeb$0$29995$c3e8da3$5496439d@news.astraweb.com> On Sat, 06 Apr 2013 14:58:23 -0700, Ethan Furman wrote: > On 04/06/2013 02:24 PM, Chris Angelico wrote: >> On Sat, Apr 6, 2013 at 8:09 PM, Serhiy Storchaka >> wrote: >>> 04.04.13 00:57, Chris Angelico ???????(??): >>>> http://bugs.python.org/issue17629 opened. >>> >>> >>> See also the discussion at >>> http://comments.gmane.org/gmane.comp.python.ideas/15640 . I agree with >>> rejection. This is an implementation detail and different Python >>> implementations (including future CPython versions) can have different >>> internal string implementations. >> >> I really don't see why this means that there can't be a function in >> sys, or something. I mean, other Pythons aren't expected to return the >> exact same values from sys.getsizeof, are they? > > What it boils down to is: > > - it can easily be done by hand now For some definition of "easily". if implementation == "CPython": if version < "3.3": if sys.maxunicode exists: use it to decide whether this is a wide or narrow build if a wide build: return 4 else: return 2 else: ??? elif version == "3.3": scan the string, in some efficient or inefficient way return 1, 2, 4 depending on the largest character you find else: ??? else: ??? > - it's a very uncommon need Well, that at least is true. But then, needing to know the platform you're running under, the size of objects, the id of a object, the largest integer, the largest float, or the number of references seen by the garbage collector are also uncommon needs. What really matters is not how often you need it, but what you can do when you need it if you don't have it. -- Steven From ian.g.kelly at gmail.com Sat Apr 6 21:58:02 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 6 Apr 2013 19:58:02 -0600 Subject: Performance of int/long in Python 3 In-Reply-To: <5160cbeb$0$29995$c3e8da3$5496439d@news.astraweb.com> References: <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> <515c45ad$0$29966$c3e8da3$5496439d@news.astraweb.com> <5160cbeb$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Apr 6, 2013 at 7:29 PM, Steven D'Aprano wrote: > For some definition of "easily". > > if implementation == "CPython": > if version < "3.3": > if sys.maxunicode exists: > use it to decide whether this is a wide or narrow build > if a wide build: return 4 > else: return 2 > else: > ??? > elif version == "3.3": > scan the string, in some efficient or inefficient way > return 1, 2, 4 depending on the largest character you find > else: > ??? > else: > ??? None of which goes away if a char width function is added to 3.4 and you still want to support earlier versions as this does. It just adds another "if". From roy at panix.com Sat Apr 6 22:18:08 2013 From: roy at panix.com (Roy Smith) Date: Sat, 06 Apr 2013 22:18:08 -0400 Subject: Performance of int/long in Python 3 References: <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> <515c45ad$0$29966$c3e8da3$5496439d@news.astraweb.com> <5160cbeb$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Ian Kelly wrote: > On Sat, Apr 6, 2013 at 7:29 PM, Steven D'Aprano > wrote: > > For some definition of "easily". > > > > if implementation == "CPython": > > if version < "3.3": > > if sys.maxunicode exists: > > use it to decide whether this is a wide or narrow build > > if a wide build: return 4 > > else: return 2 > > else: > > ??? > > elif version == "3.3": > > scan the string, in some efficient or inefficient way > > return 1, 2, 4 depending on the largest character you find > > else: > > ??? > > else: > > ??? > > None of which goes away if a char width function is added to 3.4 and > you still want to support earlier versions as this does. It just adds > another "if". The same is true of any new feature. That doesn't mean we shouldn't add new features. From ian.g.kelly at gmail.com Sun Apr 7 01:22:29 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 6 Apr 2013 23:22:29 -0600 Subject: Performance of int/long in Python 3 In-Reply-To: References: <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> <515c45ad$0$29966$c3e8da3$5496439d@news.astraweb.com> <5160cbeb$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Apr 6, 2013 at 8:18 PM, Roy Smith wrote: > In article , > Ian Kelly wrote: > >> On Sat, Apr 6, 2013 at 7:29 PM, Steven D'Aprano >> wrote: >> > For some definition of "easily". >> > >> > if implementation == "CPython": >> > if version < "3.3": >> > if sys.maxunicode exists: >> > use it to decide whether this is a wide or narrow build >> > if a wide build: return 4 >> > else: return 2 >> > else: >> > ??? >> > elif version == "3.3": >> > scan the string, in some efficient or inefficient way >> > return 1, 2, 4 depending on the largest character you find >> > else: >> > ??? >> > else: >> > ??? >> >> None of which goes away if a char width function is added to 3.4 and >> you still want to support earlier versions as this does. It just adds >> another "if". > > The same is true of any new feature. That doesn't mean we shouldn't add > new features. If you're interested in backward compatibility, then as noted the feature doesn't really make things any simpler for you. Otherwise, the only implementation that matters from the above is the 3.3 one, which isn't much more complex. From steve+comp.lang.python at pearwood.info Sun Apr 7 04:29:19 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Apr 2013 08:29:19 GMT Subject: Performance of int/long in Python 3 References: <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> <515c45ad$0$29966$c3e8da3$5496439d@news.astraweb.com> <5160cbeb$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51612e5f$0$29995$c3e8da3$5496439d@news.astraweb.com> On Sat, 06 Apr 2013 19:58:02 -0600, Ian Kelly wrote: > On Sat, Apr 6, 2013 at 7:29 PM, Steven D'Aprano > wrote: >> For some definition of "easily". >> >> if implementation == "CPython": >> if version < "3.3": >> if sys.maxunicode exists: >> use it to decide whether this is a wide or narrow build if >> a wide build: return 4 >> else: return 2 >> else: >> ??? >> elif version == "3.3": >> scan the string, in some efficient or inefficient way return 1, >> 2, 4 depending on the largest character you find >> else: >> ??? >> else: >> ??? > > None of which goes away if a char width function is added to 3.4 and you > still want to support earlier versions as this does. It just adds > another "if". I grant you that for supporting earlier versions. But it will help with *future* versions. In principle, by Python 3.9, there could be six different checks just in the CPython section, to say nothing of PyPy, Jython, IronPython, and any other implementation. An officially supported way of querying the kind of strings used will future-proof Python. In this regard, it's no different from (say) sys.float_info. -- Steven From ian.g.kelly at gmail.com Sat Apr 6 22:00:40 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 6 Apr 2013 20:00:40 -0600 Subject: Performance of int/long in Python 3 In-Reply-To: References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> <515c45ad$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Apr 6, 2013 at 3:24 PM, Chris Angelico wrote: > On Sat, Apr 6, 2013 at 8:09 PM, Serhiy Storchaka wrote: >> 04.04.13 00:57, Chris Angelico ???????(??): >>> http://bugs.python.org/issue17629 opened. >> >> >> See also the discussion at >> http://comments.gmane.org/gmane.comp.python.ideas/15640 . I agree with >> rejection. This is an implementation detail and different Python >> implementations (including future CPython versions) can have different >> internal string implementations. > > I really don't see why this means that there can't be a function in > sys, or something. I mean, other Pythons aren't expected to return the > exact same values from sys.getsizeof, are they? But clearly the weight > of opinion is against me, so fine, I don't care that much. If you want it, nobody is stopping you from writing it yourself as an extension module. But I don't think the use case is strong enough to warrant the devs adding it and then having to maintain it. From storchaka at gmail.com Sun Apr 7 04:02:03 2013 From: storchaka at gmail.com (Serhiy Storchaka) Date: Sun, 07 Apr 2013 11:02:03 +0300 Subject: Performance of int/long in Python 3 In-Reply-To: References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> <515c45ad$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 07.04.13 00:24, Chris Angelico wrote: > On Sat, Apr 6, 2013 at 8:09 PM, Serhiy Storchaka wrote: >> See also the discussion at >> http://comments.gmane.org/gmane.comp.python.ideas/15640 . I agree with >> rejection. This is an implementation detail and different Python >> implementations (including future CPython versions) can have different >> internal string implementations. > > I really don't see why this means that there can't be a function in > sys, or something. I mean, other Pythons aren't expected to return the > exact same values from sys.getsizeof, are they? But clearly the weight > of opinion is against me, so fine, I don't care that much. The most strong argument for adding this feature in stdlib is that it has O(1) complexity against of O(N) complexity of any manual implementation. But this argument is not valid for other implementations. From breamoreboy at yahoo.co.uk Sun Apr 7 11:14:10 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 07 Apr 2013 16:14:10 +0100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> <515c45ad$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06/04/2013 22:24, Chris Angelico wrote: > On Sat, Apr 6, 2013 at 8:09 PM, Serhiy Storchaka wrote: >> 04.04.13 00:57, Chris Angelico ???????(??): >>> http://bugs.python.org/issue17629 opened. >> >> >> See also the discussion at >> http://comments.gmane.org/gmane.comp.python.ideas/15640 . I agree with >> rejection. This is an implementation detail and different Python >> implementations (including future CPython versions) can have different >> internal string implementations. > > I really don't see why this means that there can't be a function in > sys, or something. I mean, other Pythons aren't expected to return the > exact same values from sys.getsizeof, are they? But clearly the weight > of opinion is against me, so fine, I don't care that much. > > ChrisA > There is nothing to stop anybody providing a patch to give this functionality. The downside is long term someone has to maintain it. I strongly prefer having python devs spending their time looking after the 3905 open issues of which 1729 have patches, see http://comments.gmane.org/gmane.comp.python.devel/138310 -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From rustompmody at gmail.com Wed Apr 3 12:10:26 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 3 Apr 2013 09:10:26 -0700 (PDT) Subject: Performance of int/long in Python 3 References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Apr 3, 6:43?pm, Roy Smith wrote: > This has to inspect the entire string, no? ?I posted (essentially) this > a few days ago: > > ? ? ? ?if all(ord(c) <= 0xffff for c in s): > ? ? ? ? ? ? return "it's all bmp" > ? ? ? ? else: > ? ? ? ? ? ? return "it's got astral crap in it" Astral crap? CRAP? Verily sir I am offended! You dont play with Mahjong characters? How crude! You dont know about cuneiform? How illiterate! You dont compose poetry with Egyptian hieroglyphs? How rude! Shavian has not reformed you? How backward! In short you are a complete philistine No? On second thoughts I take that back. For all we know philistine may be one of the blessings of the Unicode gods? So following the ilustrious example of jmf, I shall pronounce upon you the ultimate curse: You are American! From ethan at stoneleaf.us Wed Apr 3 13:09:13 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 03 Apr 2013 10:09:13 -0700 Subject: Performance of int/long in Python 3 In-Reply-To: References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: <515C6239.6090406@stoneleaf.us> On 04/03/2013 09:10 AM, rusi wrote: > On Apr 3, 6:43 pm, Roy Smith wrote: >> This has to inspect the entire string, no? I posted (essentially) this >> a few days ago: >> >> if all(ord(c) <= 0xffff for c in s): >> return "it's all bmp" >> else: >> return "it's got astral crap in it" > > Astral crap? CRAP? > Verily sir I am offended! > > You dont play with Mahjong characters? How crude! > You dont know about cuneiform? How illiterate! > You dont compose poetry with Egyptian hieroglyphs? How rude! > Shavian has not reformed you? How backward! > > In short you are a complete philistine > No? On second thoughts I take that back. For all we know philistine > may be one of the blessings of the Unicode gods? > So following the ilustrious example of jmf, I shall pronounce upon you > the ultimate curse: > > You are American! LOL! From roy at panix.com Wed Apr 3 20:46:18 2013 From: roy at panix.com (Roy Smith) Date: Wed, 03 Apr 2013 20:46:18 -0400 Subject: Performance of int/long in Python 3 References: <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , rusi wrote: > On Apr 3, 6:43?pm, Roy Smith wrote: > > This has to inspect the entire string, no? ?I posted (essentially) this > > a few days ago: > > > > ? ? ? ?if all(ord(c) <= 0xffff for c in s): > > ? ? ? ? ? ? return "it's all bmp" > > ? ? ? ? else: > > ? ? ? ? ? ? return "it's got astral crap in it" > > Astral crap? CRAP? > Verily sir I am offended! > [...] > You are American! This is true. But, to be fair, in the (I don't have the exact number here) roughly 200 million records in our recent big data import job, I found exactly FOUR strings with astral characters. Which boiled down to two versions of each of two different song titles. One had a Unicode Character 'BALLOON' (U+1F388). The other had some heart symbol (sorry, I don't remember the exact code point). These hardly seem a matter of national pride. And, if you don't believe there is astral crap, how do you explain U+1F4A9? From ian.g.kelly at gmail.com Wed Apr 3 12:53:43 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 3 Apr 2013 10:53:43 -0600 Subject: Performance of int/long in Python 3 In-Reply-To: <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> References: <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> <87dff083-14d8-4163-89f3-d78a9be6c802@c15g2000vbl.googlegroups.com> <3qadncD4-6fcPsbMnZ2dnUVZ_rqdnZ2d@westnet.com.au> <515bbedb$0$29891$c3e8da3$5496439d@news.astraweb.com> <515be00e$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 3, 2013 at 1:53 AM, Steven D'Aprano wrote: > (sys.getsizeof(s) - sys.getsizeof(''))/len(s) >>> s = '\x80\x81\x82\x83\x84\x85' >>> len(s) 6 >>> import sys >>> sys.getsizeof(s) 43 >>> sys.getsizeof(s) - sys.getsizeof('') 18 >>> (sys.getsizeof(s) - sys.getsizeof('')) / len(s) 3.0 I didn't know there was a 3-byte-width representation. :-) More seriously, it fails because '' is ASCII and s is not, and the overhead for the two strings is different. From nhodgson at iinet.net.au Tue Apr 2 05:28:11 2013 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Tue, 02 Apr 2013 20:28:11 +1100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> Message-ID: jmfauth: > 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] > [0.8343414906182101, 0.8336184057396241, 0.8330473419738562] > 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit > [1.3840254166697845, 1.3933888932429768, 1.391664674507438] That's a larger performance decrease than the 64-bit version. Reported the issue as http://bugs.python.org/issue17615 Neil From breamoreboy at yahoo.co.uk Wed Apr 3 09:56:07 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 03 Apr 2013 14:56:07 +0100 Subject: Performance of int/long in Python 3 In-Reply-To: References: <11ef1d36-0783-4cb2-b29f-9ae573ed7e47@googlegroups.com> <6a146aba-a032-4aac-b2d3-7acedcebd804@q3g2000pbv.googlegroups.com> <515941d8$0$29967$c3e8da3$5496439d@news.astraweb.com> <5159beb6$0$29967$c3e8da3$5496439d@news.astraweb.com> <4103dc28-a0dc-4740-bb38-b6bcb58bedfb@h1g2000vbx.googlegroups.com> Message-ID: On 02/04/2013 10:28, Neil Hodgson wrote: > jmfauth: > >> 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] >> [0.8343414906182101, 0.8336184057396241, 0.8330473419738562] >> 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit >> [1.3840254166697845, 1.3933888932429768, 1.391664674507438] > > That's a larger performance decrease than the 64-bit version. > > Reported the issue as > http://bugs.python.org/issue17615 > > Neil FTR this has been closed as fixed see http://bugs.python.org/issue17615#msg185862 -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From roy at panix.com Mon Apr 1 16:31:59 2013 From: roy at panix.com (Roy Smith) Date: 1 Apr 2013 16:31:59 -0400 Subject: Performance of int/long in Python 3 References: <5153f5ce$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <5159beb6$0$29967$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: >> The import job isn't done yet, but so far we've processed 116 million >> records and had to clean up four of them. I can live with that. >> Sometimes practicality trumps correctness. > >Well, true. It has to be said that few programming languages (and >databases) make it easy to do the right thing. On the other hand, you're >a programmer. Your job is to write correct code, not easy code. This is really getting off topic, but fundamentally, I'm an engineer. My job is to build stuff that make money for my company. That means making judgement calls about what's not worth fixing, because the cost to fix it exceeds the value. From breamoreboy at yahoo.co.uk Mon Apr 1 15:33:58 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 01 Apr 2013 20:33:58 +0100 Subject: Curl and python httplib? In-Reply-To: References: Message-ID: On 30/03/2013 05:08, ???PHP wrote: > Guys, > > I take a project that need send request to Hadoop by curl. > But now, the curl and pycurl can't satisfy my project. So i need use the > powerful httplib. > But failed. > > *my curl request:* > curl -i -X PUT "http://localhost:50070/webhdfs/v1/levi/7?op=CREATE" > > *my return:* > HTTP/1.1 307 TEMPORARY_REDIRECT > Content-Type: application/octet-stream > Location: > http://58.53.211.47:50075/webhdfs/v1/levi/7?op=CREATE&overwrite=false > Content-Length: 0 > Server: Jetty(6.1.26) > > *Now, i change the curl request to httplib:* > import httplib > import urllib > > params=urllib.urlencode({"@op":"CREATE","@user.name":"levi"}) > headers={"Content-type": "application/x-www-form-urlencoded","Accept": > "text/plain"} > conn=httplib.HTTPConnection("localhost:50070") > conn.request("PUT","/webhdfs/v1/levi/7.txt",params,headers) > response=conn.getresponse() > print response.status, response.reason > data=response.read() > print data > conn.close() > > *But it failed:* > #print response.status, response.reason > 500 Internal Server Error > #print data > '{"RemoteException":{"exception":"WebApplicationException","javaClassName":"javax.ws.rs.WebApplicationException","message":null}}' > > Who knows why? It's OK when i use curl, so where is the problem in > httplib method? > Or some other reasons? > Who can help me change the curl request to httplib edition? > > TIA > Levi > > Try the requests module https://pypi.python.org/pypi/requests/ as if I can successfuly use it anybody can :) -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From vasudevram at gmail.com Mon Apr 1 18:07:40 2013 From: vasudevram at gmail.com (vasudevram) Date: Mon, 1 Apr 2013 15:07:40 -0700 (PDT) Subject: Curl and python httplib? In-Reply-To: References: Message-ID: <8b190a41-9870-4eda-bce6-9e0e821e4331@googlegroups.com> On Tuesday, April 2, 2013 1:03:58 AM UTC+5:30, Mark Lawrence wrote: > On 30/03/2013 05:08, ???PHP wrote: > > > Guys, > > > > > > I take a project that need send request to Hadoop by curl. > > > But now, the curl and pycurl can't satisfy my project. So i need use the > > > powerful httplib. > > > But failed. > > > > > > *my curl request:* > > > curl -i -X PUT "http://localhost:50070/webhdfs/v1/levi/7?op=CREATE" > > > > > > *my return:* > > > HTTP/1.1 307 TEMPORARY_REDIRECT > > > Content-Type: application/octet-stream > > > Location: > > > http://58.53.211.47:50075/webhdfs/v1/levi/7?op=CREATE&overwrite=false > > > Content-Length: 0 > > > Server: Jetty(6.1.26) > > > > > > *Now, i change the curl request to httplib:* > > > import httplib > > > import urllib > > > > > > params=urllib.urlencode({"@op":"CREATE","@user.name":"levi"}) > > > headers={"Content-type": "application/x-www-form-urlencoded","Accept": > > > "text/plain"} > > > conn=httplib.HTTPConnection("localhost:50070") > > > conn.request("PUT","/webhdfs/v1/levi/7.txt",params,headers) > > > response=conn.getresponse() > > > print response.status, response.reason > > > data=response.read() > > > print data > > > conn.close() > > > > > > *But it failed:* > > > #print response.status, response.reason > > > 500 Internal Server Error > > > #print data > > > '{"RemoteException":{"exception":"WebApplicationException","javaClassName":"javax.ws.rs.WebApplicationException","message":null}}' > > > > > > Who knows why? It's OK when i use curl, so where is the problem in > > > httplib method? > > > Or some other reasons? > > > Who can help me change the curl request to httplib edition? > > > > > > TIA > > > Levi > > > > > > > > > > Try the requests module https://pypi.python.org/pypi/requests/ as if I > > can successfuly use it anybody can :) > > > > -- > > If you're using GoogleCrap? please read this > > http://wiki.python.org/moin/GoogleGroupsPython. > > > > Mark Lawrence Or try httplib2 GIYF From vasudevram at gmail.com Mon Apr 1 18:07:40 2013 From: vasudevram at gmail.com (vasudevram) Date: Mon, 1 Apr 2013 15:07:40 -0700 (PDT) Subject: Curl and python httplib? In-Reply-To: References: Message-ID: <8b190a41-9870-4eda-bce6-9e0e821e4331@googlegroups.com> On Tuesday, April 2, 2013 1:03:58 AM UTC+5:30, Mark Lawrence wrote: > On 30/03/2013 05:08, ???PHP wrote: > > > Guys, > > > > > > I take a project that need send request to Hadoop by curl. > > > But now, the curl and pycurl can't satisfy my project. So i need use the > > > powerful httplib. > > > But failed. > > > > > > *my curl request:* > > > curl -i -X PUT "http://localhost:50070/webhdfs/v1/levi/7?op=CREATE" > > > > > > *my return:* > > > HTTP/1.1 307 TEMPORARY_REDIRECT > > > Content-Type: application/octet-stream > > > Location: > > > http://58.53.211.47:50075/webhdfs/v1/levi/7?op=CREATE&overwrite=false > > > Content-Length: 0 > > > Server: Jetty(6.1.26) > > > > > > *Now, i change the curl request to httplib:* > > > import httplib > > > import urllib > > > > > > params=urllib.urlencode({"@op":"CREATE","@user.name":"levi"}) > > > headers={"Content-type": "application/x-www-form-urlencoded","Accept": > > > "text/plain"} > > > conn=httplib.HTTPConnection("localhost:50070") > > > conn.request("PUT","/webhdfs/v1/levi/7.txt",params,headers) > > > response=conn.getresponse() > > > print response.status, response.reason > > > data=response.read() > > > print data > > > conn.close() > > > > > > *But it failed:* > > > #print response.status, response.reason > > > 500 Internal Server Error > > > #print data > > > '{"RemoteException":{"exception":"WebApplicationException","javaClassName":"javax.ws.rs.WebApplicationException","message":null}}' > > > > > > Who knows why? It's OK when i use curl, so where is the problem in > > > httplib method? > > > Or some other reasons? > > > Who can help me change the curl request to httplib edition? > > > > > > TIA > > > Levi > > > > > > > > > > Try the requests module https://pypi.python.org/pypi/requests/ as if I > > can successfuly use it anybody can :) > > > > -- > > If you're using GoogleCrap? please read this > > http://wiki.python.org/moin/GoogleGroupsPython. > > > > Mark Lawrence Or try httplib2 GIYF From timr at probo.com Tue Apr 2 00:45:30 2013 From: timr at probo.com (Tim Roberts) Date: Mon, 01 Apr 2013 21:45:30 -0700 Subject: Why does 1**2**3**4**5 raise a MemoryError? References: <8e43bc87-e822-4bb3-b9ef-ccd489da8bf3@googlegroups.com> <5157e6cc$0$29974$c3e8da3$5496439d@news.astraweb.com> <8276eff6-9e5c-4060-b9e8-94fab606206f@googlegroups.com> Message-ID: morphex wrote: > >While we're on the subject, wouldn't it be nice to have some cap there so >that it isn't possible to more or less block the system with large >exponentiation? There IS a cap. It's called the "MemoryError" exception. But, seriously, what would you have it do instead? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rosuav at gmail.com Tue Apr 2 02:16:28 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Apr 2013 17:16:28 +1100 Subject: Why does 1**2**3**4**5 raise a MemoryError? In-Reply-To: References: <8e43bc87-e822-4bb3-b9ef-ccd489da8bf3@googlegroups.com> <5157e6cc$0$29974$c3e8da3$5496439d@news.astraweb.com> <8276eff6-9e5c-4060-b9e8-94fab606206f@googlegroups.com> Message-ID: On Tue, Apr 2, 2013 at 3:45 PM, Tim Roberts wrote: > morphex wrote: >> >>While we're on the subject, wouldn't it be nice to have some cap there so >>that it isn't possible to more or less block the system with large >>exponentiation? > > There IS a cap. It's called the "MemoryError" exception. > > But, seriously, what would you have it do instead? And If you want a lower cap than the one you currently have, check out ulimit/rlimit - you can trigger MemoryError sooner. ChrisA From dan at tombstonezero.net Tue Apr 2 08:56:21 2013 From: dan at tombstonezero.net (Dan Sommers) Date: Tue, 02 Apr 2013 12:56:21 GMT Subject: Why does 1**2**3**4**5 raise a MemoryError? References: <8e43bc87-e822-4bb3-b9ef-ccd489da8bf3@googlegroups.com> <5157e6cc$0$29974$c3e8da3$5496439d@news.astraweb.com> <8276eff6-9e5c-4060-b9e8-94fab606206f@googlegroups.com> Message-ID: On Mon, 01 Apr 2013 21:45:30 -0700, Tim Roberts wrote: > morphex wrote: >> >>While we're on the subject, wouldn't it be nice to have some cap there >>so that it isn't possible to more or less block the system with large >>exponentiation? > > There IS a cap. It's called the "MemoryError" exception. > > But, seriously, what would you have it do instead? One day late: http://developers.slashdot.org/story/13/04/01/2230220/erlang-getting-too- big-to-fail-process-flag From steve+comp.lang.python at pearwood.info Mon Apr 1 00:16:43 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Apr 2013 04:16:43 GMT Subject: Why does 1**2**3**4**5 raise a MemoryError? References: <8e43bc87-e822-4bb3-b9ef-ccd489da8bf3@googlegroups.com> Message-ID: <51590a2b$0$30000$c3e8da3$5496439d@news.astraweb.com> On Mon, 01 Apr 2013 00:39:56 +0000, Alex wrote: > Chris Angelico wrote: > > >> Opening paragraph, "... exponentiation, which groups from right to >> left". It follows the obvious expectation from mathematics. (The OP is >> using Python 2, but the same applies.) > > Thanks. I did miss that parenthetical comment in para 6.15, and that > would have been the correct place to look, since it appears that > operators are not parts of expressions, but rather separate them. Is > that the "obvious expectation from mathematics," though? Given that > > 3 > 5 > 4 > > (i.e.: 4**5**3) is transitive, I would have expected Python to exhibit > more consistency with the other operators. I guess that is one of the > foolish consistencies that comprise the hobgoblins of my little mind, > though. I don't think you mean "transitive" here. Transitivity refers to relations, not arbitrary operators. If ? is some relation, then it is transitive if and only if: x ? y and y ? z implies that x ? y. http://en.wikipedia.org/wiki/Transitive_relation Concrete examples of transitive relations: greater than, equal to, less than and equal to. On the other hand, "unequal to" is not a transitive relation. Nor is "approximately equal to". Suppose we say that two values are approximately equal if their difference is less than 0.5: 2.1 ? 2.4 and 2.4 ? 2.7 but 2.1 ? 2.7 Exponentiation is not commutative: 2**3 != 3**2 nor is it associative: 2**(3**2) != (2**3)**2 so I'm not really sure what you are trying to say here. -- Steven From roy at panix.com Mon Apr 1 07:48:21 2013 From: roy at panix.com (Roy Smith) Date: Mon, 01 Apr 2013 07:48:21 -0400 Subject: Why does 1**2**3**4**5 raise a MemoryError? References: <8e43bc87-e822-4bb3-b9ef-ccd489da8bf3@googlegroups.com> <51590a2b$0$30000$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <51590a2b$0$30000$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > Concrete examples of transitive relations: greater than, equal to, less > than and equal to. Will Python 4 implement "less than and equal to"? :-) [Warning: topic creep] Well, they are transitive over certain domains. Or, perhaps, a better way to say it is they are transitive according to their traditional mathematical definitions. But, computer languages don't always follow those. I used to work with a guy who was originally a math major. He used to always complain about things like: s = "foo" + "bar" because addition is supposed to be commutative. But, yeah, I know what you're saying that "transitive" applies to relations, not to operators. Although, of course, in some languages, relations *are* operators. There's that pesky math vs. programming language dichotomy again. From nobody at nowhere.com Tue Apr 2 03:40:21 2013 From: nobody at nowhere.com (Nobody) Date: Tue, 02 Apr 2013 08:40:21 +0100 Subject: Why does 1**2**3**4**5 raise a MemoryError? References: <8e43bc87-e822-4bb3-b9ef-ccd489da8bf3@googlegroups.com> Message-ID: On Mon, 01 Apr 2013 00:39:56 +0000, Alex wrote: > Given that > > 3 > 5 > 4 > > (i.e.: 4**5**3) is transitive, I think you meant "associative", and exponentiation isn't associative, i.e. (x**y)**z is not, in general, equal to x**(y**z). In fact, (x**y)**z is equal to x**(y*z). Conventional mathematical notation interprets the above example as 4**(5**3). (4**5)**3 would be written with 4**5 parenthesised. Python follows that convention, as do most languages which have an infix exponentiation operator. From neilc at norwich.edu Mon Apr 1 07:41:03 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 1 Apr 2013 11:41:03 GMT Subject: Creating a dictionary from a .txt file References: Message-ID: On 2013-03-31, Roy Smith wrote: > And, this is a good excuse to explore some of the interesting > third-party modules. For example, mwclient ("pip install > mwclient") gives you a neat Python interface to wikipedia. And > there's a whole landscape of string matching packages to > explore. > > We deal with this every day at Songza. Are Kesha and Ke$ha the > same artist? Pushing back on the record labels to clean up > their catalogs isn't going to get us very far. I tried searching for Frost*, an interesting artist I recently learned about. His name, in combination with a similarly named rap artist, breaks most search tools. My guess is this homework is simply borken. -- Neil Cerutti From steve+comp.lang.python at pearwood.info Mon Apr 1 19:53:40 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Apr 2013 23:53:40 GMT Subject: Creating a dictionary from a .txt file References: Message-ID: <515a1e03$0$29967$c3e8da3$5496439d@news.astraweb.com> On Mon, 01 Apr 2013 11:41:03 +0000, Neil Cerutti wrote: > I tried searching for Frost*, an interesting artist I recently learned > about. "Interesting artist" -- is that another term for "wanker"? *wink* > His name, in combination with a similarly named rap artist, > breaks most search tools. As far as I'm concerned, anyone in the 21st century who names themselves or their work (a movie, book, programming language, etc.) something which breaks search tools is just *begging* for obscurity, and we ought to respect their wishes. -- Steven From walterhurry at lavabit.com Mon Apr 1 20:28:23 2013 From: walterhurry at lavabit.com (Walter Hurry) Date: Tue, 2 Apr 2013 00:28:23 +0000 (UTC) Subject: Creating a dictionary from a .txt file References: <515a1e03$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, 01 Apr 2013 23:53:40 +0000, Steven D'Aprano wrote: > As far as I'm concerned, anyone in the 21st century who names themselves > or their work (a movie, book, programming language, etc.) something > which breaks search tools is just *begging* for obscurity, and we ought > to respect their wishes. IIRC, there was an eccentric musician some years back who did just that. I seem to remember that he changed his name to some kind of androgynous looking rune with what appeared to be a bent trumpet across it. Thenceforth it became known as "the (piss) artist: formally gnome ass prints", or at least something sounding vaguely like that. From neilc at norwich.edu Wed Apr 3 08:55:55 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 3 Apr 2013 12:55:55 GMT Subject: Creating a dictionary from a .txt file References: <515a1e03$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-04-01, Steven D'Aprano wrote: > On Mon, 01 Apr 2013 11:41:03 +0000, Neil Cerutti wrote: > > >> I tried searching for Frost*, an interesting artist I recently learned >> about. > > "Interesting artist" -- is that another term for "wanker"? > > *wink* hee-hee. It depends on how much of a hankering you have for pretentious progressive synth-rock. >> His name, in combination with a similarly named rap artist, >> breaks most search tools. > > As far as I'm concerned, anyone in the 21st century who names > themselves or their work (a movie, book, programming language, > etc.) something which breaks search tools is just *begging* for > obscurity, and we ought to respect their wishes. I do think it's something he did on purpose. The asterisk, I believe, symbolizes the exclusive genius of his fans. -- Neil Cerutti From swilks06 at gmail.com Mon Apr 1 19:53:53 2013 From: swilks06 at gmail.com (C.T.) Date: Mon, 1 Apr 2013 16:53:53 -0700 (PDT) Subject: Creating a dictionary from a .txt file In-Reply-To: References: Message-ID: Thanks for all the help everyone! After I manually edited the txt file, this is what I came up with: car_dict = {} car_file = open('cars.txt', 'r') for line in car_file: temp = line.strip().split(None, 2) temp2 = line.strip().split('\t') if len(temp)==3: year, manufacturer, model = temp[0] ,temp2[0][5:], temp2[1] value = (year, model) if manufacturer in car_dict: car_dict.setdefault(manufacturer,[]).append(value) else: car_dict[manufacturer] = [value] elif len(temp)==2: year, manufacturer, model = temp[0], 'Unknown' , temp2[1] value = (year, model) if manufacturer in car_dict: car_dict.setdefault(manufacturer,[]).append(value) else: car_dict[manufacturer] = [value] car_file.close() print (car_dict) It may not be the most pythonic way of doing this, but it works for me. I am learning python, and this problem was problem the most challenging so far. Thank you all, again! From davea at davea.name Mon Apr 1 20:12:31 2013 From: davea at davea.name (Dave Angel) Date: Mon, 01 Apr 2013 20:12:31 -0400 Subject: Creating a dictionary from a .txt file In-Reply-To: References: Message-ID: <515A226F.2060709@davea.name> On 04/01/2013 07:53 PM, C.T. wrote: > Thanks for all the help everyone! After I manually edited the txt file, this is what I came up with: > > car_dict = {} > car_file = open('cars.txt', 'r') > > > > for line in car_file: > temp = line.strip().split(None, 2) > temp2 = line.strip().split('\t') > > > if len(temp)==3: > year, manufacturer, model = temp[0] ,temp2[0][5:], temp2[1] > value = (year, model) > if manufacturer in car_dict: > car_dict.setdefault(manufacturer,[]).append(value) That's rather redundant. Once you've determined that the particular key is already there, why bother with the setdefault() call? Or to put it another way, why bother to test if it's there when you're going to use setdefault to handle the case where it's not? > else: > car_dict[manufacturer] = [value] > > > elif len(temp)==2: > year, manufacturer, model = temp[0], 'Unknown' , temp2[1] > value = (year, model) > if manufacturer in car_dict: > car_dict.setdefault(manufacturer,[]).append(value) > else: > car_dict[manufacturer] = [value] > > > car_file.close() > > print (car_dict) > > It may not be the most pythonic way of doing this, but it works for me. I am learning python, and this problem was problem the most challenging so far. Thank you all, again! > -- DaveA From alister.ware at ntlworld.com Mon Apr 1 13:54:46 2013 From: alister.ware at ntlworld.com (Alister) Date: Mon, 01 Apr 2013 17:54:46 GMT Subject: Help with python code! References: <37f23623-8bf5-421a-ab6a-34ff622c69f1@googlegroups.com> <2912c674-e30b-4339-9344-1f460cb96b23@googlegroups.com> <4455829d-5b4a-44ee-b65f-5f72d429ba9c@googlegroups.com> <40463d1c-013e-46c2-823a-787c1cca450f@googlegroups.com> Message-ID: On Sun, 31 Mar 2013 14:32:21 -0700, gerrymcgovern wrote: > On Sunday, March 31, 2013 5:27:06 PM UTC-4, Roy Smith wrote: >> In article <4455829d-5b4a-44ee-b65f-5f72d429ba9c at googlegroups.com>, >> >> jojo wrote: >> >> >> >> > Thanks for your replies. Just to be clear this is for a interview and >> > they >> >> > would like me to figure out what the code does and come back with >> > some test >> >> > cases. I don't need to code the tests, just give some high level >> > tests. As >> >> > far as I can make out it is some system where you input your name and >> > it will >> >> > bring back your details plus how much time you have left on your >> > card. Have >> >> > to say I find the code extremely confusing, hopefully all python >> > isn't like >> >> > this!! >> >> >> >> If this is for an interview, you really should be doing this on your >> >> own. I assume the point of the interview is to see how well you know >> >> Python. Please don't expect people here to take your interview for >> you. > > Where did I ask people to take the interview for me? I asked for some > tips on interpreting the code something which you have been unable to > give me. If a senior dev (I am assuming you are a python dev) is unable > to figure out what the code does, then I think me, been a newbie to new > language (with horrible syntax) is entitled to ask for help. I think Roy's point here is if you don't know python (as you admit) why are you applying for a job as a Python Developer. the code provided appears to be pretty poor quality to me & probably buggy as well but without the specification I can't be sure. -- I like work; it fascinates me; I can sit and look at it for hours. From jsf80238 at gmail.com Tue Apr 2 23:59:20 2013 From: jsf80238 at gmail.com (Jason Friedman) Date: Tue, 2 Apr 2013 21:59:20 -0600 Subject: Help with python code! In-Reply-To: <4455829d-5b4a-44ee-b65f-5f72d429ba9c@googlegroups.com> References: <37f23623-8bf5-421a-ab6a-34ff622c69f1@googlegroups.com> <2912c674-e30b-4339-9344-1f460cb96b23@googlegroups.com> <4455829d-5b4a-44ee-b65f-5f72d429ba9c@googlegroups.com> Message-ID: > Thanks for your replies. Just to be clear this is for a interview and they > would like me to figure out what the code does and come back with some test > cases. I don't need to code the tests, just give some high level tests. As > far as I can make out it is some system where you input your name and it > will bring back your details plus how much time you have left on your card. > Have to say I find the code extremely confusing, hopefully all python isn't > like this!! > This question causes me to recall this story. I was interviewing college student candidates for a Summer internship. The interview consisted of a 30-minute phone conversation followed by a 60-minute programming exercise (performed offsite). One candidate listed only VB and HTML as programming languages, but the candidate was local and thought I'd give the person a chance and some interviewing practice. Only two of nine candidates "aced" the programming exercise, and this candidate was one of them! The candidates could choose whatever programming language they liked, this candidate chose C#. I wrote back to acknowledge receiving the answers and asked why C# was not listed on the resume. The candidate replied that three friends helped compose the answer! I should have asked whether the candidate would, if offered the position, be able to bring those three friends to work every day. -------------- next part -------------- An HTML attachment was scrubbed... URL: From redstone-cold at 163.com Mon Apr 1 00:45:21 2013 From: redstone-cold at 163.com (iMath) Date: Sun, 31 Mar 2013 21:45:21 -0700 (PDT) Subject: executor.map() TypeError: zip argument #2 must support iteration Message-ID: <29b241a1-44ce-45a0-81b6-429245931c05@googlegroups.com> executor.map() TypeError: zip argument #2 must support iteration when I run it ,just generated TypeError: zip argument #2 must support iteration. can anyone help me fix this problem ? import time, concurrent.futures lst100=[i for i in range(100)] t1=time.clock() print(list(map(str,lst100))) t2=time.clock() print(t2-t1) t3=time.clock() with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor: future_to_url = executor.map(str,lst100, 60) print(list(future_to_url)) t4=time.clock() print(t4-t3) From steve+comp.lang.python at pearwood.info Mon Apr 1 03:48:34 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Apr 2013 07:48:34 GMT Subject: executor.map() TypeError: zip argument #2 must support iteration References: <29b241a1-44ce-45a0-81b6-429245931c05@googlegroups.com> Message-ID: <51593bd2$0$29967$c3e8da3$5496439d@news.astraweb.com> On Sun, 31 Mar 2013 21:45:21 -0700, iMath wrote: > executor.map() TypeError: zip argument #2 must support iteration > > when I run it ,just generated TypeError: zip argument #2 must support > iteration. can anyone help me fix this problem ? Yes. Read the error message, and inspect the line that is in error. You have: > future_to_url = executor.map(str,lst100, 60) executor.map has three arguments: Arg 0: str Arg 1: list of 100 ints Arg 2: int 60 Argument 2, the number 60, does not support iteration, since it is an int. Now read the docs for map. At the interactive interpreter, do this: py> from concurrent.futures import ThreadPoolExecutor py> help(ThreadPoolExecutor.map) and you will see the following documentation: map(self, fn, *iterables, timeout=None) Returns a iterator equivalent to map(fn, iter). Args: fn: A callable that will take take as many arguments as there are passed iterables. timeout: The maximum number of seconds to wait. If None, then there is no limit on the wait time. Notice that the iterables argument is prefixed with * symbol. That means that it collects all the remaining positional arguments, which means that the timeout argument is keyword only. So try this: future_to_url = executor.map(str, lst100, timeout=60) -- Steven From redstone-cold at 163.com Tue Apr 2 22:34:25 2013 From: redstone-cold at 163.com (iMath) Date: Tue, 2 Apr 2013 19:34:25 -0700 (PDT) Subject: executor.map() TypeError: zip argument #2 must support iteration In-Reply-To: <51593bd2$0$29967$c3e8da3$5496439d@news.astraweb.com> References: <29b241a1-44ce-45a0-81b6-429245931c05@googlegroups.com> <51593bd2$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: ? 2013?4?1????UTC+8??3?48?34??Steven D'Aprano??? > On Sun, 31 Mar 2013 21:45:21 -0700, iMath wrote: > > > > > executor.map() TypeError: zip argument #2 must support iteration > > > > > > when I run it ,just generated TypeError: zip argument #2 must support > > > iteration. can anyone help me fix this problem ? > > > > Yes. Read the error message, and inspect the line that is in error. You > > have: > > > > > future_to_url = executor.map(str,lst100, 60) > > > > executor.map has three arguments: > > > > Arg 0: str > > Arg 1: list of 100 ints > > Arg 2: int 60 > > > > Argument 2, the number 60, does not support iteration, since it is an int. > > > > Now read the docs for map. At the interactive interpreter, do this: > > > > py> from concurrent.futures import ThreadPoolExecutor > > py> help(ThreadPoolExecutor.map) > > > > > > and you will see the following documentation: > > > > map(self, fn, *iterables, timeout=None) > > Returns a iterator equivalent to map(fn, iter). > > > > Args: > > fn: A callable that will take take as many arguments as there are > > passed iterables. > > timeout: The maximum number of seconds to wait. If None, then > > there is no limit on the wait time. > > > > > > Notice that the iterables argument is prefixed with * symbol. That means > > that it collects all the remaining positional arguments, which means that > > the timeout argument is keyword only. > > > > So try this: > > > > > > future_to_url = executor.map(str, lst100, timeout=60) > > > > > > -- > > Steven thanks for clarification.I thought argument 2 is lst100 From khaosyt at gmail.com Mon Apr 1 01:15:54 2013 From: khaosyt at gmail.com (khaosyt at gmail.com) Date: Sun, 31 Mar 2013 22:15:54 -0700 (PDT) Subject: Help please Message-ID: <61cf6de1-179e-4d3d-8083-a2f34b144cd1@googlegroups.com> I want to add up the integers of this code in one line. For example, if I had the code integer = 0 denom = 10 again = "y" #sentinel: while again == "y" or again == "Y": integer = input("Enter a positive integer: ") while denom <= integer: denom = denom*10 while denom > 1: denom = denom/10 number = integer/denom integer = integer%denom print str(number) again = raw_input("Again? (Y/N): ") and inputted "54321," it would look like: Enter a positive integer: 54321 5 4 3 2 1 Again? (Y/N): n What I want to do is add up the "54321" so it comes out with "Sum of digits is 15." on one line. Thanks! From rosuav at gmail.com Mon Apr 1 01:24:52 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Apr 2013 16:24:52 +1100 Subject: Help please In-Reply-To: <61cf6de1-179e-4d3d-8083-a2f34b144cd1@googlegroups.com> References: <61cf6de1-179e-4d3d-8083-a2f34b144cd1@googlegroups.com> Message-ID: On Mon, Apr 1, 2013 at 4:15 PM, wrote: > integer = input("Enter a positive integer: ") > again = raw_input("Again? (Y/N): ") Okay, the first thing I'm going to say is: Don't use input() in Python 2. It's dangerous in ways you won't realize. Use int(raw_input(...)) for something like this, which will guarantee you an integer. I'm guessing this is homework. Please be honest about that; we'll help you learn but won't just give you the answers. All you need to do is initialize something to zero, and then keep adding 'number' onto it in the loop. You should be able to sort that out. ChrisA From khaosyt at gmail.com Mon Apr 1 01:41:32 2013 From: khaosyt at gmail.com (khaosyt at gmail.com) Date: Sun, 31 Mar 2013 22:41:32 -0700 (PDT) Subject: Help please In-Reply-To: References: <61cf6de1-179e-4d3d-8083-a2f34b144cd1@googlegroups.com> Message-ID: On Monday, April 1, 2013 1:24:52 AM UTC-4, Chris Angelico wrote: > On Mon, Apr 1, 2013 at 4:15 PM, wrote: > > > integer = input("Enter a positive integer: ") > > > again = raw_input("Again? (Y/N): ") > > > > Okay, the first thing I'm going to say is: Don't use input() in Python > > 2. It's dangerous in ways you won't realize. Use int(raw_input(...)) > > for something like this, which will guarantee you an integer. > > > > I'm guessing this is homework. Please be honest about that; we'll help > > you learn but won't just give you the answers. > > > > All you need to do is initialize something to zero, and then keep > > adding 'number' onto it in the loop. You should be able to sort that > > out. > > > > ChrisA Elaborate, please. From khaosyt at gmail.com Mon Apr 1 01:41:32 2013 From: khaosyt at gmail.com (khaosyt at gmail.com) Date: Sun, 31 Mar 2013 22:41:32 -0700 (PDT) Subject: Help please In-Reply-To: References: <61cf6de1-179e-4d3d-8083-a2f34b144cd1@googlegroups.com> Message-ID: On Monday, April 1, 2013 1:24:52 AM UTC-4, Chris Angelico wrote: > On Mon, Apr 1, 2013 at 4:15 PM, wrote: > > > integer = input("Enter a positive integer: ") > > > again = raw_input("Again? (Y/N): ") > > > > Okay, the first thing I'm going to say is: Don't use input() in Python > > 2. It's dangerous in ways you won't realize. Use int(raw_input(...)) > > for something like this, which will guarantee you an integer. > > > > I'm guessing this is homework. Please be honest about that; we'll help > > you learn but won't just give you the answers. > > > > All you need to do is initialize something to zero, and then keep > > adding 'number' onto it in the loop. You should be able to sort that > > out. > > > > ChrisA Elaborate, please. From steve+comp.lang.python at pearwood.info Mon Apr 1 20:09:43 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Apr 2013 00:09:43 GMT Subject: Help please References: <61cf6de1-179e-4d3d-8083-a2f34b144cd1@googlegroups.com> Message-ID: <515a21c6$0$29967$c3e8da3$5496439d@news.astraweb.com> On Sun, 31 Mar 2013 22:41:32 -0700, khaosyt wrote: > On Monday, April 1, 2013 1:24:52 AM UTC-4, Chris Angelico wrote: >> On Mon, Apr 1, 2013 at 4:15 PM, wrote: >> >> > integer = input("Enter a positive integer: ") >> >> > again = raw_input("Again? (Y/N): ") >> >> >> >> Okay, the first thing I'm going to say is: Don't use input() in Python >> >> 2. It's dangerous in ways you won't realize. Use int(raw_input(...)) [...] > Elaborate, please. The input() function takes the user's text, and automatically evaluates it as if it were code. In the hands of a non-expert, that can lead to some unexpected errors: py> answer = input("what is your name? ") what is your name? Steve Traceback (most recent call last): File "", line 1, in File "", line 1, in NameError: name 'Steve' is not defined But at least that gives you an error. It can also give you weird and unexpected results. Suppose my name was Lenny, and I did this: py> answer = input("what is your name? ") what is your name? len py> print answer Worse, because input evaluates text as code, it can do anything, including bad things: py> answer = input("what is your name? ") what is your name? 200**300**300 Traceback (most recent call last): File "", line 1, in File "", line 1, in MemoryError (while the above code was running, my computer got slower and slower and slower, and potentially it could have locked up completely). So the general advice is, treat the input() function as For Experts Only, and always use raw_input() instead. -- Steven From arwh at yahoo.com Mon Apr 1 04:00:19 2013 From: arwh at yahoo.com (ah) Date: Mon, 1 Apr 2013 01:00:19 -0700 (PDT) Subject: Is there a simple stand alone python app I can use on my Kindle fire? In-Reply-To: <1364779132.91062.YahooMailNeo@web162401.mail.bf1.yahoo.com> References: <1364779132.91062.YahooMailNeo@web162401.mail.bf1.yahoo.com> Message-ID: <1364803219.16247.YahooMailNeo@web162404.mail.bf1.yahoo.com> (it was recommended that I post this query here (originally posted on the tutor page)). Hello, I'm enjoying learning python, and would like to be able to study and practice on the go, using my kindle fire reader. (wifi enabled). Amazon does have an app, Qpython lite, but requires a? live wifi connection to the internet to run. I'm looking for a simple python app, stand alone that i can run on my kindle, without an internet connection,? just to practice while i learn. (Just a simple terminal, and text editor, and python? like ubuntu offers.) I've tried downloading portable python, and couldnt' get it to run ('can't run in DOS mode?'), I've tried downloading ubuntu to my kindle and couldn't, and tried downloading the whole 2.7 python app, but couldn't get it to run. I tried to root my kindle, but as I'm inexperienced in things tech, i'm not sure if I was successful, and not sure how this helps (if I was successful.) I have both windows 7 and ubuntu (dual boot) on my laptop, and can connect my kindle to the laptop via usb cable. I have "accept downloads from other applications" enabled on my kindle. On my kindle I have 'better terminal emulator pro' , ES file explorer, and droidedit. Any help is appreciated, I'm willing to follow step by step instructions to get python running on my kindle. I will supply any other details required. My kindle fire specs are : Model D01400 The Kindle Fire features a 7? display module from LG Display. The display is dual-sourced between LG Display and E Ink Holdings. The display touchscreen appears to be conventional capacitive glass on glass and the control IC on the touchscreen is from a previously unseen source. Meanwhile, the OMAP4430 applications processor from Texas Instruments is a dual-core RM Cortex-A9, 1GHz processor with IVA 3 Hardware Accelerator, SGX540 3D Graphic Core, 1080P 2D, 720P 3D and is produced in 45nm process geometry. Other key features include a 8GB eMMC NAND Flash Memory, 4Gbits of low power DDR2, a 3.7V battery with 4400mAh capacity (or about 16 Wh), and a module from Jorjin, which is based on Texas Instruments? WL1270. -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Tue Apr 2 01:01:26 2013 From: timr at probo.com (Tim Roberts) Date: Mon, 01 Apr 2013 22:01:26 -0700 Subject: Is there a simple stand alone python app I can use on my Kindle fire? References: <1364779132.91062.YahooMailNeo@web162401.mail.bf1.yahoo.com> Message-ID: ah wrote: > >I'm enjoying learning python, and would like to be able to study and practice >on the go, using my kindle fire reader. (wifi enabled). > >Amazon does have an app, Qpython lite, but requires a? live wifi connection >to the internet to run. I'm looking for a simple python app, stand alone >that i can run on my kindle, without an internet connection,? just to >practice while i learn. (Just a simple terminal, and text editor, and >python? like ubuntu offers.) You have identified the ingredients: you need a shell, you need an editor, and you need the Python interpreter. Your Kindle is an Android device, which means it runs Linux, but I don't know whether you have access to the general Android app store. There certainly are Android terminal applications available that will bring up a shell for you. The one you have is probably enough. There is also an implemention of Vim for Android that even supports touch commands. If you've played with Ubuntu, then you probably already know Vim. After that, you'll need Python itself. Your machine has an ARM processor, so you'll want to find a Python built for Linux ARM. I know such things are available, but you may have to do some creative searching. Just like Ubuntu, you cannot run Windows applications. You also cannot run any x86 or amd64 applications. You must have ARM binaries. If you want to go really crazy, you can get a "cross compiler" for your Ubuntu system that lets you build ARM binaries. From there, you could build Python from source. >I've tried downloading portable python, and couldnt' get it to run >('can't run in DOS mode?'), Of course not. Portable Python is a Windows product. Your Kindle doesn't run Windows. >I've tried downloading ubuntu to my kindle and couldn't, Did you download the x86 version? That will not work. There are Ubuntu distributions available for the Kindle Fire, but it's going to require getting your hands dirty. Google is your friend here. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From arwh at yahoo.com Wed Apr 3 06:11:00 2013 From: arwh at yahoo.com (ah) Date: Wed, 3 Apr 2013 03:11:00 -0700 (PDT) Subject: Solution found! Qpython+ will work on kindle fire (without live connection) In-Reply-To: <1364779132.91062.YahooMailNeo@web162401.mail.bf1.yahoo.com> References: <1364779132.91062.YahooMailNeo@web162401.mail.bf1.yahoo.com> Message-ID: <1364983860.67898.YahooMailNeo@web162402.mail.bf1.yahoo.com> + To: "tutor at python.org" Sent: Monday, 1 April 2013 9:18 AM Subject: [Tutor] is there a simple stand alone python app I can use on my Kindle fire? Hello, I'm enjoying learning python, and would like to be able to study and practice on the go, using my kindle fire reader. (wifi enabled). Amazon does have an app, Qpython lite, but requires a? live wifi connection to the internet to run. I'm looking for a simple python app, stand alone that i can run on my kindle, without an internet connection,? just to practice while i learn. (Just a simple terminal, and text editor, and python? like ubuntu offers.) I've tried downloading portable python, and couldnt' get it to run ('can't run in DOS mode?'), I've tried downloading ubuntu to my kindle and couldn't, and tried downloading the whole 2.7 python app, but couldn't get it to run. I tried to root my kindle, but as I'm inexperienced in things tech, i'm not sure if I was successful, and not sure how this helps (if I was successful.) I have both windows 7 and ubuntu (dual boot) on my laptop, and can connect my kindle to the laptop via usb cable. I have "accept downloads from other applications" enabled on my kindle. On my kindle I have 'better terminal emulator pro' , ES file explorer, and droidedit. Any help is appreciated, I'm willing to follow step by step instructions to get python running on my kindle. I will supply any other details required. My kindle fire specs are : Model D01400 The Kindle Fire features a 7? display module from LG Display. The display is dual-sourced between LG Display and E Ink Holdings. The display touchscreen appears to be conventional capacitive glass on glass and the control IC on the touchscreen is from a previously unseen source. Meanwhile, the OMAP4430 applications processor from Texas Instruments is a dual-core RM Cortex-A9, 1GHz processor with IVA 3 Hardware Accelerator, SGX540 3D Graphic Core, 1080P 2D, 720P 3D and is produced in 45nm process geometry. Other key features include a 8GB eMMC NAND Flash Memory, 4Gbits of low power DDR2, a 3.7V battery with 4400mAh capacity (or about 16 Wh), and a module from Jorjin, which is based on Texas Instruments? WL1270. _______________________________________________ Tutor maillist? -? Tutor at python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -------------- next part -------------- An HTML attachment was scrubbed... URL: From anadionisio257 at gmail.com Mon Apr 1 06:14:15 2013 From: anadionisio257 at gmail.com (=?ISO-8859-1?Q?Ana_Dion=EDsio?=) Date: Mon, 1 Apr 2013 03:14:15 -0700 (PDT) Subject: How to do this? Message-ID: <83a54022-576d-465b-b6bd-7e21cde59d99@googlegroups.com> So I have this script: " from numpy import array vt=[0]*20 vt = array(vt, dtype=dict) for t in range(20): if t == 4: vt[t]=1 else: vt[t]=0 " And have this output: [0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] What I need is when t == 4 I need to put 1 in that position and in the next 3, for example the following output: [0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0] Do you have any suggestions? I'm sorry if I can't explain this in a better way, English is not my first language Thank you From vincent.vandevyvre at swing.be Mon Apr 1 06:58:27 2013 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Mon, 01 Apr 2013 12:58:27 +0200 Subject: How to do this? In-Reply-To: <83a54022-576d-465b-b6bd-7e21cde59d99@googlegroups.com> References: <83a54022-576d-465b-b6bd-7e21cde59d99@googlegroups.com> Message-ID: <51596853.5090308@swing.be> Le 01/04/13 12:14, Ana Dion?sio a ?crit : > for t in range(20): > if t == 4: > vt[t]=1 Sets only the needed values: for t in range(4, 8): vt[t]=1 -- Vincent V.V. Oqapy . Qarte . PaQager From anadionisio257 at gmail.com Mon Apr 1 07:08:36 2013 From: anadionisio257 at gmail.com (=?ISO-8859-1?Q?Ana_Dion=EDsio?=) Date: Mon, 1 Apr 2013 04:08:36 -0700 (PDT) Subject: How to do this? In-Reply-To: References: <83a54022-576d-465b-b6bd-7e21cde59d99@googlegroups.com> Message-ID: <29fa109e-8ed0-4b1b-a9c0-473e2bace687@googlegroups.com> Nice! Thank you! And if I need something like this? [0 0 0 0 0.17 0.17 0.17 0.17 0 0 0 0.17 0.17 0.17 0 0 0 0 0 0 0] How can I do this? From anadionisio257 at gmail.com Mon Apr 1 07:08:36 2013 From: anadionisio257 at gmail.com (=?ISO-8859-1?Q?Ana_Dion=EDsio?=) Date: Mon, 1 Apr 2013 04:08:36 -0700 (PDT) Subject: How to do this? In-Reply-To: References: <83a54022-576d-465b-b6bd-7e21cde59d99@googlegroups.com> Message-ID: <29fa109e-8ed0-4b1b-a9c0-473e2bace687@googlegroups.com> Nice! Thank you! And if I need something like this? [0 0 0 0 0.17 0.17 0.17 0.17 0 0 0 0.17 0.17 0.17 0 0 0 0 0 0 0] How can I do this? From __peter__ at web.de Mon Apr 1 07:32:29 2013 From: __peter__ at web.de (Peter Otten) Date: Mon, 01 Apr 2013 13:32:29 +0200 Subject: How to do this? References: <83a54022-576d-465b-b6bd-7e21cde59d99@googlegroups.com> <29fa109e-8ed0-4b1b-a9c0-473e2bace687@googlegroups.com> Message-ID: Ana Dion?sio wrote: > Nice! Thank you! > > And if I need something like this? > > [0 0 0 0 0.17 0.17 0.17 0.17 0 0 0 0.17 0.17 0.17 0 0 0 0 0 0 0] > > How can I do this? With vanilla Python: >>> vt = [0] * 20 >>> for i, v in enumerate(vt): ... if 4 <= i < 8 or 13 <= i < 16: ... vt[i] = .17 ... >>> vt [0, 0, 0, 0, 0.17, 0.17, 0.17, 0.17, 0, 0, 0, 0, 0, 0.17, 0.17, 0.17, 0, 0, 0, 0] With vanilla Python using slices: >>> vt = [0] * 20 >>> vt[4:8] = [.17]*4 >>> vt[13:16] = [.17]*3 >>> vt [0, 0, 0, 0, 0.17, 0.17, 0.17, 0.17, 0, 0, 0, 0, 0, 0.17, 0.17, 0.17, 0, 0, 0, 0] With numpy: >>> vt = numpy.zeros(20) >>> vt[4:8] = vt[13:16] = .17 >>> vt array([ 0. , 0. , 0. , 0. , 0.17, 0.17, 0.17, 0.17, 0. , 0. , 0. , 0. , 0. , 0.17, 0.17, 0.17, 0. , 0. , 0. , 0. ]) From davea at davea.name Mon Apr 1 07:53:44 2013 From: davea at davea.name (Dave Angel) Date: Mon, 01 Apr 2013 07:53:44 -0400 Subject: How to do this? In-Reply-To: <29fa109e-8ed0-4b1b-a9c0-473e2bace687@googlegroups.com> References: <83a54022-576d-465b-b6bd-7e21cde59d99@googlegroups.com> <29fa109e-8ed0-4b1b-a9c0-473e2bace687@googlegroups.com> Message-ID: <51597548.6000905@davea.name> On 04/01/2013 07:08 AM, Ana Dion?sio wrote: > [0 0 0 0 0.17 0.17 0.17 0.17 0 0 0 0.17 0.17 0.17 0 0 0 0 0 0 0] I'd do res = "[0 0 0 0 0.17 0.17 0.17 0.17 0 0 0 0.17 0.17 0.17 0 0 0 0 0 0 0]" Unless there's a pattern you're trying to accomplish (like maybe next time you want to do "it" for a list of two million items), there's little point in writing code to do what you've already predetermined. And if there is a pattern, you'd probably better let us know. But if it's for fun, vt = [0] * 21 for index, val in enumerate(vt): if 3 References: <83a54022-576d-465b-b6bd-7e21cde59d99@googlegroups.com> Message-ID: On 01/04/2013 11:14, Ana Dion?sio wrote: > So I have this script: > > " > from numpy import array Are you aware that this overrides the Python builtin array? It's usually but not always better to do this import numpy as np vt = np.array(vt, dtype=dict) > > vt=[0]*20 > vt = array(vt, dtype=dict) > > for t in range(20): > if t == 4: > vt[t]=1 > > else: > vt[t]=0 Why the loop, you've already initialise the array to zeroes? > " > > And have this output: > > [0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] > > What I need is when t == 4 I need to put 1 in that position and in the next 3, for example the following output: > > [0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0] > > Do you have any suggestions? Use slicing. vt[4:8] = 1 > > > I'm sorry if I can't explain this in a better way, English is not my first language > > Thank you > -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From carnedhaval1995 at gmail.com Mon Apr 1 07:54:30 2013 From: carnedhaval1995 at gmail.com (Myles Dhaval Carne) Date: Mon, 1 Apr 2013 04:54:30 -0700 (PDT) Subject: Rapid CHM Maker Message-ID: Rapid CHM Maker http://t.co/dIGazO0Xbz DriverMatcher http://t.co/34lL03D9Uv AWSVideoScreenRecordHDTV http://t.co/61Ers2gX7K Stay Away Alergies Software http://t.co/WzsjycKCpv WareSoft Sudoku http://t.co/GPzieBjDsj Rapid CHM Maker From insideshoes at gmail.com Mon Apr 1 09:50:32 2013 From: insideshoes at gmail.com (inshu chauhan) Date: Mon, 1 Apr 2013 19:20:32 +0530 Subject: Error in working with Dict Message-ID: I have this program which is working with 2 dictionaries segments, class_counts.. but I am getting an error mentioned below the programme. import cv from itertools import * from math import floor, sqrt, ceil from numpy import array, dot, subtract, add, outer, argmax, linalg as lin def Computesegclass(segimage, refimage): f = open("Pixel_count_with_region_num_trial1.txt", "w") segments = {} class_count = {} for y in xrange(0, segimage.height): for x in xrange(0, segimage.width): if segimage[y,x] == (0.0, 0.0, 0.0): continue else: seg_color = segimage[y,x] blue = int(seg_color[0]) green = int(seg_color[1]) red = int(seg_color[2]) region_num = blue + 256 * green + 65536 * red #print region_num segments[region_num] = segments.setdefault(region_num, 0) + 1 #print segments class_color = refimage[y,x] if class_color == (0.0,0.0,0.0): class_number = 0 # No class elif class_color == (0.0,255.0,0.0): class_number = 1 # Trees elif class_color == (255.0, 0.0, 128.0): class_number = 2 # Buildings elif class_color == (0.0,0.0,255.0): class_number = 3 # Automobiles elif class_color == (255.0, 255.0, 0.0): class_number = 4 # Road Points elif class_color == (0.0, 64.0, 128.0): class_number = 5 # Tree trunks nad branches elif class_color == (255.0, 0.0 ,0.0): class_number = 6 # Poles elif class_color == (255.0, 0.0, 255.0): class_number = 7 # Traffic Lights else: class_number = 0 # Gray Pixel class_count.setdefault(region_num, [0, 0, 0, 0, 0, 0, 0, 0])[class_number] += 1 # print class_count for k in sorted(class_count.iterkeys()): i = argmax(class_count[k]) print >> f, i if __name__== "__main__": segimage = cv.LoadImageM(r"C:\Users\inshu\Desktop\Masters Thesis\Segmentation\segmentation_numbers_00000.tif", cv.CV_LOAD_IMAGE_UNCHANGED) refimage = cv.LoadImageM(r"C:\Users\inshu\Desktop\Masters Thesis\Segmentation\Hand_Classified1.tif", cv.CV_LOAD_IMAGE_UNCHANGED) print segimage Computesegclass(segimage, refimage) ERROR : Traceback (most recent call last): File "C:\Users\inshu\Desktop\seg.py", line 49, in for k in sorted(class_count.iterkeys()): NameError: name 'class_count' is not defined I know this error is because I have initialized both dicts inside the function, But why dicts are not saved out, if I intialize the dicts outside the function, the processing is still done inside and end result I am getting is an empty dict. Thanks in Advance for suggestions!!!! -------------- next part -------------- An HTML attachment was scrubbed... URL: From vincent.vandevyvre at swing.be Mon Apr 1 10:10:06 2013 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Mon, 01 Apr 2013 16:10:06 +0200 Subject: Error in working with Dict In-Reply-To: References: Message-ID: <5159953E.3050709@swing.be> Le 01/04/13 15:50, inshu chauhan a ?crit : > I have this program which is working with 2 dictionaries segments, > class_counts.. but I am getting an error mentioned below the programme. > > import cv > from itertools import * > from math import floor, sqrt, ceil > from numpy import array, dot, subtract, add, outer, argmax, linalg as lin > > > def Computesegclass(segimage, refimage): > f = open("Pixel_count_with_region_num_trial1.txt", "w") > segments = {} > class_count = {} > for y in xrange(0, segimage.height): > for x in xrange(0, segimage.width): > > if segimage[y,x] == (0.0, 0.0, 0.0): > continue > else: > seg_color = segimage[y,x] > blue = int(seg_color[0]) > green = int(seg_color[1]) > red = int(seg_color[2]) > region_num = blue + 256 * green + 65536 * red > #print region_num > segments[region_num] = segments.setdefault(region_num, > 0) + 1 > #print segments > > class_color = refimage[y,x] > > if class_color == (0.0,0.0,0.0): > class_number = 0 # No class > elif class_color == (0.0,255.0,0.0): > class_number = 1 # Trees > elif class_color == (255.0, 0.0, 128.0): > class_number = 2 # Buildings > elif class_color == (0.0,0.0,255.0): > class_number = 3 # Automobiles > elif class_color == (255.0, 255.0, 0.0): > class_number = 4 # Road Points > elif class_color == (0.0, 64.0, 128.0): > class_number = 5 # Tree trunks nad branches > elif class_color == (255.0, 0.0 ,0.0): > class_number = 6 # Poles > elif class_color == (255.0, 0.0, 255.0): > class_number = 7 # Traffic Lights > else: > class_number = 0 # Gray Pixel > > class_count.setdefault(region_num, [0, 0, 0, 0, 0, 0, > 0, 0])[class_number] += 1 > # print class_count > for k in sorted(class_count.iterkeys()): > i = argmax(class_count[k]) > print >> f, i > > if __name__== "__main__": > segimage = cv.LoadImageM(r"C:\Users\inshu\Desktop\Masters > Thesis\Segmentation\segmentation_numbers_00000.tif", > cv.CV_LOAD_IMAGE_UNCHANGED) > refimage = cv.LoadImageM(r"C:\Users\inshu\Desktop\Masters > Thesis\Segmentation\Hand_Classified1.tif", cv.CV_LOAD_IMAGE_UNCHANGED) > print segimage > Computesegclass(segimage, refimage) > > > ERROR : > > Traceback (most recent call last): > File "C:\Users\inshu\Desktop\seg.py", line 49, in > for k in sorted(class_count.iterkeys()): > NameError: name 'class_count' is not defined > > I know this error is because I have initialized both dicts inside the > function, But why dicts are not saved out, if I intialize the dicts > outside the function, the processing is still done inside and end > result I am getting is an empty dict. > > > Thanks in Advance for suggestions!!!! > > > Get the class_count in the return of Computesegclass cc = Computesegclass(segimage, refimage) for k in sorted(cc.iterkeys()): ... -- Vincent V.V. Oqapy . Qarte . PaQager From davea at davea.name Mon Apr 1 13:33:36 2013 From: davea at davea.name (Dave Angel) Date: Mon, 01 Apr 2013 13:33:36 -0400 Subject: Error in working with Dict In-Reply-To: References: Message-ID: <5159C4F0.7050809@davea.name> On 04/01/2013 09:50 AM, inshu chauhan wrote: > I have this program which is working with 2 dictionaries segments, > class_counts.. but I am getting an error mentioned below the programme. > > import cv > from itertools import * > from math import floor, sqrt, ceil > from numpy import array, dot, subtract, add, outer, argmax, linalg as lin > > > def Computesegclass(segimage, refimage): > f = open("Pixel_count_with_region_num_trial1.txt", "w") > segments = {} > class_count = {} > for y in xrange(0, segimage.height): > for x in xrange(0, segimage.width): > > if segimage[y,x] == (0.0, 0.0, 0.0): > continue > else: > seg_color = segimage[y,x] > blue = int(seg_color[0]) > green = int(seg_color[1]) > red = int(seg_color[2]) > region_num = blue + 256 * green + 65536 * red > #print region_num > segments[region_num] = segments.setdefault(region_num, 0) + > 1 > #print segments > > class_color = refimage[y,x] > > if class_color == (0.0,0.0,0.0): > class_number = 0 # No class > elif class_color == (0.0,255.0,0.0): > class_number = 1 # Trees > elif class_color == (255.0, 0.0, 128.0): > class_number = 2 # Buildings > elif class_color == (0.0,0.0,255.0): > class_number = 3 # Automobiles > elif class_color == (255.0, 255.0, 0.0): > class_number = 4 # Road Points > elif class_color == (0.0, 64.0, 128.0): > class_number = 5 # Tree trunks nad branches > elif class_color == (255.0, 0.0 ,0.0): > class_number = 6 # Poles > elif class_color == (255.0, 0.0, 255.0): > class_number = 7 # Traffic Lights > else: > class_number = 0 # Gray Pixel > > class_count.setdefault(region_num, [0, 0, 0, 0, 0, 0, 0, > 0])[class_number] += 1 > # print class_count You do realize you ended the function when you put the following line at the left margin? Perhaps you really intended to put the for loop inside the function? I can't tell. You don't call Computesegclass() till later, so how can you use its dicts, even if it did correctly pass them back? > for k in sorted(class_count.iterkeys()): > i = argmax(class_count[k]) > print >> f, i > > if __name__== "__main__": > segimage = cv.LoadImageM(r"C:\Users\inshu\Desktop\Masters > Thesis\Segmentation\segmentation_numbers_00000.tif", > cv.CV_LOAD_IMAGE_UNCHANGED) > refimage = cv.LoadImageM(r"C:\Users\inshu\Desktop\Masters > Thesis\Segmentation\Hand_Classified1.tif", cv.CV_LOAD_IMAGE_UNCHANGED) > print segimage > Computesegclass(segimage, refimage) > > > ERROR : > > Traceback (most recent call last): > File "C:\Users\inshu\Desktop\seg.py", line 49, in > for k in sorted(class_count.iterkeys()): > NameError: name 'class_count' is not defined > > I know this error is because I have initialized both dicts inside the > function, But why dicts are not saved out, if I intialize the dicts outside > the function, the processing is still done inside and end result I am > getting is an empty dict. > > > Thanks in Advance for suggestions!!!! > > > -- DaveA From invalid at invalid.invalid Mon Apr 1 11:30:56 2013 From: invalid at invalid.invalid (Pierre O'Dee) Date: Mon, 01 Apr 2013 08:30:56 -0700 Subject: PSF News: Guido van Rossum quitting Python to develop new, more difficult to learn, language. Message-ID: <2d2jl892k6hteccmlmjg8tlcdiqefmla5e@4ax.com> PSF [Beaverton, OR] 1 April 2013 -- At a news conference held earlier today, Guido van Rossum announced that he is quitting Python to develop a new language. "Python just makes programming too damn easy and too bug-free," Guido said as part of his remarks in a brief, prepared statement. He added, "The way things are going, soon, everyone in the world will be programming in Python -- even children!" Guido went on to say that he's now working on a new language called Giddy-up-and-Go which will take the worst features of C++, Java, and French combined with elements of both PHP and Klingon syntax. He said that this new endeavor should put the work and frustration back into programming "[where] it ought to be." Responding to a reporter's question in a brief Q&A following the announcement, Guido said, "Real programmers don't need no stinkin' easy and intuitive language to program with." Some features have already been hinted at for the new language. No Unicode -- BAUDOT is expected to be the new character encoding. Numeric types have been eliminated as it's no longer relevant or possible for most students and younger PhDs to do even simple arithmetic considering the current state of the so-called educational system. One surprising feature is that everything will be a subject using Guido's new subject-oriented programming (SOP) paradigm. Other sources said that variables (subjects in the new paradigm) will now be passed by gas. Python 3.3 will be the last version of Python. Look for announcements soon for the new Giddy-up-and-Go mailing lists. PSF will be selling its holdings to Oracle as they've embraced the open-source philosophy so freely and warmly. One insider shared unconfirmed rumors that Mr. Johnson will be attempting to revive and steer the now defunct Python language -- which elicited further concerns amongst the somewhat bewildered Python community. All newsgroups mentioning Python -- the full Monty -- will be closed today. --Pierre O'Dee, self-appointed spokesman for the PSF From rosuav at gmail.com Mon Apr 1 12:09:43 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Apr 2013 03:09:43 +1100 Subject: PSF News: Guido van Rossum quitting Python to develop new, more difficult to learn, language. In-Reply-To: <2d2jl892k6hteccmlmjg8tlcdiqefmla5e@4ax.com> References: <2d2jl892k6hteccmlmjg8tlcdiqefmla5e@4ax.com> Message-ID: On Tue, Apr 2, 2013 at 2:30 AM, Pierre O'Dee wrote: > One insider > shared unconfirmed rumors that Mr. Johnson will be attempting to > revive and steer the now defunct Python language It's about time his untiring contributions to this list and the language were recognized. I fully support this move. ChrisA From invalid at invalid.invalid Mon Apr 1 12:18:20 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 1 Apr 2013 16:18:20 +0000 (UTC) Subject: PSF News: Guido van Rossum quitting Python to develop new, more difficult to learn, language. References: <2d2jl892k6hteccmlmjg8tlcdiqefmla5e@4ax.com> Message-ID: On 2013-04-01, Pierre O'Dee wrote: [...] It took me an embarassingly long time to 'get' Mr. O'Dee's name. -- Grant Edwards grant.b.edwards Yow! I put aside my copy at of "BOWLING WORLD" and gmail.com think about GUN CONTROL legislation... From rosuav at gmail.com Mon Apr 1 12:22:38 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Apr 2013 03:22:38 +1100 Subject: PSF News: Guido van Rossum quitting Python to develop new, more difficult to learn, language. In-Reply-To: References: <2d2jl892k6hteccmlmjg8tlcdiqefmla5e@4ax.com> Message-ID: On Tue, Apr 2, 2013 at 3:18 AM, Grant Edwards wrote: > On 2013-04-01, Pierre O'Dee wrote: > > [...] > > It took me an embarassingly long time to 'get' Mr. O'Dee's name. I only just did now, after you pointed it out. Must be an accent thing, that's not really how I pronounce the word. ChrisA From woiski at gmail.com Mon Apr 1 13:21:55 2013 From: woiski at gmail.com (Emanuel Woiski) Date: Mon, 1 Apr 2013 14:21:55 -0300 Subject: PSF News: Guido van Rossum quitting Python to develop new, more difficult to learn, language. In-Reply-To: References: <2d2jl892k6hteccmlmjg8tlcdiqefmla5e@4ax.com> Message-ID: On 2013-04-01, Pierre O'Dee wrote: Guido went on to say that he's now working on a new language called Giddy-up-and-Go which will take the worst features of C++, Java, and French combined with elements of both PHP and Klingon syntax. [...] We are all eagerly waitin' for the new GuG (or GuGO?) language! Is it on github? regards woiski -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Mon Apr 1 13:48:21 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 01 Apr 2013 10:48:21 -0700 Subject: PSF News: Guido van Rossum quitting Python to develop new, more difficult to learn, language. In-Reply-To: References: <2d2jl892k6hteccmlmjg8tlcdiqefmla5e@4ax.com> Message-ID: <5159C865.7070508@stoneleaf.us> On 04/01/2013 10:21 AM, Emanuel Woiski wrote: > On 2013-04-01, Pierre O'Dee wrote: > Guido went on to say that he's now working on a new language > called Giddy-up-and-Go which will take the worst features of C++, > Java, and French combined with elements of both PHP and Klingon > syntax. > [...] > We are all eagerly waitin' for the new GuG (or GuGO?) language! I think the 'U' is silent, making it GAG. -- ~Ethan~ From breamoreboy at yahoo.co.uk Mon Apr 1 13:56:06 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 01 Apr 2013 18:56:06 +0100 Subject: PSF News: Guido van Rossum quitting Python to develop new, more difficult to learn, language. In-Reply-To: <2d2jl892k6hteccmlmjg8tlcdiqefmla5e@4ax.com> References: <2d2jl892k6hteccmlmjg8tlcdiqefmla5e@4ax.com> Message-ID: On 01/04/2013 16:30, Pierre O'Dee wrote: > > Some features have already been hinted at for the new language. > No Unicode -- BAUDOT is expected to be the new character > encoding. > > --Pierre O'Dee, self-appointed spokesman for the PSF > This is excellent news, no unicode means no chance of any performance regressions whilst implementing stupid things like memory savings and correctness. One question, why use a character encoding that's named after a very famous French actress? -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From square.steve at gmail.com Mon Apr 1 14:15:45 2013 From: square.steve at gmail.com (Steve Simmons) Date: Mon, 01 Apr 2013 19:15:45 +0100 Subject: PSF News: Guido van Rossum quitting Python to develop new, more difficult to learn, language. In-Reply-To: References: <2d2jl892k6hteccmlmjg8tlcdiqefmla5e@4ax.com> Message-ID: <5c1452ba-822e-4b31-a548-d90e57701e6b@email.android.com> It's in recognition of the gap between English and French - it helps you to bridge it. Mark Lawrence wrote: >On 01/04/2013 16:30, Pierre O'Dee wrote: >> >> Some features have already been hinted at for the new language. >> No Unicode -- BAUDOT is expected to be the new character >> encoding. >> >> --Pierre O'Dee, self-appointed spokesman for the PSF >> > >This is excellent news, no unicode means no chance of any performance >regressions whilst implementing stupid things like memory savings and >correctness. > >One question, why use a character encoding that's named after a very >famous French actress? > >-- >If you're using GoogleCrap? please read this >http://wiki.python.org/moin/GoogleGroupsPython. > >Mark Lawrence > >-- >http://mail.python.org/mailman/listinfo/python-list -- Sent from my Android phone with K-9 Mail. Please excuse my brevity. -------------- next part -------------- An HTML attachment was scrubbed... URL: From john_ladasky at sbcglobal.net Mon Apr 1 14:23:14 2013 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Mon, 1 Apr 2013 11:23:14 -0700 (PDT) Subject: PSF News: Guido van Rossum quitting Python to develop new, more difficult to learn, language. In-Reply-To: <2d2jl892k6hteccmlmjg8tlcdiqefmla5e@4ax.com> References: <2d2jl892k6hteccmlmjg8tlcdiqefmla5e@4ax.com> Message-ID: <81aaba14-5a50-494c-af5d-31d8dd6d70d1@googlegroups.com> On Monday, April 1, 2013 8:30:56 AM UTC-7, Pierre O'Dee wrote: > Guido went on to say that he's now working on a new language > called Giddy-up-and-Go which will take the worst features of C++, > Java, and French combined with elements of both PHP and Klingon > syntax. He said that this new endeavor should put the work and > frustration back into programming "[where] it ought to be." In other news, the famed University of Milan computer science professor Aprille Pazzo announced that she would be joining the Giddy-up-and-Go development team. From llanitedave at veawb.coop Mon Apr 1 14:32:58 2013 From: llanitedave at veawb.coop (llanitedave) Date: Mon, 1 Apr 2013 11:32:58 -0700 (PDT) Subject: PSF News: Guido van Rossum quitting Python to develop new, more difficult to learn, language. In-Reply-To: <2d2jl892k6hteccmlmjg8tlcdiqefmla5e@4ax.com> References: <2d2jl892k6hteccmlmjg8tlcdiqefmla5e@4ax.com> Message-ID: <9238e023-ce9f-4b58-85f4-98f3e6c98271@googlegroups.com> Another detail about the new language: the Btrees used in Python's persistent object data structures have been replaced by... A SHRUBBERY! From tundra at tundraware.com Mon Apr 1 15:59:04 2013 From: tundra at tundraware.com (Tim Daneliuk) Date: Mon, 01 Apr 2013 14:59:04 -0500 Subject: PSF News: Guido van Rossum quitting Python to develop new, more difficult to learn, language. In-Reply-To: <9238e023-ce9f-4b58-85f4-98f3e6c98271@googlegroups.com> References: <2d2jl892k6hteccmlmjg8tlcdiqefmla5e@4ax.com> <9238e023-ce9f-4b58-85f4-98f3e6c98271@googlegroups.com> Message-ID: <8h5p2a-gh71.ln1@ozzie.tundraware.com> On 04/01/2013 01:32 PM, llanitedave wrote: > Another detail about the new language: the Btrees used in Python's persistent object data structures have been replaced by... > > A SHRUBBERY! > I believe you mean "A 'oly shrubbery", do you not? -- ----------------------------------------------------------------------- Tim Daneliuk From llanitedave at veawb.coop Mon Apr 1 17:20:46 2013 From: llanitedave at veawb.coop (llanitedave) Date: Mon, 1 Apr 2013 14:20:46 -0700 (PDT) Subject: PSF News: Guido van Rossum quitting Python to develop new, more difficult to learn, language. In-Reply-To: <8h5p2a-gh71.ln1@ozzie.tundraware.com> References: <2d2jl892k6hteccmlmjg8tlcdiqefmla5e@4ax.com> <9238e023-ce9f-4b58-85f4-98f3e6c98271@googlegroups.com> <8h5p2a-gh71.ln1@ozzie.tundraware.com> Message-ID: <89a1c7c2-4334-479c-98ae-59e19aecb647@googlegroups.com> On Monday, April 1, 2013 12:59:04 PM UTC-7, Tim Daneliuk wrote: > On 04/01/2013 01:32 PM, llanitedave wrote: > > > Another detail about the new language: the Btrees used in Python's persistent object data structures have been replaced by... > > > > > > A SHRUBBERY! > > > > > > > I believe you mean "A 'oly shrubbery", do you not? > > > > -- > > ----------------------------------------------------------------------- > > Tim Daneliuk Ni! From tundra at tundraware.com Mon Apr 1 15:22:44 2013 From: tundra at tundraware.com (Tim Daneliuk) Date: Mon, 01 Apr 2013 14:22:44 -0500 Subject: PSF News: Guido van Rossum quitting Python to develop new, more difficult to learn, language. In-Reply-To: <2d2jl892k6hteccmlmjg8tlcdiqefmla5e@4ax.com> References: <2d2jl892k6hteccmlmjg8tlcdiqefmla5e@4ax.com> Message-ID: <4d3p2a-jr61.ln1@ozzie.tundraware.com> On 04/01/2013 10:30 AM, Pierre O'Dee wrote: > PSF [Beaverton, OR] 1 April 2013 -- At a news conference held Amazing that this should show up when it did. Just today, we had Board Meeting at the intergalactic HQ of TundraWare Inc. and finally decided to move forward with this project we'd announced some time ago: http://compgroups.net/comp.lang.python/ann-yapdl/1638348 We would be pleased to cooperate with you in this new venture, especially insofar as we too believe there is simply not enough French linguistic construct in the modern programming languages. Merci, Bon Chance, A la bouffe, ----------------------------------------------------------------------- Tim Daneliuk From timr at probo.com Tue Apr 2 01:04:00 2013 From: timr at probo.com (Tim Roberts) Date: Mon, 01 Apr 2013 22:04:00 -0700 Subject: PSF News: Guido van Rossum quitting Python to develop new, more difficult to learn, language. References: <2d2jl892k6hteccmlmjg8tlcdiqefmla5e@4ax.com> Message-ID: Pierre O'Dee wrote: > >Guido went on to say that he's now working on a new language >called Giddy-up-and-Go which will take the worst features of C++, >Java, and French combined with elements of both PHP and Klingon >syntax. This would seem like the ideal programming language in which to implement an open source version of the ill-fated Microsoft Bob project. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From hossamalagmy at gmail.com Mon Apr 1 12:07:41 2013 From: hossamalagmy at gmail.com (23alagmy) Date: Mon, 1 Apr 2013 09:07:41 -0700 (PDT) Subject: A Healthy Alternative to Takeaway Regret Message-ID: <1463e27d-ecec-469e-a996-44943b9d5c6f@m9g2000vbc.googlegroups.com> A Healthy Alternative to Takeaway Regret http://natigtas7ab.blogspot.com/2013/03/a-healthy-alternative-to-takeaway-regret.html From fsb at thefsb.org Mon Apr 1 15:10:35 2013 From: fsb at thefsb.org (fsb at thefsb.org) Date: Mon, 1 Apr 2013 12:10:35 -0700 (PDT) Subject: ISO deprecates ASCII Horizontal Tab control character Message-ID: <5775f963-116b-42d4-b158-4bac323fb402@googlegroups.com> The subcommittee of ISO Joint Technical Committee 1 that is responsible for coded character sets has deprecated the Horizontal Tab control character in an approved revision of ISO/IEC 646 to be published in the next few months. "The days of HT's usefulness in printer control are long gone," said Dr. Yishoki Makimi, chair of the subcommittee. "Today tabs are only used in software source code. Our research revealed they serve no function in software engineering other than to provoke arguments and therefore waste time. We measured that HTs accumulated economic cost surpassed that of big vs. little-endian byte order in 2007 and started the committee work to deprecate it shortly after that." The width of a horizontal tab was originally adjustable in printer mechanism and was never standardized. Its subsequent use for indentation of instructions in the source code of block-oriented languages was economical when computer storage was expensive. Eventually many programmers adopted spaces leading to the contraversy that motivated the subcommittee. Microsoft has responded to ISO's move by announcing that HT will contunue be supported in Windows through Version 8, after which the code point will be repurposed for the Windows Key. Hillary Jeremy, Microsoft's code quality and standards boss, welcomed the move saying, "We've probably spent more time, over the years, fighting over tabs than we have spent fixing bugs in Office." From drobinow at gmail.com Mon Apr 1 16:03:15 2013 From: drobinow at gmail.com (David Robinow) Date: Mon, 1 Apr 2013 16:03:15 -0400 Subject: ISO deprecates ASCII Horizontal Tab control character In-Reply-To: <5775f963-116b-42d4-b158-4bac323fb402@googlegroups.com> References: <5775f963-116b-42d4-b158-4bac323fb402@googlegroups.com> Message-ID: If only On Mon, Apr 1, 2013 at 3:10 PM, wrote: > The subcommittee of ISO Joint Technical Committee 1 that is responsible > for coded character sets has deprecated the Horizontal Tab control > character in an approved revision of ISO/IEC 646 to be published in the > next few months. > > "The days of HT's usefulness in printer control are long gone," said Dr. > Yishoki Makimi, chair of the subcommittee. "Today tabs are only used in > software source code. Our research revealed they serve no function in > software engineering other than to provoke arguments and therefore waste > time. We measured that HTs accumulated economic cost surpassed that of big > vs. little-endian byte order in 2007 and started the committee work to > deprecate it shortly after that." > > The width of a horizontal tab was originally adjustable in printer > mechanism and was never standardized. Its subsequent use for indentation of > instructions in the source code of block-oriented languages was economical > when computer storage was expensive. Eventually many programmers adopted > spaces leading to the contraversy that motivated the subcommittee. > > Microsoft has responded to ISO's move by announcing that HT will contunue > be supported in Windows through Version 8, after which the code point will > be repurposed for the Windows Key. Hillary Jeremy, Microsoft's code quality > and standards boss, welcomed the move saying, "We've probably spent more > time, over the years, fighting over tabs than we have spent fixing bugs in > Office." > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cevyne at gmail.com Mon Apr 1 15:22:08 2013 From: cevyne at gmail.com (cevyne at gmail.com) Date: Mon, 1 Apr 2013 12:22:08 -0700 (PDT) Subject: os.system() with imbeded quotes on centos Message-ID: <0c9717ca-52dd-49ce-8102-e1432883858a@googlegroups.com> I get the example os.system('ls -al') no problem. i'm trying to create a variable with my command built in it but needs to include quotes. Portion of code is as follows: someip = '192.168.01.01' var1 = 'lynx -dump http://' + someip + '/cgi-bin/xxxx.log&.submit=+++Go%21+++ > junk' print var1 os.system(var1) If I print var1 it looks right . If I use the os.system(var1) as above it seems to have a problem near the end of the string with msg sh: .submit=+++Go%21+++: command not found clearly there is some escape sequence that I don't understand . I tried combinations of single and double quotes and mixed around var1 in os.system(), but that generates command not found. I need it to look like how I enter it manually and works lynx -dump 'http://192.168.01.01/cgi-bin/xxxx.log&.submit=+++Go%21+++ > junk' Probably obvious to many but i'm spinning my wheels. many thanks for help . From rosuav at gmail.com Mon Apr 1 15:33:12 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 2 Apr 2013 06:33:12 +1100 Subject: os.system() with imbeded quotes on centos In-Reply-To: <0c9717ca-52dd-49ce-8102-e1432883858a@googlegroups.com> References: <0c9717ca-52dd-49ce-8102-e1432883858a@googlegroups.com> Message-ID: On Tue, Apr 2, 2013 at 6:22 AM, wrote: > var1 = 'lynx -dump http://' + someip + '/cgi-bin/xxxx.log&.submit=+++Go%21+++ > junk' > lynx -dump 'http://192.168.01.01/cgi-bin/xxxx.log&.submit=+++Go%21+++ > junk' The problem is the &, which splits the command. Note how your manual execution puts single quotes around just the URL; in the other version, you're not doing that. (Though I'm not entirely sure why your > junk is inside the quotes - is that an error?) Try this: var1 = 'lynx -dump "http://' + someip + '/cgi-bin/xxxx.log&.submit=+++Go%21+++" > junk' ChrisA From gordon at panix.com Mon Apr 1 16:26:14 2013 From: gordon at panix.com (John Gordon) Date: Mon, 1 Apr 2013 20:26:14 +0000 (UTC) Subject: os.system() with imbeded quotes on centos References: <0c9717ca-52dd-49ce-8102-e1432883858a@googlegroups.com> Message-ID: In <0c9717ca-52dd-49ce-8102-e1432883858a at googlegroups.com> cevyne at gmail.com writes: > someip = '192.168.01.01' > var1 = 'lynx -dump http://' + someip + '/cgi-bin/xxxx.log&.submit=+++Go%21+++ > junk' '&' is a special character in shell commands. You'll need to quote or escape it. Try this: someip = '192.168.01.01' var1 = 'lynx -dump "http://' + someip + '/cgi-bin/xxxx.log&.submit=+++Go%21+++" > junk' Note the extra pair of double-quotes around the http:// part. -- 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 cs at zip.com.au Fri Apr 5 18:00:39 2013 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 6 Apr 2013 09:00:39 +1100 Subject: os.system() with imbeded quotes on centos In-Reply-To: References: Message-ID: <20130405220039.GA95779@cskk.homeip.net> On 01Apr2013 20:26, John Gordon wrote: | In <0c9717ca-52dd-49ce-8102-e1432883858a at googlegroups.com> cevyne at gmail.com writes: | > someip = '192.168.01.01' | > var1 = 'lynx -dump http://' + someip + '/cgi-bin/xxxx.log&.submit=+++Go%21+++ > junk' | | '&' is a special character in shell commands. You'll need to quote or | escape it. Or better still, use the subprocess module and avoid going via the os.system() altogether: http://docs.python.org/2/library/subprocess.html#popen-constructor If you must go via the os.system(), write yourself a generic function to quote a string for the shell, and to quote a bunch of strings (essentially " ".join( quoted-individual-strings )). And use it rigorously. Anything else is asking for shell injection attacks/errors, just as bad as hand constructing SQL statements. For example, if I must construct a shell command from arbitrary strings (like your URL) I use quote() from this: https://bitbucket.org/cameron_simpson/css/src/tip/lib/python/cs/sh.py That code's nothing special, just what I rolled some years ago for exactly this purpose. The core lesson is: never waste time figuring out _whether_ you need to treat shell strings specially. Just treat them specially and consistently and be safe. Cheers, -- Cameron Simpson -- cat: /Users/cameron/rc/mail/signature.: No such file or directory The Design View editor of Visual InterDev 6.0 is currently incompatible with Compatibility Mode, and may not function correctly. - George Politis , 22apr1999, quoting http://msdn.microsoft.com/vstudio/technical/ie5.asp From clp2 at rebertia.com Fri Apr 5 19:36:28 2013 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Apr 2013 16:36:28 -0700 Subject: os.system() with imbeded quotes on centos In-Reply-To: <20130405220039.GA95779@cskk.homeip.net> References: <20130405220039.GA95779@cskk.homeip.net> Message-ID: On Fri, Apr 5, 2013 at 3:00 PM, Cameron Simpson wrote: > On 01Apr2013 20:26, John Gordon wrote: > | In <0c9717ca-52dd-49ce-8102-e1432883858a at googlegroups.com> cevyne at gmail.com writes: > | > someip = '192.168.01.01' > | > var1 = 'lynx -dump http://' + someip + '/cgi-bin/xxxx.log&.submit=+++Go%21+++ > junk' > | > | '&' is a special character in shell commands. You'll need to quote or > | escape it. > > Or better still, use the subprocess module and avoid going via the > os.system() altogether: > > http://docs.python.org/2/library/subprocess.html#popen-constructor > > If you must go via the os.system(), write yourself a generic function > to quote a string for the shell, and to quote a bunch of strings > (essentially " ".join( quoted-individual-strings )). And use it > rigorously. > > Anything else is asking for shell injection attacks/errors, just > as bad as hand constructing SQL statements. > > For example, if I must construct a shell command from arbitrary > strings (like your URL) I use quote() from this: > > https://bitbucket.org/cameron_simpson/css/src/tip/lib/python/cs/sh.py > > That code's nothing special, just what I rolled some years ago for > exactly this purpose. No need for third-party code, just use the std lib: http://docs.python.org/2/library/pipes.html#pipes.quote http://docs.python.org/3/library/shlex.html#shlex.quote (But yeah, best of all is to just use `subprocess` with shell=False.) Cheers, Chris From cs at zip.com.au Fri Apr 5 19:53:57 2013 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 6 Apr 2013 10:53:57 +1100 Subject: os.system() with imbeded quotes on centos In-Reply-To: References: Message-ID: <20130405235357.GA66641@cskk.homeip.net> On 05Apr2013 16:36, Chris Rebert wrote: | No need for third-party code, just use the std lib: | http://docs.python.org/2/library/pipes.html#pipes.quote | http://docs.python.org/3/library/shlex.html#shlex.quote Ah, handy. I must say its quote quoting is kind of verbose, though. | (But yeah, best of all is to just use `subprocess` with shell=False.) Cheers, -- Cameron Simpson Plague, Famine, Pestilence, and C++ stalk the land. We're doomed! Doomed! - Simon E Spero From vasudevram at gmail.com Mon Apr 1 16:00:49 2013 From: vasudevram at gmail.com (vasudevram) Date: Mon, 1 Apr 2013 13:00:49 -0700 (PDT) Subject: youtube-dl, a YouTube downloader in Python Message-ID: Folks may find this of interest, both from a programming and from an end-user point of view: youtube-dl, a YouTube downloader in Python: http://jugad2.blogspot.in/2013/03/youtube-dl-yourube-downloader-in-python.html I tried it out and it worked well. Downloaded a few videos using it. (The "rube" in the URL was a typo, I would have had to delete and re-enter the post to fix it - see the post for the details :) - Vasudev Ram www.dancingbison.com From nikos.gr33k at gmail.com Mon Apr 1 16:09:53 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Mon, 1 Apr 2013 13:09:53 -0700 (PDT) Subject: Switching from Apche to LiteSpeed Message-ID: <9a35850a-7fcb-4585-84ae-5e13cef9173a@googlegroups.com> Just today i changed from HostGator to EZPZ, which means from Apache Web Server to LiteSpeed. Does anyone know why iam seeing what iam seeing at http://superhost.gr I see weird encoding although inside my python script i have: #!/usr/bin/python # -*- coding=utf-8 -* Also dod you advise me to switch to VPS because none of the above webhosters is willing to support Python3 + MySQLdb ? With VPS i could isntall those packages myself and any other module i wish via 'pip install module' What do you think? From gordon at panix.com Mon Apr 1 16:29:47 2013 From: gordon at panix.com (John Gordon) Date: Mon, 1 Apr 2013 20:29:47 +0000 (UTC) Subject: Switching from Apche to LiteSpeed References: <9a35850a-7fcb-4585-84ae-5e13cef9173a@googlegroups.com> Message-ID: In <9a35850a-7fcb-4585-84ae-5e13cef9173a at googlegroups.com> =?ISO-8859-7?B?zd/q7/Igw+rxMzPq?= writes: > Just today i changed from HostGator to EZPZ, which means from Apache Web Server to LiteSpeed. > Does anyone know why iam seeing what iam seeing at http://superhost.gr > I see weird encoding although inside my python script i have: > #!/usr/bin/python > # -*- coding=utf-8 -* I believe the syntax is to use a colon, not an equal sign. i.e.: # -*- coding: utf-8 -*- Your example is also missing the final dash after the asterisk. -- 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 nagia.retsina at gmail.com Tue Apr 2 01:10:47 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Mon, 1 Apr 2013 22:10:47 -0700 (PDT) Subject: Switching from Apche to LiteSpeed In-Reply-To: References: <9a35850a-7fcb-4585-84ae-5e13cef9173a@googlegroups.com> Message-ID: <0902473e-d498-45ce-bc98-ea1df7f04f27@googlegroups.com> ?? ???????, 1 ???????? 2013 11:29:47 ?.?. UTC+3, ? ??????? John Gordon ??????: > In <9a35850a-7fcb-4585-84ae-5e13cef9173a at googlegroups.com> =?ISO-8859-7?B?zd/q7/Igw+rxMzPq?= writes: > > > > > Just today i changed from HostGator to EZPZ, which means from Apache Web Server to LiteSpeed. > > > > > Does anyone know why iam seeing what iam seeing at http://superhost.gr > > > > > I see weird encoding although inside my python script i have: > > > > > #!/usr/bin/python > > > # -*- coding=utf-8 -* > > > > I believe the syntax is to use a colon, not an equal sign. i.e.: > > > > # -*- coding: utf-8 -*- > > > > Your example is also missing the final dash after the asterisk. > > > > -- > > 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" Thank you but even like you said i still see ncoding issues as seen in my webpage From steve+comp.lang.python at pearwood.info Tue Apr 2 02:38:08 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Apr 2013 06:38:08 GMT Subject: Switching from Apche to LiteSpeed References: <9a35850a-7fcb-4585-84ae-5e13cef9173a@googlegroups.com> Message-ID: <515a7cd0$0$29891$c3e8da3$5496439d@news.astraweb.com> On Mon, 01 Apr 2013 20:29:47 +0000, John Gordon wrote: > In <9a35850a-7fcb-4585-84ae-5e13cef9173a at googlegroups.com> > =?ISO-8859-7?B?zd/q7/Igw+rxMzPq?= writes: > >> Just today i changed from HostGator to EZPZ, which means from Apache >> Web Server to LiteSpeed. > >> Does anyone know why iam seeing what iam seeing at http://superhost.gr > >> I see weird encoding although inside my python script i have: > >> #!/usr/bin/python >> # -*- coding=utf-8 -* > > I believe the syntax is to use a colon, not an equal sign. i.e.: > > # -*- coding: utf-8 -*- > > Your example is also missing the final dash after the asterisk. I don't think that will make a difference. Encoding declaration lines are *very* flexible, and will match either a colon or equals sign. So long as it matches this regular expression, it will be understood: coding[=:]\s*([-\w.]+) http://docs.python.org/2/reference/lexical_analysis.html#encoding-declarations However, it is important that the encoding being declared matches the actual encoding being used! For example, if you take a Latin-1 file, and declare that it is UTF-8, it won't magically turn the Latin-1 file into UTF-8. Instead you'll get bytes being decoded wrongly. -- Steven From breamoreboy at yahoo.co.uk Mon Apr 1 16:33:52 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 01 Apr 2013 21:33:52 +0100 Subject: Switching from Apche to LiteSpeed In-Reply-To: <9a35850a-7fcb-4585-84ae-5e13cef9173a@googlegroups.com> References: <9a35850a-7fcb-4585-84ae-5e13cef9173a@googlegroups.com> Message-ID: On 01/04/2013 21:09, ????? ???33? wrote: > Just today i changed from HostGator to EZPZ, which means from Apache Web Server to LiteSpeed. > > Does anyone know why iam seeing what iam seeing at http://superhost.gr > > I see weird encoding although inside my python script i have: > > #!/usr/bin/python > # -*- coding=utf-8 -* > > Also dod you advise me to switch to VPS because none of the above webhosters is willing to support Python3 + MySQLdb ? > > With VPS i could isntall those packages myself and any other module i wish via 'pip install module' > > What do you think? > I think you should get your cheque book out and make a donation to the PSF. -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From khaosyt at gmail.com Mon Apr 1 17:02:55 2013 From: khaosyt at gmail.com (khaosyt at gmail.com) Date: Mon, 1 Apr 2013 14:02:55 -0700 (PDT) Subject: Help Message-ID: If I wanted to get the sum of some numbers (for example: 1 + 2 + 3 + 4 + 5 = 15) from the attached program what do I do? Keep in mind that the print statement prints the integers individually. integer = 0 denom = 10 again = "y" #sentinel: while again == "y" or again == "Y": integer = input("Enter a positive integer: ") while denom <= integer: denom = denom*10 while denom > 1: denom = denom/10 number = integer/denom integer = integer%denom print str(number) again = raw_input("Again? (Y/N): ") From khaosyt at gmail.com Mon Apr 1 17:42:42 2013 From: khaosyt at gmail.com (khaosyt at gmail.com) Date: Mon, 1 Apr 2013 14:42:42 -0700 (PDT) Subject: Help In-Reply-To: References: Message-ID: <8fb27db9-e745-449e-b7f6-e30493f05b35@googlegroups.com> Self-bump From davea at davea.name Mon Apr 1 18:28:17 2013 From: davea at davea.name (Dave Angel) Date: Mon, 01 Apr 2013 18:28:17 -0400 Subject: Help In-Reply-To: <8fb27db9-e745-449e-b7f6-e30493f05b35@googlegroups.com> References: <8fb27db9-e745-449e-b7f6-e30493f05b35@googlegroups.com> Message-ID: <515A0A01.3000907@davea.name> On 04/01/2013 05:42 PM, khaosyt at gmail.com wrote: > Self-bump > Normally, bumping a message/thread means replying to it. You're leaving a NEW message with no context, no reply, and a different uninformative subject line. And you're leaving it from googlegroups, with two copies. If you want to sum things through a loop, initialize a variable to zero before the loop, then add to it each time through the loop. total=0 for whatever in something: total += whatever_expression print total -- DaveA From khaosyt at gmail.com Mon Apr 1 17:42:52 2013 From: khaosyt at gmail.com (khaosyt at gmail.com) Date: Mon, 1 Apr 2013 14:42:52 -0700 (PDT) Subject: Help In-Reply-To: References: Message-ID: Self-bump From breamoreboy at yahoo.co.uk Mon Apr 1 18:09:04 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 01 Apr 2013 23:09:04 +0100 Subject: Help In-Reply-To: References: Message-ID: On 01/04/2013 22:42, khaosyt at gmail.com wrote: > Self-bump > It's considered polite to wait for at least 24 hours before bumping a question. You might have got more answers if you'd given a decent subject line rather than "Help". As it happens all you need do is loop around the string that is input, converting every digit to an integer and storing them in a list, then call the builtin sum function against the stored list. You'll probably also need a try/except to handle any duff input. -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From khaosyt at gmail.com Mon Apr 1 18:12:20 2013 From: khaosyt at gmail.com (khaosyt at gmail.com) Date: Mon, 1 Apr 2013 15:12:20 -0700 (PDT) Subject: Help In-Reply-To: References: Message-ID: <758c0049-1bde-46de-a331-be3343618599@googlegroups.com> On Monday, April 1, 2013 6:09:04 PM UTC-4, Mark Lawrence wrote: > On 01/04/2013 22:42, khaosyt at gmail.com wrote: > > > Self-bump > > > > > > > It's considered polite to wait for at least 24 hours before bumping a > > question. You might have got more answers if you'd given a decent > > subject line rather than "Help". > > > > As it happens all you need do is loop around the string that is input, > > converting every digit to an integer and storing them in a list, then > > call the builtin sum function against the stored list. > > > > You'll probably also need a try/except to handle any duff input. > > > > -- > > If you're using GoogleCrap? please read this > > http://wiki.python.org/moin/GoogleGroupsPython. > > > > Mark Lawrence How do I go about storing them in a list? From khaosyt at gmail.com Mon Apr 1 18:12:20 2013 From: khaosyt at gmail.com (khaosyt at gmail.com) Date: Mon, 1 Apr 2013 15:12:20 -0700 (PDT) Subject: Help In-Reply-To: References: Message-ID: <758c0049-1bde-46de-a331-be3343618599@googlegroups.com> On Monday, April 1, 2013 6:09:04 PM UTC-4, Mark Lawrence wrote: > On 01/04/2013 22:42, khaosyt at gmail.com wrote: > > > Self-bump > > > > > > > It's considered polite to wait for at least 24 hours before bumping a > > question. You might have got more answers if you'd given a decent > > subject line rather than "Help". > > > > As it happens all you need do is loop around the string that is input, > > converting every digit to an integer and storing them in a list, then > > call the builtin sum function against the stored list. > > > > You'll probably also need a try/except to handle any duff input. > > > > -- > > If you're using GoogleCrap? please read this > > http://wiki.python.org/moin/GoogleGroupsPython. > > > > Mark Lawrence How do I go about storing them in a list? From breamoreboy at yahoo.co.uk Mon Apr 1 18:29:09 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 01 Apr 2013 23:29:09 +0100 Subject: Help In-Reply-To: <758c0049-1bde-46de-a331-be3343618599@googlegroups.com> References: <758c0049-1bde-46de-a331-be3343618599@googlegroups.com> Message-ID: On 01/04/2013 23:12, khaosyt at gmail.com wrote: > On Monday, April 1, 2013 6:09:04 PM UTC-4, Mark Lawrence wrote: >> On 01/04/2013 22:42, khaosyt at gmail.com wrote: >> >>> Self-bump >> >>> >> >> >> >> It's considered polite to wait for at least 24 hours before bumping a >> >> question. You might have got more answers if you'd given a decent >> >> subject line rather than "Help". >> >> >> >> As it happens all you need do is loop around the string that is input, >> >> converting every digit to an integer and storing them in a list, then >> >> call the builtin sum function against the stored list. >> >> >> >> You'll probably also need a try/except to handle any duff input. >> >> >> >> -- >> >> If you're using GoogleCrap? please read this >> >> http://wiki.python.org/moin/GoogleGroupsPython. >> >> >> >> Mark Lawrence > > How do I go about storing them in a list? > Read this http://docs.python.org/3/tutorial/introduction.html#lists -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From steve+comp.lang.python at pearwood.info Mon Apr 1 19:42:52 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Apr 2013 23:42:52 GMT Subject: Help References: Message-ID: <515a1b7c$0$29967$c3e8da3$5496439d@news.astraweb.com> On Mon, 01 Apr 2013 23:09:04 +0100, Mark Lawrence wrote: > On 01/04/2013 22:42, khaosyt at gmail.com wrote: >> Self-bump >> >> > It's considered polite to wait for at least 24 hours before bumping a > question. Yes, but the assignment is due in an hour. Therefore it's critical that we reply instantly. *wink* -- Steven From roy at panix.com Mon Apr 1 19:47:51 2013 From: roy at panix.com (Roy Smith) Date: Mon, 01 Apr 2013 19:47:51 -0400 Subject: Help References: <515a1b7c$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <515a1b7c$0$29967$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > On Mon, 01 Apr 2013 23:09:04 +0100, Mark Lawrence wrote: > > > On 01/04/2013 22:42, khaosyt at gmail.com wrote: > >> Self-bump > >> > >> > > It's considered polite to wait for at least 24 hours before bumping a > > question. > > Yes, but the assignment is due in an hour. Therefore it's critical that > we reply instantly. How do you know it's an assignment? It could be an interview. From khaosyt at gmail.com Mon Apr 1 19:55:35 2013 From: khaosyt at gmail.com (khaosyt at gmail.com) Date: Mon, 1 Apr 2013 16:55:35 -0700 (PDT) Subject: Help In-Reply-To: References: <515a1b7c$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <385dbcf0-bc21-4797-82fb-66ae03e5990a@googlegroups.com> On Monday, April 1, 2013 7:47:51 PM UTC-4, Roy Smith wrote: > In article <515a1b7c$0$29967$c3e8da3$5496439d at news.astraweb.com>, > > Steven D'Aprano wrote: > > > > > On Mon, 01 Apr 2013 23:09:04 +0100, Mark Lawrence wrote: > > > > > > > On 01/04/2013 22:42, khaosyt at gmail.com wrote: > > > >> Self-bump > > > >> > > > >> > > > > It's considered polite to wait for at least 24 hours before bumping a > > > > question. > > > > > > Yes, but the assignment is due in an hour. Therefore it's critical that > > > we reply instantly. > > > > How do you know it's an assignment? It could be an interview. It's an assignment. From walterhurry at lavabit.com Mon Apr 1 19:56:20 2013 From: walterhurry at lavabit.com (Walter Hurry) Date: Mon, 1 Apr 2013 23:56:20 +0000 (UTC) Subject: Help References: Message-ID: On Mon, 01 Apr 2013 15:12:20 -0700, khaosyt wrote: Sigh. Another one for the bozo bin. From breamoreboy at yahoo.co.uk Mon Apr 1 21:02:58 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 02 Apr 2013 02:02:58 +0100 Subject: Help In-Reply-To: References: Message-ID: On 02/04/2013 00:56, Walter Hurry wrote: > On Mon, 01 Apr 2013 15:12:20 -0700, khaosyt wrote: > > > > Sigh. Another one for the bozo bin. > I say old chap you're setting yourself up for attacks from the Python Mailing List Police for using the word bozo, so expect a visit from Vicar Sergeant or Detective Parsons. Oh sorry they're from the Church Police, but please be cautious anyway. -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From walterhurry at lavabit.com Tue Apr 2 19:41:06 2013 From: walterhurry at lavabit.com (Walter Hurry) Date: Tue, 2 Apr 2013 23:41:06 +0000 (UTC) Subject: Help References: Message-ID: On Tue, 02 Apr 2013 02:02:58 +0100, Mark Lawrence wrote: > On 02/04/2013 00:56, Walter Hurry wrote: >> On Mon, 01 Apr 2013 15:12:20 -0700, khaosyt wrote: >> >> >> >> Sigh. Another one for the bozo bin. >> >> > I say old chap you're setting yourself up for attacks from the Python > Mailing List Police for using the word bozo, so expect a visit from > Vicar Sergeant or Detective Parsons. Oh sorry they're from the Church > Police, but please be cautious anyway. Righty ho, old boy. I'll be more careful in future. Thanks! ;-) From renato.barbosa.pim.pereira at gmail.com Mon Apr 1 17:12:04 2013 From: renato.barbosa.pim.pereira at gmail.com (Renato Barbosa Pim Pereira) Date: Mon, 1 Apr 2013 18:12:04 -0300 Subject: Tkinter Message-ID: I need to create a button and a text box follows the text box to enter a number, and this number is expected to create the same screen text boxes, and these text boxes need to be referenced, ie if I enter 30 in the first text box and click the button to be created 30 text boxes so that I can then " call" each of the boxes, eg box1, box2, box3, etc. .. . This all-in Tkinter. I thank you all for understanding and help. -------------- next part -------------- An HTML attachment was scrubbed... URL: From demianbrecht at gmail.com Tue Apr 2 11:25:45 2013 From: demianbrecht at gmail.com (Demian Brecht) Date: Tue, 2 Apr 2013 08:25:45 -0700 Subject: Tkinter In-Reply-To: References: Message-ID: ...And your question is?... If you're looking for people to just do your work for you, you'll likely get little assistance and will instead project a negative image of yourself here. What have you tried? Where are you stuck? What, /specifically/, do you need help with or what do you not understand? Questions with that kind of information and showing that you've done /some/ work will likely get you helpful answers. -- Demian Brecht http://demianbrecht.github.com From jason.swails at gmail.com Tue Apr 2 11:29:01 2013 From: jason.swails at gmail.com (Jason Swails) Date: Tue, 2 Apr 2013 11:29:01 -0400 Subject: Tkinter In-Reply-To: References: Message-ID: On Mon, Apr 1, 2013 at 5:12 PM, Renato Barbosa Pim Pereira < renato.barbosa.pim.pereira at gmail.com> wrote: > I need to create a button and a text box follows the text box to enter a > number, and this number is expected to create the same screen text boxes, and > these text boxes need to be referenced, ie if I enter 30 in the first > text box and click the button to be created 30 text boxes so that I can > then "call" each of the boxes, eg box1, box2, box3, etc. .. . > > This all-in Tkinter. > > I thank you all for understanding and help. > First, you have not asked a question. You have just said you need something. Second, we are not here to do your homework. If you want help with your programming, you have to at least demonstrate an initial effort. What have you programmed so far? What does it do? What errors are you getting when you run your code? Annotating your code with what you expect each segment to do is even better -- it lets us quickly correct misconceptions. The more information you can provide, the more targeted help we can give. Simply saying "I need a program to do X" is unlikely to get a response any more helpful than mine. Good luck, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From jason.swails at gmail.com Tue Apr 2 12:11:39 2013 From: jason.swails at gmail.com (Jason Swails) Date: Tue, 2 Apr 2013 12:11:39 -0400 Subject: Tkinter In-Reply-To: References: Message-ID: Please keep response replies to the Python list (e.g., use 'reply all' or just send the email to python-list). Also, you should tell people what Python version you are using. I assume you are using Python 2 since Tkinter was renamed to tkinter in Python 3. Finally, do not top-post. Type your responses inside the body of the email you are responding to. That gives people context for your responses. On Tue, Apr 2, 2013 at 11:48 AM, Renato Barbosa Pim Pereira < renato.barbosa.pim.pereira at gmail.com> wrote: > Sorry for my inconsistence: > > I need a textbox to get one number and pass for variable called numero > with one click of button. Thanks . > > I have this: > > import numpy as np > import matplotlib.pyplot as plt > from Tkinter import * > import tkMessageBox > > prefixo = "vetor" > numero = 10 > numeroVetores = 0 > > def makeWidgets(numero): > global entries > window = Tk() > window.title('Vetores') > form = Frame(window) > form.pack() > entries = {} > for ix in range(numero): > label = "%s %s" % (prefixo , ix + 1) > lab = Label(form, text=label) > ent = Entry(form) > lab.grid(row=ix, column=0) > ent.grid(row=ix, column=1) > entries[label] = ent > > > > > > Button(window, text="Calcular", command=calcular).pack(side=LEFT) > Button(window, text="Media", command=media).pack(side=LEFT) > > > > return window > > > > def pegavalores(): > valores = [] > for chave, entrada in sorted(entries.items()): > valores.append(entrada.get()) > > return valores > > > def calcular(): > calcular = pegavalores() > plt.plot(calcular) > plt.show() > > def media(): > media = pegavalores() > elementos = len(media) > media = np.asarray(media, dtype=np.float64) > valormedio = np.sum(media)/elementos > tkMessageBox.showinfo("Media", valormedio) > > > window = makeWidgets(numero) > window.mainloop() > I'm not sure exactly what you are trying to do. My guess is that you want to get "numero" from user input. Luckily, the tkSimpleDialog module contains a handy function that does just this: askinteger. So add a call: numero = tkSimpleDialog.askinteger('Window Title', 'Please insert the number of input values you want') window = makeWidgets(numero) window.mainloop() I leave to you the task of bringing tkSimpleDialog into your namespace. Good luck, Jason -- Jason M. Swails Quantum Theory Project, University of Florida Ph.D. Candidate 352-392-4032 -------------- next part -------------- An HTML attachment was scrubbed... URL: From renato.barbosa.pim.pereira at gmail.com Tue Apr 2 22:04:25 2013 From: renato.barbosa.pim.pereira at gmail.com (Renato Barbosa Pim Pereira) Date: Tue, 2 Apr 2013 23:04:25 -0300 Subject: Tkinter In-Reply-To: References: Message-ID: Thanks for the advices, I need now one scrollbar to roll under screen, I created the scrollbar but cant roll, please help me on this. http://pastebin.com/L6XWY6cm 2013/4/2 Jason Swails > Please keep response replies to the Python list (e.g., use 'reply all' or > just send the email to python-list). > > Also, you should tell people what Python version you are using. I assume > you are using Python 2 since Tkinter was renamed to tkinter in Python 3. > > Finally, do not top-post. Type your responses inside the body of the > email you are responding to. That gives people context for your responses. > > On Tue, Apr 2, 2013 at 11:48 AM, Renato Barbosa Pim Pereira < > renato.barbosa.pim.pereira at gmail.com> wrote: > >> Sorry for my inconsistence: >> >> I need a textbox to get one number and pass for variable called numero >> with one click of button. Thanks . >> >> I have this: >> >> import numpy as np >> import matplotlib.pyplot as plt >> from Tkinter import * >> import tkMessageBox >> >> prefixo = "vetor" >> numero = 10 >> numeroVetores = 0 >> >> def makeWidgets(numero): >> global entries >> window = Tk() >> window.title('Vetores') >> form = Frame(window) >> form.pack() >> entries = {} >> for ix in range(numero): >> label = "%s %s" % (prefixo , ix + 1) >> lab = Label(form, text=label) >> ent = Entry(form) >> lab.grid(row=ix, column=0) >> ent.grid(row=ix, column=1) >> entries[label] = ent >> >> >> >> >> >> Button(window, text="Calcular", command=calcular).pack(side=LEFT) >> Button(window, text="Media", command=media).pack(side=LEFT) >> >> >> >> return window >> >> >> >> def pegavalores(): >> valores = [] >> for chave, entrada in sorted(entries.items()): >> valores.append(entrada.get()) >> >> return valores >> >> >> def calcular(): >> calcular = pegavalores() >> plt.plot(calcular) >> plt.show() >> >> def media(): >> media = pegavalores() >> elementos = len(media) >> media = np.asarray(media, dtype=np.float64) >> valormedio = np.sum(media)/elementos >> tkMessageBox.showinfo("Media", valormedio) >> >> >> window = makeWidgets(numero) >> window.mainloop() >> > > I'm not sure exactly what you are trying to do. My guess is that you want > to get "numero" from user input. Luckily, the tkSimpleDialog module > contains a handy function that does just this: askinteger. So add a call: > > numero = tkSimpleDialog.askinteger('Window Title', 'Please insert the > number of input values you want') > window = makeWidgets(numero) > window.mainloop() > > I leave to you the task of bringing tkSimpleDialog into your namespace. > > Good luck, > Jason > -- > Jason M. Swails > Quantum Theory Project, > University of Florida > Ph.D. Candidate > 352-392-4032 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jason.swails at gmail.com Wed Apr 3 08:05:53 2013 From: jason.swails at gmail.com (Jason Swails) Date: Wed, 3 Apr 2013 08:05:53 -0400 Subject: Tkinter In-Reply-To: References: Message-ID: On Tue, Apr 2, 2013 at 10:04 PM, Renato Barbosa Pim Pereira < renato.barbosa.pim.pereira at gmail.com> wrote: > Thanks for the advices, I need now one scrollbar to roll under screen, I > created the scrollbar but cant roll, please help me on this. > > http://pastebin.com/L6XWY6cm > You need to bind your scrollbar to a particular action. It does not roll because you never told it what 'rolling' should do. That said, you need to bind your scrollbar command to a widget that actually supports scrolling. According to [1], your options are the Listbox, Text, Canvas, and Entry widgets. What that means is that you will need to replace your Frame widget with a Canvas widget (or embed a Canvas in your Frame, although with your existing code that latter approach does not serve much purpose). Then bind your scrollbar command to the xview method of your Canvas instance (or the yview method of your Canvas instance if you want to scroll vertically). HTH, Jason [1] http://effbot.org/zone/tkinter-scrollbar-patterns.htm -------------- next part -------------- An HTML attachment was scrubbed... URL: From khaosyt at gmail.com Mon Apr 1 17:44:45 2013 From: khaosyt at gmail.com (khaosyt at gmail.com) Date: Mon, 1 Apr 2013 14:44:45 -0700 (PDT) Subject: Help Message-ID: If I wanted to get the sum of some numbers (for example: 1 + 2 + 3 + 4 + 5 = 15) from the attached program what do I do? Keep in mind that the print statement prints the integers individually. integer = 0 denom = 10 again = "y" #sentinel: while again == "y" or again == "Y": integer = input("Enter a positive integer: ") while denom <= integer: denom = denom*10 while denom > 1: denom = denom/10 number = integer/denom integer = integer%denom print str(number) again = raw_input("Again? (Y/N): ") From gordon at panix.com Mon Apr 1 18:12:43 2013 From: gordon at panix.com (John Gordon) Date: Mon, 1 Apr 2013 22:12:43 +0000 (UTC) Subject: Help References: Message-ID: In khaosyt at gmail.com writes: > If I wanted to get the sum of some numbers (for example: 1 + 2 + 3 + 4 > + 5 = 15) from the attached program what do I do? Keep in mind that the > print statement prints the integers individually. It's not clear what you're asking for. The attached program doesn't (appear to) work with sums at all; why would you want to use it? Writing a new program from scratch would seem to be a better choice. -- 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 khaosyt at gmail.com Mon Apr 1 18:22:37 2013 From: khaosyt at gmail.com (khaosyt at gmail.com) Date: Mon, 1 Apr 2013 15:22:37 -0700 (PDT) Subject: Help In-Reply-To: References: Message-ID: <118e161a-4981-4696-8bdb-780bf82484cc@googlegroups.com> On Monday, April 1, 2013 6:12:43 PM UTC-4, John Gordon wrote: > In khaosyt at gmail.com writes: > > > > > If I wanted to get the sum of some numbers (for example: 1 + 2 + 3 + 4 > > > + 5 = 15) from the attached program what do I do? Keep in mind that the > > > print statement prints the integers individually. > > > > It's not clear what you're asking for. The attached program doesn't > > (appear to) work with sums at all; why would you want to use it? > > Writing a new program from scratch would seem to be a better choice. > > > > -- > > 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" It doesn't work with sums yet; it only returns individual positive integers in a longer number. From gordon at panix.com Mon Apr 1 18:33:08 2013 From: gordon at panix.com (John Gordon) Date: Mon, 1 Apr 2013 22:33:08 +0000 (UTC) Subject: Help References: <118e161a-4981-4696-8bdb-780bf82484cc@googlegroups.com> Message-ID: In <118e161a-4981-4696-8bdb-780bf82484cc at googlegroups.com> khaosyt at gmail.com writes: > > It's not clear what you're asking for. The attached program doesn't > > (appear to) work with sums at all; why would you want to use it? > > Writing a new program from scratch would seem to be a better choice. > It doesn't work with sums yet; it only returns individual positive > integers in a longer number. Yes, I can see that. But your original request said that you wanted to get a sum of numbers "from the attached program", which sort of implies that you want to use the program exactly as it was posted, without modifications. -- 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 khaosyt at gmail.com Mon Apr 1 18:57:56 2013 From: khaosyt at gmail.com (khaosyt at gmail.com) Date: Mon, 1 Apr 2013 15:57:56 -0700 (PDT) Subject: Help In-Reply-To: References: <118e161a-4981-4696-8bdb-780bf82484cc@googlegroups.com> Message-ID: <7c0a74a6-dd3b-457f-8eb3-ce0e8bccb415@googlegroups.com> On Monday, April 1, 2013 6:33:08 PM UTC-4, John Gordon wrote: > In <118e161a-4981-4696-8bdb-780bf82484cc at googlegroups.com> khaosyt at gmail.com writes: > > > > > > It's not clear what you're asking for. The attached program doesn't > > > > (appear to) work with sums at all; why would you want to use it? > > > > Writing a new program from scratch would seem to be a better choice. > > > > > It doesn't work with sums yet; it only returns individual positive > > > integers in a longer number. > > > > Yes, I can see that. But your original request said that you wanted to > > get a sum of numbers "from the attached program", which sort of implies > > that you want to use the program exactly as it was posted, without > > modifications. > > > > -- > > 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" I want to modify it so it can be used to find the sums. From steve+comp.lang.python at pearwood.info Mon Apr 1 20:00:30 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 02 Apr 2013 00:00:30 GMT Subject: Help References: Message-ID: <515a1f9d$0$29967$c3e8da3$5496439d@news.astraweb.com> On Mon, 01 Apr 2013 14:44:45 -0700, khaosyt wrote: > If I wanted to get the sum of some numbers (for example: 1 + 2 + 3 + 4 + > 5 = 15) from the attached program what do I do? Keep in mind that the > print statement prints the integers individually. Yes, we know what the print statement does. Some of us have been using Python for weeks now. Some comments interspersed within your code below: > integer = 0 > denom = 10 > again = "y" #sentinel: Technically, that's not a sentinel. > while again == "y" or again == "Y": > integer = input("Enter a positive integer: ") I believe that the last time you asked this question, you were told not to use the "input" function as it was dangerous or can lead to hard-to- understand bugs. Change the above line to: integer = raw_input("Enter a positive integer: ") Notice that if you do this, the so-called "integer" is actually a string. This is a good thing! You want it as a string, since that makes it easy to extract individual digits. > while denom <= integer: > denom = denom*10 > while denom > 1: > denom = denom/10 > number = integer/denom > integer = integer%denom > print str(number) All this stuff with denom seems to be aimed at extracting the digits from a number. There's an easier way: just work with the string. After the line I suggested above integer = raw_input("Enter a positive integer: ") "integer" is a string of digits. So you can iterate over the digits using a for-loop: # this is not what you want! for digit in integer: print digit Instead of printing the digits, you want to add them up. So start by initialising a total, then add them: total = 0 for digit in integer: total = total + digit Warning! The above three lines contains a bug. If you make the changes I suggest, and try it, you will get an error. That's okay. Read the error. Try to understand what it is telling you. Hint: remember that total is an actual int, a number, while each digit is a single character, a string. You need to convert each digit into a number before adding it. Hint: the int function takes a string, and converts it to a number. py> 42 + "23" Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'int' and 'str' py> 42 + int("23") 65 This should hopefully give you enough information to get some working code. Try to write as much of the code as you can, and come back with any further questions *after* making a good effort. Another hint: try experimenting at the interactive interpreter, or IDLE. If you're unsure about something, try it and see what happens *before* asking. Good luck. -- Steven From khaosyt at gmail.com Mon Apr 1 20:38:05 2013 From: khaosyt at gmail.com (khaosyt at gmail.com) Date: Mon, 1 Apr 2013 17:38:05 -0700 (PDT) Subject: Help In-Reply-To: <515a1f9d$0$29967$c3e8da3$5496439d@news.astraweb.com> References: <515a1f9d$0$29967$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0d182421-22cf-4886-8406-bf9150026bac@googlegroups.com> On Monday, April 1, 2013 8:00:30 PM UTC-4, Steven D'Aprano wrote: > On Mon, 01 Apr 2013 14:44:45 -0700, khaosyt wrote: > > > > > If I wanted to get the sum of some numbers (for example: 1 + 2 + 3 + 4 + > > > 5 = 15) from the attached program what do I do? Keep in mind that the > > > print statement prints the integers individually. > > > > > > Yes, we know what the print statement does. Some of us have been using > > Python for weeks now. > > > > > > Some comments interspersed within your code below: > > > > > > > > > integer = 0 > > > denom = 10 > > > again = "y" #sentinel: > > > > Technically, that's not a sentinel. > > > > > while again == "y" or again == "Y": > > > integer = input("Enter a positive integer: ") > > > > I believe that the last time you asked this question, you were told not > > to use the "input" function as it was dangerous or can lead to hard-to- > > understand bugs. Change the above line to: > > > > integer = raw_input("Enter a positive integer: ") > > > > > > Notice that if you do this, the so-called "integer" is actually a string. > > This is a good thing! You want it as a string, since that makes it easy > > to extract individual digits. > > > > > > > while denom <= integer: > > > denom = denom*10 > > > while denom > 1: > > > denom = denom/10 > > > number = integer/denom > > > integer = integer%denom > > > print str(number) > > > > All this stuff with denom seems to be aimed at extracting the digits from > > a number. There's an easier way: just work with the string. > > > > After the line I suggested above > > > > integer = raw_input("Enter a positive integer: ") > > > > > > "integer" is a string of digits. So you can iterate over the digits using > > a for-loop: > > > > # this is not what you want! > > for digit in integer: > > print digit > > > > > > Instead of printing the digits, you want to add them up. So start by > > initialising a total, then add them: > > > > total = 0 > > for digit in integer: > > total = total + digit > > > > > > Warning! The above three lines contains a bug. If you make the changes I > > suggest, and try it, you will get an error. That's okay. Read the error. > > Try to understand what it is telling you. Hint: remember that total is an > > actual int, a number, while each digit is a single character, a string. > > > > You need to convert each digit into a number before adding it. Hint: the > > int function takes a string, and converts it to a number. > > > > py> 42 + "23" > > Traceback (most recent call last): > > File "", line 1, in > > TypeError: unsupported operand type(s) for +: 'int' and 'str' > > py> 42 + int("23") > > 65 > > > > > > This should hopefully give you enough information to get some working > > code. Try to write as much of the code as you can, and come back with any > > further questions *after* making a good effort. > > > > Another hint: try experimenting at the interactive interpreter, or IDLE. > > If you're unsure about something, try it and see what happens *before* > > asking. > > > > > > Good luck. > > > > > > > > > > -- > > Steven Thanks. I'll try it out. From madeleine.udell at gmail.com Mon Apr 1 18:35:44 2013 From: madeleine.udell at gmail.com (madeleine.udell at gmail.com) Date: Mon, 1 Apr 2013 15:35:44 -0700 (PDT) Subject: Get multiprocessing.Queue to do priorities In-Reply-To: References: <4a05b27a_2@news.arcor-ip.de> <4a05b6c6_2@news.arcor-ip.de> <28KdnTocUpw2X5jXnZ2dnUVZ_sudnZ2d@pdx.net> <529683651263584828.031438address_is-invalid.invalid@news.arcor.de> <-vKdnex07oQzQpjXnZ2dnUVZ_hZi4p2d@pdx.net> <4a05ff89_1@news.arcor-ip.de> Message-ID: <7c6a6cc5-fd1f-475c-aa7e-233a53ebeebb@googlegroups.com> Was this issue ever resolved? What is the current best practice for those wishing to use a priority queue with multiprocessing? On Sunday, May 10, 2009 6:35:03 AM UTC-7, Jesse Noller wrote: > On Sat, May 9, 2009 at 6:11 PM, uuid wrote: > > The Queue module, apparently, is thread safe, but *not* process safe. If you > > try to use an ordinary Queue, it appears inaccessible to the worker process. > > (Which, after all, is quite logical, since methods for moving items between > > the threads of the same process are quite different from inter-process > > communication.) It appears that creating a manager that holds a shared queue > > might be an option > > (http://stackoverflow.com/questions/342556/python-2-6-multiprocessing-queue-compatible-with-threads). > > Using a manager, or submitting a patch which adds priority queue to > the multiprocessing.queue module is the correct solution for this. > > You can file an enhancement in the tracker, and assign/add me to it, > but without a patch it may take me a bit (wicked busy right now). > > jesse From madeleine.udell at gmail.com Mon Apr 1 18:35:44 2013 From: madeleine.udell at gmail.com (madeleine.udell at gmail.com) Date: Mon, 1 Apr 2013 15:35:44 -0700 (PDT) Subject: Get multiprocessing.Queue to do priorities In-Reply-To: References: <4a05b27a_2@news.arcor-ip.de> <4a05b6c6_2@news.arcor-ip.de> <28KdnTocUpw2X5jXnZ2dnUVZ_sudnZ2d@pdx.net> <529683651263584828.031438address_is-invalid.invalid@news.arcor.de> <-vKdnex07oQzQpjXnZ2dnUVZ_hZi4p2d@pdx.net> <4a05ff89_1@news.arcor-ip.de> Message-ID: <7c6a6cc5-fd1f-475c-aa7e-233a53ebeebb@googlegroups.com> Was this issue ever resolved? What is the current best practice for those wishing to use a priority queue with multiprocessing? On Sunday, May 10, 2009 6:35:03 AM UTC-7, Jesse Noller wrote: > On Sat, May 9, 2009 at 6:11 PM, uuid wrote: > > The Queue module, apparently, is thread safe, but *not* process safe. If you > > try to use an ordinary Queue, it appears inaccessible to the worker process. > > (Which, after all, is quite logical, since methods for moving items between > > the threads of the same process are quite different from inter-process > > communication.) It appears that creating a manager that holds a shared queue > > might be an option > > (http://stackoverflow.com/questions/342556/python-2-6-multiprocessing-queue-compatible-with-threads). > > Using a manager, or submitting a patch which adds priority queue to > the multiprocessing.queue module is the correct solution for this. > > You can file an enhancement in the tracker, and assign/add me to it, > but without a patch it may take me a bit (wicked busy right now). > > jesse From usmani.kashif9957 at gmail.com Mon Apr 1 21:13:20 2013 From: usmani.kashif9957 at gmail.com (usmani.kashif9957 at gmail.com) Date: Mon, 1 Apr 2013 18:13:20 -0700 (PDT) Subject: python mock Requests and the response Message-ID: <46e77d09-ddb9-4430-8ac6-78f69cc24f51@googlegroups.com> I am a beginner to using mock in python and trying to use http://www.voidspace.org.uk/python/mock. Please tell me the basic calls to get me working in below scenario. I am using python's Requests module (http://docs.python-requests.org/en/latest/) . In my views.py, I have a function that makes variety of requests.get() calls with different response each time def myview(request): res1 = requests.get('aurl') res2 = request.get('burl') res3 = request.get('curl') In my test class I want to do something like this but cannot figure out exact method calls Step 1: //Mock the requests module //when mockedRequests.get('aurl') is called then return 'a response' //when mockedRequests.get('burl') is called then return 'b response' //when mockedRequests.get('curl') is called then return 'C response' Step 2: Call my view Step 3: verify response contains 'a response', 'b response' , 'c response' Please help me to complete Step 1. From jeanmichel at sequans.com Tue Apr 2 05:40:54 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 2 Apr 2013 11:40:54 +0200 (CEST) Subject: python mock Requests and the response In-Reply-To: <46e77d09-ddb9-4430-8ac6-78f69cc24f51@googlegroups.com> Message-ID: <1975125219.4226540.1364895654381.JavaMail.root@sequans.com> ----- Original Message ----- > I am a beginner to using mock in python and trying to use > http://www.voidspace.org.uk/python/mock. > > Please tell me the basic calls to get me working in below scenario. I > am using python's Requests module > (http://docs.python-requests.org/en/latest/) . > > In my views.py, I have a function that makes variety of > requests.get() calls with different response each time > > def myview(request): > res1 = requests.get('aurl') > res2 = request.get('burl') > res3 = request.get('curl') > > In my test class I want to do something like this but cannot figure > out exact method calls > > Step 1: > > //Mock the requests module > //when mockedRequests.get('aurl') is called then return 'a > response' > //when mockedRequests.get('burl') is called then return 'b > response' > //when mockedRequests.get('curl') is called then return 'C > response' > > Step 2: > > Call my view > > Step 3: > > verify response contains 'a response', 'b response' , 'c response' > > Please help me to complete Step 1. > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, Why are you passing the requests (with typo ?) module to the function ? anyway, the code could look like this: !! untested code, I don't have the requests module installed !! import requests import mock def myView(): res1 = requests.get('aurl') res2 = requests.get('burl') res3 = requests.get('curl') @mock.patch('requests.get', mock.Mock(side_effect = lambda k:{'aurl': 'a response', 'burl' : 'b response'}.get(k, 'unhandled request %s'%k))) def testMyView(mockedGet): # you can further customize the mock object here mockedGet.whatever() myView() testMyView() side_effect is the mock way of returning multiple values. Hope it helps, JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From rustompmody at gmail.com Mon Apr 1 23:36:53 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 1 Apr 2013 20:36:53 -0700 (PDT) Subject: Python install Win 7 Problem References: Message-ID: <4eec099c-b8ff-4025-9135-89224f5e1b56@kk9g2000pbc.googlegroups.com> On Apr 2, 6:02?am, Joe Hill wrote: > Python install Win 7 Problem > > This is some of what others have experienced attempting to install Python > in Win 7 ?- I'm attempting to do the same with hopefully fewer detours. > > http://www.andrewsturges.com/2012/05/installing-numpy-for-python-3-in... > It's time to do some scientific computing, which, in the Python world, > means using NumPy. I'm in a Windows 7 (64-bit) environment running Python > 3.2.3 (64-bit). > > Getting NumPy installed for Python 2 or Python 3 in Ubuntu was easy. > Getting it to work in Windows turned out to be more tricky. > The Short Takeaway > > ? ? In a Windows 7 environment (even a 64-bit Windows 7 environment), you > must install the 32-bit version of Python 3. The 64-bit version will not > work with NumPy 1.6. Not claiming I can be of much help. Still... I dont see in your description, which numpy you used. Did you use this? http://www.scipy.org/Download#head-f64942d62faddeb27278a2c735e81ef2a7349db0 From drobinow at gmail.com Tue Apr 2 11:44:55 2013 From: drobinow at gmail.com (David Robinow) Date: Tue, 2 Apr 2013 11:44:55 -0400 Subject: Python install Win 7 Problem In-Reply-To: References: Message-ID: On Mon, Apr 1, 2013 at 9:02 PM, Joe Hill wrote: > ... > > In a Windows 7 environment (even a 64-bit Windows 7 environment), you > must install the 32-bit version of Python 3. The 64-bit version will not > work with NumPy 1.6. > 1.7 is the current version. I use 32-bit Python myself. > Furthermore, the 32-bit version of Python 3 must be installed 'just > for me', and not 'for everyone on this computer'. > Nonsense. > Finally, make sure you select the proper NumPy version (for Python > 3.2), not the default version from SourceForge (which is for Python 2.6). > Use http://sourceforge.net/projects/numpy/files/NumPy/1.7.0/numpy-1.7.0-win32-superpack-python3.2.exe/download > > In this post I'm assuming you have already installed Python 3 and that > you're running Windows 7. Specifically, I'm running Windows 7 > Professional, 64-bit, Service Pack 1. What follows is the whole story of > the troubleshooting, in case it helps out anyone else having the same > issues. > etc. > I'm running Windows 7 Home Premium > > > http://docs.python.org/3.2/install/ > More alternatives than an encyclopedia! > See no reference to Win 7. > This is NO help > I'm not aware of any peculiarities due to use of Win 7 (except it's not Linux) > > http://www.python.org/getit/releases/3.2.3/ > got > Gzipped source tar ball (3.2.3) (sig), ~ 13 MB > which was a file: > Python-3.2.3.tgz > Download the Windows executables. > ... > > I'm a total novice - my last program writing was 35+ years ago. My reason > for wanting Python is purely for fun an recreation. I used to just love > code writing. > > Questions: > 1. is 3.2.3 the correct version for me? On April 6 I see that additional > releases will become available. I see value in having the latest stable > programs. Is any of this for me - I can wait 5 days? > 3.3.0 is the current version > > 2. Would it make sense to install Python on the D: drive or will that > just further confuse matters? > It shouldn't hurt anything but why would you want to? -------------- next part -------------- An HTML attachment was scrubbed... URL: From balasurfs at gmail.com Tue Apr 2 14:07:12 2013 From: balasurfs at gmail.com (balasubramanian Achuthan) Date: Tue, 2 Apr 2013 11:07:12 -0700 (PDT) Subject: Python install Win 7 Problem In-Reply-To: References: Message-ID: Try using Activestate python. The free version would suffice your needs and it comes with a clean install. From martin.schoon at gmail.com Wed Apr 3 13:51:57 2013 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 3 Apr 2013 17:51:57 GMT Subject: Python install Win 7 Problem References: Message-ID: On 2013-04-02, balasubramanian Achuthan wrote: > Try using Activestate python. The free version would suffice your > needs and it comes with a clean install. I have been travelling and have not had time to read this thread in detail so this may be old hat but on Windows (at work) I simply install Python(x,y) https://code.google.com/p/pythonxy/ /Martin From tjreedy at udel.edu Wed Apr 3 14:33:48 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Wed, 03 Apr 2013 14:33:48 -0400 Subject: Python install Win 7 Problem In-Reply-To: References: Message-ID: On 4/3/2013 1:51 PM, Martin Sch??n wrote: > On 2013-04-02, balasubramanian Achuthan wrote: >> Try using Activestate python. The free version would suffice your >> needs and it comes with a clean install. > > I have been travelling and have not had time to read this thread in > detail so this may be old hat but on Windows (at work) I simply > install Python(x,y) > > https://code.google.com/p/pythonxy/ Only available for 2.x From drobinow at gmail.com Tue Apr 2 15:27:22 2013 From: drobinow at gmail.com (David Robinow) Date: Tue, 2 Apr 2013 15:27:22 -0400 Subject: Python install Win 7 Problem In-Reply-To: References: Message-ID: On Tue, Apr 2, 2013 at 12:45 PM, Joe Hill wrote: > On Tue, 2 Apr 2013 11:44:55 -0400, David Robinow > >Download the Windows executables. > > > >3.3.0 is the current version > > Is "numpy" an option that is needed (guess for math?)? > No, it's not needed to run Python. It can be useful. I only mentioned it because you did. > > Assuming 3.3 the current version - what are the "Download the Windows > executables." files? and in which order must they be installed? > The 32 bit version is at http://www.python.org/ftp/python/3.3.0/python-3.3.0.msi The 64 bit version is at http://www.python.org/ftp/python/3.3.0/python-3.3.0.amd64.msi Install one or the other. That's it. If you want to install numpy, do it after you install python. [The suggestion to install the Activestate version is reasonable. I've never used it. Please use a search engine if you decide to look for it.] > I never claimed to be a mind reader . > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From info at egenix.com Tue Apr 2 04:16:05 2013 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Tue, 02 Apr 2013 10:16:05 +0200 Subject: ANN: eGenix mxODBC Zope/Plone Database Adapter 2.1.1 Message-ID: <515A93C5.5010509@egenix.com> ________________________________________________________________________ ANNOUNCEMENT mxODBC Zope/Plone Database Adapter Version 2.1.1 for Zope and the Plone CMS Available for Plone 4.0, 4.1 and 4.2, Zope 2.12 and 2.13, on Windows, Linux, Mac OS X, FreeBSD and other platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mxODBC-Zope-DA-2.1.1-GA.html ________________________________________________________________________ INTRODUCTION The eGenix mxODBC Zope DA allows you to easily connect your Zope or Plone CMS installation to just about any database backend on the market today, giving you the reliability of the commercially supported eGenix product mxODBC and the flexibility of the ODBC standard as middle-tier architecture. The mxODBC Zope Database Adapter is highly portable, just like Zope itself and provides a high performance interface to all your ODBC data sources, using a single well-supported interface on Windows, Linux, Mac OS X, FreeBSD and other platforms. This makes it ideal for deployment in ZEO Clusters and Zope hosting environments where stability and high performance are a top priority, establishing an excellent basis and scalable solution for your Plone CMS. Product page: http://www.egenix.com/products/zope/mxODBCZopeDA/ ________________________________________________________________________ NEWS We are pleased to announce the new version 2.1.1 of our mxODBC Zope/Plone Database Adapter product. Feature Enhancements -------------------- * Added a new connection property "ODBC cursor type" which allows easily adjusting the ODBC cursor type to be used for mxODBC Zope DA connection objects. This new property allows enhancing the performance of the adapter significantly, when using it with MS SQL Server or IBM DB2 database backends. Please see below for details. Driver Compatibility -------------------- * MS SQL Server performance can now be much enhanced, and increased to levels beyond that of previous mxODBC Zope DA releases, by adjusting the connection ODBC cursor type to "Forward only cursors". The performance increase compared to mxODBC Zope DA 2.1.0 is enormous: from 2-3x faster executes/fetches for average queries, up to 300x faster for simple cases. In mxODBC Zope DA 2.2, we will switch to using "Forward only cursors" per default for all database backends. * IBM DB2 can benefit from the same performance enhancements using "Forward only cursors". The effect is a lot smaller, but still noticeable: up to 2x faster executes/fetches with forward-only cursors, compared to mxODBC Zope DA 2.1.0. * Added documentation to explain the different cursor types, compatibility with different database backends and effects on performance. Fixes ----- * Fixed the installation instructions to be more generic and easily adaptable to Plone and Zope installations on both Windows and Unix platforms. For the full set of changes please check the change log: http://www.egenix.com/products/zope/mxODBCZopeDA/changelog.html ________________________________________________________________________ FEATURES Version 2.1.0 of our mxODBC Zope/Plone Database Adapter product was released on 2012-09-18. Please see the full announcement for highlights of the 2.1 release: http://www.egenix.com/company/news/eGenix-mxODBC-Zope-DA-2.1.0-GA.html For the full set of features mxODBC has to offer, please see: http://www.egenix.com/products/zope/mxODBCZopeDA/#Features ________________________________________________________________________ UPGRADING Users are encouraged to upgrade to this latest mxODBC Zope/Plone DA release to benefit from the new features and updated ODBC driver support. We have taken special care not to introduce backwards incompatible changes, making the upgrade experience as smooth as possible. As always, patch level upgrades (e.g. from 2.1.0 to 2.1.1) are free of charge. The licenses you have purchased for 2.1 will continue to work with this new release. For major and minor upgrade purchases, we will give out 20% discount coupons going from mxODBC Zope DA 1.x to 2.1 and 50% coupons for upgrades from mxODBC 2.x to 2.1. After upgrade, use of the original license from which you upgraded is no longer permitted. Please contact the eGenix.com Sales Team with your existing license serials for details for an upgrade discount coupon. If you want to try the new release before purchace, you can request 30-day evaluation licenses by visiting our web-site or writing to sales at egenix.com, stating your name (or the name of the company) and the number of eval licenses that you need. _______________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. ________________________________________________________________________ MORE INFORMATION For more information on the mxODBC Zope Database Adapter, licensing and download instructions, please visit our web-site: http://www.egenix.com/products/zope/mxODBCZopeDA/ You can buy mxODBC Zope DA licenses online from the eGenix.com shop at: http://shop.egenix.com/ About Python (http://www.python.org/): Python is an object-oriented Open Source programming language which runs on all modern platforms. By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for today's IT challenges. About eGenix (http://www.egenix.com/): eGenix is a software project, consulting and product company focusing on expert project services and professional quality products for companies, Python users and developers. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Apr 02 2013) >>> Python Projects, Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2013-03-25: Released mxODBC 3.2.2 ... http://egenix.com/go40 2013-04-10: Python Meeting Duesseldorf ... 8 days to go ::::: Try our 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 robin at reportlab.com Tue Apr 2 05:49:51 2013 From: robin at reportlab.com (Robin Becker) Date: Tue, 02 Apr 2013 10:49:51 +0100 Subject: distutils without a compiler Message-ID: <515AA9BF.4010602@chamonix.reportlab.co.uk> Is there a neat way to get distutils to report compiler absence? Most windows users don't have a compiler so building extensions usually doesn't work. However, python's builtin batteries would allow pre-built pyds to be downloaded in lieu of an actual build. Has anyone created a fallback download compiler or similar? -- Robin Becker From nad at acm.org Tue Apr 2 19:26:59 2013 From: nad at acm.org (Ned Deily) Date: Tue, 02 Apr 2013 16:26:59 -0700 Subject: distutils without a compiler References: <515AA9BF.4010602@chamonix.reportlab.co.uk> Message-ID: In article <515AA9BF.4010602 at chamonix.reportlab.co.uk>, Robin Becker wrote: > Is there a neat way to get distutils to report compiler absence? Most windows > users don't have a compiler so building extensions usually doesn't work. > > However, python's builtin batteries would allow pre-built pyds to be > downloaded > in lieu of an actual build. > > Has anyone created a fallback download compiler or similar? I'm not totally sure I understand what you are asking but here's a guess. Today, probably the most widely-used solution to provide packages with pre-built C extension modules is to use setuptools or its Distribute fork and build a bdist egg which can then be downloaded and installed with the easy_install command. Note the whole area of binary distributions for Python is one that is now under intense active development. The standard library replacement for binary eggs will be wheels; various tools to support building and installing them are being designed and implemented and are expected to be part of Python 3.4 with downloadable support for selected earlier releases. It's all happening on the distutils-sig and in various PEPs. Nick Coughlan, the core developer leading the design effort, gives an overview of the current plans here: http://python-notes.boredomandlaziness.org/en/latest/pep_ideas/core_packa ging_api.html -- Ned Deily, nad at acm.org From kramerh at gmail.com Tue Apr 2 06:22:46 2013 From: kramerh at gmail.com (kramer65) Date: Tue, 2 Apr 2013 03:22:46 -0700 (PDT) Subject: Installation on Mac OSX 10.6.8 doesn't create the folder: /System/Library/Frameworks/Python.framework/Versions/2.7/ Message-ID: <2c4f00a8-ec73-409c-84da-dea0059b630d@googlegroups.com> Hello people, I installed python 2.7 on Mac OSX 10.6.8 with no problems and it is working fine. When I try to install Kivy however (www.kivy.org), I get an error saying: /usr/local/bin/kivy: line 24: /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7: No such file or directory /usr/local/bin/kivy: line 24: exec: /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7: cannot execute: No such file or directory Upon inspection the there are folders named 2.3, 2.5 and 2.6 in the Versions folder, but indeed no folder named "2.7". When I log into the interactive python command line however, it clearly says I've got python 2.7.3 installed. Does anybody know what the problem might be here? Kind regards, kramer From jason.swails at gmail.com Tue Apr 2 09:50:53 2013 From: jason.swails at gmail.com (Jason Swails) Date: Tue, 2 Apr 2013 09:50:53 -0400 Subject: Installation on Mac OSX 10.6.8 doesn't create the folder: /System/Library/Frameworks/Python.framework/Versions/2.7/ In-Reply-To: <2c4f00a8-ec73-409c-84da-dea0059b630d@googlegroups.com> References: <2c4f00a8-ec73-409c-84da-dea0059b630d@googlegroups.com> Message-ID: On Tue, Apr 2, 2013 at 6:22 AM, kramer65 wrote: > Hello people, > > > I installed python 2.7 on Mac OSX 10.6.8 with no problems and it is > working fine. When I try to install Kivy however (www.kivy.org), I get an > error saying: > How did you install Python 2.7? How did you install Kivy? Note that Kivy states 10.7 or 10.8 is required. My suggestion is to use MacPorts to build Python 2.7 (or something similar, like HomeBrew or Fink), then build Kivy from source, rather than using the Mac installer. The Mac installer for Kivy would be reasonable in expecting Python 2.7 to be installed in the standard Frameworks directory since it requires Python 2.7. Another option is to grok the MacPorts Portfile for Python 2.7 to figure out how they compile it using the Mac Framework and emulate that process when you build Python 2.7 from source (but don't install to /opt/local). If all else fails, upgrade to 10.7 ;). Good luck, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From nad at acm.org Tue Apr 2 19:09:35 2013 From: nad at acm.org (Ned Deily) Date: Tue, 02 Apr 2013 16:09:35 -0700 Subject: Installation on Mac OSX 10.6.8 doesn't create the folder: /System/Library/Frameworks/Python.framework/Versions/2.7/ References: <2c4f00a8-ec73-409c-84da-dea0059b630d@googlegroups.com> Message-ID: In article , Jason Swails wrote: > On Tue, Apr 2, 2013 at 6:22 AM, kramer65 wrote: > > > Hello people, > > > > > > I installed python 2.7 on Mac OSX 10.6.8 with no problems and it is > > working fine. When I try to install Kivy however (www.kivy.org), I get an > > error saying: > > > > How did you install Python 2.7? How did you install Kivy? Note that Kivy > states 10.7 or 10.8 is required. > > /> /usr/local/bin/kivy: line 24: > > /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7: No > > such file or directory > > /usr/local/bin/kivy: line 24: exec: > > /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7: > > cannot execute: No such file or directory > > > > Upon inspection the there are folders named 2.3, 2.5 and 2.6 in the > > Versions > > folder, but indeed no folder named "2.7". When I log into the interactive > > python command line however, it clearly says I've got python 2.7.3 > > installed. /System/Library/Frameworks is the location for Apple-supplied system Pythons. OS X 10.6 ships with complete versions of Python 2.6 and 2.5 (and the shared libs for 2.3). So you won't find a 2.7 folder there in 10.6.8. In OS X 10.7 and 10.8, Apple ships 2.7, 2.6, and 2.5. If you used one of the python.org installers to install 2.7, it will be installed into /Library/Frameworks and, by default, symlinks will be installed in /usr/local/bin for python, python2.7, etc. Since /usr/local/bin/kivy appears to be a script of some sort, examine it and see exactly what command is on line 24. The solution might be as simple as editing a line there to remove the "/System" part. > Another option is to grok the MacPorts Portfile for Python 2.7 to figure > out how they compile it using the Mac Framework and emulate that process > when you build Python 2.7 from source (but don't install to /opt/local). I'm not sure what you are proposing there. But you should never attempt to install anything into /System/Library: that's part of OS X and controlled by Apple. -- Ned Deily, nad at acm.org From jakubxmuszynski at googlemail.com Tue Apr 2 07:05:57 2013 From: jakubxmuszynski at googlemail.com (Jakub Muszynski) Date: Tue, 2 Apr 2013 13:05:57 +0200 Subject: Fwd: Python subdomains https In-Reply-To: <292AF4C0B342D54EB1FA919291D05791B74F5CBBBC@POCZTA01.inteligo.com.pl> References: <292AF4C0B342D54EB1FA919291D05791B74F5CBBBC@POCZTA01.inteligo.com.pl> Message-ID: Hi, I need to add python.org https to my company firewall policy, but I'm not allowed to add rule for https://*.python.org subdomains. Can You give me/publish list of important subdomains (like https://pypi.python.org) so I won't miss important sites? Greetings Jakub Muszynski -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Tue Apr 2 12:52:14 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Tue, 02 Apr 2013 12:52:14 -0400 Subject: Fwd: Python subdomains https In-Reply-To: References: <292AF4C0B342D54EB1FA919291D05791B74F5CBBBC@POCZTA01.inteligo.com.pl> Message-ID: <515B0CBE.5060306@udel.edu> On 4/2/2013 7:05 AM, Jakub Muszynski wrote: > Hi, > > I need to add python.org https to my company > firewall policy, but I'm not allowed to add rule for > https://*.python.org subdomains. > > Can You give me/publish list of important subdomains (like > https://pypi.python.org) so I won't miss important sites? docs - for the online docs bugs - for the issue tracker hg - for the source repository svn - for the external dependencies for building python You could also try all the links on python.org to see if there is anything else. psf.python.org? or is it only python.org/psf? Python.org is getting a facelift under a paid contract, so things might change in the future. I believe the trend is toward more sugdomains. --Terry From tjreedy at udel.edu Tue Apr 2 17:35:04 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Tue, 02 Apr 2013 17:35:04 -0400 Subject: Fwd: Python subdomains https In-Reply-To: <515B0CBE.5060306@udel.edu> References: <292AF4C0B342D54EB1FA919291D05791B74F5CBBBC@POCZTA01.inteligo.com.pl> <515B0CBE.5060306@udel.edu> Message-ID: On 4/2/2013 12:52 PM, Terry Jan Reedy wrote: > On 4/2/2013 7:05 AM, Jakub Muszynski wrote: >> Hi, >> >> I need to add python.org https to my company >> firewall policy, but I'm not allowed to add rule for >> https://*.python.org subdomains. >> >> Can You give me/publish list of important subdomains (like >> https://pypi.python.org) so I won't miss important sites? > > docs - for the online docs > bugs - for the issue tracker > hg - for the source repository > svn - for the external dependencies for building python mail - for the mailing lists and archives > You could also try all the links on python.org to see if there is > anything else. psf.python.org? or is it only python.org/psf? > > Python.org is getting a facelift under a paid contract, so things might > change in the future. I believe the trend is toward more sugdomains. > > --Terry > > > From pydev at hotmail.com Tue Apr 2 09:27:25 2013 From: pydev at hotmail.com (Fabian PyDEV) Date: Tue, 02 Apr 2013 08:27:25 -0500 Subject: extending class static members and inheritance Message-ID: Hi All, I have a question. Let says I have the following two classes: class Base(object): __mylist__ = ["value1", "value2"] def somemethod(self): pass class Derived(Base): __mylist__ = ["value3", "value4"] def anothermethod(self): pass what I would like to accomplish is that the class Derived has the member __mylist__ extended or merged as ["value1", "value2", "value3", "value4"]. Is there anyway I could accomplish this? I was thinking on accomplishing this as follows: class Derived(Base): __mylist__ = Base.__mylist__ + ["value3", "value4"] def anothermethod(self): pass Is there a better way? Perhaps a decorator? Thanks in advance and regards, Fabian From davea at davea.name Tue Apr 2 09:42:44 2013 From: davea at davea.name (Dave Angel) Date: Tue, 02 Apr 2013 09:42:44 -0400 Subject: extending class static members and inheritance In-Reply-To: References: Message-ID: <515AE054.1010502@davea.name> On 04/02/2013 09:27 AM, Fabian PyDEV wrote: > Hi All, > > I have a question. > > Let says I have the following two classes: > > class Base(object): > __mylist__ = ["value1", "value2"] > > def somemethod(self): > pass > > > class Derived(Base): > __mylist__ = ["value3", "value4"] > > def anothermethod(self): > pass > > > > > what I would like to accomplish is that the class Derived has the member __mylist__ extended or merged as ["value1", "value2", "value3", "value4"]. > > Is there anyway I could accomplish this? > > I was thinking on accomplishing this as follows: > > > class Derived(Base): > __mylist__ = Base.__mylist__ + ["value3", "value4"] > > def anothermethod(self): > pass > > > Is there a better way? Perhaps a decorator? > This is already done the best (clearest) way I know of. However, I'd like to point out two things: 1) they're not called class members, but class attributes. You have class attributes and instance attributes. 2) dunder methods should only be used to fulfill special methods defined by the language. If it's a public attribute, just leave off the underscores entirely. And if it's private, put just one leading underscore. -- DaveA From arnodel at gmail.com Tue Apr 2 11:24:42 2013 From: arnodel at gmail.com (Arnaud Delobelle) Date: Tue, 2 Apr 2013 16:24:42 +0100 Subject: extending class static members and inheritance In-Reply-To: References: Message-ID: On 2 April 2013 14:27, Fabian PyDEV wrote: > Hi All, > > I have a question. > > Let says I have the following two classes: > > class Base(object): > __mylist__ = ["value1", "value2"] > > def somemethod(self): > pass > > > class Derived(Base): > __mylist__ = ["value3", "value4"] > > def anothermethod(self): > pass > > > > > what I would like to accomplish is that the class Derived has the member __mylist__ extended or merged as ["value1", "value2", "value3", "value4"]. > > Is there anyway I could accomplish this? > > I was thinking on accomplishing this as follows: > > > class Derived(Base): > __mylist__ = Base.__mylist__ + ["value3", "value4"] > > def anothermethod(self): > pass > > > Is there a better way? Perhaps a decorator? class Base(object): mybits = ["value1", "value2"] @classmethod def mylist(cls): return sum((getattr(p, 'mybits', []) for p in cls.mro()[::-1]), []) class Derived(Base): mybits = ["value3", "value4"] class FurtherDerived(Derived): mybits = ["value5"] >>> Derived.mylist() ['value1', 'value2', 'value3', 'value4'] >>> FurtherDerived.mylist() ['value1', 'value2', 'value3', 'value4', 'value5'] HTH -- Arnaud From chris.hulan at gmail.com Tue Apr 2 09:52:14 2013 From: chris.hulan at gmail.com (Chris Hulan) Date: Tue, 2 Apr 2013 06:52:14 -0700 (PDT) Subject: OSError: [Errno 127] Value too large to be stored in data type Message-ID: Running Python 2.3.2 on AIX getting "OSError: [Errno 127] Value too large to be stored in data type" when executing: os.listdir('/some/NFS/dir') The error only happens on NFS mounted dirs Anyone else seen this? From chris.hulan at gmail.com Tue Apr 2 11:44:31 2013 From: chris.hulan at gmail.com (Chris Hulan) Date: Tue, 2 Apr 2013 08:44:31 -0700 (PDT) Subject: OSError: [Errno 127] Value too large to be stored in data type In-Reply-To: References: Message-ID: On Tuesday, April 2, 2013 9:52:14 AM UTC-4, Chris Hulan wrote: > Running Python 2.3.2 on AIX > > getting "OSError: [Errno 127] Value too large to be stored in data type" > > when executing: > > > > os.listdir('/some/NFS/dir') > > > > The error only happens on NFS mounted dirs > > Anyone else seen this? Looks like it may be a aix and NFS config issue as it only affects 1 NFS server and only on AIX From steve+comp.lang.python at pearwood.info Tue Apr 2 22:44:59 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Apr 2013 02:44:59 GMT Subject: OSError: [Errno 127] Value too large to be stored in data type References: Message-ID: <515b97ab$0$29891$c3e8da3$5496439d@news.astraweb.com> On Tue, 02 Apr 2013 08:44:31 -0700, Chris Hulan wrote: > On Tuesday, April 2, 2013 9:52:14 AM UTC-4, Chris Hulan wrote: >> Running Python 2.3.2 on AIX >> >> getting "OSError: [Errno 127] Value too large to be stored in data >> type" >> >> when executing: >> >> os.listdir('/some/NFS/dir') >> >> The error only happens on NFS mounted dirs >> >> Anyone else seen this? > > Looks like it may be a aix and NFS config issue as it only affects 1 > NFS server and only on AIX Thanks for responding on-list with a follow-up, and I'm sorry that nobody was able to give you any useful answers. If you do find a solution, work- around or even just an explanation, please consider replying again with an answer. -- Steven From suryak at ieee.org Tue Apr 2 10:54:25 2013 From: suryak at ieee.org (Surya Kasturi) Date: Tue, 2 Apr 2013 20:24:25 +0530 Subject: Help: pickle module unable to load "rb" mode files in linux Message-ID: Hi, hope you can help me on it.. with open(pickle_f, 'r') as fhand: obj = pickle.load(fhand) This works on linux but not in windows until I use "rb" mode while creating file object. Surprisingly, the "rb" mode is not working on Linux.. raising EOFError. Why is this happening? -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Tue Apr 2 11:20:19 2013 From: __peter__ at web.de (Peter Otten) Date: Tue, 02 Apr 2013 17:20:19 +0200 Subject: Help: pickle module unable to load "rb" mode files in linux References: Message-ID: Surya Kasturi wrote: > Hi, hope you can help me on it.. > > with open(pickle_f, 'r') as fhand: > obj = pickle.load(fhand) > > > This works on linux but not in windows until I use "rb" mode while > creating file object. Surprisingly, the "rb" mode is not working on > Linux.. raising EOFError. > > Why is this happening? I don't know. Please give a complete self-contained example that uses "wb" to write the file and "rb" to read it, and that fails on Linux. Don't forget to tell us the version of Python you used to run that script. From suryak at ieee.org Sun Apr 7 05:40:39 2013 From: suryak at ieee.org (Surya Kasturi) Date: Sun, 7 Apr 2013 15:10:39 +0530 Subject: Help: pickle module unable to load "rb" mode files in linux In-Reply-To: References: Message-ID: I am attaching the file which has to be read.. please take a look into it. The actual source code can be observed at https://github.com/scipy/SciPyCentral/blob/master/scipy_central/rest_comments/views.py#L235 when we use "rb" mode in windows, its working. but its not working in linux system (particularly CentOS) On Tue, Apr 2, 2013 at 8:50 PM, Peter Otten <__peter__ at web.de> wrote: > Surya Kasturi wrote: > > > Hi, hope you can help me on it.. > > > > with open(pickle_f, 'r') as fhand: > > obj = pickle.load(fhand) > > > > > > This works on linux but not in windows until I use "rb" mode while > > creating file object. Surprisingly, the "rb" mode is not working on > > Linux.. raising EOFError. > > > > Why is this happening? > > I don't know. > > Please give a complete self-contained example that uses "wb" to write the > file and "rb" to read it, and that fails on Linux. Don't forget to tell us > the version of Python you used to run that script. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: index.fpickle Type: application/octet-stream Size: 328 bytes Desc: not available URL: From __peter__ at web.de Sun Apr 7 08:51:31 2013 From: __peter__ at web.de (Peter Otten) Date: Sun, 07 Apr 2013 14:51:31 +0200 Subject: Help: pickle module unable to load "rb" mode files in linux References: Message-ID: Surya Kasturi wrote: > I am attaching the file which has to be read.. please take a look into it. > The actual source code can be observed at > https://github.com/scipy/SciPyCentral/blob/master/scipy_central/rest_comments/views.py#L235 > > > when we use "rb" mode in windows, its working. but its not working in > linux system (particularly CentOS) > > > > On Tue, Apr 2, 2013 at 8:50 PM, Peter Otten <__peter__ at web.de> wrote: > >> Surya Kasturi wrote: >> >> > Hi, hope you can help me on it.. >> > >> > with open(pickle_f, 'r') as fhand: >> > obj = pickle.load(fhand) >> > >> > >> > This works on linux but not in windows until I use "rb" mode while >> > creating file object. Surprisingly, the "rb" mode is not working on >> > Linux.. raising EOFError. >> > >> > Why is this happening? >> >> I don't know. >> >> Please give a complete self-contained example that uses "wb" to write the >> file and "rb" to read it, and that fails on Linux. Don't forget to tell >> us the version of Python you used to run that script. I am using Linux, but I cannot reproduce an EOFError with the attached file: Python 2.7.2+ (default, Jul 20 2012, 22:15:08) [GCC 4.6.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import pickle >>> with open("index.fpickle", "rb") as f: ... obj = pickle.load(f) ... >>> obj {'body': u'

yahoo

\n', 'prev': None, 'display_toc': False, 'title': u'<no title>', 'sourcename': 'index.txt', 'customsidebar': None, 'current_page_name': 'index', 'next': None, 'rellinks': [('genindex', u'General Index', 'I', u'index')], 'meta': {}, 'parents': [], 'toc': u'
    \n
\n', 'sidebars': None, 'metatags': ''} As the data has only built-in types it cannot be a library thing either. Given that the file's location is determined dynamically [views.py] call_sphinx_to_compile(settings.SPC['comment_compile_dir']) pickle_f = ''.join([settings.SPC['comment_compile_dir'], os.sep, '_build', os.sep, 'pickle', os.sep, 'index.fpickle']) with open(pickle_f, 'rb') as fhand: obj = pickle.load(fhand) I'd add a print pickle_f statement just before the with-statement to ensure that you don't have two different pickle files, one of them being empty or otherwise broken. From dihedral88888 at googlemail.com Sun Apr 7 09:43:41 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sun, 7 Apr 2013 06:43:41 -0700 (PDT) Subject: Help: pickle module unable to load "rb" mode files in linux In-Reply-To: References: Message-ID: Surya Kasturi? 2013?4?2????UTC+8??10?54?25???? > Hi, hope you can help me on it.. > > > > with open(pickle_f, 'r') as fhand: > ? ? ? ? obj = pickle.load(fhand) > > > > > This works on linux but not in windows until ?I use "rb" mode while creating file object. Surprisingly, the "rb" mode is not working on Linux.. raising EOFError. > Just use a decorator with a pass in parameter about the OS to wrap the two versions in different platforms. By the way any function can be saved in a variable to be passed around means that the lambda 1-liner is not necessarily required in Python. In C++, the sub-classing with virtual membership function reload mechanism is the equivalent part. From dihedral88888 at googlemail.com Sun Apr 7 09:43:41 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sun, 7 Apr 2013 06:43:41 -0700 (PDT) Subject: Help: pickle module unable to load "rb" mode files in linux In-Reply-To: References: Message-ID: Surya Kasturi? 2013?4?2????UTC+8??10?54?25???? > Hi, hope you can help me on it.. > > > > with open(pickle_f, 'r') as fhand: > ? ? ? ? obj = pickle.load(fhand) > > > > > This works on linux but not in windows until ?I use "rb" mode while creating file object. Surprisingly, the "rb" mode is not working on Linux.. raising EOFError. > Just use a decorator with a pass in parameter about the OS to wrap the two versions in different platforms. By the way any function can be saved in a variable to be passed around means that the lambda 1-liner is not necessarily required in Python. In C++, the sub-classing with virtual membership function reload mechanism is the equivalent part. From nagia.retsina at gmail.com Tue Apr 2 10:53:19 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Tue, 2 Apr 2013 07:53:19 -0700 (PDT) Subject: Reseller Hosting Plan with Python 3 support Message-ID: <62375cc8-4c93-4ee7-97a9-cbf118815b07@googlegroups.com> I'am looking for this: Reseller Plan with 200$ per year ?) 20 GB ftp quota b) 200 GB traffic c) cPanel d) Python 3 e) Python MySQLdb module f) ssh support Please make the best offer possible. Thank you. From nikos.gr33k at gmail.com Tue Apr 2 10:54:27 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 2 Apr 2013 07:54:27 -0700 (PDT) Subject: Reseller Hosting Plan with Python 3 support In-Reply-To: <62375cc8-4c93-4ee7-97a9-cbf118815b07@googlegroups.com> References: <62375cc8-4c93-4ee7-97a9-cbf118815b07@googlegroups.com> Message-ID: it's me Nikos i just posted under the wrong gmail account again....sorry for that. From nikos.gr33k at gmail.com Tue Apr 2 11:05:50 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 2 Apr 2013 08:05:50 -0700 (PDT) Subject: Reseller Host with Python 3 support Message-ID: <3647b81f-a8ba-465d-9cca-ad508065a32f@googlegroups.com> I'am looking for this: Reseller Plan with 200$ per year ?) 20 GB ftp quota b) 200 GB traffic c) cPanel d) Python 3 e) Python MySQLdb module f) ssh support Please make the best offer possible. Thank you. From nagia.retsina at gmail.com Tue Apr 2 16:57:01 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Tue, 2 Apr 2013 13:57:01 -0700 (PDT) Subject: Reseller Host with Python 3 support In-Reply-To: <3647b81f-a8ba-465d-9cca-ad508065a32f@googlegroups.com> References: <3647b81f-a8ba-465d-9cca-ad508065a32f@googlegroups.com> Message-ID: <1a67199b-f522-4b11-bfee-e6ac0ecd0c3c@googlegroups.com> An offer someone please? From gouzounakis at hotmail.com Tue Apr 2 11:39:07 2013 From: gouzounakis at hotmail.com (D. Xenakis) Date: Tue, 2 Apr 2013 08:39:07 -0700 (PDT) Subject: Help installing latest PyQT Message-ID: <9056d15b-1610-4e16-a2d7-f987c97fb7e9@googlegroups.com> Hi there im trying to install PyQT (version PyQt4-4.10-gpl-Py3.3-Qt5.0.1-x64-2.exe) but i dont know how to make sure i have installed everything correctly. I tried to find documentation about this but most links were very dead.. So far so good.. i have: 1)Downloaded and installed "Python 3.3.0 Windows X86-64 MSI Installer" from http://www.python.org/download/ , here: "C:\Python33" (i have 64 bit Win7 pro Greek edition) 2)Downloaded and unzipped "sip-4.14.5.zip" from http://www.riverbankcomputing.com/software/sip/download , here: "D:\Downloads\sip-4.14.5" (other than that, haven't played with this folder any further, cause i dont know what exactly i should do with that so everything is get properly done..) I suppose after having it unzipped, i should then move that somewhere (maybe here "C:\Python33") and then maybe run some commands but.. help needed here so i dont do something wrong, as this link http://goo.gl/UuLjz doesnt make that clear to me what exact steps i should follow :( . 3)Downloaded and installed "PyQt4-4.10-gpl-Py3.3-Qt5.0.1-x64-2.exe" from http://www.riverbankcomputing.com/software/pyqt/download , here: "C:\Python33" (It was the setup's default choice so i assumed it was also the right one). And thats it.. What should i do exactly now foks :) Thx in advance From drobinow at gmail.com Tue Apr 2 12:10:49 2013 From: drobinow at gmail.com (David Robinow) Date: Tue, 2 Apr 2013 12:10:49 -0400 Subject: Help installing latest PyQT In-Reply-To: <9056d15b-1610-4e16-a2d7-f987c97fb7e9@googlegroups.com> References: <9056d15b-1610-4e16-a2d7-f987c97fb7e9@googlegroups.com> Message-ID: On Tue, Apr 2, 2013 at 11:39 AM, D. Xenakis wrote: > Hi there im trying to install PyQT (version > PyQt4-4.10-gpl-Py3.3-Qt5.0.1-x64-2.exe) but i dont know how to make sure i > have installed everything correctly. I tried to find documentation about > this but most links were very dead.. > > So far so good.. i have: > 1)Downloaded and installed "Python 3.3.0 Windows X86-64 MSI Installer" > from http://www.python.org/download/ , here: "C:\Python33" (i have 64 bit > Win7 pro Greek edition) > > 2)Downloaded and unzipped "sip-4.14.5.zip" from > http://www.riverbankcomputing.com/software/sip/download , here: > "D:\Downloads\sip-4.14.5" (other than that, haven't played with this folder > any further, cause i dont know what exactly i should do with that so > everything is get properly done..) I suppose after having it unzipped, i > should then move that somewhere (maybe here "C:\Python33") and then maybe > run some commands but.. help needed here so i dont do something wrong, as > this link http://goo.gl/UuLjz doesnt make that clear to me what exact > steps i should follow :( . > sip is not required unless you're building PyQt from sources. You don't need to do anything with this. > > 3)Downloaded and installed "PyQt4-4.10-gpl-Py3.3-Qt5.0.1-x64-2.exe" from > http://www.riverbankcomputing.com/software/pyqt/download , here: > "C:\Python33" (It was the setup's default choice so i assumed it was also > the right one). > Yes. > > And thats it.. > > What should i do exactly now foks :) > You should be done.Start an interactive python and enter: >>>import PyQt4 If there's no traceback you're good to go. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nulla.epistola at web.de Tue Apr 2 15:44:43 2013 From: nulla.epistola at web.de (Sibylle Koczian) Date: Tue, 02 Apr 2013 21:44:43 +0200 Subject: Help installing latest PyQT In-Reply-To: References: <9056d15b-1610-4e16-a2d7-f987c97fb7e9@googlegroups.com> Message-ID: Am 02.04.2013 18:10, schrieb David Robinow: > On Tue, Apr 2, 2013 at 11:39 AM, D. Xenakis > wrote: > > 3)Downloaded and installed "PyQt4-4.10-gpl-Py3.3-Qt5.0.1-x64-2.exe" > from http://www.riverbankcomputing.com/software/pyqt/download , > here: "C:\Python33" (It was the setup's default choice so i assumed > it was also the right one). > > Yes. > > > And thats it.. > > What should i do exactly now foks :) > > You should be done.Start an interactive python and enter: > >>>import PyQt4 > > If there's no traceback you're good to go. > I'd try one thing more from that interactive python prompt: from PyQt4 import QtCore from PyQt4 import QtGui Do you get tracebacks with this? (I do, that's why I ask.) The examples that come with the installation usually do both imports in one line, but for a first test this may be better: if you get an error, you see a little more. HTH Sibylle From gouzounakis at hotmail.com Tue Apr 2 16:47:41 2013 From: gouzounakis at hotmail.com (D. Xenakis) Date: Tue, 2 Apr 2013 13:47:41 -0700 (PDT) Subject: Help installing latest PyQT In-Reply-To: References: <9056d15b-1610-4e16-a2d7-f987c97fb7e9@googlegroups.com> Message-ID: ?? ?????, 2 ???????? 2013 10:44:43 ?.?. UTC+3, ? ??????? Sibylle Koczian ??????: > Am 02.04.2013 18:10, schrieb David Robinow: > > > > > > 3)Downloaded and installed "PyQt4-4.10-gpl-Py3.3-Qt5.0.1-x64-2.exe" > > > from http://www.riverbankcomputing.com/software/pyqt/download , > > > here: "C:\Python33" (It was the setup's default choice so i assumed > > > it was also the right one). > > > > > > Yes. > > > > > > > > > And thats it.. > > > > > > What should i do exactly now foks :) > > > > > > You should be done.Start an interactive python and enter: > > > >>>import PyQt4 > > > > > > If there's no traceback you're good to go. > > > > > > > I'd try one thing more from that interactive python prompt: > > > > from PyQt4 import QtCore > > from PyQt4 import QtGui > > > > Do you get tracebacks with this? (I do, that's why I ask.) > > > > The examples that come with the installation usually do both imports in > > one line, but for a first test this may be better: if you get an error, > > you see a little more. > > > > HTH > > Sibylle from PyQt4 import QtCore from PyQt4 import QtGui I get no error using those on IDLE 3.3 From gouzounakis at hotmail.com Tue Apr 2 16:47:41 2013 From: gouzounakis at hotmail.com (D. Xenakis) Date: Tue, 2 Apr 2013 13:47:41 -0700 (PDT) Subject: Help installing latest PyQT In-Reply-To: References: <9056d15b-1610-4e16-a2d7-f987c97fb7e9@googlegroups.com> Message-ID: ?? ?????, 2 ???????? 2013 10:44:43 ?.?. UTC+3, ? ??????? Sibylle Koczian ??????: > Am 02.04.2013 18:10, schrieb David Robinow: > > > > > > 3)Downloaded and installed "PyQt4-4.10-gpl-Py3.3-Qt5.0.1-x64-2.exe" > > > from http://www.riverbankcomputing.com/software/pyqt/download , > > > here: "C:\Python33" (It was the setup's default choice so i assumed > > > it was also the right one). > > > > > > Yes. > > > > > > > > > And thats it.. > > > > > > What should i do exactly now foks :) > > > > > > You should be done.Start an interactive python and enter: > > > >>>import PyQt4 > > > > > > If there's no traceback you're good to go. > > > > > > > I'd try one thing more from that interactive python prompt: > > > > from PyQt4 import QtCore > > from PyQt4 import QtGui > > > > Do you get tracebacks with this? (I do, that's why I ask.) > > > > The examples that come with the installation usually do both imports in > > one line, but for a first test this may be better: if you get an error, > > you see a little more. > > > > HTH > > Sibylle from PyQt4 import QtCore from PyQt4 import QtGui I get no error using those on IDLE 3.3 From gouzounakis at hotmail.com Tue Apr 2 16:35:56 2013 From: gouzounakis at hotmail.com (D. Xenakis) Date: Tue, 2 Apr 2013 13:35:56 -0700 (PDT) Subject: Help installing latest PyQT In-Reply-To: <9056d15b-1610-4e16-a2d7-f987c97fb7e9@googlegroups.com> References: <9056d15b-1610-4e16-a2d7-f987c97fb7e9@googlegroups.com> Message-ID: <7d14b104-c5f6-424c-a75c-a4a4b7a89788@googlegroups.com> ?? ?????, 2 ???????? 2013 6:39:07 ?.?. UTC+3, ? ??????? D. Xenakis ??????: > Hi there im trying to install PyQT (version PyQt4-4.10-gpl-Py3.3-Qt5.0.1-x64-2.exe) but i dont know how to make sure i have installed everything correctly. I tried to find documentation about this but most links were very dead.. > > > > So far so good.. i have: > > 1)Downloaded and installed "Python 3.3.0 Windows X86-64 MSI Installer" from http://www.python.org/download/ , here: "C:\Python33" (i have 64 bit Win7 pro Greek edition) > > > > 2)Downloaded and unzipped "sip-4.14.5.zip" from http://www.riverbankcomputing.com/software/sip/download , here: "D:\Downloads\sip-4.14.5" (other than that, haven't played with this folder any further, cause i dont know what exactly i should do with that so everything is get properly done..) I suppose after having it unzipped, i should then move that somewhere (maybe here "C:\Python33") and then maybe run some commands but.. help needed here so i dont do something wrong, as this link http://goo.gl/UuLjz doesnt make that clear to me what exact steps i should follow :( . > > > > 3)Downloaded and installed "PyQt4-4.10-gpl-Py3.3-Qt5.0.1-x64-2.exe" from http://www.riverbankcomputing.com/software/pyqt/download , here: "C:\Python33" (It was the setup's default choice so i assumed it was also the right one). > > > > And thats it.. > > > > What should i do exactly now foks :) > > Thx in advance From gouzounakis at hotmail.com Tue Apr 2 16:42:02 2013 From: gouzounakis at hotmail.com (D. Xenakis) Date: Tue, 2 Apr 2013 13:42:02 -0700 (PDT) Subject: Help installing latest PyQT In-Reply-To: <9056d15b-1610-4e16-a2d7-f987c97fb7e9@googlegroups.com> References: <9056d15b-1610-4e16-a2d7-f987c97fb7e9@googlegroups.com> Message-ID: <34f2f92b-5ec1-4aa8-8080-7e550c0ff70d@googlegroups.com> I had also installed in the past python 2.7 . Now when im trying to run a .py, interpreter 2.7 is always being called.. (also when im right clicking and sellecting to run in IDLE, 2.7 is agai n starting instead of 3.3) so PyQt4 is crashing. Any tip to make 3.3 the default interpreter plz? From giovanni.buccinon at ipruniv.cce.unipr.it Tue Apr 2 07:34:30 2013 From: giovanni.buccinon at ipruniv.cce.unipr.it (Ghita) Date: Tue, 02 Apr 2013 07:34:30 -0400 Subject: L'applicazione e approvato. Message-ID: <005601ce2f96$053ff300$3906000a@server01.love-life.co.za> Su vostra richiesta, ha lasciato sul forum inviare una nuova legge. http://ftp.heljemo.com/Debito.zip?NRzXa4efa7Dut == Tel./Fax.: (070) 354 67 54 From maroso at libero.it Tue Apr 2 14:39:19 2013 From: maroso at libero.it (io) Date: 02 Apr 2013 18:39:19 GMT Subject: HTTP GET REQUEST WITH PARAMETERS Message-ID: <515b25d6$0$1365$4fafbaef@reader2.news.tin.it> HI, everyone, how can i make a HTTP GET REQUEST using python and passing parameters? I would like to recall my script from within openoffice basic and pass parameters to it. Some of the GET or POST are here : https://www.bitstamp.net/api/ thanks for anyhelp From breamoreboy at yahoo.co.uk Tue Apr 2 15:00:02 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 02 Apr 2013 20:00:02 +0100 Subject: HTTP GET REQUEST WITH PARAMETERS In-Reply-To: <515b25d6$0$1365$4fafbaef@reader2.news.tin.it> References: <515b25d6$0$1365$4fafbaef@reader2.news.tin.it> Message-ID: On 02/04/2013 19:39, io wrote: > HI, everyone, > > how can i make a HTTP GET REQUEST using python and passing parameters? > > I would like to recall my script from within openoffice basic and pass > parameters to it. > > Some of the GET or POST are here : https://www.bitstamp.net/api/ > > thanks for anyhelp > Easiest way I know is to use the highly rated requests module http://docs.python-requests.org/en/latest/ which is available on pypi. -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From svenito at gmail.com Tue Apr 2 18:18:58 2013 From: svenito at gmail.com (Sven) Date: Tue, 2 Apr 2013 23:18:58 +0100 Subject: Getting USB volume serial number from inserted device on OSX Message-ID: Hello, I am using Python 2.7 with pyobjc on Lion and NSNotification center to monitor any inserted USB volumes. This works fine. I've also got some ideas how to get a device's serial number, but these involve just parsing all the USB devices ('system_profiler SPUSBDataType' command). However I'd like to specifically query the inserted device only (the one creating the notification) rather than checking the entire USB device list. The latter seems a little inefficient and "wrong". Can this be accomplished in a sensible way? The NSNotification object passed to my handler function doesn't have that kind of information and I've not been able to find any information on doing the above with the information provided by the NSNotification object. I've tried DBus (I use this for the linux handler) but I've not had much luck getting it to work reliably on OS X and installing it wasn't as straightforward as I hoped. I have no requirement to use pyobjc so other suggestions welcome as long as it's straightforward to install and without too many other dependencies. I'd like to keep installation straightforward for the end users. Thanks -- ./Sven -------------- next part -------------- An HTML attachment was scrubbed... URL: From nad at acm.org Tue Apr 2 19:37:56 2013 From: nad at acm.org (Ned Deily) Date: Tue, 02 Apr 2013 16:37:56 -0700 Subject: Getting USB volume serial number from inserted device on OSX References: Message-ID: In article , Sven wrote: > I am using Python 2.7 with pyobjc on Lion and NSNotification center to > monitor any inserted USB volumes. This works fine. [...] Since your question really is about OS X APIs and not Python or even PyObjC, you're more likely to get a meaningful answer elsewhere. Try StackOverflow or one of the OS X lists. -- Ned Deily, nad at acm.org From svenito at gmail.com Wed Apr 3 04:14:13 2013 From: svenito at gmail.com (Sven) Date: Wed, 3 Apr 2013 09:14:13 +0100 Subject: Getting USB volume serial number from inserted device on OSX In-Reply-To: References: Message-ID: Apologies. The main app is in python, and I would like to know any alternative methods to do this in Python on OS X. Doesn't have to use the OS X APIs. I'll try elsewhere too though. Thanks On 3 April 2013 00:37, Ned Deily wrote: > In article > , > Sven wrote: > > I am using Python 2.7 with pyobjc on Lion and NSNotification center to > > monitor any inserted USB volumes. This works fine. > [...] > > Since your question really is about OS X APIs and not Python or even > PyObjC, you're more likely to get a meaningful answer elsewhere. Try > StackOverflow or one of the OS X lists. > > -- > Ned Deily, > nad at acm.org > > -- > http://mail.python.org/mailman/listinfo/python-list > -- ./Sven -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Thu Apr 4 21:58:42 2013 From: nagle at animats.com (John Nagle) Date: Thu, 04 Apr 2013 18:58:42 -0700 Subject: Getting USB volume serial number from inserted device on OSX In-Reply-To: References: Message-ID: On 4/2/2013 3:18 PM, Sven wrote: > Hello, > > I am using Python 2.7 with pyobjc on Lion and NSNotification center to > monitor any inserted USB volumes. This works fine. > > I've also got some ideas how to get a device's serial number, but these > involve just parsing all the USB devices ('system_profiler SPUSBDataType' > command). However I'd like to specifically query the inserted device only > (the one creating the notification) rather than checking the entire USB > device list. The latter seems a little inefficient and "wrong". That would be useful to have as a portable function for all USB devices. Serial port devices are particularly annoying, because their port number is somewhat random when there's more than one, and changes on hot-plugging. John Nagle From timr at probo.com Fri Apr 5 01:20:08 2013 From: timr at probo.com (Tim Roberts) Date: Thu, 04 Apr 2013 22:20:08 -0700 Subject: Getting USB volume serial number from inserted device on OSX References: Message-ID: <2knsl8t9uacsb612cd2kuv43ipr7djrcmg@4ax.com> John Nagle wrote: > > That would be useful to have as a portable function for all USB >devices. Serial port devices are particularly annoying, because their >port number is somewhat random when there's more than one, and changes >on hot-plugging. There is no portable solution. Every operating system handles this kind of this very differently. Remember, the operating system abstractions are all designed to hide this from you. When you open a serial port or an audio device or use a file system, you aren't supposed to KNOW that there is a USB device behind it. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From svenito at gmail.com Fri Apr 5 09:23:21 2013 From: svenito at gmail.com (Sven) Date: Fri, 5 Apr 2013 14:23:21 +0100 Subject: Getting USB volume serial number from inserted device on OSX In-Reply-To: <2knsl8t9uacsb612cd2kuv43ipr7djrcmg@4ax.com> References: <2knsl8t9uacsb612cd2kuv43ipr7djrcmg@4ax.com> Message-ID: On 5 April 2013 06:20, Tim Roberts wrote: > John Nagle wrote: > > > > That would be useful to have as a portable function for all USB > >devices. Serial port devices are particularly annoying, because their > >port number is somewhat random when there's more than one, and changes > >on hot-plugging. > > There is no portable solution. Every operating system handles this kind of > this very differently. Remember, the operating system abstractions are all > designed to hide this from you. When you open a serial port or an audio > device or use a file system, you aren't supposed to KNOW that there is a > USB device behind it > Indeed. Which means I have a working solution under Linux, but I am struggling to find one under OS X. Looks like I might have to resort to just parsing the USB tree until I find the device that was inserted. -- ./Sven -------------- next part -------------- An HTML attachment was scrubbed... URL: From cmpython at gmail.com Tue Apr 2 20:04:12 2013 From: cmpython at gmail.com (CM) Date: Tue, 2 Apr 2013 17:04:12 -0700 (PDT) Subject: Time zone changing while Win app is running Message-ID: <65e456f0-a59d-4461-9af9-d5bb1413d91f@p5g2000yqj.googlegroups.com> Although there is an answer to my concern posted on Stack Overflow[1], I thought I'd run this by the Python group to just get a read on it, since it strikes me as a concern. To summarize the issue: In an application, I have been using Python's datetime module to get the current time. But it seems that, at least with Windows (XP), whatever time zone your computer is set to when you start the application, that's what datetime will use--the time zone will *not* be updated in the application when you update it manually with Windows. So, if you change the time zone (say, after traveling with your laptop), all datetimes will be incorrect as compared to your system clock. The S.O. page has an answer that uses ctypes and Kernel32's GetLocalTime, and I've found I could do that, though it seems it would require me to substitute this for all uses of Python's datetime...and that is not a happy consideration at all. If I'm not using datetime, I am not using dateutil, not doing the same kind of date math, tons of rewriting... Not good. I haven't thought things through too well yet, but I was thinking I could get the correct system time via this ctypes based approach and then take that and turn it into a Python datetime to preserve all the benefits of datetime, but even that is going to be a lot of work for this corner case. Are things regarding this issue basically as I've understood them? I hope not. [1] http://stackoverflow.com/questions/4360981/make-python-respond-to-windows-timezone-changes) From steve+comp.lang.python at pearwood.info Wed Apr 3 03:37:33 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Apr 2013 07:37:33 GMT Subject: Time zone changing while Win app is running References: <65e456f0-a59d-4461-9af9-d5bb1413d91f@p5g2000yqj.googlegroups.com> Message-ID: <515bdc3d$0$29891$c3e8da3$5496439d@news.astraweb.com> On Tue, 02 Apr 2013 17:04:12 -0700, CM wrote: > To summarize the issue: In an application, I have been using Python's > datetime module to get the current time. But it seems that, at least > with Windows (XP), whatever time zone your computer is set to when you > start the application, that's what datetime will use--the time zone will > *not* be updated in the application when you update it manually with > Windows. So, if you change the time zone (say, after traveling with > your laptop), all datetimes will be incorrect as compared to your system > clock. I am not the maintainer of the datetime module, but based purely on what you have said, I would consider that a bug. I suggest you report it as an issue on the Python bug tracker. -- Steven From cmpython at gmail.com Wed Apr 3 14:46:48 2013 From: cmpython at gmail.com (CM) Date: Wed, 3 Apr 2013 11:46:48 -0700 (PDT) Subject: Time zone changing while Win app is running References: <65e456f0-a59d-4461-9af9-d5bb1413d91f@p5g2000yqj.googlegroups.com> <515bdc3d$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57d569df-8d29-4941-945d-46e416fc7016@n2g2000yqg.googlegroups.com> On Apr 3, 7:37?am, Steven D'Aprano wrote: > On Tue, 02 Apr 2013 17:04:12 -0700, CM wrote: > > To summarize the issue: ?In an application, I have been using Python's > > datetime module to get the current time. ?But it seems that, at least > > with Windows (XP), whatever time zone your computer is set to when you > > start the application, that's what datetime will use--the time zone will > > *not* be updated in the application when you update it manually with > > Windows. ?So, if you change the time zone (say, after traveling with > > your laptop), all datetimes will be incorrect as compared to your system > > clock. > > I am not the maintainer of the datetime module, but based purely on what > you have said, I would consider that a bug. I suggest you report it as an > issue on the Python bug tracker. Thanks, I submitted an issue about it. On 2.7.3, on Windows, it's easy to demonstrate: (Actual time = 2:40pm; tz = Eastern U.S.) > import datetime > print datetime.datetime.now() 2013-04-03 14:40:03.124000 <---- RIGHT (Now change time zone to UTC, for example. Now clock reads 6:41pm.) > import datetime > print datetime.datetime.now() 2013-04-03 14:41:13.124000 <---- WRONG ^ From cmpython at gmail.com Wed Apr 3 14:47:51 2013 From: cmpython at gmail.com (CM) Date: Wed, 3 Apr 2013 11:47:51 -0700 (PDT) Subject: Time zone changing while Win app is running References: <65e456f0-a59d-4461-9af9-d5bb1413d91f@p5g2000yqj.googlegroups.com> <515bdc3d$0$29891$c3e8da3$5496439d@news.astraweb.com> <57d569df-8d29-4941-945d-46e416fc7016@n2g2000yqg.googlegroups.com> Message-ID: > 2013-04-03 14:41:13.124000 ? ? <---- WRONG > ? ? ? ? ? ? ? ? ? ?^ (That carrot is supposed to be pointing to the 4 in 14, which should be 18.) From tjreedy at udel.edu Wed Apr 3 17:41:43 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Wed, 03 Apr 2013 17:41:43 -0400 Subject: Time zone changing while Win app is running In-Reply-To: <57d569df-8d29-4941-945d-46e416fc7016@n2g2000yqg.googlegroups.com> References: <65e456f0-a59d-4461-9af9-d5bb1413d91f@p5g2000yqj.googlegroups.com> <515bdc3d$0$29891$c3e8da3$5496439d@news.astraweb.com> <57d569df-8d29-4941-945d-46e416fc7016@n2g2000yqg.googlegroups.com> Message-ID: On 4/3/2013 2:46 PM, CM wrote: > On Apr 3, 7:37 am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> On Tue, 02 Apr 2013 17:04:12 -0700, CM wrote: >>> To summarize the issue: In an application, I have been using Python's >>> datetime module to get the current time. But it seems that, at least >>> with Windows (XP), whatever time zone your computer is set to when you >>> start the application, that's what datetime will use--the time zone will >>> *not* be updated in the application when you update it manually with >>> Windows. So, if you change the time zone (say, after traveling with >>> your laptop), all datetimes will be incorrect as compared to your system >>> clock. >> >> I am not the maintainer of the datetime module, but based purely on what >> you have said, I would consider that a bug. I don't. Do you really want every time function slowed by re-initializing the timezone? >> I suggest you report it as an issue on the Python bug tracker. I do believe that time.tzget can now be make to work now on Windows, and that would be a proper tracker issue. > > Thanks, I submitted an issue about it. On 2.7.3, on Windows, it's > easy to demonstrate: > > (Actual time = 2:40pm; tz = Eastern U.S.) > >> import datetime >> print datetime.datetime.now() > 2013-04-03 14:40:03.124000 <---- RIGHT > > (Now change time zone to UTC, for example. Now clock reads 6:41pm.) >> import datetime Without a restart, this is a no=op. >> print datetime.datetime.now() > 2013-04-03 14:41:13.124000 <---- WRONG As I said on the issue, passing a tz arg to now() will give the answer for any timezone on earth. A user-friendly app displaying times should let users choose. -- Terry Jan Reedy From cmpython at gmail.com Thu Apr 4 01:05:32 2013 From: cmpython at gmail.com (CM) Date: Wed, 3 Apr 2013 22:05:32 -0700 (PDT) Subject: Time zone changing while Win app is running References: <65e456f0-a59d-4461-9af9-d5bb1413d91f@p5g2000yqj.googlegroups.com> <515bdc3d$0$29891$c3e8da3$5496439d@news.astraweb.com> <57d569df-8d29-4941-945d-46e416fc7016@n2g2000yqg.googlegroups.com> Message-ID: > >> I am not the maintainer of the datetime module, but based purely on what > >> you have said, I would consider that a bug. > > I don't. Do you really want every time function slowed by > re-initializing the timezone? It depends; do you know what re-initializing entails and how costly that would be? I don't. The way I was thinking of it is, if the documentation for datetime.datetime.now() is (to begin), "Return the current local date and time." ...then, at least in the cases in which one changes one's system timezone during a running Python instance*, the docs are just not accurate for this method. (*which is not such a corner case given laptops that travel with us across them--often this timezone crossing is fundamental to one's work with that laptop) > I do believe that time.tzget can now be make to work now on Windows, and > that would be a proper tracker issue. Can you elaborate on how this would help my case? > > (Now change time zone to UTC, for example. ?Now clock reads 6:41pm.) > >> import datetime > > Without a restart, this is a no=op. Whoops, thanks; I just copied and pasted it twice. > As I said on the issue, passing a tz arg to now() will give the answer > for any timezone on earth. A user-friendly app displaying times should > let users choose. Are you saying that the app should require that the user enter their current time zone into the whenever they change time zones (in addition to their changing it in the Windows system clock)? And then using that tz in every call to datetime.datetime.now()? Thanks. From sg552 at hotmail.co.uk Tue Apr 2 21:05:31 2013 From: sg552 at hotmail.co.uk (Rotwang) Date: Wed, 03 Apr 2013 02:05:31 +0100 Subject: Decorating functions without losing their signatures Message-ID: Hi all, Here's a Python problem I've come up against and my crappy solution. Hopefully someone here can suggest something better. I want to decorate a bunch of functions with different signatures; for example, I might want to add some keyword-only arguments to all functions that return instances of a particular class so that the caller can create instances with additional attributes. So I do something like this: import functools def mydecorator(f): @functools.wraps(f) def wrapped(*args, attribute = None, **kwargs): result = f(*args, **kwargs) result.attribute = attribute return result return wrapped @mydecorator def f(x, y = 1, *a, z = 2, **k): return something The problem with this is, when I subsequently type 'f(' in IDLE, the signature prompt that appears is not very useful; it looks like this: (*args, attribute=None, **kwargs) whereas I'd like it to look like this: (x, y=1, *a, z=2, attribute=None, **k) After thinking about it for a while I've come up with the following abomination: import inspect def sigwrapper(sig): if not isinstance(sig, inspect.Signature): sig = inspect.signature(sig) def wrapper(f): ps = 'args = []\n\t\t' ks = 'kwargs = {}\n\t\t' for p in sig.parameters.values(): if p.kind in (p.POSITIONAL_ONLY, p.POSITIONAL_OR_KEYWORD): ps = '%sargs.append(%s)\n\t\t' % (ps, p.name) elif p.kind == p.VAR_POSITIONAL: ps = '%sargs.extend(%s)\n\t\t' % (ps, p.name) elif p.kind == p.KEYWORD_ONLY: ks = '%skwargs[%r] = %s\n\t\t' % (ks, p.name, p.name) elif p.kind == p.VAR_KEYWORD: ks = '%skwargs.update(%s)\n\t\t' % (ks, p.name) loc = {'wrapped': f} defstring = ('def wrapouter(wrapped = wrapped):' '\n\tdef wrapinner%s:' '\n\t\t%s%sreturn wrapped(*args, **kwargs)' '\n\treturn wrapinner' % (sig, ps, ks)) exec(defstring, f.__globals__, loc) return loc['wrapouter']() return wrapper The function sigwrapper() may be passed an inspect.Signature object sig (or function, if that function has the right signature) and returns a decorator that gives any function the signature sig. I can then replace my original decorator with something like def mydecorator(f): sig = inspect.signature(f) sig = do_something(sig) # add an additional kw-only argument to sig @functools.wraps(f) @sigwrapper(sig) def wrapped(*args, attribute = None, **kwargs): result = f(*args, **kwargs) result.attribute = attribute return result return wrapped It seems to work, but I don't like it. Does anyone know of a better way of doing the same thing? From steve+comp.lang.python at pearwood.info Wed Apr 3 00:15:05 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Apr 2013 04:15:05 GMT Subject: Decorating functions without losing their signatures References: Message-ID: <515bacc8$0$29891$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Apr 2013 02:05:31 +0100, Rotwang wrote: > Hi all, > > Here's a Python problem I've come up against and my crappy solution. > Hopefully someone here can suggest something better. I want to decorate > a bunch of functions with different signatures; [...] > After thinking about it for a while I've come up with the following > abomination: [...] > It seems to work, but I don't like it. Does anyone know of a better way > of doing the same thing? Wait until Python 3.4 or 3.5 (or Python 4000?) when functools.wraps automatically preserves the function signature? Alas, I think this is a hard problem to solve with current Python. You might like to compare your solution with that of Michele Simionato's "decorator" module: http://micheles.googlecode.com/hg/decorator/documentation.html See this for some other ideas: http://numericalrecipes.wordpress.com/2009/05/25/signature-preserving- function-decorators/ Good luck! -- Steven From sg552 at hotmail.co.uk Wed Apr 3 21:53:30 2013 From: sg552 at hotmail.co.uk (Rotwang) Date: Thu, 04 Apr 2013 02:53:30 +0100 Subject: Decorating functions without losing their signatures In-Reply-To: <515bacc8$0$29891$c3e8da3$5496439d@news.astraweb.com> References: <515bacc8$0$29891$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 03/04/2013 05:15, Steven D'Aprano wrote: > On Wed, 03 Apr 2013 02:05:31 +0100, Rotwang wrote: > >> Hi all, >> >> Here's a Python problem I've come up against and my crappy solution. >> Hopefully someone here can suggest something better. I want to decorate >> a bunch of functions with different signatures; > [...] >> After thinking about it for a while I've come up with the following >> abomination: > [...] >> It seems to work, but I don't like it. Does anyone know of a better way >> of doing the same thing? > > > Wait until Python 3.4 or 3.5 (or Python 4000?) when functools.wraps > automatically preserves the function signature? > > Alas, I think this is a hard problem to solve with current Python. You > might like to compare your solution with that of Michele Simionato's > "decorator" module: > > http://micheles.googlecode.com/hg/decorator/documentation.html > > > See this for some other ideas: > > http://numericalrecipes.wordpress.com/2009/05/25/signature-preserving- > function-decorators/ > > > > Good luck! Thanks. It'll take me a while to fully absorb the links, but it looks like both are similarly based on abusing the exec function. Thanks to Jan too. From janpeterr at freenet.de Wed Apr 3 01:06:11 2013 From: janpeterr at freenet.de (Jan Riechers) Date: Wed, 03 Apr 2013 08:06:11 +0300 Subject: Decorating functions without losing their signatures In-Reply-To: References: Message-ID: <515BB8C3.6010107@freenet.de> On 03.04.2013 04:05, Rotwang wrote: > Hi all, > > Here's a Python problem I've come up against and my crappy solution. > Hopefully someone here can suggest something better. I want to decorate > a bunch of functions with different signatures; for example, I might > want to add some keyword-only arguments to all functions that return > instances of a particular class so that the caller can create instances > with additional attributes. So I do something like this: [...] > It seems to work, but I don't like it. Does anyone know of a better way > of doing the same thing? Hi, I think you might want to check out that Pycon2013 Video about Metaclass Prgoramming of David Beazley: http://www.pyvideo.org/video/1716/python-3-metaprogramming He explains how to passing attributes, such creating custom classes on demand and returning there signatures even when wrapped. I think that was what you wanted to archive? Regards Jan From michele.simionato at gmail.com Wed Apr 3 21:18:47 2013 From: michele.simionato at gmail.com (Michele Simionato) Date: Wed, 3 Apr 2013 18:18:47 -0700 (PDT) Subject: Decorating functions without losing their signatures In-Reply-To: References: Message-ID: On Wednesday, April 3, 2013 3:05:31 AM UTC+2, Rotwang wrote: > After thinking about it for a while I've come up with the following > > abomination Alas, there is actually no good way to implement this feature in pure Python without abominations. Internally the decorator module does something similar to what you are doing. However, instead of cooking up yourself your custom solution, it is probably better if you stick to the decorator module which has been used in production for several years and has hundreds of thousands of downloads. I am not claiming that it is bug free, but it is stable, bug reports come very rarely and it works for all versions of Python from 2.5 to 3.3. From sg552 at hotmail.co.uk Wed Apr 3 22:17:58 2013 From: sg552 at hotmail.co.uk (Rotwang) Date: Thu, 04 Apr 2013 03:17:58 +0100 Subject: Decorating functions without losing their signatures In-Reply-To: References: Message-ID: On 04/04/2013 02:18, Michele Simionato wrote: > On Wednesday, April 3, 2013 3:05:31 AM UTC+2, Rotwang wrote: >> After thinking about it for a while I've come up with the following >> >> abomination > > Alas, there is actually no good way to implement this feature in pure > Python without abominations. Internally the decorator module does > something similar to what you are doing. However, instead of cooking up > yourself your custom solution, it is probably better if you stick to > the decorator module which has been used in production for several > years and has hundreds of thousands of downloads. I am not claiming > that it is bug free, but it is stable, bug reports come very rarely and > it works for all versions of Python from 2.5 to 3.3. Thanks, I'll check it out. Looking at the link Steven provided, I didn't see an easy way to add additional keyword-only arguments to a function's signature, though (but then I've yet to figure out how the FunctionMaker class works). From sg552 at hotmail.co.uk Wed Apr 3 21:44:40 2013 From: sg552 at hotmail.co.uk (Rotwang) Date: Thu, 04 Apr 2013 02:44:40 +0100 Subject: Decorating functions without losing their signatures In-Reply-To: References: Message-ID: On 03/04/2013 02:05, Rotwang wrote: > [...] > > After thinking about it for a while I've come up with the following > abomination: > > import inspect > > def sigwrapper(sig): > if not isinstance(sig, inspect.Signature): > sig = inspect.signature(sig) > def wrapper(f): > ps = 'args = []\n\t\t' > ks = 'kwargs = {}\n\t\t' > for p in sig.parameters.values(): > if p.kind in (p.POSITIONAL_ONLY, p.POSITIONAL_OR_KEYWORD): > ps = '%sargs.append(%s)\n\t\t' % (ps, p.name) > elif p.kind == p.VAR_POSITIONAL: > ps = '%sargs.extend(%s)\n\t\t' % (ps, p.name) > elif p.kind == p.KEYWORD_ONLY: > ks = '%skwargs[%r] = %s\n\t\t' % (ks, p.name, p.name) > elif p.kind == p.VAR_KEYWORD: > ks = '%skwargs.update(%s)\n\t\t' % (ks, p.name) > loc = {'wrapped': f} > defstring = ('def wrapouter(wrapped = wrapped):' > '\n\tdef wrapinner%s:' > '\n\t\t%s%sreturn wrapped(*args, **kwargs)' > '\n\treturn wrapinner' % (sig, ps, ks)) > exec(defstring, f.__globals__, loc) > return loc['wrapouter']() > return wrapper Oops! Earlier I found out the hard way that this fails when the decorated function has arguments called 'args' or 'kwargs'. Here's a modified version that fixes said bug, but presumably not the many others I haven't noticed yet: def sigwrapper(sig): if not isinstance(sig, inspect.Signature): sig = inspect.signature(sig) n = 0 while True: pn = 'p_%i' % n kn = 'k_%i' % n if pn not in sig.parameters and kn not in sig.parameters: break n += 1 ps = '%s = []\n\t\t' % pn ks = '%s = {}\n\t\t' % kn for p in sig.parameters.values(): if p.kind in (p.POSITIONAL_ONLY, p.POSITIONAL_OR_KEYWORD): ps = '%s%s.append(%s)\n\t\t' % (ps, pn, p.name) elif p.kind == p.VAR_POSITIONAL: ps = '%s%s.extend(%s)\n\t\t' % (ps, pn, p.name) elif p.kind == p.KEYWORD_ONLY: ks = '%s%s[%r] = %s\n\t\t' % (ks, kn, p.name, p.name) elif p.kind == p.VAR_KEYWORD: ks = '%s%s.update(%s)\n\t\t' % (ks, kn, p.name) defstring = ('def wrapouter(wrapped = wrapped):' '\n\tdef wrapinner%s:' '\n\t\t%s%sreturn wrapped(*%s, **%s)' '\n\treturn wrapinner' % (sig, ps, ks, pn, kn)) def wrapper(f): loc = {'wrapped': f} exec(defstring, f.__globals__, loc) return loc['wrapouter']() return wrapper From alec.taylor6 at gmail.com Wed Apr 3 02:14:58 2013 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Wed, 3 Apr 2013 17:14:58 +1100 Subject: How to choose between ORMs? Message-ID: SQLalchemy and Storm are a few of the popular ORMs out there. Personally I have been using web2py's DAL. Other than form generator availability, 'print as raw SQL', multiple primary keys, widgets*, `check` conditions and compatibility with OracleDB, Postgres, SQLite and some of the NoSQL systems; what else should I be looking for? Thanks for all suggestions, Alec Taylor *not sure if widgets should be a requirement; by widgets I mean annotation of db schema to specify which widget to use with the form generator PS: Will likely use this ORM with: Flask, Bottle or Twisted Matrix From roy at panix.com Wed Apr 3 09:16:07 2013 From: roy at panix.com (Roy Smith) Date: Wed, 03 Apr 2013 09:16:07 -0400 Subject: How to choose between ORMs? References: Message-ID: In article , Alec Taylor wrote: > SQLalchemy and Storm are a few of the popular ORMs out there. > > Personally I have been using web2py's DAL. > > Other than form generator availability, 'print as raw SQL', multiple > primary keys, widgets*, `check` conditions and compatibility with > OracleDB, Postgres, SQLite and some of the NoSQL systems; what else > should I be looking for? Depending on what you're doing, schema discovery (aka introspection, reflection, etc) may or may not be important to you. And it should come with a nice shrubbery. From rodrick.brown at gmail.com Wed Apr 3 13:05:30 2013 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Wed, 3 Apr 2013 13:05:30 -0400 Subject: How to choose between ORMs? In-Reply-To: References: Message-ID: <-3028215168351722430@unknownmsgid> Pick the one you learn and know. Sent from my iPhone On Apr 3, 2013, at 2:17 AM, Alec Taylor wrote: > SQLalchemy and Storm are a few of the popular ORMs out there. > > Personally I have been using web2py's DAL. > > Other than form generator availability, 'print as raw SQL', multiple > primary keys, widgets*, `check` conditions and compatibility with > OracleDB, Postgres, SQLite and some of the NoSQL systems; what else > should I be looking for? > > Thanks for all suggestions, > > Alec Taylor > > *not sure if widgets should be a requirement; by widgets I mean > annotation of db schema to specify which widget to use with the form > generator > > PS: Will likely use this ORM with: Flask, Bottle or Twisted Matrix > -- > http://mail.python.org/mailman/listinfo/python-list From alec.taylor6 at gmail.com Thu Apr 4 01:38:45 2013 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Thu, 4 Apr 2013 16:38:45 +1100 Subject: How to choose between ORMs? In-Reply-To: <-3028215168351722430@unknownmsgid> References: <-3028215168351722430@unknownmsgid> Message-ID: I know None. Currently I use web2py's; which is a DAL not an ORM. On Thu, Apr 4, 2013 at 4:05 AM, Rodrick Brown wrote: > Pick the one you learn and know. > > Sent from my iPhone > > On Apr 3, 2013, at 2:17 AM, Alec Taylor wrote: > >> SQLalchemy and Storm are a few of the popular ORMs out there. >> >> Personally I have been using web2py's DAL. >> >> Other than form generator availability, 'print as raw SQL', multiple >> primary keys, widgets*, `check` conditions and compatibility with >> OracleDB, Postgres, SQLite and some of the NoSQL systems; what else >> should I be looking for? >> >> Thanks for all suggestions, >> >> Alec Taylor >> >> *not sure if widgets should be a requirement; by widgets I mean >> annotation of db schema to specify which widget to use with the form >> generator >> >> PS: Will likely use this ORM with: Flask, Bottle or Twisted Matrix >> -- >> http://mail.python.org/mailman/listinfo/python-list From gouzounakis at hotmail.com Wed Apr 3 04:44:31 2013 From: gouzounakis at hotmail.com (D. Xenakis) Date: Wed, 3 Apr 2013 01:44:31 -0700 (PDT) Subject: Make python 3.3 the default one and not 2.7 Message-ID: Hi there, i installed python 2.7 (windows 32bit version) from http://www.enthought.com/products/epd_free.php and after that i installed official 3.3 version too. So now i got two python folders like this.. c:/Python27 and c:/Python33 . My problem is that when im trying to execute a .py file, the 2.7 version interpreter launces. In addition if i right click and select Edit with IDLE, again version 2.7 interpreter opens. How can i make python 3.3 the default one, as i need this cause i have PyQt4 installed there and so it does not work with 2.7 . Thx in advance. From wolfgang.maier at biologie.uni-freiburg.de Wed Apr 3 05:43:43 2013 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Wed, 3 Apr 2013 09:43:43 +0000 (UTC) Subject: Make python 3.3 the default one and not 2.7 References: Message-ID: D. Xenakis hotmail.com> writes: > > Hi there, i installed python 2.7 (windows 32bit version) from > http://www.enthought.com/products/epd_free.php and after that i installed official 3.3 version > too. So now i got two python folders like this.. c:/Python27 and c:/Python33 . > My problem is that when im trying to execute a .py file, the 2.7 version interpreter launces. In addition if i > right click and select Edit with IDLE, again version 2.7 interpreter opens. How can i make python 3.3 the > default one, as i need this cause i have PyQt4 installed there and so it does not work with 2.7 . > Thx in advance. > Check out the post at http://stackoverflow.com/questions/4664646/how-to-change-default-python-version-on-windows-xp . Especially the part about changing the registry. The Python.File entry mentioned there also has the information about the IDLE version to use. Best, Wolfgang From davea at davea.name Wed Apr 3 06:24:32 2013 From: davea at davea.name (Dave Angel) Date: Wed, 03 Apr 2013 06:24:32 -0400 Subject: Make python 3.3 the default one and not 2.7 In-Reply-To: References: Message-ID: <515C0360.4060301@davea.name> On 04/03/2013 04:44 AM, D. Xenakis wrote: > Hi there, i installed python 2.7 (windows 32bit version) from http://www.enthought.com/products/epd_free.php and after that i installed official 3.3 version too. So now i got two python folders like this.. c:/Python27 and c:/Python33 . > My problem is that when im trying to execute a .py file, the 2.7 version interpreter launces. In addition if i right click and select Edit with IDLE, again version 2.7 interpreter opens. How can i make python 3.3 the default one, as i need this cause i have PyQt4 installed there and so it does not work with 2.7 . > Thx in advance. > That was one of the choices you were presented with during the install. It defaults to making the newly installed one the default, but there was a checkbox or something. (It's been years since I did a Windows install, so I don't really remember) Anyway, if Wolfgang's link doesn't do it for you, consider re-installing 3.3. It should just go on top of the existing one, and the only change should be that it would then become the default one. -- DaveA From breamoreboy at yahoo.co.uk Wed Apr 3 08:19:27 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 03 Apr 2013 13:19:27 +0100 Subject: Make python 3.3 the default one and not 2.7 In-Reply-To: References: Message-ID: On 03/04/2013 09:44, D. Xenakis wrote: > Hi there, i installed python 2.7 (windows 32bit version) from http://www.enthought.com/products/epd_free.php and after that i installed official 3.3 version too. So now i got two python folders like this.. c:/Python27 and c:/Python33 . > My problem is that when im trying to execute a .py file, the 2.7 version interpreter launces. In addition if i right click and select Edit with IDLE, again version 2.7 interpreter opens. How can i make python 3.3 the default one, as i need this cause i have PyQt4 installed there and so it does not work with 2.7 . > Thx in advance. > Not quite answering your question but are you aware of http://docs.python.org/3/using/windows.html#launcher ? -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From gouzounakis at hotmail.com Wed Apr 3 09:23:45 2013 From: gouzounakis at hotmail.com (D. Xenakis) Date: Wed, 3 Apr 2013 06:23:45 -0700 (PDT) Subject: Make python 3.3 the default one and not 2.7 In-Reply-To: References: Message-ID: <110af028-2d33-4120-823e-9c27bdfafeee@googlegroups.com> I tried to reinstall python 3.3 but there was not change :(. I selected to run all component from my PC. I'll give it a try with those registries. From gouzounakis at hotmail.com Wed Apr 3 09:23:45 2013 From: gouzounakis at hotmail.com (D. Xenakis) Date: Wed, 3 Apr 2013 06:23:45 -0700 (PDT) Subject: Make python 3.3 the default one and not 2.7 In-Reply-To: References: Message-ID: <110af028-2d33-4120-823e-9c27bdfafeee@googlegroups.com> I tried to reinstall python 3.3 but there was not change :(. I selected to run all component from my PC. I'll give it a try with those registries. From gouzounakis at hotmail.com Wed Apr 3 10:19:16 2013 From: gouzounakis at hotmail.com (D. Xenakis) Date: Wed, 3 Apr 2013 07:19:16 -0700 (PDT) Subject: Make python 3.3 the default one and not 2.7 In-Reply-To: References: Message-ID: ?? ???????, 3 ???????? 2013 12:43:43 ?.?. UTC+3, ? ??????? Wolfgang Maier ??????: > D. Xenakis hotmail.com> writes: > > > > > > > > Hi there, i installed python 2.7 (windows 32bit version) from > > > http://www.enthought.com/products/epd_free.php and after that i installed > > official 3.3 version > > > too. So now i got two python folders like this.. c:/Python27 and c:/Python33 . > > > My problem is that when im trying to execute a .py file, the 2.7 version > > interpreter launces. In addition if i > > > right click and select Edit with IDLE, again version 2.7 interpreter opens. > > How can i make python 3.3 the > > > default one, as i need this cause i have PyQt4 installed there and so it does > > not work with 2.7 . > > > Thx in advance. > > > > > > > Check out the post at > > http://stackoverflow.com/questions/4664646/how-to-change-default-python-version-on-windows-xp > > . > > Especially the part about changing the registry. The Python.File entry mentioned > > there also has the information about the IDLE version to use. > > Best, > > Wolfgang I changed this too Python.CompiledFile to my 33 version. Should i not touch this key? From gouzounakis at hotmail.com Wed Apr 3 10:19:16 2013 From: gouzounakis at hotmail.com (D. Xenakis) Date: Wed, 3 Apr 2013 07:19:16 -0700 (PDT) Subject: Make python 3.3 the default one and not 2.7 In-Reply-To: References: Message-ID: ?? ???????, 3 ???????? 2013 12:43:43 ?.?. UTC+3, ? ??????? Wolfgang Maier ??????: > D. Xenakis hotmail.com> writes: > > > > > > > > Hi there, i installed python 2.7 (windows 32bit version) from > > > http://www.enthought.com/products/epd_free.php and after that i installed > > official 3.3 version > > > too. So now i got two python folders like this.. c:/Python27 and c:/Python33 . > > > My problem is that when im trying to execute a .py file, the 2.7 version > > interpreter launces. In addition if i > > > right click and select Edit with IDLE, again version 2.7 interpreter opens. > > How can i make python 3.3 the > > > default one, as i need this cause i have PyQt4 installed there and so it does > > not work with 2.7 . > > > Thx in advance. > > > > > > > Check out the post at > > http://stackoverflow.com/questions/4664646/how-to-change-default-python-version-on-windows-xp > > . > > Especially the part about changing the registry. The Python.File entry mentioned > > there also has the information about the IDLE version to use. > > Best, > > Wolfgang I changed this too Python.CompiledFile to my 33 version. Should i not touch this key? From wolfgang.maier at biologie.uni-freiburg.de Wed Apr 3 10:36:09 2013 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Wed, 3 Apr 2013 14:36:09 +0000 (UTC) Subject: Make python 3.3 the default one and not 2.7 References: Message-ID: D. Xenakis hotmail.com> writes: > > The Python.File entry mentioned > > there also has the information about the IDLE version to use. > > > > Best, > > > > Wolfgang > > I changed this too Python.CompiledFile to my 33 version. > Should i not touch this key? The [.CompiledFile\shell\open\command] sets the python version used for running pre-compiled .pyc files. Likewise, [.NoConFile\shell\open\command] sets it for .pyw files (intended to be run not from a console window - hence the name of the entry). Usually, you will want to have all of them point to the same Python version. Best, Wolfgang From gouzounakis at hotmail.com Wed Apr 3 15:44:26 2013 From: gouzounakis at hotmail.com (D. Xenakis) Date: Wed, 3 Apr 2013 12:44:26 -0700 (PDT) Subject: Make python 3.3 the default one and not 2.7 In-Reply-To: References: Message-ID: thx solved From therve at free.fr Wed Apr 3 07:11:21 2013 From: therve at free.fr (=?ISO-8859-1?Q?Thomas_Herv=E9?=) Date: Wed, 03 Apr 2013 13:11:21 +0200 Subject: Twisted 13.0.0 released Message-ID: <515C0E59.8070109@free.fr> On behalf of Twisted Matrix Laboratories, I am pleased to announce the release of Twisted 13.0. Among the 70 tickets closed, we can see: * A new "Introduction to Deferreds" document that you can find here: http://twistedmatrix.com/documents/13.0.0/core/howto/defer-intro.html * A fix in twisted.web.template where attributes were not quoted properly, risking HTML injection. * Support for unicode domain names in twisted.names SRVConnector and Name classes, after a 12.3 regression. * A workaround for platform limitations when trying to schedule events far in the future. For more information, see the NEWS file here: http://twistedmatrix.com/Releases/Twisted/13.0/NEWS.txt Download it now from: http://pypi.python.org/packages/source/T/Twisted/Twisted-13.0.0.tar.bz2 or http://pypi.python.org/packages/2.7/T/Twisted/Twisted-13.0.0.win32-py2.7.msi Thanks to the supporters of Twisted via the Software Freedom Conservancy and to the many contributors for this release. -- Thomas From glyph at twistedmatrix.com Wed Apr 3 17:36:28 2013 From: glyph at twistedmatrix.com (Glyph) Date: Wed, 3 Apr 2013 14:36:28 -0700 Subject: [Twisted-Python] Twisted 13.0.0 released In-Reply-To: <515C0E59.8070109@free.fr> References: <515C0E59.8070109@free.fr> Message-ID: <9F157DE3-726F-405C-AC11-94904D8D9380@twistedmatrix.com> On Apr 3, 2013, at 4:11 AM, Thomas Herv? wrote: > On behalf of Twisted Matrix Laboratories, I am pleased to announce the > release of Twisted 13.0. Thank you Thomas for managing yet another excellent release! > Among the 70 tickets closed, we can see: > > * A new "Introduction to Deferreds" document that you can find here: > http://twistedmatrix.com/documents/13.0.0/core/howto/defer-intro.html > > * A fix in twisted.web.template where attributes were not quoted > properly, risking HTML injection. > > * Support for unicode domain names in twisted.names SRVConnector and > Name classes, after a 12.3 regression. > > * A workaround for platform limitations when trying to schedule events > far in the future. This is a great list. And we have even more great stuff in the pipeline. Everybody get to work on 13.1 ;-). -glyph From _ at lvh.cc Wed Apr 3 17:59:38 2013 From: _ at lvh.cc (Laurens Van Houtven) Date: Wed, 3 Apr 2013 23:59:38 +0200 Subject: [Twisted-Python] Twisted 13.0.0 released In-Reply-To: <515C0E59.8070109@free.fr> References: <515C0E59.8070109@free.fr> Message-ID: Yay! Thanks, Thomas and everyone who contributed to this release :) On Wed, Apr 3, 2013 at 1:11 PM, Thomas Herv? wrote: > On behalf of Twisted Matrix Laboratories, I am pleased to announce the > release of Twisted 13.0. > > Among the 70 tickets closed, we can see: > > * A new "Introduction to Deferreds" document that you can find here: > http://twistedmatrix.com/documents/13.0.0/core/howto/defer-intro.html > > * A fix in twisted.web.template where attributes were not quoted > properly, risking HTML injection. > > * Support for unicode domain names in twisted.names SRVConnector and > Name classes, after a 12.3 regression. > > * A workaround for platform limitations when trying to schedule events > far in the future. > > > For more information, see the NEWS file here: > > http://twistedmatrix.com/Releases/Twisted/13.0/NEWS.txt > > > Download it now from: > > http://pypi.python.org/packages/source/T/Twisted/Twisted-13.0.0.tar.bz2or > > > http://pypi.python.org/packages/2.7/T/Twisted/Twisted-13.0.0.win32-py2.7.msi > > > Thanks to the supporters of Twisted via the Software Freedom Conservancy > and to the many contributors for this release. > > -- > Thomas > > _______________________________________________ > Twisted-Python mailing list > Twisted-Python at twistedmatrix.com > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python > -- cheers lvh -------------- next part -------------- An HTML attachment was scrubbed... URL: From sambez_14 at hotmail.co.uk Wed Apr 3 09:39:04 2013 From: sambez_14 at hotmail.co.uk (Sam Berry) Date: Wed, 3 Apr 2013 06:39:04 -0700 (PDT) Subject: Threading within a GUI and OpenCV Message-ID: Hey, I'm fairly new to python, and have had no experience with threading. Iv made a small GUI App using the kivy module and OpenCV, i have currently got a button that when pressed runs a function that records from my webcam for 20 seconds. However i have two other buttons, that when pressed i want to stop the recording. However when the button to record has been pressed the App freezes until the recording function has finished. I have read that threading can be used to run a function as a deamon? so that other functions can be ran simultaneously? I was just wondering if this would be the way to go, or if there are alternative routes? A snippet from my code can be seen at (http://pastebin.com/9uFRjkgV) with a failed attempt of using threading! Any help would be appreciated. Thanks, Sam From andrea.crotti.0 at gmail.com Wed Apr 3 10:04:51 2013 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Wed, 3 Apr 2013 15:04:51 +0100 Subject: Mixin way? Message-ID: I have some classes that have shared behaviours, for example in our scenario an object can be "visited", where something that is visitable would have some behaviour like --8<---------------cut here---------------start------------->8--- class Visitable(Mixin): FIELDS = { 'visits': [], 'unique_visits': 0, } def record_view(self, who, when): self.visits += {'who': who, 'when': when} self.unique_visits += 1 --8<---------------cut here---------------end--------------->8--- Where the Mixin class simply initialises the attributes: --8<---------------cut here---------------start------------->8--- class Mixin(object): def __init__(self, **kwargs): for key, val in self.FIELDS.items(): setattr(self, key, val) for key, val in kwargs.items(): if key in self.FIELDS: setattr(self, key, val) --8<---------------cut here---------------end--------------->8--- So now I'm not sure how to use it though. One way would be multiple subclasses class MyObjectBase(object): pass class MyObj(MyObjectBase, Visitable): pass for example. This solution is probably easy, but at the same time disturbing because MyObjectBase is semantically quite different from Visitable, so subclassing from both seems wrong.. The other solution (which is what is partially done now) is to use another class attribute: class ObjectWithMixin(CouchObject): MIXINS = [Visitable] and then do all the smart things needed: - at object construction time - when setting attributes and so on.. This solution is more complicated to implement but maybe is more flexible and more "correct", what do you think? -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Wed Apr 3 11:47:20 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 03 Apr 2013 15:47:20 GMT Subject: Mixin way? References: Message-ID: <515c4f07$0$29966$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Apr 2013 15:04:51 +0100, andrea crotti wrote: > I have some classes that have shared behaviours, for example in our > scenario an object can be "visited", where something that is visitable > would have some behaviour like [snip mixins] By the way, it's a common convention to name mixin classes as "SpamMixin". > So now I'm not sure how to use it though. > One way would be multiple subclasses > > class MyObjectBase(object): > pass > > class MyObj(MyObjectBase, Visitable): > pass > > for example. What's the purpose of MyObjectBase? Either your example is too simple, or it actually has no purpose, and you should simply write: class MyObj(object, VisitableMixin): # code goes here instead of having one extra layer in the inheritance hierarchy. > This solution is probably easy, but at the same time disturbing because > MyObjectBase is semantically quite different from Visitable, so > subclassing from both seems wrong.. Not really. From what you describe, this seems to be exactly the use-case for mixins. Yes, mixins are by definition somewhat of an abuse of Object- Oriented concepts. Mixins don't so much represent a "type of thing" as a convenient bundle of encapsulated behaviour and/or state. E.g. MyObj represents some sort of "MyObj thing" (or at least it *should*, if your OO classes are well-planned), but Visitable(Mixin) does not represent a thing at all. But here's a way to look at it to justify the concept of mixins. Think of regular classes and subclasses as representing trees of descent, like biological groups: Animal -> Mammal -> Rodent -> Porcupine Animal -> Monotreme -> Echidna Then mixins represent convergent evolution of some trait: Animal -> Mammal -> Rodent + QuillsMixin -> Porcupine Animal -> Monotreme + QuillsMixin -> Echidna > The other solution (which is what is partially done now) is to use > another class attribute: > > class ObjectWithMixin(CouchObject): > MIXINS = [Visitable] > > and then do all the smart things needed: > - at object construction time > - when setting attributes and so on.. > > This solution is more complicated to implement but maybe is more > flexible and more "correct", what do you think? I think that's worse. You seem to have *almost* stumbled onto the design pattern known as "composition" or "delegation", only not quite. Normal class-based design models a "is-a" relationship. "Lassie is a Dog", so we would do: lassie = Dog() Composition models a "has-a" relationship. For example, both cars and boats have engines, so we might be tempted to use a mixin: class Car(EngineMixin): pass class Boat(EngineMixin): pass which isn't an awful solution. But a conceptually cleaner solution might be to do this: class Car: def __init__(self): self.engine = Engine() def go(self): print "Fasten your seat belt" self.engine.start() self.handbrake = False self.change_gear("drive") self.accelerate() class Boat: def __init__(self): self.engine = Engine() def go(self): ... and then both cars and boats can *delegate* behaviour to the engine object. So, if you think of "Visitable" as a gadget that can be strapped onto your MyObj as a component, then composition is probably a better design. But if you think of "Visitable" as a mere collection of behaviour and state, then a mixin is probably a better design. -- Steven From andrea.crotti.0 at gmail.com Wed Apr 3 12:29:02 2013 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Wed, 3 Apr 2013 17:29:02 +0100 Subject: Mixin way? In-Reply-To: <515c4f07$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <515c4f07$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: 2013/4/3 Steven D'Aprano > [snip] > > So, if you think of "Visitable" as a gadget that can be strapped onto > your MyObj as a component, then composition is probably a better design. > But if you think of "Visitable" as a mere collection of behaviour and > state, then a mixin is probably a better design. > > Well I can explain better the situation to make it more clear. We are using CouchDb and so far it has been (sigh) a brutal manipulation of dictionaries everywhere, with code duplication and so on. Now I wanted to encapsulate all the entities in the DB in proper objects, so I have a CouchObject: class CouchObject(object) : """ Encapsulate an object which has the ability to be saved to a couch database. """ #: list of fields that get filled in automatically if not passed in AUTO = ['created_datetime', 'doc_type', '_id', '_rev'] #: dictionary with some extra fields with default values if not # passed in the constructor the default value gets set to the attribute DEFAULTS = {} REQUIRED = [] OPTIONAL = [] TO_RESOLVE = [] MIXINS = [] Where every subclass can redefine these attributes to get something done automatically by the constructor for convenience. Now however there is a lot of behaviour shared between them, so I want to encapsulate it out in different places. I think the MIXINS as I would use it is the normal composition pattern, the only difference is that the composition is done per class and not per object (again for lazyness reasons), right? Probably subclassing might be fine as well, and makes it simpler, but I don't like too much to do subclass from multiple classes... -------------- next part -------------- An HTML attachment was scrubbed... URL: From neilc at norwich.edu Wed Apr 3 13:16:07 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 3 Apr 2013 17:16:07 GMT Subject: Mixin way? References: <515c4f07$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-04-03, andrea crotti wrote: > Well I can explain better the situation to make it more clear. > > We are using CouchDb and so far it has been (sigh) a brutal > manipulation of dictionaries everywhere, with code duplication > and so on. > > Now I wanted to encapsulate all the entities in the DB in > proper objects, so I have a CouchObject: > > > class CouchObject(object) : > """ > Encapsulate an object which has the ability to be saved to a couch > database. > """ > #: list of fields that get filled in automatically if not passed in > AUTO = ['created_datetime', 'doc_type', '_id', '_rev'] > #: dictionary with some extra fields with default values if not > # passed in the constructor the default value gets set to the attribute > DEFAULTS = {} > REQUIRED = [] > OPTIONAL = [] > TO_RESOLVE = [] > MIXINS = [] > > Where every subclass can redefine these attributes to get > something done automatically by the constructor for > convenience. Hopefully someone with experience with them can help you further, but this seems like a job for a metaclass. -- Neil Cerutti From tjreedy at udel.edu Wed Apr 3 14:40:38 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Wed, 03 Apr 2013 14:40:38 -0400 Subject: IDLE printing problem In-Reply-To: <7glol8dqdbd0a7cijteuqs3apr68jvjn65@4ax.com> References: <7glol8dqdbd0a7cijteuqs3apr68jvjn65@4ax.com> Message-ID: On 4/3/2013 12:24 PM, Joe Hill wrote: On 4/3/2013 12:24 PM, Joe Hill wrote: > I attempted to print about 10 pages of documentation from the help files > using IDLE. On all the pages the side of each page was missing about 1/4 > inch of text. You neglected to say what you actually did to have a problem. I tried the following with the font set to the default Courier. >>> help(tuple) Everything printed, with longest lines just fitting within the margins. > Am I missing a setting? Is this a known problem? Will it do the same > with lines of code? Printing depends on font, font size, OS printer driver, and printer. I suspect Idle just sends print command to tk text widget. Its 'print dialog' is as primitive as possible: the only choice is to print to the default printer or not; no printer choice, no page setup. Tk, in turn, should just put the text in a temporary file and turn it over to the OS printer driver. > Using W7, 64 bit. PY 3.3. > > It worked just fine when I pasted the text in Word 2010. I am sure it is has more knowledge about the vagaries of printing. You might try a single page (with max length lines) after Word prints to see if it left the printer in a better state. From tjreedy at udel.edu Wed Apr 3 16:20:20 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Wed, 03 Apr 2013 16:20:20 -0400 Subject: IDLE printing problem In-Reply-To: References: <7glol8dqdbd0a7cijteuqs3apr68jvjn65@4ax.com> Message-ID: On 4/3/2013 2:50 PM, Joe Hill wrote: > On Wed, 03 Apr 2013 14:40:38 -0400, Terry Jan Reedy > wrote: > >> On 4/3/2013 12:24 PM, Joe Hill wrote: >>> I attempted to print about 10 pages of documentation from the help files >>> using IDLE. On all the pages the side of each page was missing about 1/4 >>> inch of text. >> >> You neglected to say what you actually did to have a problem. > Text that I needed to make sense of the page did not print from the help > file. Characters were missing on the right side on every long line on > every page. I got that already. Until you say what you did, in enough detail to reproduce your actions, I cannot comment further. From tjreedy at udel.edu Wed Apr 3 18:17:26 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Wed, 03 Apr 2013 18:17:26 -0400 Subject: IDLE printing problem In-Reply-To: References: <7glol8dqdbd0a7cijteuqs3apr68jvjn65@4ax.com> Message-ID: On 4/3/2013 5:16 PM, Joe Hill wrote: > On Wed, 03 Apr 2013 16:20:20 -0400, Terry Jan Reedy > wrote: > >> On 4/3/2013 2:50 PM, Joe Hill wrote: >>> On Wed, 03 Apr 2013 14:40:38 -0400, Terry Jan Reedy >>> wrote: >>> >> >>>> On 4/3/2013 12:24 PM, Joe Hill wrote: >>>>> I attempted to print about 10 pages of documentation from the help files >>>>> using IDLE. On all the pages the side of each page was missing about 1/4 >>>>> inch of text. >>>> >>>> You neglected to say what you actually did to have a problem. >> >>> Text that I needed to make sense of the page did not print from the help >>> file. Characters were missing on the right side on every long line on >>> every page. >> >> I got that already. Until you say what you did, in enough detail to >> reproduce your actions, I cannot comment further. > I Open IDLE and click on Help and select the second option which is > Documentation - select Glossary. The three options I see are 1) 'About Idle', 2) 'Idle help', which brings as a 2 page doc starting "[See the end of this file for ** TIPS **", and 3) "Python Docs - F1". On Windows, this third option brings up Windows Help opened to the windows-help version of the docs, which are also available online in a browser. In either case, Glossary is one of the docs. We have left IDLE so your problem has nothing to do with IDLE. On Windows, one can open the same doc from the Start menu by selecting Python x.y / Python Docs. > I then click on the Print icon at the > top of the Help/Documentation screen - then let er rip. > The word/line wrap on the screen is ok and the printed output is not. The word wrap on the screen adjusts to the window width. With the window too wide for the printer, I selected about five paragraphs, printed the selection, and the text was properly re-wrapped for printing with nothing lost, as if the display window had been narrowed. Windows obvious knows how wide the virtual window is for the particular combination of font (about 14 pt proportional sans serif) and printer. Apparently it is mis-calculating for your font and printer combination. > This was all unexpected outcomes. > I appreciate your help and that perhaps a fix can be found for everyone. > Mine is a very standard setup W7 Ult, 64bit and an Epson printer > (WP-4020) I have 64 bit Win7 pro with Canon and HP printers. The help window with a sheet+? icon in the upper left is Microsoft's program. The only thing I can suggest is to check for updated drivers, and make sure you have the correct driver. -- Terry Jan Reedy From tjreedy at udel.edu Wed Apr 3 22:01:25 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Wed, 03 Apr 2013 22:01:25 -0400 Subject: Windows printing problem (was re; IDLE printing problem_ In-Reply-To: References: <7glol8dqdbd0a7cijteuqs3apr68jvjn65@4ax.com> Message-ID: On 4/3/2013 6:26 PM, Joe Hill wrote: > In light of the fact that this is a new problem and has only occurred in > Python - I shall just regard that as either a feature or flaw... Based on what you have said, the problem IS NOT OCCURRING IN PYTHON. It is occurring in the Microsoft HTML help viewer. From nagle at animats.com Wed Apr 3 15:41:25 2013 From: nagle at animats.com (John Nagle) Date: Wed, 03 Apr 2013 12:41:25 -0700 Subject: Distributing a Python program hell Message-ID: I'm struggling with radio hams who are trying to get my antique Teletype program running. I hate having to write instructions like this: Installation instructions (Windows): Download and install Python 2.7 (32-bit) if not already installed. (Python 2.6 or 2.7 is required; "pyserial" will not work correctly on older versions, and "feedparser" is not supported in 3.x versions.) Install the Python module "setuptools" from the Python Package Index. (Needed by other installers. Has a Windows installer.) Install the Python module "feedparser" from Google Code. (Unpack ZiP file, run "setup.py install") Install the Python module "pyserial" from SourceForge. (Windows installer, but 32-bit only) Install the Python module "pygooglevoice" from Google Code. (Requires 7Zip to unpack the .tar.gz file. Then "setup.py install") Download "BaudotRSS" from SourceForge. (ZIP file, put in your chosen directory for this program.) Run: python baudotrss.py --help I'm thinking of switching to Go. John Nagle From ian.g.kelly at gmail.com Wed Apr 3 15:50:05 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 3 Apr 2013 13:50:05 -0600 Subject: Distributing a Python program hell In-Reply-To: References: Message-ID: On Wed, Apr 3, 2013 at 1:41 PM, John Nagle wrote: > I'm struggling with radio hams who are trying to get my > antique Teletype program running. I hate having to write > instructions like this: > > Installation instructions (Windows): You should check out pyInstaller or py2exe or cx_Freeze. From neilc at norwich.edu Wed Apr 3 15:54:19 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 3 Apr 2013 19:54:19 GMT Subject: Distributing a Python program hell References: Message-ID: On 2013-04-03, John Nagle wrote: > I'm struggling with radio hams who are trying to get my antique > Teletype program running. I hate having to write instructions > like this: > > Installation instructions (Windows): > > Download and install Python 2.7 (32-bit) if not already installed. > (Python 2.6 or 2.7 is required; "pyserial" will not work correctly on > older versions, and "feedparser" is not supported in 3.x versions.) > > Install the Python module "setuptools" from the Python Package Index. > (Needed by other installers. Has a Windows installer.) > > Install the Python module "feedparser" from Google Code. > (Unpack ZiP file, run "setup.py install") > > Install the Python module "pyserial" from SourceForge. > (Windows installer, but 32-bit only) > > Install the Python module "pygooglevoice" from Google Code. > (Requires 7Zip to unpack the .tar.gz file. Then "setup.py install") > > Download "BaudotRSS" from SourceForge. (ZIP file, put in your > chosen directory for this program.) > > Run: python baudotrss.py --help > > I'm thinking of switching to Go. Python programs can be distributed as binary-like packages, e.g., www.py2exe.org. -- Neil Cerutti From invalid at invalid.invalid Wed Apr 3 16:10:59 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 3 Apr 2013 20:10:59 +0000 (UTC) Subject: Distributing a Python program hell References: Message-ID: On 2013-04-03, Neil Cerutti wrote: > On 2013-04-03, John Nagle wrote: > >> I'm struggling with radio hams who are trying to get my antique >> Teletype program running. I hate having to write instructions >> like this: >> >> [...] > > Python programs can be distributed as binary-like packages, e.g., > www.py2exe.org. I'd second the recommendation for for py2exe. It's been a couple years since I used it, but for 6-7 years before that I used it regularly to distribute about a half-dozen different wxPython apps to Windows users, and it worked very nicely. It sometimes requires some effort to get the configuration tweaked right and then adjusted so the result works on a variety of Windows versions, but in the end it always worked great. I usually used one of the various free "self-installer generators" to bundle up the .exe file(s) produced by py2exe along with whatever else was needed to go with them and make them simple to install. [I've forgotten which ones I used, but they all do basically the same thing.] I did all my development on Linux. When I boot over to Windows (on a VM, generally) I had Cygwin installed and just ran a "make" to do all the executable creation and bundling via command-line calls to py2exe and self-installer utilities. -- Grant Edwards grant.b.edwards Yow! It's a hole all the at way to downtown Burbank! gmail.com From irmen.NOSPAM at xs4all.nl Wed Apr 3 18:01:17 2013 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Thu, 04 Apr 2013 00:01:17 +0200 Subject: Serpent, a serializer based on ast.literal_eval. Now also with Java and .net implementations Message-ID: <515ca6ac$0$6989$e4fe514c@news.xs4all.nl> Hi, I've made "serpent", a serializer based around ast.literal_eval(). You can find it on Pypi: http://pypi.python.org/pypi/serpent Serpent takes a Python object tree and turns it into a serialized form that can be safely read back by ast.literal_eval(). This avoids security issues that other serialization protocols such as pickle have. It also has a few other nice properties such as the readability of the serialized data. I also wrote a Java and a .NET implementation so that you can easily exchange data between the different ecosystemens. The library works with Python 2.6+ (including 3.x), IronPython 2.7, Jython 2.7, Java 1.6, .NET 3.5, or newer versions. A little bit of documentation can be found on serpent's Pypi page, including a little demo program and its output. The full source and the Java/.NET versions are not available from Pypi obviously, but a download link for them is provided in the description. 'FAQ': - Why not use XML? Answer: because XML. - Why not use JSON? Answer: because JSON is quite limited in the number of datatypes it supports, and you can't use comments in a JSON file. - Why not use pickle? Answer: because pickle has security problems. - Why not use repr()/ast.literal_eval()? See above; serpent is a superset of this and provides more convenience. Serpent provides automatic serialization mappings for some types other than the builtin primitive types. repr() can't serialize these to literals that ast.literal_eval() understands. - Why not a binary format? Answer: because binary isn't readable. - But I don't care about readability. Answer: too bad, ast.literal_eval() wants a literal string. - But I want better performance. Answer: ok, maybe you shouldn't use serpent in this case. Find an efficient binary protocol (protobuf?) - Why only Python, Java and .NET, but no bindings for insert-favorite-language-here? Answer: I don't speak that language. Maybe you could port serpent yourself? Serpent on Pypi: http://pypi.python.org/pypi/serpent Cheers Irmen de Jong From bind-users-bounces at lists.isc.org Wed Apr 3 18:03:28 2013 From: bind-users-bounces at lists.isc.org (bind-users-bounces at lists.isc.org) Date: Wed, 03 Apr 2013 22:03:28 +0000 Subject: Your message to bind-users awaits moderator approval Message-ID: Your mail to 'bind-users' with the subject Delivery reports about your e-mail Is being held until the list moderator can review it for approval. The reason it is being held: Post by non-member to a members-only list Either the message will get posted to the list, or you will receive notification of the moderator's decision. If you would like to cancel this posting, please visit the following URL: https://lists.isc.org/mailman/confirm/bind-users/09343741199629285eb8ad1c851fa8c74f8e4d17 From irmen.NOSPAM at xs4all.nl Wed Apr 3 18:53:19 2013 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Thu, 04 Apr 2013 00:53:19 +0200 Subject: Data storage Py 3.3 In-Reply-To: References: Message-ID: <515cb2de$0$6877$e4fe514c@news.xs4all.nl> On 4-4-2013 0:33, Joe Hill wrote: > IDLE wants to use Python33 as the data storage folder - with exe files > etc. > Typically the 'default data storage' is in 'last used' directory or most > programs even have a browse setting that one can quickly set and reset. > > What do people here generally do? > > When I installed 3.3, (W7- 64) I selected the first option for paths etc. > and everything seems to just run fine > > j > Don't store your files in the Python33 directory even though it is idle's default suggestion. I have my Python code sitting in appropriate subdirectories of a 'Projects' folder somewhere (on a different drive on my Windows system, or just a subfolder in my homedirectory on my Linux VM). I don't use idle myself, but you can simply browse to the appropriate folder and file location. Idle will remember that location for the next time you use the file dialog. Irmen From tjreedy at udel.edu Wed Apr 3 22:09:53 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Wed, 03 Apr 2013 22:09:53 -0400 Subject: Data storage Py 3.3 In-Reply-To: <515cb2de$0$6877$e4fe514c@news.xs4all.nl> References: <515cb2de$0$6877$e4fe514c@news.xs4all.nl> Message-ID: On 4/3/2013 6:53 PM, Irmen de Jong wrote: > On 4-4-2013 0:33, Joe Hill wrote: >> IDLE wants to use Python33 as the data storage folder - with exe files >> etc. >> Typically the 'default data storage' is in 'last used' directory or most >> programs even have a browse setting that one can quickly set and reset. >> >> What do people here generally do? >> >> When I installed 3.3, (W7- 64) I selected the first option for paths etc. >> and everything seems to just run fine I have a c:\Programs folder where I put multiple versions of python and selected other programs whose directories I might want to visit. > Don't store your files in the Python33 directory even though it is idle's default > suggestion. I once did that, but then I had to move stuff when the Python x.y directory became obsolete. It was also a problem when I wanted to test a file with more than one python version. > > I have my Python code sitting in appropriate subdirectories of a 'Projects' folder > somewhere (on a different drive on my Windows system, or just a subfolder in my > homedirectory on my Linux VM). I have a file tem.py in my miscellaneous python directory. When I am writing possibly throwaway code, I open it from the recent files list, empty the old code, and go. I can always save as another name if I want to keep the code. tem.py is almost always on the list because I use it frequently. From norm.clerman at gmail.com Wed Apr 3 21:26:48 2013 From: norm.clerman at gmail.com (Norman Clerman) Date: Wed, 3 Apr 2013 18:26:48 -0700 (PDT) Subject: question about csv.DictReader Message-ID: <846339ea-366a-4bb2-b234-0e03bf87489e@googlegroups.com> Hello, I have the following python script (some of lines are wrapped): #! /usr/bin/env python import csv def dict_test_1(): """ csv test program """ # Open the file Holdings_EXA.csv HOLDING_FILE = 'Holdings_EXA.csv' try: csv_file = open(HOLDING_FILE, 'rt') except IOError: print('Problem opening {0}\nExiting').format(HOLDING_FILE) exit() # create a dictionary reader try: csv_reader = csv.DictReader(csv_file) except NameError: print('Cannot find file {0} to create a dictionary reader \nExiting').format(HOLDING_FILE) exit() # Print the keys in each row i_row = 1 for row in csv_reader: print ('There are {0} keys in row {1}').format(len(row.keys()), i_row) print ('The keys in row {0} are \n{1}').format(i_row, row.keys()) i_row += 1 dict_test_1() Here are the lines in file Holdings_EXA.csv: Please note that the first field in the first row is "Holdings" "Holdings","Weighting","Type","Ticker","Style","First Bought","Shares Owned","Shares Change","Sector","Price","Day Change","Day high/low","Volume","52-Wk high/low","Country","3-Month Return","1-Year Return","3-Year Return","5-Year Return","Market Cap Mil","Currency","Morningstar Rating","YTD Return","P/E","Maturity Date","Coupon %","Yield to Maturity" "Nestle SA","1.91","EQUITY","NESN","Large Core","1999-12-31","3732276","197810","Consumer Defensive","67.65","-","67.75-67.35","1211531","67.75-53.8","Switzerland","10.42","21.25","10.5","8.84","213475.59","CHF","2","12.92","21.69","-","-","-" "HSBC Holdings PLC","1.75","EQUITY","HSBA","Large Value","1999-12-31","21120203","1711934","Financial Services","733.3","-1.4|-0","738.8-731","7839724","739.9-501.2","United Kingdom","14.51","37.17","3.88","2.77","132694.66","GBP","3","13.93","15.55","-","-","-" "Novartis AG","1.33","EQUITY","NOVN","Large Core","2003-06-30","2669523","206851","Healthcare","65.95","0.5|0.01","66-65.4","1121549","66-48.29","Switzerland","15.1","36.5","6.16","8.53","158671.66","CHF","4","16.7","17.76","-","-","-" "Roche Holding AG","1.31","EQUITY","ROG","Large Growth","2003-05-31","817830","59352","Healthcare","214.8","1.4|0.01","215.2-213.1","684173","220.4-148.4","Switzerland","17.45","37.95","7.78","4.09","34000","CHF","3","18.09","19.05","-","-","-" Finally, here are the results of running the script: norm at lima:~/python/overlap$ python dict_test_1.py There are 27 keys in row 1 The keys in row 1 are ['Style', 'Day Change', 'Coupon %', 'Yield to Maturity', 'P/E', 'Type', 'Weighting', 'Price', '3-Month Return', 'Volume', '\xef\xbb\xbf"Holdings"', 'Ticker', 'Shares Change', 'Shares Owned', 'YTD Return', '5-Year Return', 'Market Cap Mil', 'Country', '3-Year Return', 'Day high/low', 'Maturity Date', '1-Year Return', 'Sector', 'Morningstar Rating', 'Currency', '52-Wk high/low', 'First Bought'] There are 27 keys in row 2 The keys in row 2 are ['Style', 'Day Change', 'Coupon %', 'Yield to Maturity', 'P/E', 'Type', 'Weighting', 'Price', '3-Month Return', 'Volume', '\xef\xbb\xbf"Holdings"', 'Ticker', 'Shares Change', 'Shares Owned', 'YTD Return', '5-Year Return', 'Market Cap Mil', 'Country', '3-Year Return', 'Day high/low', 'Maturity Date', '1-Year Return', 'Sector', 'Morningstar Rating', 'Currency', '52-Wk high/low', 'First Bought'] There are 27 keys in row 3 The keys in row 3 are ['Style', 'Day Change', 'Coupon %', 'Yield to Maturity', 'P/E', 'Type', 'Weighting', 'Price', '3-Month Return', 'Volume', '\xef\xbb\xbf"Holdings"', 'Ticker', 'Shares Change', 'Shares Owned', 'YTD Return', '5-Year Return', 'Market Cap Mil', 'Country', '3-Year Return', 'Day high/low', 'Maturity Date', '1-Year Return', 'Sector', 'Morningstar Rating', 'Currency', '52-Wk high/low', 'First Bought'] There are 27 keys in row 4 The keys in row 4 are ['Style', 'Day Change', 'Coupon %', 'Yield to Maturity', 'P/E', 'Type', 'Weighting', 'Price', '3-Month Return', 'Volume', '\xef\xbb\xbf"Holdings"', 'Ticker', 'Shares Change', 'Shares Owned', 'YTD Return', '5-Year Return', 'Market Cap Mil', 'Country', '3-Year Return', 'Day high/low', 'Maturity Date', '1-Year Return', 'Sector', 'Morningstar Rating', 'Currency', '52-Wk high/low', 'First Bought'] norm at lima:~/python/overlap$ Can anyone explain the presence of the characters "\xref\xbb\xbf" before the first field contents "Holdings" ? Thanks, Norm From python at mrabarnett.plus.com Wed Apr 3 22:46:18 2013 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 04 Apr 2013 03:46:18 +0100 Subject: question about csv.DictReader In-Reply-To: <846339ea-366a-4bb2-b234-0e03bf87489e@googlegroups.com> References: <846339ea-366a-4bb2-b234-0e03bf87489e@googlegroups.com> Message-ID: <515CE97A.6060405@mrabarnett.plus.com> On 04/04/2013 02:26, Norman Clerman wrote: > Hello, > > I have the following python script (some of lines are wrapped): > > #! /usr/bin/env python > > import csv > > def dict_test_1(): > """ csv test program """ > > # Open the file Holdings_EXA.csv > HOLDING_FILE = 'Holdings_EXA.csv' > try: > csv_file = open(HOLDING_FILE, 'rt') > except IOError: > print('Problem opening {0}\nExiting').format(HOLDING_FILE) > exit() > > # create a dictionary reader > try: > csv_reader = csv.DictReader(csv_file) > except NameError: > print('Cannot find file {0} to create a dictionary reader \nExiting').format(HOLDING_FILE) > exit() > > # Print the keys in each row > i_row = 1 > for row in csv_reader: > print ('There are {0} keys in row {1}').format(len(row.keys()), i_row) > print ('The keys in row {0} are \n{1}').format(i_row, row.keys()) > i_row += 1 > dict_test_1() > > Here are the lines in file Holdings_EXA.csv: > Please note that the first field in the first row is "Holdings" > > "Holdings","Weighting","Type","Ticker","Style","First Bought","Shares Owned","Shares Change","Sector","Price","Day Change","Day high/low","Volume","52-Wk high/low","Country","3-Month Return","1-Year Return","3-Year Return","5-Year Return","Market Cap Mil","Currency","Morningstar Rating","YTD Return","P/E","Maturity Date","Coupon %","Yield to Maturity" > "Nestle SA","1.91","EQUITY","NESN","Large Core","1999-12-31","3732276","197810","Consumer Defensive","67.65","-","67.75-67.35","1211531","67.75-53.8","Switzerland","10.42","21.25","10.5","8.84","213475.59","CHF","2","12.92","21.69","-","-","-" > "HSBC Holdings PLC","1.75","EQUITY","HSBA","Large Value","1999-12-31","21120203","1711934","Financial Services","733.3","-1.4|-0","738.8-731","7839724","739.9-501.2","United Kingdom","14.51","37.17","3.88","2.77","132694.66","GBP","3","13.93","15.55","-","-","-" > "Novartis AG","1.33","EQUITY","NOVN","Large Core","2003-06-30","2669523","206851","Healthcare","65.95","0.5|0.01","66-65.4","1121549","66-48.29","Switzerland","15.1","36.5","6.16","8.53","158671.66","CHF","4","16.7","17.76","-","-","-" > "Roche Holding AG","1.31","EQUITY","ROG","Large Growth","2003-05-31","817830","59352","Healthcare","214.8","1.4|0.01","215.2-213.1","684173","220.4-148.4","Switzerland","17.45","37.95","7.78","4.09","34000","CHF","3","18.09","19.05","-","-","-" > > Finally, here are the results of running the script: > > > norm at lima:~/python/overlap$ python dict_test_1.py > There are 27 keys in row 1 > The keys in row 1 are > ['Style', 'Day Change', 'Coupon %', 'Yield to Maturity', 'P/E', 'Type', 'Weighting', 'Price', '3-Month Return', 'Volume', '\xef\xbb\xbf"Holdings"', 'Ticker', 'Shares Change', 'Shares Owned', 'YTD Return', '5-Year Return', 'Market Cap Mil', 'Country', '3-Year Return', 'Day high/low', 'Maturity Date', '1-Year Return', 'Sector', 'Morningstar Rating', 'Currency', '52-Wk high/low', 'First Bought'] > There are 27 keys in row 2 > The keys in row 2 are > ['Style', 'Day Change', 'Coupon %', 'Yield to Maturity', 'P/E', 'Type', 'Weighting', 'Price', '3-Month Return', 'Volume', '\xef\xbb\xbf"Holdings"', 'Ticker', 'Shares Change', 'Shares Owned', 'YTD Return', '5-Year Return', 'Market Cap Mil', 'Country', '3-Year Return', 'Day high/low', 'Maturity Date', '1-Year Return', 'Sector', 'Morningstar Rating', 'Currency', '52-Wk high/low', 'First Bought'] > There are 27 keys in row 3 > The keys in row 3 are > ['Style', 'Day Change', 'Coupon %', 'Yield to Maturity', 'P/E', 'Type', 'Weighting', 'Price', '3-Month Return', 'Volume', '\xef\xbb\xbf"Holdings"', 'Ticker', 'Shares Change', 'Shares Owned', 'YTD Return', '5-Year Return', 'Market Cap Mil', 'Country', '3-Year Return', 'Day high/low', 'Maturity Date', '1-Year Return', 'Sector', 'Morningstar Rating', 'Currency', '52-Wk high/low', 'First Bought'] > There are 27 keys in row 4 > The keys in row 4 are > ['Style', 'Day Change', 'Coupon %', 'Yield to Maturity', 'P/E', 'Type', 'Weighting', 'Price', '3-Month Return', 'Volume', '\xef\xbb\xbf"Holdings"', 'Ticker', 'Shares Change', 'Shares Owned', 'YTD Return', '5-Year Return', 'Market Cap Mil', 'Country', '3-Year Return', 'Day high/low', 'Maturity Date', '1-Year Return', 'Sector', 'Morningstar Rating', 'Currency', '52-Wk high/low', 'First Bought'] > norm at lima:~/python/overlap$ > > > Can anyone explain the presence of the characters "\xref\xbb\xbf" before the first field contents "Holdings" ? > Microsoft Windows indicates that a text file contains text encoded as UTF-8 by including a signature at its start. (Does the file also have "\r\n" line endings? Presumably it was created on a Windows system.) Try opening the file with the "utf-8-sig" encoding instead; this will drop the signature if present. From python.list at tim.thechases.com Wed Apr 3 22:52:26 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 3 Apr 2013 21:52:26 -0500 Subject: question about csv.DictReader In-Reply-To: <846339ea-366a-4bb2-b234-0e03bf87489e@googlegroups.com> References: <846339ea-366a-4bb2-b234-0e03bf87489e@googlegroups.com> Message-ID: <20130403215226.2a94ac26@bigbox.christie.dr> On 2013-04-03 18:26, Norman Clerman wrote: > Can anyone explain the presence of the characters "\xref\xbb\xbf" > before the first field contents "Holdings" ? (you mean "\xef", not "\xref") This is a byte-order-mark (BOM), which you can read about at [1]. In this case, it denotes the file as UTF-8 encoded. Certain programs insert these, though it's more important with UTF-16 or UTF-32 encodings where the byte-order and endian'ness actually matters. I believe Notepad and Visual Studio on Win32 were both offenders when it came to inserting unbidden BOMs. -tkc [1] http://en.wikipedia.org/wiki/Byte_order_mark From norm.clerman at gmail.com Thu Apr 4 15:09:49 2013 From: norm.clerman at gmail.com (Norman Clerman) Date: Thu, 4 Apr 2013 12:09:49 -0700 (PDT) Subject: question about csv.DictReader In-Reply-To: <846339ea-366a-4bb2-b234-0e03bf87489e@googlegroups.com> References: <846339ea-366a-4bb2-b234-0e03bf87489e@googlegroups.com> Message-ID: Thanks for your replies. Greatly appreciated. Norm From steve+comp.lang.python at pearwood.info Wed Apr 3 21:36:25 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Apr 2013 01:36:25 GMT Subject: In defence of 80-char lines Message-ID: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> Although PEP 8 is only compulsory for the Python standard library, many users like to stick to PEP 8 for external projects. http://www.python.org/dev/peps/pep-0008/ With perhaps one glaring exception: many people hate, or ignore, PEP 8's recommendation to limit lines to 80 characters. (Strictly speaking, 79 characters.) Here is a good defence of 80 char lines: http://wrongsideofmemphis.com/2013/03/25/80-chars-per-line-is-great/ -- Steven From bahamutzero8825 at gmail.com Wed Apr 3 21:59:09 2013 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Wed, 03 Apr 2013 20:59:09 -0500 Subject: In defence of 80-char lines In-Reply-To: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <515CDE6D.3000502@gmail.com> While I agree that not having a line take up hundreds of characters is a good thing, 80 is really arbitrary in 2013 and having any self-imposed hard limit is silly. When you put a single 4- or 5-character word on a new line because you don't want to go over 80 (or 120 or whatever), the code is /less/ readable. A better guideline is to make new lines as necessary to make things more readable rather than blindly stick to some hard limit and say it's more readable just because. Also, IMO, 80 is far too limiting and I find 120-130 much better. Then again, I like small font sizes and avoid lower resolution screens like the plague. -- CPython 3.3.0 | Windows NT 6.2.9200 / FreeBSD 9.1 From msirenef at lightbird.net Wed Apr 3 22:40:51 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Wed, 03 Apr 2013 22:40:51 -0400 Subject: In defence of 80-char lines In-Reply-To: <515CDE6D.3000502@gmail.com> References: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> <515CDE6D.3000502@gmail.com> Message-ID: <515CE833.2090808@lightbird.net> On 04/03/2013 09:59 PM, Andrew Berg wrote: > While I agree that not having a line take up hundreds of characters is a > good thing, 80 is really arbitrary in 2013 and having any self-imposed > hard limit is silly. When you put a single 4- or 5-character word on a > new line because you don't want to go over 80 (or 120 or whatever), the > code is /less/ readable. A better guideline is to make new lines as > necessary to make things more readable rather than blindly stick to some > hard limit and say it's more readable just because. > > Also, IMO, 80 is far too limiting and I find 120-130 much better. Then > again, I like small font sizes and avoid lower resolution screens like > the plague. I have to agree. To some degree, it's a matter of taste: for me, 80c limit looks ugly to the extreme, at least in Django; but 140+ looks even uglier, and the longer line is, the uglier it looks. The optimal size for Django code is a 105 char soft limit -- by soft limit I mean that under 105 it's always one line, 105-110 I decide on a case-by-case basis and over 110 is always split. So my preference is: 105 > 120-130 > 140 > 80 > 140+ The trade-off is that on one hand, the code is more readable when a single line is a single "operation", from a cognitive standpoint, when you're thinking about the logic of the function as a whole, or a subset of a function if it's too long (which it shouldn't be, right?) On the other hand, even if your monitor is wide, you probably still want to fit in the browser window and the terminal window, and as the blog author rightly notes, really long lines do get harder to read. Again, I mostly work with Django and I suspect if I worked in regular Python I would possibly gravitate towards 95-100 limit. I find the blog author's point about fitting more text nonsensical: you can obviously fit more text PER LINE if lines are longer! And you can quite easily fit two 120-130 wide gvim screens on a modern monitor with room to spare. I'm sure eyesight acuity also figures into this: I prefer to work without glasses -- otherwise my eyes get tired after a couple of hours; but this means I can't see code on my second monitor. If I could, I might have preferred having browser and terminal on one monitor and Gvim with slightly longer width limits than I use now. -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ The Bible is literature, not dogma. George Santayana From llanitedave at veawb.coop Thu Apr 4 00:32:33 2013 From: llanitedave at veawb.coop (llanitedave) Date: Wed, 3 Apr 2013 21:32:33 -0700 (PDT) Subject: In defence of 80-char lines In-Reply-To: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: I also tend to prefer a maximum between 110 and 120 characters. I find continuation lines confusing, and when you use some third-party tools, such as wxPython, for example, the boilerplate code leads to some long lines. I would hate to have to break up this line, for instance: self.mainLabel.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = "FreeSans")) Especially if it's already indented a few levels to begin with. With most of your code in classes, you already got most of it indented two levels right off the bat. From steve+comp.lang.python at pearwood.info Thu Apr 4 02:33:50 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 04 Apr 2013 06:33:50 GMT Subject: In defence of 80-char lines References: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <515d1ecd$0$29891$c3e8da3$5496439d@news.astraweb.com> On Wed, 03 Apr 2013 21:32:33 -0700, llanitedave wrote: > I also tend to prefer a maximum between 110 and 120 characters. I find > continuation lines confusing, and when you use some third-party tools, > such as wxPython, for example, the boilerplate code leads to some long > lines. Excessive boilerplate, and long lines, is a code-smell that suggests strongly that the code needs refactoring and/or simplifying. > I would hate to have to break up this line, for instance: > > self.mainLabel.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, > faceName = "FreeSans")) Here, let me do that for you, with two, no, three, no FOUR levels of indentation :-) self.mainLabel.SetFont(self.label_format) Now when you want to change the font of your labels, you can change them all with *one* edit. Or you can add themes to your application by reading style info from a config file. Even if you don't want to do that, you still have the benefit of much more readable code. Clearly you have to define the label format in the class. Here's one simple way: class MyClass(whatever): label_format = wx.Font( 12, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName="FreeSans") def __init__(self, label_format=None): if label_format is not None: # Over-ride the default. self.label_format = label_format Even if you don't want to do that, you can still fit it into 80 char lines: # 80 characters, not 79. Oh well. font = wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName="FreeSans") self.mainLabel.SetFont(font) And finally, when all is said and done, the most important rule from PEP 8 applies: know when to break the rules. -- Steven From __peter__ at web.de Thu Apr 4 02:43:06 2013 From: __peter__ at web.de (Peter Otten) Date: Thu, 04 Apr 2013 08:43:06 +0200 Subject: In defence of 80-char lines References: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: llanitedave wrote: > I also tend to prefer a maximum between 110 and 120 characters. I find > continuation lines confusing, and when you use some third-party tools, > such as wxPython, for example, the boilerplate code leads to some long > lines. > > I would hate to have to break up this line, for instance: > > self.mainLabel.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, > faceName = "FreeSans")) I'm not a wx user, but I think I would prefer labelfont = wx.Font( pointSize=12, style=wx.DEFAULT, family=wx.NORMAL, weight=wx.BOLD, faceName="FreeSans") self.mainLabel.SetFont(labelfont) even if I knew the order of the arguments and the meaning of constants like DEFAULT and NORMAL by heart. From python.list at tim.thechases.com Thu Apr 4 07:09:13 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 4 Apr 2013 06:09:13 -0500 Subject: In defence of 80-char lines In-Reply-To: References: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20130404060913.2e771293@bigbox.christie.dr> On 2013-04-04 08:43, Peter Otten wrote: > llanitedave wrote: >> self.mainLabel.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = "FreeSans")) > > I think I would prefer > > labelfont = wx.Font( > pointSize=12, > style=wx.DEFAULT, > family=wx.NORMAL, > weight=wx.BOLD, > faceName="FreeSans") > self.mainLabel.SetFont(labelfont) +1 The only change I'd make to this suggestion would be to add a semi-superfluous comma+newline after the last keyword argument too: labelfont = wx.Font( pointSize=12, style=wx.DEFAULT, family=wx.NORMAL, weight=wx.BOLD, faceName="FreeSans", ) which makes diffs cleaner when you need to insert something after faceName: --- peter1.txt 2013-04-04 06:03:01.420762566 -0500 +++ peter2.txt 2013-04-04 06:03:34.736762582 -0500 @@ -3,4 +3,5 @@ style=wx.DEFAULT, family=wx.NORMAL, weight=wx.BOLD, - faceName="FreeSans") + faceName="FreeSans", + otherValue=42) vs. --- tkc1.txt 2013-04-04 06:02:52.436762562 -0500 +++ tkc2.txt 2013-04-04 06:03:51.392762588 -0500 @@ -4,4 +4,5 @@ family=wx.NORMAL, weight=wx.BOLD, faceName="FreeSans", + otherValue=42, ) Additionally, if there are lots of keyword parameters like this, I'd be tempted to keep them in sorted order for ease of tracking them down (though CSS has long-standing arguments on how properties should be ordered, so to each their own on this). -tkc From jason.swails at gmail.com Thu Apr 4 08:18:37 2013 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 4 Apr 2013 08:18:37 -0400 Subject: In defence of 80-char lines In-Reply-To: <20130404060913.2e771293@bigbox.christie.dr> References: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> <20130404060913.2e771293@bigbox.christie.dr> Message-ID: On Thu, Apr 4, 2013 at 7:09 AM, Tim Chase wrote: > On 2013-04-04 08:43, Peter Otten wrote: > > llanitedave wrote: > >> self.mainLabel.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, > faceName = "FreeSans")) > > > > I think I would prefer > > > > labelfont = wx.Font( > > pointSize=12, > > style=wx.DEFAULT, > > family=wx.NORMAL, > > weight=wx.BOLD, > > faceName="FreeSans") > > self.mainLabel.SetFont(labelfont) > > +1 > The only change I'd make to this suggestion would be to add a > semi-superfluous comma+newline after the last keyword argument too: > > labelfont = wx.Font( > pointSize=12, > style=wx.DEFAULT, > family=wx.NORMAL, > weight=wx.BOLD, > faceName="FreeSans", > ) > > which makes diffs cleaner when you need to insert something after > faceName: > > --- peter1.txt 2013-04-04 06:03:01.420762566 -0500 > +++ peter2.txt 2013-04-04 06:03:34.736762582 -0500 > @@ -3,4 +3,5 @@ > style=wx.DEFAULT, > family=wx.NORMAL, > weight=wx.BOLD, > - faceName="FreeSans") > + faceName="FreeSans", > + otherValue=42) > > vs. > > --- tkc1.txt 2013-04-04 06:02:52.436762562 -0500 > +++ tkc2.txt 2013-04-04 06:03:51.392762588 -0500 > @@ -4,4 +4,5 @@ > family=wx.NORMAL, > weight=wx.BOLD, > faceName="FreeSans", > + otherValue=42, > ) > +1 I wasn't aware you could do this (superfluous trailing commas), although I admit it hadn't occurred to me to try. I use git for virtually everything, and I regularly parse diffstats -- this would make them much easier to grok. (It's an incredibly helpful bug-tracking technique) Thanks! Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From joshua.landau.ws at gmail.com Thu Apr 4 13:18:00 2013 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Thu, 4 Apr 2013 18:18:00 +0100 Subject: In defence of 80-char lines In-Reply-To: <20130404060913.2e771293@bigbox.christie.dr> References: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> <20130404060913.2e771293@bigbox.christie.dr> Message-ID: On 4 April 2013 12:09, Tim Chase wrote: > On 2013-04-04 08:43, Peter Otten wrote: > > llanitedave wrote: > >> self.mainLabel.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, > faceName = "FreeSans")) > > > > I think I would prefer > > > > labelfont = wx.Font( > > pointSize=12, > > style=wx.DEFAULT, > > family=wx.NORMAL, > > weight=wx.BOLD, > > faceName="FreeSans") > > self.mainLabel.SetFont(labelfont) > > +1 > The only change I'd make to this suggestion would be to add a > semi-superfluous comma+newline after the last keyword argument too: > > labelfont = wx.Font( > pointSize=12, > style=wx.DEFAULT, > family=wx.NORMAL, > weight=wx.BOLD, > faceName="FreeSans", > ) > Since we're all showing opinions, I've always prefered the typical block indentation: labelfont = wx.Font( pointSize=12, style=wx.DEFAULT, family=wx.NORMAL, weight=wx.BOLD, faceName="FreeSans", ) # Not indented here as A( B( C, D, E, ) ) reads a lot cleaner than A( B( C, D, E ) ) which makes diffs cleaner when you need to insert something after > faceName: > That is a very good point :). Additionally, if there are lots of keyword parameters like this, I'd > be tempted to keep them in sorted order for ease of tracking them > down (though CSS has long-standing arguments on how properties should > be ordered, so to each their own on this). > Personally I'd rarely be tempted to put more than 9 or so arguments directly into a function or class. Most of the time I can imagine unpacking (or equiv.) would look much more readable in the circumstances that apply. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gregor at ediwo.com Thu Apr 4 02:40:56 2013 From: gregor at ediwo.com (gregor) Date: Thu, 4 Apr 2013 08:40:56 +0200 Subject: In defence of 80-char lines References: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20130404084056.682541bd@florenz> Am Wed, 3 Apr 2013 21:32:33 -0700 (PDT) schrieb llanitedave : > I would hate to have to break up this line, for instance: > > self.mainLabel.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, > faceName = "FreeSans")) I think this is much more readable: self.mainLabel.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = "FreeSans")) Emacs for example does this indentation with the TAB key automatically. -- Greg From roy at panix.com Thu Apr 4 07:52:38 2013 From: roy at panix.com (Roy Smith) Date: Thu, 04 Apr 2013 07:52:38 -0400 Subject: In defence of 80-char lines References: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , llanitedave wrote: > I would hate to have to break up this line, for instance: > > self.mainLabel.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = > "FreeSans")) I would write that as some variation on self.mainLabel.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName="FreeSans")) This lets the reader see at a glance that all the arguments go with wx.Font(), not with SetFont(), without having to visually parse and match parenthesis levels. Actually, I would probably break it up further as: my_font = wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName="FreeSans") self.mainLabel.SetFont(my_font) The last thing on my mind when deciding how to format this is whether I would be able to punch it onto a single card. From llanitedave at veawb.coop Thu Apr 4 11:28:13 2013 From: llanitedave at veawb.coop (llanitedave) Date: Thu, 4 Apr 2013 08:28:13 -0700 (PDT) Subject: In defence of 80-char lines In-Reply-To: References: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <59b9df11-b5b5-430a-b37f-958cbbf9f3f0@googlegroups.com> On Thursday, April 4, 2013 4:52:38 AM UTC-7, Roy Smith wrote: > In article , > > llanitedave wrote: > > > > > I would hate to have to break up this line, for instance: > > > > > > self.mainLabel.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = > > > "FreeSans")) > > > > I would write that as some variation on > > > > self.mainLabel.SetFont(wx.Font(12, > > wx.DEFAULT, > > wx.NORMAL, > > wx.BOLD, > > faceName="FreeSans")) > > > > This lets the reader see at a glance that all the arguments go with > > wx.Font(), not with SetFont(), without having to visually parse and > > match parenthesis levels. > > > > Actually, I would probably break it up further as: > > > > my_font = wx.Font(12, > > wx.DEFAULT, > > wx.NORMAL, > > wx.BOLD, > > faceName="FreeSans") > > self.mainLabel.SetFont(my_font) > > > > The last thing on my mind when deciding how to format this is whether I > > would be able to punch it onto a single card. To each their own, definitely. For myself, I don't see the utility in adding a bunch of what appears to be superfluous horizontal white space at the expense of extra lines to scroll down. I like to limit my scrolling needs in *both* directions. (Although I do tend to be fairly generous with blank lines to break up code "paragraphs") From rustompmody at gmail.com Thu Apr 4 00:56:25 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 3 Apr 2013 21:56:25 -0700 (PDT) Subject: In defence of 80-char lines References: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0df4abca-211c-42e9-8589-25b1d96299b2@ps9g2000pbb.googlegroups.com> On Apr 4, 6:36?am, Steven D'Aprano wrote: > Although PEP 8 is only compulsory for the Python standard library, many > users like to stick to PEP 8 for external projects. > > http://www.python.org/dev/peps/pep-0008/ > > http://blog.languager.org/2012/10/layout-imperative-in-functional.htmlith perhaps one glaring exception: many people hate, or ignore, PEP 8's > recommendation to limit lines to 80 characters. (Strictly speaking, 79 > characters.) > > Here is a good defence of 80 char lines: > > http://wrongsideofmemphis.com/2013/03/25/80-chars-per-line-is-great/ The exchange on hacker news linked from there makes for a nice read -- tnx. I had a blog article http://blog.languager.org/2012/10/layout-imperative-in-functional.html on this subject. It started from a python discussion, though its more relevant to Haskell. What does not so easily come out there is that the wide-line code samples I posted which read ok to me were not to some readers. So I moved it to gist, but even there some would get the horizontal scroll bar. Reading it 'raw' seems to remove the problem -- though I can hardly promise that for all devices. So from this POV the point that was made was opposite to the one I was trying to make =) The discussion that followed on haskell cafe http://www.haskell.org/pipermail/haskell-cafe/2012-October/104224.html made a number of interesting points about pros and cons of long lines. From rui.maciel at gmail.com Thu Apr 4 03:15:25 2013 From: rui.maciel at gmail.com (Rui Maciel) Date: Thu, 04 Apr 2013 08:15:25 +0100 Subject: In defence of 80-char lines References: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Although PEP 8 is only compulsory for the Python standard library, many > users like to stick to PEP 8 for external projects. > > http://www.python.org/dev/peps/pep-0008/ > > With perhaps one glaring exception: many people hate, or ignore, PEP 8's > recommendation to limit lines to 80 characters. (Strictly speaking, 79 > characters.) > > > Here is a good defence of 80 char lines: > > http://wrongsideofmemphis.com/2013/03/25/80-chars-per-line-is-great/ The now arbitrary 80-column limit is a remnant of the limitations built into ancient terminals. Why not let the text editor auto-wrap the lines? They can do that now. Rui Maciel From jason.swails at gmail.com Thu Apr 4 08:13:30 2013 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 4 Apr 2013 08:13:30 -0400 Subject: In defence of 80-char lines In-Reply-To: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 3, 2013 at 9:36 PM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > Although PEP 8 is only compulsory for the Python standard library, many > users like to stick to PEP 8 for external projects. > But even the standard library breaks this rule on occasion. e.g., /usr/lib/python2.7/urllib.py:1095 (I remember seeing others, but this is the first example I was able to find quickly). > > http://www.python.org/dev/peps/pep-0008/ > > With perhaps one glaring exception: many people hate, or ignore, PEP 8's > recommendation to limit lines to 80 characters. (Strictly speaking, 79 > characters.) > > > Here is a good defence of 80 char lines: > > http://wrongsideofmemphis.com/2013/03/25/80-chars-per-line-is-great/ Personally, I try my best to keep all lines at 80 character max (80 + newline, not 79). In addition to liking my 84-character-width gvim windows (to allow a little leeway) side-by-side for code references, I'm definitely not above printing out some code to lay it out on a desk---that's not something you can do on-screen without a wall of monitors in front of you. The only time I regularly break my rule is for regular expressions (at some point I may embrace re.X to allow me to break those up, too). All the best, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Thu Apr 4 08:39:46 2013 From: roy at panix.com (Roy Smith) Date: Thu, 04 Apr 2013 08:39:46 -0400 Subject: In defence of 80-char lines References: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Jason Swails wrote: > The only time I regularly break my rule is for regular expressions (at some > point I may embrace re.X to allow me to break those up, too). re.X is a pretty cool tool for making huge regexes readable. But, it turns out that python's auto-continuation and string literal concatenation rules are enough to let you get much the same effect. Here's a regex we use to parse haproxy log files. This would be utter line noise all run together. This way, it's almost readable :-) pattern = re.compile(r'haproxy\[(?P\d+)]: ' r'(?P(\d{1,3}\.){3}\d{1,3}):' r'(?P\d{1,5}) ' r'\[(?P\d{2}/\w{3}/\d{4}(:\d{2}){3}\.\d{3})] ' r'(?P\S+) ' r'(?P\S+)/' r'(?P\S+) ' r'(?P(-1|\d+))/' r'(?P(-1|\d+))/' r'(?P(-1|\d+))/' r'(?P(-1|\d+))/' r'(?P\+?\d+) ' r'(?P\d{3}) ' r'(?P\d+) ' r'(?P\S+) ' r'(?P\S+) ' r'(?P[\w-]{4}) ' r'(?P\d+)/' r'(?P\d+)/' r'(?P\d+)/' r'(?P\d+)/' r'(?P\d+) ' r'(?P\d+)/' r'(?P\d+) ' r'(\{(?P.*?)\} )?' r'(\{(?P.*?)\} )?' r'(\{(?P.*?)\} )?' r'"(?P.+)"' ) And, for those of you who go running in the other direction every time regex is suggested as a solution, I challenge you to come up with easier to read (or write) code for parsing a line like this (probably hopelessly mangled by the time you read it): 2013-04-03T00:00:00+00:00 localhost haproxy[5199]: 10.159.19.244:57291 [02/Apr/2013:23:59:59.811] app-nodes next-song-nodes/web8.songza.com 0/0/3/214/219 200 593 sessionid=NWiX5KGOdvg6dSaA sessionid=NWiX5KGOdvg6dSaA ---- 249/249/149/14/0 0/0 {4C0ABFA9-515B6DEF-933229} "POST /api/1/station/892337/song/16024201/notify-play HTTP/1.0" From jason.swails at gmail.com Thu Apr 4 09:23:37 2013 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 4 Apr 2013 09:23:37 -0400 Subject: In defence of 80-char lines In-Reply-To: References: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Apr 4, 2013 at 8:39 AM, Roy Smith wrote: > In article , > Jason Swails wrote: > > > The only time I regularly break my rule is for regular expressions (at > some > > point I may embrace re.X to allow me to break those up, too). > > re.X is a pretty cool tool for making huge regexes readable. But, it > turns out that python's auto-continuation and string literal > concatenation rules are enough to let you get much the same effect. > Here's a regex we use to parse haproxy log files. This would be utter > line noise all run together. This way, it's almost readable :-) > > pattern = re.compile(r'haproxy\[(?P\d+)]: ' > r'(?P(\d{1,3}\.){3}\d{1,3}):' > r'(?P\d{1,5}) ' > For some reason that never occurred to me. I use this technique every other time I want to break up a long string, but never for regexes... Now I will. I was wary of using re.X since I sometimes use meaningful whitespace in my regexes, and I didn't want to have to figure out how to prevent them from being ignored... This is a much better solution. Thanks, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From neilc at norwich.edu Thu Apr 4 11:56:56 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 4 Apr 2013 15:56:56 GMT Subject: In defence of 80-char lines References: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-04-04, Roy Smith wrote: > re.X is a pretty cool tool for making huge regexes readable. > But, it turns out that python's auto-continuation and string > literal concatenation rules are enough to let you get much the > same effect. Here's a regex we use to parse haproxy log files. > This would be utter line noise all run together. This way, it's > almost readable :-) > > pattern = re.compile(r'haproxy\[(?P\d+)]: ' > r'(?P(\d{1,3}\.){3}\d{1,3}):' > r'(?P\d{1,5}) ' > > r'\[(?P\d{2}/\w{3}/\d{4}(:\d{2}){3}\.\d{3})] ' > r'(?P\S+) ' > r'(?P\S+)/' > r'(?P\S+) ' > r'(?P(-1|\d+))/' > r'(?P(-1|\d+))/' > r'(?P(-1|\d+))/' > r'(?P(-1|\d+))/' > r'(?P\+?\d+) ' > r'(?P\d{3}) ' > r'(?P\d+) ' > r'(?P\S+) ' > r'(?P\S+) ' > r'(?P[\w-]{4}) ' > r'(?P\d+)/' > r'(?P\d+)/' > r'(?P\d+)/' > r'(?P\d+)/' > r'(?P\d+) ' > r'(?P\d+)/' > r'(?P\d+) ' > r'(\{(?P.*?)\} )?' > r'(\{(?P.*?)\} )?' > r'(\{(?P.*?)\} )?' > r'"(?P.+)"' > ) > > And, for those of you who go running in the other direction every time > regex is suggested as a solution, I challenge you to come up with easier > to read (or write) code for parsing a line like this (probably > hopelessly mangled by the time you read it): > > 2013-04-03T00:00:00+00:00 localhost haproxy[5199]: 10.159.19.244:57291 > [02/Apr/2013:23:59:59.811] app-nodes next-song-nodes/web8.songza.com > 0/0/3/214/219 200 593 sessionid=NWiX5KGOdvg6dSaA > sessionid=NWiX5KGOdvg6dSaA ---- 249/249/149/14/0 0/0 > {4C0ABFA9-515B6DEF-933229} "POST > /api/1/station/892337/song/16024201/notify-play HTTP/1.0" The big win from the above seems to me the groupdict result. The parsing is also very simple, with virtually no nesting. It's a good application of re. It seems easy enough to do with str methods, but would it be an improvement? I ran out of time before the prototype was finished, but here's a sketch. import re import datetime import pprint s =('2013-04-03T00:00:00+00:00 localhost haproxy[5199]: 10.159.19.244:57291' ' [02/Apr/2013:23:59:59.811] app-nodes next-song-nodes/web8.songza.com' ' 0/0/3/214/219 200 593 sessionid=NWiX5KGOdvg6dSaA' ' sessionid=NWiX5KGOdvg6dSaA ---- 249/249/149/14/0 0/0' ' {4C0ABFA9-515B6DEF-933229}' ' "POST /api/1/station/892337/song/16024201/notify-play HTTP/1.0"') def get_haproxy(s): prefix = 'haproxy[' if s.startswith(prefix): return int(s[len(prefix):s.index(']')]) return False def get_client_info(s): ip, colon, port = s.partition(':') if colon != ':': return False else: return ip, int(port) def get_accept_date(s): try: return datetime.datetime.strptime(s, '[%d/%b/%Y:%H:%M:%S.%f]') except ValueError: return False def get_backend(s): name, slash, server = s.partition('/') if slash != '/': return False else: return name, server def get_track_info(s): try: return s.split('/') except TypeError: return False matchers = [ (None, None), (None, 'localhost'), ('haproxy', get_haproxy), (('client_ip', 'client_port'), get_client_info), ('accept_date', get_accept_date), ('frontend_name', lambda s: s), (('backend_name', 'server_name'), get_backend), (('Tq', 'Tw', 'Tc', 'Tr', 'Tt'), get_track_info), ] result = {} for i, s in enumerate(s.split()): if i < len(matchers): # I'm not finished writing matchers yet. key, matcher = matchers[i] if matcher is None: pass else: if isinstance(matcher, str): value = matcher == s else: value = matcher(s) if value is False: raise ValueError('Parse error {}: {} "{}"'.format( key, matcher, s)) if isinstance(key, tuple): result.update(zip(*[key, value])) elif key is not None: result[key] = value pprint.pprint(result) The engine would need to be improved in implementation and made more flexible once it's working and tested. I think the error handling is a good feature and the ability to customize parsing and return custom types is cool. -- Neil Cerutti From kushal.kumaran+python at gmail.com Thu Apr 4 13:34:07 2013 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Thu, 04 Apr 2013 23:04:07 +0530 Subject: In defence of 80-char lines In-Reply-To: References: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <515db999.4f79420a.0da9.306d@mx.google.com> Roy Smith writes: > In article , > Jason Swails wrote: > >> The only time I regularly break my rule is for regular expressions (at some >> point I may embrace re.X to allow me to break those up, too). > > re.X is a pretty cool tool for making huge regexes readable. But, it > turns out that python's auto-continuation and string literal > concatenation rules are enough to let you get much the same effect. > Here's a regex we use to parse haproxy log files. This would be utter > line noise all run together. This way, it's almost readable :-) > > pattern = re.compile(r'haproxy\[(?P\d+)]: ' > r'(?P(\d{1,3}\.){3}\d{1,3}):' > r'(?P\d{1,5}) ' > > r'\[(?P\d{2}/\w{3}/\d{4}(:\d{2}){3}\.\d{3})] ' > r'(?P\S+) ' > r'(?P\S+)/' > r'(?P\S+) ' > r'(?P(-1|\d+))/' > r'(?P(-1|\d+))/' > r'(?P(-1|\d+))/' > r'(?P(-1|\d+))/' > r'(?P\+?\d+) ' > r'(?P\d{3}) ' > r'(?P\d+) ' > r'(?P\S+) ' > r'(?P\S+) ' > r'(?P[\w-]{4}) ' > r'(?P\d+)/' > r'(?P\d+)/' > r'(?P\d+)/' > r'(?P\d+)/' > r'(?P\d+) ' > r'(?P\d+)/' > r'(?P\d+) ' > r'(\{(?P.*?)\} )?' > r'(\{(?P.*?)\} )?' > r'(\{(?P.*?)\} )?' > r'"(?P.+)"' > ) > > And, for those of you who go running in the other direction every time > regex is suggested as a solution, I challenge you to come up with easier > to read (or write) code for parsing a line like this (probably > hopelessly mangled by the time you read it): > > 2013-04-03T00:00:00+00:00 localhost haproxy[5199]: 10.159.19.244:57291 > [02/Apr/2013:23:59:59.811] app-nodes next-song-nodes/web8.songza.com > 0/0/3/214/219 200 593 sessionid=NWiX5KGOdvg6dSaA > sessionid=NWiX5KGOdvg6dSaA ---- 249/249/149/14/0 0/0 > {4C0ABFA9-515B6DEF-933229} "POST > /api/1/station/892337/song/16024201/notify-play HTTP/1.0" Is using csv.DictReader with delimiter=' ' not sufficient for this? I did not actually read the regular expression in its entirety. -- regards, kushal From roy at panix.com Thu Apr 4 19:55:58 2013 From: roy at panix.com (Roy Smith) Date: Thu, 04 Apr 2013 19:55:58 -0400 Subject: In defence of 80-char lines References: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Kushal Kumaran wrote: > > Is using csv.DictReader with delimiter=' ' not sufficient for this? I > did not actually read the regular expression in its entirety. I believe your second sentence answers the question raised in your first sentence :-) From msirenef at lightbird.net Thu Apr 4 12:12:26 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Thu, 04 Apr 2013 12:12:26 -0400 Subject: In defence of 80-char lines In-Reply-To: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <515DA66A.5080202@lightbird.net> On 04/03/2013 09:36 PM, Steven D'Aprano wrote: > Although PEP 8 is only compulsory for the Python standard library, many > users like to stick to PEP 8 for external projects. > > http://www.python.org/dev/peps/pep-0008/ > > With perhaps one glaring exception: many people hate, or ignore, PEP 8's > recommendation to limit lines to 80 characters. (Strictly speaking, 79 > characters.) > > > Here is a good defence of 80 char lines: > > http://wrongsideofmemphis.com/2013/03/25/80-chars-per-line-is-great/ > > > I think one important consideration that wasn't mentioned yet is one of Python principles: practicality beats purity. I can see how someone could have a preference for 80 char width, there are some valid reasons to prefer it. I think other reasons to prefer (slightly) longer width outweigh them, but that's a judgement call. However, if you work with other people's code, you will surely run into all kinds of widths, 100, 120, 140+, etc. For someone with a rigid 80 limit, it's a real pain. I feel that somewhere around 100 width, must be the reasonable middle ground: for me at soft 105 limit, editing 80 limit code feels almost like my own, in fact the range of 80-110 is going to fit neatly into my setup without any hassle. 120 is minimal hassle: I adjust Gvim to take a bit more space, resize browser to take a bit less space and I'm set. 140 is a bit uncomfortable, but I generally notice that even when people code to 140 limit, nearly all of their lines are actually going to be at about 120 limit at most, with only a few offenders, so it's trivial to adjust to 120 limit. If people go over 140, that conclusively proves they're smoking crack and the code needs to be refactored anyway. I also find the argument about 80 width used in books a little odd. I read webpages with 100-140 widths all the time with not the slightest problem. As far as I know, no browser in existence lets you uniformly adjust all pages to wrap at 80 limit except for lynx/links; if it was hard to read at wider sizes, surely there would be at least one graphical browser that would give that option (and get all the user share from other browsers?) Code is rather different from regular text. I would not want my books formatted like this: The story had held us, round the fire, sufficiently breathless, but except the obvious remark that it was gruesome, as, on Christmas Eve in an old house, a strange tale should essentially be, I remember no comment uttered till somebody happened to say that it was the only case he had met in which such a visitation had fallen on a child. Nor am I (warning: understatement) particularly enthusiastic about editing code that looks like (formatted to 72 width): try: request = self.request_class(environ) except UnicodeDecodeError: logger.warning('Bad Request (UnicodeDecodeError)', exc_info=sys.exc_info(), extra={ 'status_code': 400, }) response = http.HttpResponseBadRequest() else: response = self.get_response(request) response._handler_class = self.__class__ try: status_text = STATUS_CODE_TEXT[response.status_code] except KeyError: status_text = 'UNKNOWN STATUS CODE' status = '%s %s' % (response.status_code, status_text) response_headers = [(str(k), str(v)) for k, v in response.items()] for c in response.cookies.values(): response_headers.append((str('Set-Cookie'), str(c.output(header='')))) start_response(force_str(status), response_headers) return response -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From wxjmfauth at gmail.com Thu Apr 4 16:28:04 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Thu, 4 Apr 2013 13:28:04 -0700 (PDT) Subject: In defence of 80-char lines References: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4 avr, 03:36, Steven D'Aprano wrote: > Although PEP 8 is only compulsory for the Python standard library, many > users like to stick to PEP 8 for external projects. > > http://www.python.org/dev/peps/pep-0008/ > > With perhaps one glaring exception: many people hate, or ignore, PEP 8's > recommendation to limit lines to 80 characters. (Strictly speaking, 79 > characters.) > > Here is a good defence of 80 char lines: > > http://wrongsideofmemphis.com/2013/03/25/80-chars-per-line-is-great/ > > -- > Steven ----- With "unicode fonts", where even the monospaced fonts present char widths with a variable width depending on the unicode block (obvious reasons), speaking of a "text width" in chars has not even a sense. jmf From jason.swails at gmail.com Thu Apr 4 17:00:53 2013 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 4 Apr 2013 17:00:53 -0400 Subject: In defence of 80-char lines In-Reply-To: References: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Apr 4, 2013 at 4:28 PM, jmfauth wrote: > On 4 avr, 03:36, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: > > Although PEP 8 is only compulsory for the Python standard library, many > > users like to stick to PEP 8 for external projects. > > > > http://www.python.org/dev/peps/pep-0008/ > > > > With perhaps one glaring exception: many people hate, or ignore, PEP 8's > > recommendation to limit lines to 80 characters. (Strictly speaking, 79 > > characters.) > > > > Here is a good defence of 80 char lines: > > > > http://wrongsideofmemphis.com/2013/03/25/80-chars-per-line-is-great/ > > > > -- > > Steven > > ----- > > With "unicode fonts", Didn't see this coming. > where even the monospaced fonts > present char widths with a variable width depending on > the unicode block (obvious reasons), speaking of a "text > width" in chars has not even a sense. > Let's log this as an exception to the rule of 80. There are plenty of threads not-about-Unicode-but-are-now-about-Unicode that we don't have to create another one. Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Thu Apr 4 20:14:01 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Apr 2013 00:14:01 GMT Subject: In defence of 80-char lines References: <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> Message-ID: <515e1749$0$29966$c3e8da3$5496439d@news.astraweb.com> On Thu, 04 Apr 2013 13:28:04 -0700, jmfauth wrote: > With "unicode fonts", where even the monospaced fonts present char > widths with a variable width depending on the unicode block (obvious > reasons), speaking of a "text width" in chars has not even a sense. A properly-designed Unicode monospaced font should still be monospaced. Or at worst, bispaced, if it also supports East Asian halfwidth and fullwidth forms. In that case, the text width in chars should be interpreted as halfwidth chars. Or if you prefer, the rule can be interpreted as: Line width should be no greater than 79 halfwidth characters, or 39 fullwidth characters, or some combination thereof. http://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms -- Steven From teslafrequency at aol.com Wed Apr 3 23:45:51 2013 From: teslafrequency at aol.com (teslafrequency at aol.com) Date: Wed, 3 Apr 2013 20:45:51 -0700 (PDT) Subject: Python 3.3 Tkinter Fullscreen - Taskbar not Hiding Message-ID: Hi, I am working with Tkinter, and I have set up some simple code to run: import tkinter import re from tkinter import * global master master = Tk() # Start game Launcher def FormGUI(): master.title("GAME TITLE") SW = master.winfo_screenwidth() / 3.2 SH = master.winfo_screenheight() / 3.2 master.geometry("500x300+%d+%d" % (SW, SH)) Label(master,text="game:\nGAME TITLE").pack() Button(master, text="Start game", command=DestroyStart, takefocus=1).pack() master.wm_state(zoom) # Destroy the GUI launcher window upon player starting the game. def DestroyStart(): global master master.destroy() master = Tk() ReformGui() # Form the game's GUI window in full screen. def ReformGui(): master.title("GAME TITLE") SW = master.winfo_screenwidth() SH = master.winfo_screenheight() master.geometry("%dx%d+0+0" % (SW,SH)) master.attributes("-fullscreen", 1) master.configure(bg="black") Label(master, text="\"GAME TESTING TEXT\"", background="black", foreground="white").pack() FormGUI() master.mainloop() # END OF CODE Everything in this code runs appropriately. The main goal of this code is to open up two windows, one with fixed dimensions, the other with full-screen enabled. My problem is that with the code above, the full-screen window opens up properly, however my taskbar shows over the full-screen. Until I click on the full-screen window, the taskbar will not be hidden. Am I doing something wrong, or is there a better way to create a full-screen window in Tkinter with the taskbar hidden? Note: Removing the 'import re' code above fixes the taskbar problem, however the re module is apparently needed as I can't run the program properly as an executable. Importing re fixes this problem. I'm running this program under Windows. From jason.swails at gmail.com Thu Apr 4 09:49:36 2013 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 4 Apr 2013 09:49:36 -0400 Subject: Python 3.3 Tkinter Fullscreen - Taskbar not Hiding In-Reply-To: References: Message-ID: I've added some comments about the code in question as well... On Wed, Apr 3, 2013 at 11:45 PM, wrote: > Hi, I am working with Tkinter, and I have set up some simple code to run: > > import tkinter > import re > from tkinter import * > If you import everything from tkinter into your top-level namespace, then the "import tkinter" at the top serves no purpose. > global master > This 'global master' statement does nothing (and is actually misleading IMO). > master = Tk() > > # Start game Launcher > def FormGUI(): > master.title("GAME TITLE") > SW = master.winfo_screenwidth() / 3.2 > SH = master.winfo_screenheight() / 3.2 > master.geometry("500x300+%d+%d" % (SW, SH)) > Label(master,text="game:\nGAME TITLE").pack() > Button(master, text="Start game", command=DestroyStart, > takefocus=1).pack() > master.wm_state(zoom) > What is "zoom"? This variable is not defined. In fact, I get a NameError when I try running your code because of this: Traceback (most recent call last): File "test_tk.py", line 38, in FormGUI() File "test_tk.py", line 18, in FormGUI master.wm_state(zoom) NameError: global name 'zoom' is not defined If I change zoom to "normal" (with quotes), it appears to work (although I'm testing on Linux, not Windows). > # Destroy the GUI launcher window upon player starting the game. > def DestroyStart(): > global master > master.destroy() > master = Tk() > ReformGui() > > # Form the game's GUI window in full screen. > def ReformGui(): > master.title("GAME TITLE") > SW = master.winfo_screenwidth() > SH = master.winfo_screenheight() > master.geometry("%dx%d+0+0" % (SW,SH)) > master.attributes("-fullscreen", 1) > master.configure(bg="black") > Label(master, text="\"GAME TESTING TEXT\"", > background="black", foreground="white").pack() > FormGUI() > > master.mainloop() > > # END OF CODE > > Everything in this code runs appropriately. The main goal of this code is > to open up two windows, one with fixed dimensions, the other with > full-screen enabled. > > My problem is that with the code above, the full-screen window opens up > properly, however my taskbar shows over the full-screen. Until I click on > the full-screen window, the taskbar will not be hidden. > > Am I doing something wrong, or is there a better way to create a > full-screen window in Tkinter with the taskbar hidden? > This sounds to me that your full screen window does not have the focus (i.e., it is not the `active' window). Try adding a "master.focus_force()" call in the ReformGui function to force it to take focus. Note that focus_force() is often considered 'impolite'---it's akin to that kid that always needs to be the center of attention. Of course it's not as bad as master.grab_set_global :) If your application already has 'focus', then you can use focus_set instead of focus_force. The problem may be that you are destroying the original master window and re-creating another (I typically avoid destroying the root window mid-application). Also as a note, it would be helpful to have some kind of button or something to exit the app or exit fullscreen. I had to Alt-F4 in order to quit your sample program ;). Hope this helps, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From sg552 at hotmail.co.uk Thu Apr 4 13:30:25 2013 From: sg552 at hotmail.co.uk (Rotwang) Date: Thu, 04 Apr 2013 18:30:25 +0100 Subject: Python 3.3 Tkinter Fullscreen - Taskbar not Hiding In-Reply-To: References: Message-ID: On 04/04/2013 14:49, Jason Swails wrote: > I've added some comments about the code in question as well... > > On Wed, Apr 3, 2013 at 11:45 PM, > wrote: > > Hi, I am working with Tkinter, and I have set up some simple code to > run: > > import tkinter > import re > from tkinter import * > > > If you import everything from tkinter into your top-level namespace, > then the "import tkinter" at the top serves no purpose. I don't know whether this applies to the OP's code, but I can think of at least one reason why one would want both "import module" and "from module import*" at the top of one's code: monkey patching. From jason.swails at gmail.com Thu Apr 4 15:00:46 2013 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 4 Apr 2013 15:00:46 -0400 Subject: Python 3.3 Tkinter Fullscreen - Taskbar not Hiding In-Reply-To: References: Message-ID: On Thu, Apr 4, 2013 at 1:30 PM, Rotwang wrote: > On 04/04/2013 14:49, Jason Swails wrote: > >> I've added some comments about the code in question as well... >> >> On Wed, Apr 3, 2013 at 11:45 PM, > > wrote: >> >> Hi, I am working with Tkinter, and I have set up some simple code to >> run: >> >> import tkinter >> import re >> from tkinter import * >> >> >> If you import everything from tkinter into your top-level namespace, >> then the "import tkinter" at the top serves no purpose. >> > > I don't know whether this applies to the OP's code, but I can think of at > least one reason why one would want both "import module" and "from module > import*" at the top of one's code: monkey patching. That was not happening in the OP's code (it actually had no references to tkinter after the initial import). That said, if you change any attributes inside tkinter (by binding names inside tkinter to another object) after the top three lines, those changes will not percolate down to the attributes imported via "from tkinter import *" -- you would obviously have to do that work before importing the tkinter namespace into the toplevel namespace. I'd be interested to see if there's actually an example where someone does this in a way that would not be done better another way. In any case, it served no purpose in this particular program :). All the best, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From sg552 at hotmail.co.uk Thu Apr 4 18:21:15 2013 From: sg552 at hotmail.co.uk (Rotwang) Date: Thu, 04 Apr 2013 23:21:15 +0100 Subject: Python 3.3 Tkinter Fullscreen - Taskbar not Hiding In-Reply-To: References: Message-ID: On 04/04/2013 20:00, Jason Swails wrote: > On Thu, Apr 4, 2013 at 1:30 PM, Rotwang > wrote: > [...] > > I don't know whether this applies to the OP's code, but I can think > of at least one reason why one would want both "import module" and > "from module import*" at the top of one's code: monkey patching. > > > That was not happening in the OP's code (it actually had no references > to tkinter after the initial import). Sure. > That said, if you change any > attributes inside tkinter (by binding names inside tkinter to another > object) after the top three lines, those changes will not percolate down > to the attributes imported via "from tkinter import *" -- you would > obviously have to do that work before importing the tkinter namespace > into the toplevel namespace. What I had in mind was something like this: # begin module derp.py global_variable = 4 def f(): print('global_variable == %i' % global_variable) # end module derp.py >>> # in the interactive interpreter... >>> import derp >>> from derp import * >>> global_variable = 5 >>> f() global_variable == 4 >>> derp.global_variable = 5 >>> f() global_variable == 5 Off the top of my head I don't know whether there's any purpose to doing that kind of thing with tkinter, but I can conceive that it might be useful for e.g. changing widget default behaviour or something. > I'd be interested to see if there's actually an example where someone > does this in a way that would not be done better another way. No idea, sorry. From teslafrequency at aol.com Thu Apr 4 13:31:25 2013 From: teslafrequency at aol.com (teslafrequency at aol.com) Date: Thu, 4 Apr 2013 10:31:25 -0700 (PDT) Subject: Python 3.3 Tkinter Fullscreen - Taskbar not Hiding In-Reply-To: References: Message-ID: <86c277d0-2f8c-4387-85c0-784a757c6a95@googlegroups.com> Thanks a lot for your help, I've implemented the code you suggested and it seems to be functioning properly now. I've cleaned up the code a bit as well. I'll also take into account not destroying the master. Thanks again for your help! From hendikoy at gmail.com Thu Apr 4 04:19:13 2013 From: hendikoy at gmail.com (YE SHANG) Date: Thu, 4 Apr 2013 01:19:13 -0700 (PDT) Subject: Help me with PyCharm on Mac OS Message-ID: <43fd272e-1518-4a8c-916c-f9288e3e9949@googlegroups.com> Hello! I'm a newbie of developing GAE Apps on Mac. My Mac OS is Mountain Lion, I reinstalled python 2.7.3 instead of pre-installed python 2.7.2, as well as GAE SDK. I finished configuration of Python interpreter(/usr/local/bin/python2.7), and Google App Engine(/usr/local/google_appengine). It looks fine until I run the GAE project, there is an error appeared like below: --------------------------------------------------------------- /usr/local/bin/python2.7 /usr/local/bin/pythonw /usr/local/google_appengine/dev_appserver.py . File "/usr/local/bin/pythonw", line 1 SyntaxError: Non-ASCII character '\xca' in file /usr/local/bin/pythonw on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details Process finished with exit code 1 ---------------------------------------------------------------- I can't understand what's going on, I've already add "-*- coding: utf-8 -*-" at the line 1 in main.py. I created another python file and ran it on pycharm, it works well. So I'm just confused what happend with my GAE project. PS: I can run GAE project on GAE launcher, so I guess there must be something wrong with my configuration of pycharm. I used pycharm both on Windows or Ubuntu before, they all functioned well. Can anybody help me? Thanks. From davea at davea.name Thu Apr 4 06:13:03 2013 From: davea at davea.name (Dave Angel) Date: Thu, 04 Apr 2013 06:13:03 -0400 Subject: Help me with PyCharm on Mac OS In-Reply-To: <43fd272e-1518-4a8c-916c-f9288e3e9949@googlegroups.com> References: <43fd272e-1518-4a8c-916c-f9288e3e9949@googlegroups.com> Message-ID: <515D522F.8050501@davea.name> On 04/04/2013 04:19 AM, YE SHANG wrote: > Hello! > > I'm a newbie of developing GAE Apps on Mac. > > My Mac OS is Mountain Lion, I reinstalled python 2.7.3 instead of pre-installed python 2.7.2, as well as GAE SDK. > > I finished configuration of Python interpreter(/usr/local/bin/python2.7), and Google App Engine(/usr/local/google_appengine). > > It looks fine until I run the GAE project, there is an error appeared like below: > > --------------------------------------------------------------- > /usr/local/bin/python2.7 /usr/local/bin/pythonw /usr/local/google_appengine/dev_appserver.py . > File "/usr/local/bin/pythonw", line 1 > SyntaxError: Non-ASCII character '\xca' in file /usr/local/bin/pythonw on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details > > Process finished with exit code 1 > ---------------------------------------------------------------- > I can't understand what's going on, I've already add "-*- coding: utf-8 -*-" at the line 1 in main.py. > I created another python file and ran it on pycharm, it works well. > So I'm just confused what happend with my GAE project. > > PS: I can run GAE project on GAE launcher, so I guess there must be something wrong with my configuration of pycharm. > I used pycharm both on Windows or Ubuntu before, they all functioned well. > > Can anybody help me? Thanks. > I don't know anything about GAE, but I may be able to point you to the problem. Is /usr/local/bin/pythonw a file you put there? Is it a text file or binary? The error message shows that Python thinks it's supposed to be a text file, but the lack of a .py extension makes me suspicious. Could it be an executable supplied by GAE that you're supposed to run instead of python2.7 ? What command line are you using to launch this? Are you typing python pythonw by any chance? If so, you're telling Python to treat it as a text file, specifically as your main script. Wild guess: maybe GAE wants you to use a command line like: pythonw main.py -- DaveA From hendikoy at gmail.com Thu Apr 4 10:02:49 2013 From: hendikoy at gmail.com (YE SHANG) Date: Thu, 4 Apr 2013 07:02:49 -0700 (PDT) Subject: Help me with PyCharm on Mac OS In-Reply-To: References: <43fd272e-1518-4a8c-916c-f9288e3e9949@googlegroups.com> Message-ID: <5e77cb8d-fdb4-443b-9b17-83286139dbfc@googlegroups.com> Thank you for your help. I've figured it out, problem is that I wrote bad options in interpretor options. ? 2013?4?4????UTC+8??6?13?03??Dave Angel??? > On 04/04/2013 04:19 AM, YE SHANG wrote: > > > Hello! > > > > > > I'm a newbie of developing GAE Apps on Mac. > > > > > > My Mac OS is Mountain Lion, I reinstalled python 2.7.3 instead of pre-installed python 2.7.2, as well as GAE SDK. > > > > > > I finished configuration of Python interpreter(/usr/local/bin/python2.7), and Google App Engine(/usr/local/google_appengine). > > > > > > It looks fine until I run the GAE project, there is an error appeared like below: > > > > > > --------------------------------------------------------------- > > > /usr/local/bin/python2.7 /usr/local/bin/pythonw /usr/local/google_appengine/dev_appserver.py . > > > File "/usr/local/bin/pythonw", line 1 > > > SyntaxError: Non-ASCII character '\xca' in file /usr/local/bin/pythonw on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details > > > > > > Process finished with exit code 1 > > > ---------------------------------------------------------------- > > > I can't understand what's going on, I've already add "-*- coding: utf-8 -*-" at the line 1 in main.py. > > > I created another python file and ran it on pycharm, it works well. > > > So I'm just confused what happend with my GAE project. > > > > > > PS: I can run GAE project on GAE launcher, so I guess there must be something wrong with my configuration of pycharm. > > > I used pycharm both on Windows or Ubuntu before, they all functioned well. > > > > > > Can anybody help me? Thanks. > > > > > > > I don't know anything about GAE, but I may be able to point you to the > > problem. > > > > Is /usr/local/bin/pythonw a file you put there? Is it a text file or > > binary? The error message shows that Python thinks it's supposed to be > > a text file, but the lack of a .py extension makes me suspicious. Could > > it be an executable supplied by GAE that you're supposed to run instead > > of python2.7 ? > > > > What command line are you using to launch this? Are you typing > > > > python pythonw > > > > by any chance? If so, you're telling Python to treat it as a text file, > > specifically as your main script. > > > > Wild guess: maybe GAE wants you to use a command line like: > > > > pythonw main.py > > > > > > -- > > DaveA From hendikoy at gmail.com Thu Apr 4 10:02:49 2013 From: hendikoy at gmail.com (YE SHANG) Date: Thu, 4 Apr 2013 07:02:49 -0700 (PDT) Subject: Help me with PyCharm on Mac OS In-Reply-To: References: <43fd272e-1518-4a8c-916c-f9288e3e9949@googlegroups.com> Message-ID: <5e77cb8d-fdb4-443b-9b17-83286139dbfc@googlegroups.com> Thank you for your help. I've figured it out, problem is that I wrote bad options in interpretor options. ? 2013?4?4????UTC+8??6?13?03??Dave Angel??? > On 04/04/2013 04:19 AM, YE SHANG wrote: > > > Hello! > > > > > > I'm a newbie of developing GAE Apps on Mac. > > > > > > My Mac OS is Mountain Lion, I reinstalled python 2.7.3 instead of pre-installed python 2.7.2, as well as GAE SDK. > > > > > > I finished configuration of Python interpreter(/usr/local/bin/python2.7), and Google App Engine(/usr/local/google_appengine). > > > > > > It looks fine until I run the GAE project, there is an error appeared like below: > > > > > > --------------------------------------------------------------- > > > /usr/local/bin/python2.7 /usr/local/bin/pythonw /usr/local/google_appengine/dev_appserver.py . > > > File "/usr/local/bin/pythonw", line 1 > > > SyntaxError: Non-ASCII character '\xca' in file /usr/local/bin/pythonw on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details > > > > > > Process finished with exit code 1 > > > ---------------------------------------------------------------- > > > I can't understand what's going on, I've already add "-*- coding: utf-8 -*-" at the line 1 in main.py. > > > I created another python file and ran it on pycharm, it works well. > > > So I'm just confused what happend with my GAE project. > > > > > > PS: I can run GAE project on GAE launcher, so I guess there must be something wrong with my configuration of pycharm. > > > I used pycharm both on Windows or Ubuntu before, they all functioned well. > > > > > > Can anybody help me? Thanks. > > > > > > > I don't know anything about GAE, but I may be able to point you to the > > problem. > > > > Is /usr/local/bin/pythonw a file you put there? Is it a text file or > > binary? The error message shows that Python thinks it's supposed to be > > a text file, but the lack of a .py extension makes me suspicious. Could > > it be an executable supplied by GAE that you're supposed to run instead > > of python2.7 ? > > > > What command line are you using to launch this? Are you typing > > > > python pythonw > > > > by any chance? If so, you're telling Python to treat it as a text file, > > specifically as your main script. > > > > Wild guess: maybe GAE wants you to use a command line like: > > > > pythonw main.py > > > > > > -- > > DaveA From karthik.murugesan at delphi.com Thu Apr 4 05:05:56 2013 From: karthik.murugesan at delphi.com (Murugesan, Karthik) Date: Thu, 4 Apr 2013 09:05:56 +0000 Subject: Gnuplot Message-ID: <520A0D56671AE442AB2E81CC326608620A9FCCCD@017-CH1MPN2-061.017d.mgd.msft.net> Hello, I am having a few issues interfacing gnuplot with python. When I try to run the demo.py file I get the following error messages: Traceback (most recent call last): File "C:\Program Files\Common Files\dSPACE\Python25\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript exec codeObject in __main__.__dict__ File "C:\Program Files\Common Files\dSPACE\Python25\Lib\site-packages\Gnuplot\demo.py", line 110, in demo() File "C:\Program Files\Common Files\dSPACE\Python25\Lib\site-packages\Gnuplot\demo.py", line 36, in demo g.reset() File "C:\Program Files\Common Files\dSPACE\Python25\Lib\site-packages\Gnuplot\_Gnuplot.py", line 366, in reset self('reset') File "C:\Program Files\Common Files\dSPACE\Python25\Lib\site-packages\Gnuplot\_Gnuplot.py", line 210, in __call__ self.gnuplot(s) File "C:\Program Files\Common Files\dSPACE\Python25\lib\site-packages\Gnuplot\gp_win32.py", line 130, in __call__ self.write(s + '\n') IOError: [Errno 22] Invalid argument After reading other users having similar problems, I altered the 'gnuplot_command' line in gp_win32.py to 'gnuplot_command = "c:\Program Files\wgnuplot\bin\pgnuplot.exe", in an attempt to directly get the pgnuplot.exe(which I believe is the root of the problem). However, I still get the same error message. Any ideas on how to solve this? Thanks **************************************************************************************** Note: If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. Thank you. **************************************************************************************** -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Thu Apr 4 07:50:00 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 04 Apr 2013 12:50:00 +0100 Subject: Gnuplot In-Reply-To: <520A0D56671AE442AB2E81CC326608620A9FCCCD@017-CH1MPN2-061.017d.mgd.msft.net> References: <520A0D56671AE442AB2E81CC326608620A9FCCCD@017-CH1MPN2-061.017d.mgd.msft.net> Message-ID: On 04/04/2013 10:05, Murugesan, Karthik wrote: > Hello, I am having a few issues interfacing gnuplot with python. > > Any ideas on how to solve this? > > Thanks > > Sorry not a direct response but I found the best solution to gnuplot problems was using matplotlib instead. -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From mattgraves7 at gmail.com Thu Apr 4 11:16:20 2013 From: mattgraves7 at gmail.com (mattgraves7 at gmail.com) Date: Thu, 4 Apr 2013 08:16:20 -0700 (PDT) Subject: Error running any script in IDLE Message-ID: Im fairly new to Python. I was trying to run a script using IDLE and it came back with an error and immediately shut down. After this, every script I tried to test within IDLE would do the same. I wrote the following script: while True x = input("test") It seems simple enough to not be screwed up in any way, but when I hit F5 to test, it gets red text and shuts down IDLE. It scrolls too fast to see before shutting down, but I right clicked the text quickly to pause it. This is what it comes back with: http://s21.postimg.org/4so8merdz/asdfg.png Can anyone tell me what's going on, and why this error comes up regardless of what script I try to run in IDLE? If I run it in cmd, it seems to work fine. From rosuav at gmail.com Thu Apr 4 11:29:55 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 5 Apr 2013 02:29:55 +1100 Subject: Error running any script in IDLE In-Reply-To: References: Message-ID: On Fri, Apr 5, 2013 at 2:16 AM, wrote: > Im fairly new to Python. I was trying to run a script using IDLE and it came back with an error and immediately shut down. After this, every script I tried to test within IDLE would do the same. I wrote the following script: > > while True > x = input("test") > > It seems simple enough to not be screwed up in any way, but when I hit F5 to test, it gets red text and shuts down IDLE. It scrolls too fast to see before shutting down, but I right clicked the text quickly to pause it. This is what it comes back with: > http://s21.postimg.org/4so8merdz/asdfg.png > > Can anyone tell me what's going on, and why this error comes up regardless of what script I try to run in IDLE? It looks like you've made a module called 'random.py', which is shadowing the standard library 'random' module. In that file, you appear to have line numbers - note how line 42 is prefixed with the actual number 42 - and that's causing syntax errors deep inside IDLE. Try renaming or deleting your random.py to see if that fixes it. ChrisA From mattgraves7 at gmail.com Thu Apr 4 11:33:55 2013 From: mattgraves7 at gmail.com (mattgraves7 at gmail.com) Date: Thu, 4 Apr 2013 08:33:55 -0700 (PDT) Subject: Error running any script in IDLE In-Reply-To: References: Message-ID: <6b0a1f2c-21ff-4ff0-9d57-2a155a27ca2b@googlegroups.com> Thanks Chris, that worked. Like I said, I'm fairly new to python so I am still learning the ins and outs. Thank you. From rosuav at gmail.com Thu Apr 4 11:38:01 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 5 Apr 2013 02:38:01 +1100 Subject: Error running any script in IDLE In-Reply-To: <6b0a1f2c-21ff-4ff0-9d57-2a155a27ca2b@googlegroups.com> References: <6b0a1f2c-21ff-4ff0-9d57-2a155a27ca2b@googlegroups.com> Message-ID: On Fri, Apr 5, 2013 at 2:33 AM, wrote: > Thanks Chris, that worked. Like I said, I'm fairly new to python so I am still learning the ins and outs. Thank you. No probs. You provided all the information needed to solve the problem, for which I am very much appreciative. All the best! ChrisA From mattgraves7 at gmail.com Thu Apr 4 11:33:55 2013 From: mattgraves7 at gmail.com (mattgraves7 at gmail.com) Date: Thu, 4 Apr 2013 08:33:55 -0700 (PDT) Subject: Error running any script in IDLE In-Reply-To: References: Message-ID: <6b0a1f2c-21ff-4ff0-9d57-2a155a27ca2b@googlegroups.com> Thanks Chris, that worked. Like I said, I'm fairly new to python so I am still learning the ins and outs. Thank you. From breamoreboy at yahoo.co.uk Thu Apr 4 12:12:56 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 04 Apr 2013 17:12:56 +0100 Subject: Error running any script in IDLE In-Reply-To: References: Message-ID: On 04/04/2013 16:16, mattgraves7 at gmail.com wrote: > Im fairly new to Python. I was trying to run a script using IDLE and it came back with an error and immediately shut down. After this, every script I tried to test within IDLE would do the same. I wrote the following script: > > while True > x = input("test") > I see you've already got an answer but you didn't run the above code as you'd get a syntax error. As you're new I'll leave you to find out where :) -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From renato.barbosa.pim.pereira at gmail.com Thu Apr 4 11:41:05 2013 From: renato.barbosa.pim.pereira at gmail.com (Renato Barbosa Pim Pereira) Date: Thu, 4 Apr 2013 12:41:05 -0300 Subject: IDE for GUI Designer Message-ID: Guys, is this, I wonder if there is an IDE with native support for the development of GUI's such as Netbeans with Swing, Visual Basic, etc., already tested the Boa Constructor, and PyQt, but did not like what I'm looking for is an IDE "all in one", ie power encode and draw the screens of the program, someone indicates some?, but what I would like to know everything together with an IDE: Coding + GUI (via visual elements) without the need to import or export anything, like so: I want a button, I click and drag it to a window, give two clicks and encode their actions, understand? Thanks for all. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ed at leafe.com Thu Apr 4 13:12:21 2013 From: ed at leafe.com (Ed Leafe) Date: Thu, 4 Apr 2013 12:12:21 -0500 Subject: IDE for GUI Designer In-Reply-To: References: Message-ID: <16438E61-FBCB-4655-93F7-5839666CB072@leafe.com> On Apr 4, 2013, at 10:41 AM, Renato Barbosa Pim Pereira wrote: > Guys, is this, I wonder if there is an IDE with native support for the development of GUI's such as Netbeans with Swing,Visual Basic, etc., already tested the Boa Constructor, and PyQt, but did not like what I'm looking for is an IDE "all in one", ie power encode and draw the screens of the program, someone indicates some?, but what I would like to knoweverything together with an IDE: Coding + GUI (via visual elements) without the need to import or export anything, like so: I want a button, I click and drag it to a window, give two clicks and encode their actions, understand? Check out Dabo: http://dabodev.com -- Ed Leafe (one of the authors) From cmpython at gmail.com Thu Apr 4 13:41:25 2013 From: cmpython at gmail.com (CM) Date: Thu, 4 Apr 2013 10:41:25 -0700 (PDT) Subject: IDE for GUI Designer References: Message-ID: <1596b1ee-c146-4221-a9e0-dbd447a83f04@p5g2000yqj.googlegroups.com> On Apr 4, 11:41?am, Renato Barbosa Pim Pereira wrote: > Guys, is this, I wonder if there is an IDE with native support for the > development of GUI's such as Netbeans with Swing, Visual Basic, etc., The term you want to use is "GUI Builder". Because there can be IDEs without a GUI builder. You want both. > already tested the Boa Constructor, and PyQt, but did not like what I'm looking What did you not like about Boa Constructor? PyQT is not an IDE nor is it a GUI builder. It is a "widget toolkit" (or "framework"). > for is an IDE "all in one", ie power encode and draw the screens of the > program, someone indicates some?, but what I would like to know everything > together with an IDE: Coding + GUI (via visual elements) without the need > to import or export anything, like so: I want a button, I click and drag it to > a window, give two clicks and encode their actions, understand? This is exactly what Boa Constructor does. > Thanks for all. From feliphil at gmx.net Sun Apr 7 13:40:31 2013 From: feliphil at gmx.net (Wolfgang Keller) Date: Sun, 7 Apr 2013 19:40:31 +0200 Subject: IDE for GUI Designer References: Message-ID: <20130407194031.ee59e3bc94b02b03d735990f@gmx.net> > Guys, is this, I wonder if there is an IDE with native support for the > development of GUI's A decent Python IDE would probably integrate well enough with any decent GUI builder. If there was one (decent GUI builder). Unfortunately there's afaik currently no GUI builder available for any of the Python GUI frameworks that actually makes use of the dynamic interpreted nature of Python (in a way comparable to Cocoa's Interface Builder or the Visualworks Smalltalk IDE). They are unfortunately all just conceived following the clumsy tedious static C++-ish code-generation method. X-( Sincerely, Wolfgang From fabiofz at gmail.com Sun Apr 7 15:04:44 2013 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Sun, 7 Apr 2013 16:04:44 -0300 Subject: IDE for GUI Designer In-Reply-To: <20130407194031.ee59e3bc94b02b03d735990f@gmx.net> References: <20130407194031.ee59e3bc94b02b03d735990f@gmx.net> Message-ID: Well, I usually use the Qt Designer and it does work well for me. It generates a .ui file with it which has to be passed to pyuic to generate the actual Python code -- and you have to generate a subclass to implement the slots -- for that, I add an external builder to Eclipse, so, in the end it's mostly a matter of saving the ui in designer and going on to implement the actual code for the actions in PyDev/Eclipse (sure, you don't click on a link to add Python code, but for me that separation is good). Cheers, Fabio On Sun, Apr 7, 2013 at 2:40 PM, Wolfgang Keller wrote: > > Guys, is this, I wonder if there is an IDE with native support for the > > development of GUI's > > A decent Python IDE would probably integrate well enough with any decent > GUI builder. If there was one (decent GUI builder). > > Unfortunately there's afaik currently no GUI builder available for any > of the Python GUI frameworks that actually makes use of the dynamic > interpreted nature of Python (in a way comparable to Cocoa's Interface > Builder or the Visualworks Smalltalk IDE). They are unfortunately all > just conceived following the clumsy tedious static C++-ish > code-generation method. X-( > > Sincerely, > > Wolfgang > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From feliphil at gmx.net Sat Apr 13 14:31:19 2013 From: feliphil at gmx.net (Wolfgang Keller) Date: Sat, 13 Apr 2013 20:31:19 +0200 Subject: IDE for GUI Designer In-Reply-To: References: <20130407194031.ee59e3bc94b02b03d735990f@gmx.net> Message-ID: <20130413203119.df42e7ae28b64c8e29f66c58@gmx.net> > Well, I usually use the Qt Designer and it does work well for me. > > It generates a .ui file with it which has to be passed to pyuic to > generate the actual Python code Wow. Even one more step than with code generation directly from the GUI builder. Clumsy, tedious, static. Cocoa's Interface Builder shows how to do it even though Objective-C is a *compiled* language, unlike Python. Sincerely, Wolfgang From robert.kern at gmail.com Sat Apr 13 14:38:55 2013 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 14 Apr 2013 00:08:55 +0530 Subject: IDE for GUI Designer In-Reply-To: <20130413203119.df42e7ae28b64c8e29f66c58@gmx.net> References: <20130407194031.ee59e3bc94b02b03d735990f@gmx.net> <20130413203119.df42e7ae28b64c8e29f66c58@gmx.net> Message-ID: On 2013-04-14 00:01, Wolfgang Keller wrote: >> Well, I usually use the Qt Designer and it does work well for me. >> >> It generates a .ui file with it which has to be passed to pyuic to >> generate the actual Python code > > Wow. > > Even one more step than with code generation directly from > the GUI builder. You don't have to use pyuic. You can load the .ui file directly from your program. > Clumsy, tedious, static. > > Cocoa's Interface Builder shows how to do it even though Objective-C is > a *compiled* language, unlike Python. The workflow is about the same, really. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From satamukh at gmail.com Thu Apr 4 15:08:36 2013 From: satamukh at gmail.com (Satabdi Mukherjee) Date: Thu, 4 Apr 2013 12:08:36 -0700 (PDT) Subject: problem in running a basic code in python 3.3.0 that includes HTML file Message-ID: <4b7526eb-b501-4ff8-a257-8cfefbeda413@googlegroups.com> i have written this code and i need to run this file def CreateEvent(str): "This prints a passed string into this function"; print str; return; CreateEvent (print''' content-type: text/html the list of all possible events that can be notified by our system
tsunami
earthquake
volcano
hurricane
sinkholes
tornado
landslide
downburst
''') but it gives this error expected an intended block. can anyone please tell me how to overcome this problem? i am working in python 3.3.0 thank you From tjreedy at udel.edu Thu Apr 4 15:48:27 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Thu, 04 Apr 2013 15:48:27 -0400 Subject: problem in running a basic code in python 3.3.0 that includes HTML file In-Reply-To: <4b7526eb-b501-4ff8-a257-8cfefbeda413@googlegroups.com> References: <4b7526eb-b501-4ff8-a257-8cfefbeda413@googlegroups.com> Message-ID: On 4/4/2013 3:08 PM, Satabdi Mukherjee wrote: > i have written this code and i need to run this file > > def CreateEvent(str): Using the builtin name 'str' as a parameter name is a bad idea. Use 's' or 'string' or something instead. > "This prints a passed string into this function"; The line above has to be indented. Leave off the trailing ';' > print str; This is not valid in Python 3, where print() is a function This line would have to be 'print(s)'. However, the function as written is senseless; just call print() directly. > return; And empty return at the end does nothing. There is already an implicit 'return None' at the end of every function. > CreateEvent (print''' delete 'print' -- it is another syntax error. > content-type: text/html > > > > the list of all possible events that can be notified by our system > > >
> tsunami
> earthquake
> volcano
> hurricane
> sinkholes
> tornado
> landslide
> downburst
>
> > > > > ''') -- Terry Jan Reedy From amachu at amachu.me Thu Apr 4 16:16:35 2013 From: amachu at amachu.me (=?UTF-8?B?4K6G4K6u4K6+4K6a4K+N4K6a4K+B?=) Date: Fri, 05 Apr 2013 01:46:35 +0530 Subject: docs.python.org source Message-ID: <515DDFA3.8040106@amachu.me> I am looking forward to checkout all rst files of docs.python.org to my local for having a local copy of the site for quick reference. I couldn't find it immediately, searching for few minutes now. Any pointers? -- Sri Ramadoss M From irmen.NOSPAM at xs4all.nl Thu Apr 4 17:27:52 2013 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Thu, 04 Apr 2013 23:27:52 +0200 Subject: docs.python.org source In-Reply-To: References: Message-ID: <515df057$0$6890$e4fe514c@news.xs4all.nl> On 4-4-2013 22:16, ??????? wrote: > I am looking forward to checkout all rst files of docs.python.org to my > local for having a local copy of the site for quick reference. > > I couldn't find it immediately, searching for few minutes now. Any > pointers? > > -- > > Sri Ramadoss M > If you're on windows: the windows installer of Python comes with a compressed html file containing all documentation (in HTML). For instance on my machine, the full documentation of my Python 3.3 install can be found here: C:\Python33\Doc\python330.chm If you're on another OS you can get all the .rst source files of the documentation as part of the Python source code tarball, see http://www.python.org/getit/ Irmen From amachu at amachu.me Thu Apr 4 23:10:20 2013 From: amachu at amachu.me (=?UTF-8?B?4K6G4K6u4K6+4K6a4K+N4K6a4K+B?=) Date: Fri, 05 Apr 2013 08:40:20 +0530 Subject: docs.python.org source In-Reply-To: <20130404173146.ba3d9d4ca3e345f357258106@lavabit.com> References: <515DDFA3.8040106@amachu.me> <20130404173146.ba3d9d4ca3e345f357258106@lavabit.com> Message-ID: <515E409C.9020603@amachu.me> Thanks. Will it be possible to get the sphinx source? On Friday 05 April 2013 06:01 AM, rh wrote: > 1. wget -q http://docs.python.org/2/archives/python-2.7.3-docs-html.tar.bz2 > 2. unroll > 3. cd python-2.7.3-docs-html > 4. python -m SimpleHTTPServer 9292 > 5. point browser to 0:9292 > > From nad at acm.org Fri Apr 5 01:18:37 2013 From: nad at acm.org (Ned Deily) Date: Thu, 04 Apr 2013 22:18:37 -0700 Subject: docs.python.org source References: <515DDFA3.8040106@amachu.me> <20130404173146.ba3d9d4ca3e345f357258106@lavabit.com> <515E409C.9020603@amachu.me> Message-ID: In article <515E409C.9020603 at amachu.me>, ??????? wrote: > Will it be possible to get the sphinx source? You can also get the up-to-date source of the documentation set for each Python release branch from the Mercurial source repositories. There is a Doc/Makefile there that will automatically download and build all required tools and then the docs themselves. See the details in the Python Developer's Guide: http://docs.python.org/devguide/documenting.html -- Ned Deily, nad at acm.org From amachu at amachu.me Fri Apr 5 04:15:27 2013 From: amachu at amachu.me (=?UTF-8?B?4K6G4K6u4K6+4K6a4K+N4K6a4K+B?=) Date: Fri, 05 Apr 2013 13:45:27 +0530 Subject: docs.python.org source In-Reply-To: References: <515DDFA3.8040106@amachu.me> <20130404173146.ba3d9d4ca3e345f357258106@lavabit.com> <515E409C.9020603@amachu.me> Message-ID: <515E881F.3020200@amachu.me> On Friday 05 April 2013 10:48 AM, Ned Deily wrote: > You can also get the up-to-date source of the documentation set for each > Python release branch from the Mercurial source repositories. I was able to that. Thanks for all the responses. From naccttemha at gmail.com Thu Apr 4 19:17:55 2013 From: naccttemha at gmail.com (Nac Temha) Date: Fri, 5 Apr 2013 02:17:55 +0300 Subject: Python log parser Message-ID: Hi, I'm working to parse log files. But I need to help this matter. I want to parse syslog(wihch program is running, timestamp,host,etc) of system I could not find any module of python for this. Or do you have suggestion? Best regards. -------------- next part -------------- An HTML attachment was scrubbed... URL: From naccttemha at gmail.com Fri Apr 5 07:20:35 2013 From: naccttemha at gmail.com (Nac Temha) Date: Fri, 5 Apr 2013 14:20:35 +0300 Subject: Python log parser In-Reply-To: <20130404180032.d9e3ac2a466ade53fd164029@lavabit.com> References: <20130404180032.d9e3ac2a466ade53fd164029@lavabit.com> Message-ID: I could not do using syslog module. On Fri, Apr 5, 2013 at 4:00 AM, rh wrote: > pydoc syslog > > That intenough? > > On Fri, 5 Apr 2013 02:17:55 +0300 > Nac Temha wrote: > > > Hi, I'm working to parse log files. But I need to help this matter. I > > want to parse syslog(wihch program is running, timestamp,host,etc) of > > system I could not find any module of python for this. Or do you have > > suggestion? > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Fri Apr 5 07:56:26 2013 From: davea at davea.name (Dave Angel) Date: Fri, 05 Apr 2013 07:56:26 -0400 Subject: Python log parser In-Reply-To: References: <20130404180032.d9e3ac2a466ade53fd164029@lavabit.com> Message-ID: <515EBBEA.8040603@davea.name> On 04/05/2013 07:20 AM, Nac Temha wrote: > I could not do using syslog module. > Please don't top-post. It messes up the history order entirely. What could you not do using syslog? What did you try, and what exception did it throw? Show your code, and either say precisely in what way it didn't "work" or post the full exception traceack. -- DaveA From invalid at invalid.invalid Fri Apr 5 09:39:12 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 5 Apr 2013 13:39:12 +0000 (UTC) Subject: Python log parser References: <20130404180032.d9e3ac2a466ade53fd164029@lavabit.com> Message-ID: On 2013-04-05, Dave Angel wrote: > On 04/05/2013 07:20 AM, Nac Temha wrote: >> I could not do using syslog module. > What could you not do using syslog? Parse syslog files, presumably -- that's what he asked about. > What did you try, and what exception did it throw? I'm rather at a loss as to how the syslog module can be used to parse syslog files. Perhaps somebody can be a little more detailed? -- Grant Edwards grant.b.edwards Yow! I am a jelly donut. at I am a jelly donut. gmail.com From invalid at invalid.invalid Fri Apr 5 09:31:57 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 5 Apr 2013 13:31:57 +0000 (UTC) Subject: Python log parser References: Message-ID: On 2013-04-05, rh wrote: > On Fri, 5 Apr 2013 02:17:55 +0300 Nac Temha wrote: > >> Hi, I'm working to parse log files. But I need to help this matter. I >> want to parse syslog(wihch program is running, timestamp,host,etc) of >> system I could not find any module of python for this. Or do you have >> suggestion? > > pydoc syslog > > That intenough? No. Can you be more specific? All the documentation I've found for the syslog module is for _generating_ log entries (it's a wrapper for the Unix syslog library). That's not what the OP asked about. The OP asked about parsing syslog files, not generating syslog file entries. Parsing syslog files is not a well-defined problem. The format of a syslog file depends on which system log daemon you're running and now it's configured. -- Grant Edwards grant.b.edwards Yow! Do I have a lifestyle at yet? gmail.com From naccttemha at gmail.com Fri Apr 5 09:42:27 2013 From: naccttemha at gmail.com (Nac Temha) Date: Fri, 5 Apr 2013 16:42:27 +0300 Subject: Python log parser In-Reply-To: References: Message-ID: On Fri, Apr 5, 2013 at 4:31 PM, Grant Edwards wrote: > On 2013-04-05, rh wrote: > > On Fri, 5 Apr 2013 02:17:55 +0300 Nac Temha > wrote: > > > >> Hi, I'm working to parse log files. But I need to help this matter. I > >> want to parse syslog(wihch program is running, timestamp,host,etc) of > >> system I could not find any module of python for this. Or do you have > >> suggestion? > > > > pydoc syslog > > > > That intenough? > > No. Can you be more specific? All the documentation I've found for > the syslog module is for _generating_ log entries (it's a wrapper for > the Unix syslog library). > > Thanks for understand me. > That's not what the OP asked about. > > The OP asked about parsing syslog files, not generating syslog file > entries. > > Can syslog module parsing syslog messages? I give you example for better explain this matter; I can parse perl module( http://search.cpan.org/dist/Parse-Syslog/lib/Parse/Syslog.pm). I obtained host,program,message text. I want to do them with python. > Parsing syslog files is not a well-defined problem. The format of a > syslog file depends on which system log daemon you're running and now > it's configured. > > -- > Grant Edwards grant.b.edwards Yow! Do I have a > lifestyle > at yet? > gmail.com > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From darnold992000 at yahoo.com Fri Apr 5 16:42:22 2013 From: darnold992000 at yahoo.com (darnold) Date: Fri, 5 Apr 2013 13:42:22 -0700 (PDT) Subject: Python log parser References: Message-ID: <4efea6c8-8943-450c-8e6d-5f145fb5f514@y12g2000yqb.googlegroups.com> i know literally nothing about syslogs, but a google search for "python syslog parser" shows that some people have had success using the pyparsing module: http://www.j-schmitz.net/blog/how-to-parse-a-syslog-logfile-in-python https://gist.github.com/leandrosilva/3651640 hth, Don From john_ladasky at sbcglobal.net Thu Apr 4 22:29:40 2013 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Thu, 4 Apr 2013 19:29:40 -0700 (PDT) Subject: JIT compilers for Python, what is the latest news? Message-ID: <6ac24546-6cc6-4a01-9fa6-3b52d64484e3@googlegroups.com> I'm revisiting a project that I haven't touched in over a year. It was written in Python 2.6, and executed on 32-bit Ubuntu 10.10. I experienced a 20% performance increase when I used Psyco, because I had a computationally-intensive routine which occupied most of my CPU cycles, and always received the same data type. (Multiprocessing also helped, and I was using that too.) I have now migrated to a 64-bit Ubuntu 12.10.1, and Python 3.3. I would rather not revert to my older configuration. That being said, it would appear from my initial reading that 1) Psyco is considered obsolete and is no longer maintained, 2) Psyco is being superseded by PyPy, 3) PyPy doesn't support Python 3.x, or 64-bit optimizations. Do I understand all that correctly? I guess I can live with the 20% slower execution, but sometimes my code would run for three solid days... From python at mrabarnett.plus.com Thu Apr 4 22:39:16 2013 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 05 Apr 2013 03:39:16 +0100 Subject: JIT compilers for Python, what is the latest news? In-Reply-To: <6ac24546-6cc6-4a01-9fa6-3b52d64484e3@googlegroups.com> References: <6ac24546-6cc6-4a01-9fa6-3b52d64484e3@googlegroups.com> Message-ID: <515E3954.4060105@mrabarnett.plus.com> On 05/04/2013 03:29, John Ladasky wrote: > I'm revisiting a project that I haven't touched in over a year. It > was written in Python 2.6, and executed on 32-bit Ubuntu 10.10. I > experienced a 20% performance increase when I used Psyco, because I > had a computationally-intensive routine which occupied most of my CPU > cycles, and always received the same data type. (Multiprocessing > also helped, and I was using that too.) > > I have now migrated to a 64-bit Ubuntu 12.10.1, and Python 3.3. I > would rather not revert to my older configuration. That being said, > it would appear from my initial reading that 1) Psyco is considered > obsolete and is no longer maintained, 2) Psyco is being superseded by > PyPy, 3) PyPy doesn't support Python 3.x, or 64-bit optimizations. > > Do I understand all that correctly? > > I guess I can live with the 20% slower execution, but sometimes my > code would run for three solid days... > Have you looked at Cython? Not quite the same, but still... From rosuav at gmail.com Fri Apr 5 04:27:40 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 5 Apr 2013 19:27:40 +1100 Subject: JIT compilers for Python, what is the latest news? In-Reply-To: <6ac24546-6cc6-4a01-9fa6-3b52d64484e3@googlegroups.com> References: <6ac24546-6cc6-4a01-9fa6-3b52d64484e3@googlegroups.com> Message-ID: On Fri, Apr 5, 2013 at 1:29 PM, John Ladasky wrote: > I'm revisiting a project that I haven't touched in over a year. It was written in Python 2.6, and executed on 32-bit Ubuntu 10.10. I experienced a 20% performance increase when I used Psyco, because I had a computationally-intensive routine which occupied most of my CPU cycles, and always received the same data type. (Multiprocessing also helped, and I was using that too.) > > I guess I can live with the 20% slower execution, but sometimes my code would run for three solid days... Two things to try, in order: 1) Can you optimize your algorithms? Three days of processing is... a LOT. 2) Rewrite some key portions in C, possibly using Cython (as MRAB suggested). You may well find that you don't actually need to make any language-level changes. If there's some critical mathematical function that already exists in C, making use of it might make all the difference you need. ChrisA From john_ladasky at sbcglobal.net Fri Apr 5 04:34:19 2013 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Fri, 5 Apr 2013 01:34:19 -0700 (PDT) Subject: JIT compilers for Python, what is the latest news? In-Reply-To: References: <6ac24546-6cc6-4a01-9fa6-3b52d64484e3@googlegroups.com> Message-ID: On Thursday, April 4, 2013 7:39:16 PM UTC-7, MRAB wrote: > Have you looked at Cython? Not quite the same, but still... I'm already using Numpy, compiled with what is supposed to be a fast LAPACK. I don't think I want to attempt to improve on all the work that has gone into Numpy. From john_ladasky at sbcglobal.net Fri Apr 5 04:34:19 2013 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Fri, 5 Apr 2013 01:34:19 -0700 (PDT) Subject: JIT compilers for Python, what is the latest news? In-Reply-To: References: <6ac24546-6cc6-4a01-9fa6-3b52d64484e3@googlegroups.com> Message-ID: On Thursday, April 4, 2013 7:39:16 PM UTC-7, MRAB wrote: > Have you looked at Cython? Not quite the same, but still... I'm already using Numpy, compiled with what is supposed to be a fast LAPACK. I don't think I want to attempt to improve on all the work that has gone into Numpy. From jeanpierreda at gmail.com Fri Apr 5 14:37:54 2013 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Fri, 5 Apr 2013 14:37:54 -0400 Subject: JIT compilers for Python, what is the latest news? In-Reply-To: References: <6ac24546-6cc6-4a01-9fa6-3b52d64484e3@googlegroups.com> Message-ID: On Fri, Apr 5, 2013 at 4:34 AM, John Ladasky wrote: > On Thursday, April 4, 2013 7:39:16 PM UTC-7, MRAB wrote: >> Have you looked at Cython? Not quite the same, but still... > > I'm already using Numpy, compiled with what is supposed to be a fast LAPACK. I don't think I want to attempt to improve on all the work that has gone into Numpy. There's no reason you can't use both cython and numpy. See: http://docs.cython.org/src/tutorial/numpy.html -- Devin From joshua.landau.ws at gmail.com Sat Apr 6 06:23:43 2013 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Sat, 6 Apr 2013 11:23:43 +0100 Subject: JIT compilers for Python, what is the latest news? In-Reply-To: References: <6ac24546-6cc6-4a01-9fa6-3b52d64484e3@googlegroups.com> Message-ID: On 5 April 2013 19:37, Devin Jeanpierre wrote: > On Fri, Apr 5, 2013 at 4:34 AM, John Ladasky > wrote: > > On Thursday, April 4, 2013 7:39:16 PM UTC-7, MRAB wrote: > >> Have you looked at Cython? Not quite the same, but still... > > > > I'm already using Numpy, compiled with what is supposed to be a fast > LAPACK. I don't think I want to attempt to improve on all the work that > has gone into Numpy. > > There's no reason you can't use both cython and numpy. See: > http://docs.cython.org/src/tutorial/numpy.html Don't use this. Use memoryviews: http://docs.cython.org/src/userguide/memoryviews.html. I have no idea why that doc page isn't headed "DEPRICATED" by now. -------------- next part -------------- An HTML attachment was scrubbed... URL: From john_ladasky at sbcglobal.net Fri Apr 5 04:39:07 2013 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Fri, 5 Apr 2013 01:39:07 -0700 (PDT) Subject: JIT compilers for Python, what is the latest news? In-Reply-To: References: <6ac24546-6cc6-4a01-9fa6-3b52d64484e3@googlegroups.com> Message-ID: <590d71e1-5f78-475e-a5bc-8210694a7616@googlegroups.com> On Friday, April 5, 2013 1:27:40 AM UTC-7, Chris Angelico wrote: > 1) Can you optimize your algorithms? Three days of processing is... a LOT. Neural network training. Yes, it takes a long time. Still, it's not the most tedious code I run. I also do molecular-dynamics simulations with GROMACS, those runs can take over a week! > 2) Rewrite some key portions in C, possibly using Cython (as MRAB suggested). And as I replied to MRAB, my limiting code is within Numpy. I've taken care to look for ways that I might have been using Numpy itself inefficiently (and I did find a problem once: fixing it tripled my execution speed). But I would like to think that Numpy itself, since it is already a C extension, should be optimal. From rosuav at gmail.com Fri Apr 5 04:49:12 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 5 Apr 2013 19:49:12 +1100 Subject: JIT compilers for Python, what is the latest news? In-Reply-To: <590d71e1-5f78-475e-a5bc-8210694a7616@googlegroups.com> References: <6ac24546-6cc6-4a01-9fa6-3b52d64484e3@googlegroups.com> <590d71e1-5f78-475e-a5bc-8210694a7616@googlegroups.com> Message-ID: On Fri, Apr 5, 2013 at 7:39 PM, John Ladasky wrote: > On Friday, April 5, 2013 1:27:40 AM UTC-7, Chris Angelico wrote: >> 1) Can you optimize your algorithms? Three days of processing is... a LOT. > > Neural network training. Yes, it takes a long time. Still, it's not the most tedious code I run. I also do molecular-dynamics simulations with GROMACS, those runs can take over a week! > >> 2) Rewrite some key portions in C, possibly using Cython (as MRAB suggested). > > And as I replied to MRAB, my limiting code is within Numpy. I've taken care to look for ways that I might have been using Numpy itself inefficiently (and I did find a problem once: fixing it tripled my execution speed). But I would like to think that Numpy itself, since it is already a C extension, should be optimal. Ahh, yeah, that's gonna take a while. Your minimum processing time is likely to remain fairly high. There won't be any stupidly easy improvements to make (like one of my favorite examples from databasing: an overnight job became a three-second run, just by making proper use of a Btrieve file's index). ChrisA From john_ladasky at sbcglobal.net Fri Apr 5 04:39:07 2013 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Fri, 5 Apr 2013 01:39:07 -0700 (PDT) Subject: JIT compilers for Python, what is the latest news? In-Reply-To: References: <6ac24546-6cc6-4a01-9fa6-3b52d64484e3@googlegroups.com> Message-ID: <590d71e1-5f78-475e-a5bc-8210694a7616@googlegroups.com> On Friday, April 5, 2013 1:27:40 AM UTC-7, Chris Angelico wrote: > 1) Can you optimize your algorithms? Three days of processing is... a LOT. Neural network training. Yes, it takes a long time. Still, it's not the most tedious code I run. I also do molecular-dynamics simulations with GROMACS, those runs can take over a week! > 2) Rewrite some key portions in C, possibly using Cython (as MRAB suggested). And as I replied to MRAB, my limiting code is within Numpy. I've taken care to look for ways that I might have been using Numpy itself inefficiently (and I did find a problem once: fixing it tripled my execution speed). But I would like to think that Numpy itself, since it is already a C extension, should be optimal. From ian.g.kelly at gmail.com Fri Apr 5 13:32:21 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 5 Apr 2013 11:32:21 -0600 Subject: JIT compilers for Python, what is the latest news? In-Reply-To: <590d71e1-5f78-475e-a5bc-8210694a7616@googlegroups.com> References: <6ac24546-6cc6-4a01-9fa6-3b52d64484e3@googlegroups.com> <590d71e1-5f78-475e-a5bc-8210694a7616@googlegroups.com> Message-ID: On Fri, Apr 5, 2013 at 2:39 AM, John Ladasky wrote: >> 2) Rewrite some key portions in C, possibly using Cython (as MRAB suggested). > > And as I replied to MRAB, my limiting code is within Numpy. I've taken care to look for ways that I might have been using Numpy itself inefficiently (and I did find a problem once: fixing it tripled my execution speed). But I would like to think that Numpy itself, since it is already a C extension, should be optimal. That doesn't seem to follow from your original post. Because Numpy is a C extension, its performance would not be improved by psyco at all. The 20% performance increase that you reported must have been a result of the JIT compiling of some Python code, and if you can identify that and rewrite it in C, then you may be able to see the same sort of boost you had from psyco. From john_ladasky at sbcglobal.net Fri Apr 5 14:13:27 2013 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Fri, 5 Apr 2013 11:13:27 -0700 (PDT) Subject: JIT compilers for Python, what is the latest news? In-Reply-To: References: <6ac24546-6cc6-4a01-9fa6-3b52d64484e3@googlegroups.com> <590d71e1-5f78-475e-a5bc-8210694a7616@googlegroups.com> Message-ID: <7b11dcee-12ee-4dac-a8aa-2e9ff1a66262@googlegroups.com> On Friday, April 5, 2013 10:32:21 AM UTC-7, Ian wrote: > That doesn't seem to follow from your original post. Because Numpy is > a C extension, its performance would not be improved by psyco at all. What about the fact that Numpy accommodates Python's dynamic typing? You can pass arrays of integers, floats, bytes, or even PyObjects. I don't know exactly how all that is implemented. In my case, I was always passing floats. So what I assumed that psyco was doing for me was compiling a neural network class that always expected floats. From john_ladasky at sbcglobal.net Fri Apr 5 14:13:27 2013 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Fri, 5 Apr 2013 11:13:27 -0700 (PDT) Subject: JIT compilers for Python, what is the latest news? In-Reply-To: References: <6ac24546-6cc6-4a01-9fa6-3b52d64484e3@googlegroups.com> <590d71e1-5f78-475e-a5bc-8210694a7616@googlegroups.com> Message-ID: <7b11dcee-12ee-4dac-a8aa-2e9ff1a66262@googlegroups.com> On Friday, April 5, 2013 10:32:21 AM UTC-7, Ian wrote: > That doesn't seem to follow from your original post. Because Numpy is > a C extension, its performance would not be improved by psyco at all. What about the fact that Numpy accommodates Python's dynamic typing? You can pass arrays of integers, floats, bytes, or even PyObjects. I don't know exactly how all that is implemented. In my case, I was always passing floats. So what I assumed that psyco was doing for me was compiling a neural network class that always expected floats. From ian.g.kelly at gmail.com Fri Apr 5 15:05:07 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 5 Apr 2013 13:05:07 -0600 Subject: JIT compilers for Python, what is the latest news? In-Reply-To: <7b11dcee-12ee-4dac-a8aa-2e9ff1a66262@googlegroups.com> References: <6ac24546-6cc6-4a01-9fa6-3b52d64484e3@googlegroups.com> <590d71e1-5f78-475e-a5bc-8210694a7616@googlegroups.com> <7b11dcee-12ee-4dac-a8aa-2e9ff1a66262@googlegroups.com> Message-ID: On Fri, Apr 5, 2013 at 12:13 PM, John Ladasky wrote: > On Friday, April 5, 2013 10:32:21 AM UTC-7, Ian wrote: > >> That doesn't seem to follow from your original post. Because Numpy is >> a C extension, its performance would not be improved by psyco at all. > > What about the fact that Numpy accommodates Python's dynamic typing? You can pass arrays of integers, floats, bytes, or even PyObjects. I don't know exactly how all that is implemented. I don't know exactly either, but psyco JIT compiles Python, not C. In the PyObject case you might see some benefit if numpy ends up calling back into methods that are implemented in Python. > In my case, I was always passing floats. So what I assumed that psyco was doing for me was compiling a neural network class that always expected floats. Right, so if you take that routine and rewrite it as a C function that expects floats and handles them internally as such, I would think that you might see a similar improvement. From robert.kern at gmail.com Fri Apr 5 05:46:22 2013 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 05 Apr 2013 10:46:22 +0100 Subject: JIT compilers for Python, what is the latest news? In-Reply-To: <590d71e1-5f78-475e-a5bc-8210694a7616@googlegroups.com> References: <6ac24546-6cc6-4a01-9fa6-3b52d64484e3@googlegroups.com> <590d71e1-5f78-475e-a5bc-8210694a7616@googlegroups.com> Message-ID: On 2013-04-05 09:39, John Ladasky wrote: > On Friday, April 5, 2013 1:27:40 AM UTC-7, Chris Angelico wrote: >> 1) Can you optimize your algorithms? Three days of processing is... a LOT. > > Neural network training. Yes, it takes a long time. Still, it's not the most tedious code I run. I also do molecular-dynamics simulations with GROMACS, those runs can take over a week! > >> 2) Rewrite some key portions in C, possibly using Cython (as MRAB suggested). > > And as I replied to MRAB, my limiting code is within Numpy. I've taken care to look for ways that I might have been using Numpy itself inefficiently (and I did find a problem once: fixing it tripled my execution speed). But I would like to think that Numpy itself, since it is already a C extension, should be optimal. Well, Psyco obviously wasn't optimizing numpy. I believe the suggestion is to identify the key parts of the code that Psyco was optimizing to get you the 20% performance increase and port those to Cython. -- 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 petertbrady at gmail.com Fri Apr 5 08:18:27 2013 From: petertbrady at gmail.com (ptb) Date: Fri, 5 Apr 2013 05:18:27 -0700 (PDT) Subject: JIT compilers for Python, what is the latest news? In-Reply-To: References: <6ac24546-6cc6-4a01-9fa6-3b52d64484e3@googlegroups.com> Message-ID: <25e4ff84-9168-4b8e-ab7c-0ac2eba34e7d@googlegroups.com> Have you looked into numba? I haven't checked to see if it's python 3 compatible. From ian at feete.org Fri Apr 5 08:50:51 2013 From: ian at feete.org (Ian Foote) Date: Fri, 05 Apr 2013 13:50:51 +0100 Subject: JIT compilers for Python, what is the latest news? In-Reply-To: <6ac24546-6cc6-4a01-9fa6-3b52d64484e3@googlegroups.com> References: <6ac24546-6cc6-4a01-9fa6-3b52d64484e3@googlegroups.com> Message-ID: <515EC8AB.3020506@feete.org> On 05/04/13 03:29, John Ladasky wrote: > I'm revisiting a project that I haven't touched in over a year. It was written in Python 2.6, and executed on 32-bit Ubuntu 10.10. I experienced a 20% performance increase when I used Psyco, because I had a computationally-intensive routine which occupied most of my CPU cycles, and always received the same data type. (Multiprocessing also helped, and I was using that too.) > > I have now migrated to a 64-bit Ubuntu 12.10.1, and Python 3.3. I would rather not revert to my older configuration. That being said, it would appear from my initial reading that 1) Psyco is considered obsolete and is no longer maintained, 2) Psyco is being superseded by PyPy, 3) PyPy doesn't support Python 3.x, or 64-bit optimizations. > > Do I understand all that correctly? > > I guess I can live with the 20% slower execution, but sometimes my code would run for three solid days... > Pypy is working on porting to python 3. They are accepting donations: http://pypy.org/py3donate.html Regards, Ian F From joshua.landau.ws at gmail.com Sat Apr 6 06:27:34 2013 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Sat, 6 Apr 2013 11:27:34 +0100 Subject: JIT compilers for Python, what is the latest news? In-Reply-To: <6ac24546-6cc6-4a01-9fa6-3b52d64484e3@googlegroups.com> References: <6ac24546-6cc6-4a01-9fa6-3b52d64484e3@googlegroups.com> Message-ID: On 5 April 2013 03:29, John Ladasky wrote: > I'm revisiting a project that I haven't touched in over a year. It was > written in Python 2.6, and executed on 32-bit Ubuntu 10.10. I experienced > a 20% performance increase when I used Psyco, because I had a > computationally-intensive routine which occupied most of my CPU cycles, and > always received the same data type. (Multiprocessing also helped, and I > was using that too.) > > I have now migrated to a 64-bit Ubuntu 12.10.1, and Python 3.3. I would > rather not revert to my older configuration. That being said, it would > appear from my initial reading that 1) Psyco is considered obsolete and is > no longer maintained, 2) Psyco is being superseded by PyPy, 3) PyPy doesn't > support Python 3.x, or 64-bit optimizations. > > Do I understand all that correctly? > > I guess I can live with the 20% slower execution, but sometimes my code > would run for three solid days... > If you're not willing to go far, I've heard really, really good things about Numba. I've not used it, but seriously: http://jakevdp.github.io/blog/2012/08/24/numba-vs-cython/. Also, PyPy is fine for 64 bit, even if it doesn't gain much from it. So going back to 2.7 might give you that 20% back for almost free. It depends how complex the code is, though. -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Sat Apr 6 15:41:18 2013 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 06 Apr 2013 21:41:18 +0200 Subject: JIT compilers for Python, what is the latest news? In-Reply-To: References: <6ac24546-6cc6-4a01-9fa6-3b52d64484e3@googlegroups.com> Message-ID: Joshua Landau, 06.04.2013 12:27: > On 5 April 2013 03:29, John Ladasky wrote: >> I'm revisiting a project that I haven't touched in over a year. It was >> written in Python 2.6, and executed on 32-bit Ubuntu 10.10. I experienced >> a 20% performance increase when I used Psyco, because I had a >> computationally-intensive routine which occupied most of my CPU cycles, and >> always received the same data type. (Multiprocessing also helped, and I >> was using that too.) >> >> I have now migrated to a 64-bit Ubuntu 12.10.1, and Python 3.3. I would >> rather not revert to my older configuration. That being said, it would >> appear from my initial reading that 1) Psyco is considered obsolete and is >> no longer maintained, 2) Psyco is being superseded by PyPy, 3) PyPy doesn't >> support Python 3.x, or 64-bit optimizations. >> >> Do I understand all that correctly? >> >> I guess I can live with the 20% slower execution, but sometimes my code >> would run for three solid days... > > If you're not willing to go far, I've heard really, really good things > about Numba. I've not used it, but seriously: > http://jakevdp.github.io/blog/2012/08/24/numba-vs-cython/. > > Also, PyPy is fine for 64 bit, even if it doesn't gain much from it. So > going back to 2.7 might give you that 20% back for almost free. It depends > how complex the code is, though. I would guess that the main problem is rather that PyPy doesn't support NumPy (it has its own array implementation, but that's about it). John already mentioned that most of the heavy lifting in his code is done by NumPy. Stefan From rustompmody at gmail.com Sat Apr 6 11:45:42 2013 From: rustompmody at gmail.com (rusi) Date: Sat, 6 Apr 2013 08:45:42 -0700 (PDT) Subject: JIT compilers for Python, what is the latest news? References: <6ac24546-6cc6-4a01-9fa6-3b52d64484e3@googlegroups.com> Message-ID: On Apr 5, 7:29?am, John Ladasky wrote: > I guess I can live with the 20% slower execution, but sometimes my code would run for three solid days... Oooff! Do you know where your goal-posts are? ie if your code were redone in (top-class) C or Fortran would it go from 3 days to 2 days or 2 hours? [The 'top-class' qualification is needed because it could also go from 3 days to 5!] From steve+comp.lang.python at pearwood.info Fri Apr 5 05:37:43 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 05 Apr 2013 20:37:43 +1100 Subject: test - please ignore Message-ID: <515e9b68$0$29985$c3e8da3$5496439d@news.astraweb.com> Sorry for the noise. -- Steven From moraa.lovetakes2 at gmail.com Fri Apr 5 05:52:52 2013 From: moraa.lovetakes2 at gmail.com (Ombongi Moraa Fe) Date: Fri, 5 Apr 2013 12:52:52 +0300 Subject: Passing soap response to python script Message-ID: Hello Group, I am newbie to python and getting my way around. However, my first project that introduced me to the language deals with SOAP requests. The server I communicate with basically sends me 2 soap responses; One with a requestIdentifier which I should use to query the delivery status of the message originally sent. Therefore, my main.py script already calls the client.last_received() which contains 1 value for requestIdentifier. I have another script getDelivery.py; In this script I need to pass 6 parameters which we used in the main.py script and add the requestIdentifier parameter - total 7 paramters. I want to call the getDelivery.py script at the end of main.py script after the client.last_received(). q1) How do I get the requestIdentifier parameter that is received through the client.last_received() method call? q2) How do I pass these 7 parameters to the method call from the main.py script? q3) And how do I receive these passed parameters in the getDelivery.py script? I am conversant with the php post/get but still having trouble doing the same in python. I've checked on urllib2 and request modules but still having trouble understanding their implementation. Thanks In Advance/ Saludos Faith -------------- next part -------------- An HTML attachment was scrubbed... URL: From burak.arslan at arskom.com.tr Fri Apr 5 08:06:07 2013 From: burak.arslan at arskom.com.tr (Burak Arslan) Date: Fri, 05 Apr 2013 15:06:07 +0300 Subject: Passing soap response to python script In-Reply-To: References: Message-ID: <515EBE2F.30809@arskom.com.tr> Hello, On 04/05/13 12:52, Ombongi Moraa Fe wrote: > Hello Group, > > I am newbie to python and getting my way around. However, my first project > that introduced me to the language deals with SOAP requests. Before going any further, there's a project called "suds" which implements a soap client. If the service you're consuming exposes a WSDL document, it's very easy to get started with suds. Here's its home page: https://fedorahosted.org/suds/ > The server I communicate with basically sends me 2 soap responses; One with > a requestIdentifier which I should use to query the delivery status of the > message originally sent. Therefore, my main.py script already calls the > client.last_received() which contains 1 value for requestIdentifier. > > I have another script getDelivery.py; In this script I need to pass 6 > parameters which we used in the main.py script and add the > requestIdentifier parameter - total 7 paramters. > > I want to call the getDelivery.py script at the end of main.py script after > the client.last_received(). > > q1) How do I get the requestIdentifier parameter that is received through > the client.last_received() method call? > > q2) How do I pass these 7 parameters to the method call from the main.py > script? > > q3) And how do I receive these passed parameters in the getDelivery.py > script? It's a bit difficult to answer as you didn't provide any source code, but let me try. First, please modify the code inside getDelivery.py to be inside a function. for argument's sake, let's say it's called 'some_function'. Then, in the main.py, you can import the function and call it. Assuming getDelivery.py and main.py are in the same directory, this should work: from getDelivery import some_function def main(): # some code that defines the 6 other parameters somehow # (...) last = client.last_received some_function(param1, param2, param3, param4, param5, param6, last) > I am conversant with the php post/get but still having trouble doing the > same in python. I've checked on urllib2 and request modules but still > having trouble understanding their implementation. First, just to confirm: urllib2 is a http client library. It's not a http server. The most fashionable http client library in the python world nowadays is requests: http://www.python-requests.org/ It's pretty easy to use and actually, it wraps urllib2. You can give it a try. I hope that helps. Best regards, Burak PS: If you're not sure about how to install Python packages, I'm sure a quick google would turn return a lot of resources. From moraa.lovetakes2 at gmail.com Fri Apr 5 09:36:39 2013 From: moraa.lovetakes2 at gmail.com (Ombongi Moraa Fe) Date: Fri, 5 Apr 2013 16:36:39 +0300 Subject: Passing soap response to python script In-Reply-To: <515EBE2F.30809@arskom.com.tr> References: <515EBE2F.30809@arskom.com.tr> Message-ID: Hi Burak, Thanks a lot. I've been working with suds in this project and I am amazed at how much little code I am using compared to my original php scripts; from your answer, I realized my major headache was not assigning the value of client.last_received method call to another object. With this assignation and the function call, I've solved a lot of problems and been able to use my parameters to update my database tables as I required. Thanks again. On 5 April 2013 15:06, Burak Arslan wrote: > ast = client.last_received > Saludos Ombongi Moraa Faith -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Fri Apr 5 05:30:47 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 05 Apr 2013 20:30:47 +1100 Subject: How do I tell if I'm running under IDLE? Message-ID: <515e99c8$0$30001$c3e8da3$5496439d@news.astraweb.com> (Apologies in advance if you get multiple copies of this. My Usenet connection seems to be having a conniption fit at the moment.) I'm looking for an official way to tell what interpreter (if any) is running, or at least a not-too-horrible unofficial way. Googling comes up with a number of hacks for detecting IDLE. Some of them are terrible. For example, I can't believe that somebody actually suggested this: if len(sys.modules) > 20: print "running under IDLE" This one is better, but still not exactly what I consider great: sys.stdin.__class__.__module__.startswith('idlelib') Ideally, I'd like to detect any arbitrary environment such as Spyder, IPython, BPython, etc., but will settle for just IDLE. -- Steven From davea at davea.name Fri Apr 5 07:04:35 2013 From: davea at davea.name (Dave Angel) Date: Fri, 05 Apr 2013 07:04:35 -0400 Subject: How do I tell if I'm running under IDLE? In-Reply-To: <515e99c8$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <515e99c8$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <515EAFC3.3070102@davea.name> On 04/05/2013 05:30 AM, Steven D'Aprano wrote: > (Apologies in advance if you get multiple copies of this. My Usenet > connection seems to be having a conniption fit at the moment.) > > I'm looking for an official way to tell what interpreter (if any) is > running, or at least a not-too-horrible unofficial way. > > Googling comes up with a number of hacks for detecting IDLE. Some of them > are terrible. For example, I can't believe that somebody actually > suggested this: > > if len(sys.modules) > 20: > print "running under IDLE" > > > This one is better, but still not exactly what I consider great: > > sys.stdin.__class__.__module__.startswith('idlelib') > > > > Ideally, I'd like to detect any arbitrary environment such as Spyder, > IPython, BPython, etc., but will settle for just IDLE. > > > Are you open to OS-specific techniques? For example, on Linux, you could learn things from ps aux. -- DaveA From steve+comp.lang.python at pearwood.info Fri Apr 5 09:37:43 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Apr 2013 13:37:43 GMT Subject: How do I tell if I'm running under IDLE? References: <515e99c8$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <515ed3a7$0$29995$c3e8da3$5496439d@news.astraweb.com> On Fri, 05 Apr 2013 07:04:35 -0400, Dave Angel wrote: > On 04/05/2013 05:30 AM, Steven D'Aprano wrote: >> (Apologies in advance if you get multiple copies of this. My Usenet >> connection seems to be having a conniption fit at the moment.) >> >> I'm looking for an official way to tell what interpreter (if any) is >> running, or at least a not-too-horrible unofficial way. [...] >> Ideally, I'd like to detect any arbitrary environment such as Spyder, >> IPython, BPython, etc., but will settle for just IDLE. > > Are you open to OS-specific techniques? For example, on Linux, you > could learn things from ps aux. I'd prefer a pure-Python solution, but if the choice is between an accurate solution using an external tool, and an inaccurate Python heuristic, I'm willing to use external tools. -- Steven From python.list at tim.thechases.com Fri Apr 5 10:33:42 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 5 Apr 2013 09:33:42 -0500 Subject: How do I tell if I'm running under IDLE? In-Reply-To: <515ed3a7$0$29995$c3e8da3$5496439d@news.astraweb.com> References: <515e99c8$0$30001$c3e8da3$5496439d@news.astraweb.com> <515ed3a7$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20130405093342.6bc193dc@bigbox.christie.dr> On 2013-04-05 13:37, Steven D'Aprano wrote: > On Fri, 05 Apr 2013 07:04:35 -0400, Dave Angel wrote: > > > On 04/05/2013 05:30 AM, Steven D'Aprano wrote: > >> (Apologies in advance if you get multiple copies of this. My > >> Usenet connection seems to be having a conniption fit at the > >> moment.) > >> > >> I'm looking for an official way to tell what interpreter (if > >> any) is running, or at least a not-too-horrible unofficial way. > [...] > >> Ideally, I'd like to detect any arbitrary environment such as > >> Spyder, IPython, BPython, etc., but will settle for just IDLE. > > > > Are you open to OS-specific techniques? For example, on Linux, > > you could learn things from ps aux. > > I'd prefer a pure-Python solution, but if the choice is between an > accurate solution using an external tool, and an inaccurate Python > heuristic, I'm willing to use external tools. If you're looking for a heuristic, you might take a look at whether there are bunch of entries in sys.modules that start with "idlelib". There seem to be a bunch when tested in the IDLE Python shell. You could set some low-water mark to suggest that IDLE is loaded, and take the count: import sys IDLE_LOW_WATER_MARK = min([ 49, # Python 2.4 on WinXP 55, # Python 2.6 on Linux 22, # Python 3.1 on Linux # I seem to recall you have oodles of other # versions installed that you can test # to find a good low-water mark ]) idle_module_count = sum([ 1 for m in sys.modules if m.startswith("idlelib.") or m == "idlelib" ]) print("Found %i idlelib module(s), hunting %i" % idle_module_count, IDLE_LOW_WATER_MARK) if idle_module_count >= IDLE_LOW_WATER_MARK: print("Hey, it looks like we're running in IDLE") else: print("I'm pretty sure we're not running in IDLE") It doesn't stop you from manually importing IDLE_LOW_WATER_MARK modules into your own code, but then you just get to keep the pieces when it breaks that way ;-) -tkc From tjreedy at udel.edu Sat Apr 6 19:23:00 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Sat, 06 Apr 2013 19:23:00 -0400 Subject: How do I tell if I'm running under IDLE? In-Reply-To: <515e99c8$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <515e99c8$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/5/2013 5:30 AM, Steven D'Aprano wrote: > I'm looking for an official way to tell what interpreter (if any) is > running, or at least a not-too-horrible unofficial way. The interpreters distributed by PSF identify themselves on startup, as least in interactive mode, by displaying a line like "Python 3.3.0+ (default, Mar 30 2013, 17:36:11) [MSC v.1600 32 bit (Intel)] on win32" The version available as sys.version, sys.hexversion, and sys._version(). The platform is available as sys.platform. The compiler and compile date are not officially available. But you seem not to be actually asking 'what interpreter is running' but 'who started the interpreter' and 'is the interpreter i/o connected to a text-mode OS console or to a gui program, such as IDLE, more or less simulating an OS console. There is no official way because it should not matter to a running program. It is the goal of at least some IDLE developers to make the connection to the IDLE shell as transparent as possible to Python code, so that it matters as little as possible*. This is one reason for the shift from running user code in the same process and interpreter instance as Idle to running user code in a separate process with its own interpreter instance. * There are current tracker issues about making this true. We really do not want people to have to write conditional code, unless it is to work around a console problem if Idle is not being used ;-). If you have an issue not already covered on the tracker, I am curious what it is. > Googling comes up with a number of hacks for detecting IDLE. Some of them > are terrible. For example, I can't believe that somebody actually > suggested this: > > if len(sys.modules) > 20: > print "running under IDLE" This is based on the fact that if running in the same process, there are a lot more imported modules and if running in a separate process, there are at least a few more imported modules to set up the rpc connection. I do not know that '20' is particularly reliable, even on startup. > This one is better, but still not exactly what I consider great: Why not, if is works for all Idle versions so far? The irreducible effect of any non-OS-console environment is to override the normal i/o. > sys.stdin.__class__.__module__.startswith('idlelib') 'idlelib' in sys.stdin.__class__.__module__' is possibly more future-proof. > Ideally, I'd like to detect any arbitrary environment such as Spyder, > IPython, BPython, etc., but will settle for just IDLE. I expect that looking as sys.stdin in someway should work for all. -- Terry Jan Reedy From dreamingforward at gmail.com Sat Apr 6 20:35:32 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Sat, 6 Apr 2013 17:35:32 -0700 Subject: How do I tell if I'm running under IDLE? In-Reply-To: <515e99c8$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <515e99c8$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: > (Apologies in advance if you get multiple copies of this. My Usenet > connection seems to be having a conniption fit at the moment.) > > I'm looking for an official way to tell what interpreter (if any) is > running, or at least a not-too-horrible unofficial way. I was going to work on this IDLE TODO myself, but haven't got around to it. I think the best way is to use the tempfile module (to be clear this is a fix within IDLE itself). This is the whole procedure that should be necessary: 1) At IDLE startup check to see if there is an existing idle tempfile and delete it, if so. 2) Create an IDLE temp file. 3) At IDLE shutdown, delete prior tempfile. Now if anyone wants to see if IDLE is running, they only need to check to see if the tempfile exists. Hope that helps. If you implement it, you can take the item off the IDLE todo list too. MarkJ Tacoma, Washington From davea at davea.name Sat Apr 6 20:43:09 2013 From: davea at davea.name (Dave Angel) Date: Sat, 06 Apr 2013 20:43:09 -0400 Subject: How do I tell if I'm running under IDLE? In-Reply-To: References: <515e99c8$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5160C11D.1030107@davea.name> On 04/06/2013 08:35 PM, Mark Janssen wrote: >> (Apologies in advance if you get multiple copies of this. My Usenet >> connection seems to be having a conniption fit at the moment.) >> >> I'm looking for an official way to tell what interpreter (if any) is >> running, or at least a not-too-horrible unofficial way. > > I was going to work on this IDLE TODO myself, but haven't got around > to it. I think the best way is to use the tempfile module (to be > clear this is a fix within IDLE itself). > > This is the whole procedure that should be necessary: > > 1) At IDLE startup check to see if there is an existing idle tempfile > and delete it, if so. > 2) Create an IDLE temp file. > 3) At IDLE shutdown, delete prior tempfile. > > Now if anyone wants to see if IDLE is running, they only need to check > to see if the tempfile exists. > > Hope that helps. If you implement it, you can take the item off the > IDLE todo list too. > Are you assuming then that there can be only one instance of IDLE ? And that if a separate Python program is run, we should pretend that it's running under IDLE? -- DaveA From werotizy at freent.dd Fri Apr 5 07:02:38 2013 From: werotizy at freent.dd (Tom P) Date: Fri, 05 Apr 2013 13:02:38 +0200 Subject: HTTPserver: how to access variables of a higher class? Message-ID: First, here's a sample test program: import sys from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler class MyRequestHandler(BaseHTTPRequestHandler, object): def do_GET(self): top_self = super(MyRequestHandler, self) # try to access MyWebServer instance self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write("thanks for trying, but I'd like to get at self.foo and self.bar") return class MyWebServer(object): def __init__(self): self.foo = "foo" # these are what I want to access from inside do_GET self.bar = "bar" self.httpd = HTTPServer(('127.0.0.1', 8000), MyRequestHandler) sa = self.httpd.socket.getsockname() print "Serving HTTP on", sa[0], "port", sa[1], "..." def runIt(self): self.httpd.serve_forever() server = MyWebServer() server.runIt() I want to access the foo and bar variables from do_GET, but I can't figure out how. I suppose this is something to do with new-style vs. old-style classes, but I lost for a solution. From davea at davea.name Fri Apr 5 07:54:06 2013 From: davea at davea.name (Dave Angel) Date: Fri, 05 Apr 2013 07:54:06 -0400 Subject: HTTPserver: how to access variables of a higher class? In-Reply-To: References: Message-ID: <515EBB5E.9090507@davea.name> On 04/05/2013 07:02 AM, Tom P wrote: > First, here's a sample test program: > > import sys > from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler > > class MyRequestHandler(BaseHTTPRequestHandler, object): > def do_GET(self): > top_self = super(MyRequestHandler, self) # try to access > MyWebServer instance > self.send_response(200) > self.send_header('Content-type', 'text/html') > self.end_headers() > self.wfile.write("thanks for trying, but I'd like to get at > self.foo and self.bar") > return > > class MyWebServer(object): > def __init__(self): > self.foo = "foo" # these are what I want to access from inside > do_GET > self.bar = "bar" > self.httpd = HTTPServer(('127.0.0.1', 8000), MyRequestHandler) > sa = self.httpd.socket.getsockname() > print "Serving HTTP on", sa[0], "port", sa[1], "..." > > def runIt(self): > self.httpd.serve_forever() > > server = MyWebServer() > server.runIt() > > > > I want to access the foo and bar variables from do_GET, but I can't > figure out how. I suppose this is something to do with new-style vs. > old-style classes, but I lost for a solution. It'd have been good to tell us that this was on Python 2.7 Is MyWebServer class intended to have exactly one instance? If so, you could save the instance as a class attribute, and trivially access it from outside the class. If it might have more than one instance, then we'd need to know more about the class BaseHTTPServer.HTTPServer, From a quick glance at the docs, it looks like you get an attribute called server. So inside the do_GET() method, you should be able to access self.server.foo and self.server.bar See http://docs.python.org/2/library/basehttpserver.html -- DaveA From dylan at dje.me Fri Apr 5 08:27:54 2013 From: dylan at dje.me (Dylan Evans) Date: Fri, 5 Apr 2013 22:27:54 +1000 Subject: HTTPserver: how to access variables of a higher class? In-Reply-To: References: Message-ID: On 05/04/2013 9:09 PM, "Tom P" wrote: > > First, here's a sample test program: > > import sys > from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler > > class MyRequestHandler(BaseHTTPRequestHandler, object): > def do_GET(self): > top_self = super(MyRequestHandler, self) # try to access MyWebServer instance > self.send_response(200) > self.send_header('Content-type', 'text/html') > self.end_headers() > self.wfile.write("thanks for trying, but I'd like to get at self.foo and self.bar") > return > > class MyWebServer(object): > def __init__(self): > self.foo = "foo" # these are what I want to access from inside do_GET > self.bar = "bar" > self.httpd = HTTPServer(('127.0.0.1', 8000), MyRequestHandler) > sa = self.httpd.socket.getsockname() > print "Serving HTTP on", sa[0], "port", sa[1], "..." > > def runIt(self): > self.httpd.serve_forever() > > server = MyWebServer() > server.runIt() > > > > I want to access the foo and bar variables from do_GET, but I can't figure out how. I suppose this is something to do with new-style vs. old-style classes, but I lost for a solution. Consider inheriting HTTPServer in MyWebServer which is passed to the request handler. > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From werotizy at freent.dd Fri Apr 5 09:21:12 2013 From: werotizy at freent.dd (Tom P) Date: Fri, 05 Apr 2013 15:21:12 +0200 Subject: HTTPserver: how to access variables of a higher class? In-Reply-To: References: Message-ID: On 04/05/2013 02:27 PM, Dylan Evans wrote: > On 05/04/2013 9:09 PM, "Tom P" wrote: >> >> First, here's a sample test program: >> >> import sys >> from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler >> >> class MyRequestHandler(BaseHTTPRequestHandler, object): >> def do_GET(self): >> top_self = super(MyRequestHandler, self) # try to access > MyWebServer instance >> self.send_response(200) >> self.send_header('Content-type', 'text/html') >> self.end_headers() >> self.wfile.write("thanks for trying, but I'd like to get at > self.foo and self.bar") >> return >> >> class MyWebServer(object): >> def __init__(self): >> self.foo = "foo" # these are what I want to access from inside > do_GET >> self.bar = "bar" >> self.httpd = HTTPServer(('127.0.0.1', 8000), MyRequestHandler) >> sa = self.httpd.socket.getsockname() >> print "Serving HTTP on", sa[0], "port", sa[1], "..." >> >> def runIt(self): >> self.httpd.serve_forever() >> >> server = MyWebServer() >> server.runIt() >> >> >> >> I want to access the foo and bar variables from do_GET, but I can't > figure out how. I suppose this is something to do with new-style vs. > old-style classes, but I lost for a solution. > > Consider inheriting HTTPServer in MyWebServer which is passed to the > request handler. > That was the next thing I was going to try, thanks. >> -- >> http://mail.python.org/mailman/listinfo/python-list > From werotizy at freent.dd Sat Apr 6 11:05:22 2013 From: werotizy at freent.dd (Tom P) Date: Sat, 06 Apr 2013 17:05:22 +0200 Subject: HTTPserver: how to access variables of a higher class? In-Reply-To: References: Message-ID: On 04/05/2013 02:27 PM, Dylan Evans wrote: > On 05/04/2013 9:09 PM, "Tom P" wrote: >> >> First, here's a sample test program: >> >> import sys >> from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler >> >> class MyRequestHandler(BaseHTTPRequestHandler, object): >> def do_GET(self): >> top_self = super(MyRequestHandler, self) # try to access > MyWebServer instance >> self.send_response(200) >> self.send_header('Content-type', 'text/html') >> self.end_headers() >> self.wfile.write("thanks for trying, but I'd like to get at > self.foo and self.bar") >> return >> >> class MyWebServer(object): >> def __init__(self): >> self.foo = "foo" # these are what I want to access from inside > do_GET >> self.bar = "bar" >> self.httpd = HTTPServer(('127.0.0.1', 8000), MyRequestHandler) >> sa = self.httpd.socket.getsockname() >> print "Serving HTTP on", sa[0], "port", sa[1], "..." >> >> def runIt(self): >> self.httpd.serve_forever() >> >> server = MyWebServer() >> server.runIt() >> >> >> >> I want to access the foo and bar variables from do_GET, but I can't > figure out how. I suppose this is something to do with new-style vs. > old-style classes, but I lost for a solution. > > Consider inheriting HTTPServer in MyWebServer which is passed to the > request handler. > >> -- >> http://mail.python.org/mailman/listinfo/python-list > I keep getting the same problem - if inherit from any of these classes in BaseHTTPServer and try to use super(class, self) to initiate the higher class, I get the error "TypeError: must be type, not classobj" - in other words, these are old-style classes. That means that in this call - self.httpd = MyHTTPServer(('127.0.0.1', 8000), MyRequestHandler) there doesn't seem to be a way to define a class MyHTTPServer(HTTPServer) From dylan at dje.me Sat Apr 6 21:51:27 2013 From: dylan at dje.me (Dylan Evans) Date: Sun, 7 Apr 2013 11:51:27 +1000 Subject: HTTPserver: how to access variables of a higher class? In-Reply-To: References: Message-ID: On Sun, Apr 7, 2013 at 1:05 AM, Tom P wrote: > On 04/05/2013 02:27 PM, Dylan Evans wrote: > >> On 05/04/2013 9:09 PM, "Tom P" wrote: >> >>> >>> First, here's a sample test program: >>> >>> import sys >>> from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler >>> >>> class MyRequestHandler(**BaseHTTPRequestHandler, object): >>> def do_GET(self): >>> top_self = super(MyRequestHandler, self) # try to access >>> >> MyWebServer instance >> >>> self.send_response(200) >>> self.send_header('Content-**type', 'text/html') >>> self.end_headers() >>> self.wfile.write("thanks for trying, but I'd like to get at >>> >> self.foo and self.bar") >> >>> return >>> >>> class MyWebServer(object): >>> def __init__(self): >>> self.foo = "foo" # these are what I want to access from inside >>> >> do_GET >> >>> self.bar = "bar" >>> self.httpd = HTTPServer(('127.0.0.1', 8000), MyRequestHandler) >>> sa = self.httpd.socket.getsockname(**) >>> print "Serving HTTP on", sa[0], "port", sa[1], "..." >>> >>> def runIt(self): >>> self.httpd.serve_forever() >>> >>> server = MyWebServer() >>> server.runIt() >>> >>> >>> >>> I want to access the foo and bar variables from do_GET, but I can't >>> >> figure out how. I suppose this is something to do with new-style vs. >> old-style classes, but I lost for a solution. >> >> Consider inheriting HTTPServer in MyWebServer which is passed to the >> request handler. >> >> -- >>> http://mail.python.org/**mailman/listinfo/python-list >>> >> >> > I keep getting the same problem - if inherit from any of these classes in > BaseHTTPServer and try to use super(class, self) to initiate the higher > class, I get the error "TypeError: must be type, not classobj" - in other > words, these are old-style classes. > That means that in this call - > self.httpd = MyHTTPServer(('127.0.0.1', 8000), MyRequestHandler) > > there doesn't seem to be a way to define a > class MyHTTPServer(HTTPServer) > > > You can call the __init__ method on the class as a workaround for it being old style. This works on 2.7 from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler class MyRequestHandler(BaseHTTPRequestHandler): def do_GET(self): self.send_response(200) self.send_header('Content-type', 'text/plain') self.end_headers() self.wfile.write('Got foo? %s' % self.server.foo) class MyWebServer(HTTPServer): def __init__(self): self.foo = 'foo' HTTPServer.__init__(self, ('127.0.0.1', 8000), MyRequestHandler) sa = self.socket.getsockname() print "Serving HTTP on", sa[0], "port", sa[1] def runit(self): self.serve_forever() server = MyWebServer() server.runit() > > > > -- > http://mail.python.org/**mailman/listinfo/python-list > -- "The UNIX system has a command, nice ... in order to be nice to the other users. Nobody ever uses it." - Andrew S. Tanenbaum -------------- next part -------------- An HTML attachment was scrubbed... URL: From werotizy at freent.dd Fri Apr 5 09:26:20 2013 From: werotizy at freent.dd (Tom P) Date: Fri, 05 Apr 2013 15:26:20 +0200 Subject: HTTPserver: how to access variables of a higher class? In-Reply-To: References: Message-ID: On 04/05/2013 01:54 PM, Dave Angel wrote: > On 04/05/2013 07:02 AM, Tom P wrote: >> First, here's a sample test program: >> >> import sys >> from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler >> >> class MyRequestHandler(BaseHTTPRequestHandler, object): >> def do_GET(self): >> top_self = super(MyRequestHandler, self) # try to access >> MyWebServer instance >> self.send_response(200) >> self.send_header('Content-type', 'text/html') >> self.end_headers() >> self.wfile.write("thanks for trying, but I'd like to get at >> self.foo and self.bar") >> return >> >> class MyWebServer(object): >> def __init__(self): >> self.foo = "foo" # these are what I want to access from inside >> do_GET >> self.bar = "bar" >> self.httpd = HTTPServer(('127.0.0.1', 8000), MyRequestHandler) >> sa = self.httpd.socket.getsockname() >> print "Serving HTTP on", sa[0], "port", sa[1], "..." >> >> def runIt(self): >> self.httpd.serve_forever() >> >> server = MyWebServer() >> server.runIt() >> >> >> >> I want to access the foo and bar variables from do_GET, but I can't >> figure out how. I suppose this is something to do with new-style vs. >> old-style classes, but I lost for a solution. > > It'd have been good to tell us that this was on Python 2.7 > Yes, sorry for the omission. > Is MyWebServer class intended to have exactly one instance? Yes, but I was trying to keep it general. If so, you > could save the instance as a class attribute, and trivially access it > from outside the class. > > If it might have more than one instance, then we'd need to know more > about the class BaseHTTPServer.HTTPServer, From a quick glance at the > docs, it looks like you get an attribute called server. So inside the > do_GET() method, you should be able to access self.server.foo and > self.server.bar ok, let me test that. Do I assume correctly from what you write that the super() is not needed? In reality there is just one instance of MyWebServer, but I was looking for a general solution. > > See http://docs.python.org/2/library/basehttpserver.html > From werotizy at freent.dd Fri Apr 5 17:41:00 2013 From: werotizy at freent.dd (Tom P) Date: Fri, 05 Apr 2013 23:41:00 +0200 Subject: HTTPserver: how to access variables of a higher class? In-Reply-To: References: Message-ID: On 04/05/2013 01:54 PM, Dave Angel wrote: > On 04/05/2013 07:02 AM, Tom P wrote: >> First, here's a sample test program: >> >> import sys >> from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler >> >> class MyRequestHandler(BaseHTTPRequestHandler, object): >> def do_GET(self): >> top_self = super(MyRequestHandler, self) # try to access >> MyWebServer instance >> self.send_response(200) >> self.send_header('Content-type', 'text/html') >> self.end_headers() >> self.wfile.write("thanks for trying, but I'd like to get at >> self.foo and self.bar") >> return >> >> class MyWebServer(object): >> def __init__(self): >> self.foo = "foo" # these are what I want to access from inside >> do_GET >> self.bar = "bar" >> self.httpd = HTTPServer(('127.0.0.1', 8000), MyRequestHandler) >> sa = self.httpd.socket.getsockname() >> print "Serving HTTP on", sa[0], "port", sa[1], "..." >> >> def runIt(self): >> self.httpd.serve_forever() >> >> server = MyWebServer() >> server.runIt() >> >> >> >> I want to access the foo and bar variables from do_GET, but I can't >> figure out how. I suppose this is something to do with new-style vs. >> old-style classes, but I lost for a solution. > > It'd have been good to tell us that this was on Python 2.7 > > Is MyWebServer class intended to have exactly one instance? If so, you > could save the instance as a class attribute, and trivially access it > from outside the class. > > If it might have more than one instance, then we'd need to know more > about the class BaseHTTPServer.HTTPServer, From a quick glance at the > docs, it looks like you get an attribute called server. So inside the > do_GET() method, you should be able to access self.server.foo and > self.server.bar > > See http://docs.python.org/2/library/basehttpserver.html > That doesn't work. Maybe you mean something that I'm missing? Setting a breakpoint in do_GET: Pdb) b 7 Breakpoint 1 at /home/tom/Desktop/tidy/Python/webserver/simpleWebserver.py:7 (Pdb) c Serving HTTP on 127.0.0.1 port 8000 ... > /home/tom/Desktop/tidy/Python/webserver/simpleWebserver.py(7)do_GET() -> self.send_response(200) (Pdb) self <__main__.MyRequestHandler instance at 0x7ff20dde3bd8> (Pdb) self.server (Pdb) dir(self.server) ['RequestHandlerClass', '_BaseServer__is_shut_down', '_BaseServer__shutdown_request', '__doc__', '__init__', '__module__', '_handle_request_noblock', 'address_family', 'allow_reuse_address', 'close_request', 'fileno', 'finish_request', 'get_request', 'handle_error', 'handle_request', 'handle_timeout', 'process_request', 'request_queue_size', 'serve_forever', 'server_activate', 'server_address', 'server_bind', 'server_close', 'server_name', 'server_port', 'shutdown', 'shutdown_request', 'socket', 'socket_type', 'timeout', 'verify_request'] (Pdb) self.server.foo *** AttributeError: HTTPServer instance has no attribute 'foo' From davea at davea.name Fri Apr 5 23:19:35 2013 From: davea at davea.name (Dave Angel) Date: Fri, 05 Apr 2013 23:19:35 -0400 Subject: HTTPserver: how to access variables of a higher class? In-Reply-To: References: Message-ID: <515F9447.3080905@davea.name> On 04/05/2013 05:41 PM, Tom P wrote: > On 04/05/2013 01:54 PM, Dave Angel wrote: >> On 04/05/2013 07:02 AM, Tom P wrote: >>> First, here's a sample test program: >>> >>> import sys >>> from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler >>> >>> class MyRequestHandler(BaseHTTPRequestHandler, object): >>> def do_GET(self): >>> top_self = super(MyRequestHandler, self) # try to access >>> MyWebServer instance >>> self.send_response(200) >>> self.send_header('Content-type', 'text/html') >>> self.end_headers() >>> self.wfile.write("thanks for trying, but I'd like to get at >>> self.foo and self.bar") >>> return >>> >>> class MyWebServer(object): >>> def __init__(self): >>> self.foo = "foo" # these are what I want to access from inside >>> do_GET >>> self.bar = "bar" >>> self.httpd = HTTPServer(('127.0.0.1', 8000), MyRequestHandler) >>> sa = self.httpd.socket.getsockname() >>> print "Serving HTTP on", sa[0], "port", sa[1], "..." >>> >>> def runIt(self): >>> self.httpd.serve_forever() >>> >>> server = MyWebServer() >>> server.runIt() >>> >>> >>> >>> I want to access the foo and bar variables from do_GET, but I can't >>> figure out how. I suppose this is something to do with new-style vs. >>> old-style classes, but I lost for a solution. >> >> It'd have been good to tell us that this was on Python 2.7 >> >> Is MyWebServer class intended to have exactly one instance? If so, you >> could save the instance as a class attribute, and trivially access it >> from outside the class. >> >> If it might have more than one instance, then we'd need to know more >> about the class BaseHTTPServer.HTTPServer, From a quick glance at the >> docs, it looks like you get an attribute called server. So inside the >> do_GET() method, you should be able to access self.server.foo and >> self.server.bar >> >> See http://docs.python.org/2/library/basehttpserver.html >> > That doesn't work. Maybe you mean something that I'm missing? > Setting a breakpoint in do_GET: > Pdb) b 7 > Breakpoint 1 at > /home/tom/Desktop/tidy/Python/webserver/simpleWebserver.py:7 > (Pdb) c > Serving HTTP on 127.0.0.1 port 8000 ... > > /home/tom/Desktop/tidy/Python/webserver/simpleWebserver.py(7)do_GET() > -> self.send_response(200) > (Pdb) self > <__main__.MyRequestHandler instance at 0x7ff20dde3bd8> > (Pdb) self.server > > (Pdb) dir(self.server) > ['RequestHandlerClass', '_BaseServer__is_shut_down', > '_BaseServer__shutdown_request', '__doc__', '__init__', '__module__', > '_handle_request_noblock', 'address_family', 'allow_reuse_address', > 'close_request', 'fileno', 'finish_request', 'get_request', > 'handle_error', 'handle_request', 'handle_timeout', 'process_request', > 'request_queue_size', 'serve_forever', 'server_activate', > 'server_address', 'server_bind', 'server_close', 'server_name', > 'server_port', 'shutdown', 'shutdown_request', 'socket', 'socket_type', > 'timeout', 'verify_request'] > (Pdb) self.server.foo > *** AttributeError: HTTPServer instance has no attribute 'foo' > I did a quick scan of the page whose link I showed you above. It doesn't say there what 'server' attribute actually is. Sounds like you need to combine my suggestion with Dylan's. Once your server class inherits from the HTTPServer class, there should be an attriute 'foo'. But my understanding is still quite superficial, so you'll have to continue the good testing you're already doing. -- DaveA From werotizy at freent.dd Sat Apr 6 17:38:25 2013 From: werotizy at freent.dd (Tom P) Date: Sat, 06 Apr 2013 23:38:25 +0200 Subject: The SOLUTION HTTPserver: how to access variables of a higher class In-Reply-To: References: Message-ID: On 04/05/2013 01:02 PM, Tom P wrote: ok, after much experimenting it looks like the solution is as follows: class MyWebServer(object): def __init__(self): # self.foo = "foo" delete these from self # self.bar = "bar" myServer = HTTPServer myServer.foo = "foo" #define foo,bar here myServer.bar = "bar" self.httpd = myServer(('127.0.0.1', 8000), MyRequestHandler) Then, in the request handler: class MyRequestHandler(BaseHTTPRequestHandler): def do_GET(self): ss=self.server print ss.foo From insideshoes at gmail.com Fri Apr 5 08:34:03 2013 From: insideshoes at gmail.com (inshu chauhan) Date: Fri, 5 Apr 2013 18:04:03 +0530 Subject: Trying to understand working with dicts Message-ID: Hello everyone, Here in my part of the code where cc is a dictionary. I want to understand what actually cc.iterkeys() and cc[k] actually doing. I am already reading http://docs.python.org/2/library/stdtypes.html#dict.items and http://www.tutorialspoint.com/python/python_dictionary.htm but still not very clear. cc = Computesegclass(segimage, refimage) for k in sorted(cc.iterkeys()): i = argmax(cc[k]) print >> f, i+1 Thanks in Advance -------------- next part -------------- An HTML attachment was scrubbed... URL: From ppearson at nowhere.invalid Fri Apr 5 12:05:50 2013 From: ppearson at nowhere.invalid (Peter Pearson) Date: 5 Apr 2013 16:05:50 GMT Subject: Trying to understand working with dicts References: Message-ID: On Fri, 5 Apr 2013 18:04:03 +0530, inshu chauhan wrote: > --089e0111cf5068b65204d99c4d46 > Content-Type: text/plain; charset=ISO-8859-1 [snip] > Here in my part of the code where cc is a dictionary. I want to understand > what actually cc.iterkeys() and cc[k] actually doing. > I am already reading > http://docs.python.org/2/library/stdtypes.html#dict.items > and http://www.tutorialspoint.com/python/python_dictionary.htm but still > not very clear. > > cc = Computesegclass(segimage, refimage) > for k in sorted(cc.iterkeys()): > i = argmax(cc[k]) > print >> f, i+1 Is this a question about dictionaries, or a question about Computesegclass? In either case, an experiment without the added complexities of sorted() and argmax() would be better. -- To email me, substitute nowhere->spamcop, invalid->net. From dylan at dje.me Fri Apr 5 12:24:54 2013 From: dylan at dje.me (Dylan Evans) Date: Sat, 6 Apr 2013 02:24:54 +1000 Subject: Trying to understand working with dicts In-Reply-To: References: Message-ID: On Fri, Apr 5, 2013 at 10:34 PM, inshu chauhan wrote: > Hello everyone, > > Here in my part of the code where cc is a dictionary. I want to understand > what actually cc.iterkeys() and cc[k] actually doing. > I am already reading > http://docs.python.org/2/library/stdtypes.html#dict.items > and http://www.tutorialspoint.com/python/python_dictionary.htm but still > not very clear. > > cc = Computesegclass(segimage, refimage) > for k in sorted(cc.iterkeys()): > i = argmax(cc[k]) > print >> f, i+1 > > Not sure what Computesegclass is but i am guessing that it is a class which implements __getitem__ and __setitem__, which allows the use of the square bracket notation cc[k], you could also write cc.__getitem__(k) , if you really wanted to. See http://docs.python.org/2/reference/datamodel.html#object.__getitem__ iterkeys returns an iterator over the dictionary keys, which is an object with a next method which returns each key in the dictionary until there are no more, then it raises StopIteration. > Thanks in Advance > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- "The UNIX system has a command, nice ... in order to be nice to the other users. Nobody ever uses it." - Andrew S. Tanenbaum -------------- next part -------------- An HTML attachment was scrubbed... URL: From cjw at ncf.ca Fri Apr 5 08:38:40 2013 From: cjw at ncf.ca (Colin J. Williams) Date: Fri, 05 Apr 2013 08:38:40 -0400 Subject: Fwd: Re: distutils without a compiler In-Reply-To: <515E2946.5060504@ncf.ca> References: <515E2946.5060504@ncf.ca> Message-ID: <515EC5D0.6040002@ncf.ca> An HTML attachment was scrubbed... URL: From c.candide at laposte.net Fri Apr 5 09:49:14 2013 From: c.candide at laposte.net (Candide Dandide) Date: Fri, 5 Apr 2013 06:49:14 -0700 (PDT) Subject: is operator versus id() function Message-ID: Until now, I was quite sure that the is operator acts the same as the id builtin function, or, to be more formal, that o1 is o2 to be exactly equivalent to id(o1) == id(o2). This equivalence is reported in many books, for instance Martelli's Python in a Nutshell. But with the following code, I'm not still sure the equivalence above is correct. Here's the code : #-------------------------------------------------------- class A(object): def f(self): print "A" a=A() print id(A.f) == id(a.f), A.f is a.f #-------------------------------------------------------- outputing: True False So, could someone please explain what exactly the is operator returns ? The official doc says : The ?is? operator compares the identity of two objects; the id() function returns an integer representing its identity (currently implemented as its address). From arnodel at gmail.com Fri Apr 5 10:53:55 2013 From: arnodel at gmail.com (Arnaud Delobelle) Date: Fri, 5 Apr 2013 15:53:55 +0100 Subject: is operator versus id() function In-Reply-To: References: Message-ID: On 5 April 2013 14:49, Candide Dandide wrote: > Until now, I was quite sure that the is operator acts the same as the id builtin function, or, to be more formal, that o1 is o2 to be exactly equivalent to id(o1) == id(o2). This equivalence is reported in many books, for instance Martelli's Python in a Nutshell. > > But with the following code, I'm not still sure the equivalence above is correct. Here's the code : > > > #-------------------------------------------------------- > class A(object): > def f(self): > print "A" > > a=A() > print id(A.f) == id(a.f), A.f is a.f > #-------------------------------------------------------- > > > outputing: > > True False > > So, could someone please explain what exactly the is operator returns ? The official doc says : > > The ?is? operator compares the identity of two objects; the id() function returns an integer representing its identity (currently implemented as its address). And the doc is right! >>> Af = A.f >>> af = a.f >>> print id(Af) == id(af), Af is af False False You've fallen victim to the fact that CPython is very quick to collect garbage. More precisely, when Python interprets `id(A.f) == id(a.f)`, it does the following: 1. Create a new unbound method (A.f) 2. Calculate its id 3. Now the refcount of A.f is down to 0, so it's garbage collected 4 Create a new bound method (a.f) **and very probably use the same memory slot as that of A.f** 5 Calculate its id 6 ... -- Arnaud From c.candide at laposte.net Fri Apr 5 12:40:17 2013 From: c.candide at laposte.net (candide) Date: Fri, 5 Apr 2013 09:40:17 -0700 (PDT) Subject: is operator versus id() function In-Reply-To: References: Message-ID: Le vendredi 5 avril 2013 16:53:55 UTC+2, Arnaud Delobelle a ?crit?: > > You've fallen victim to the fact that CPython is very quick to collect > > garbage. OK, I get it but it's a fairly unexpected behavior. Thanks for the demonstrative snippet of code and the instructive answer. From c.candide at laposte.net Fri Apr 5 12:40:17 2013 From: c.candide at laposte.net (candide) Date: Fri, 5 Apr 2013 09:40:17 -0700 (PDT) Subject: is operator versus id() function In-Reply-To: References: Message-ID: Le vendredi 5 avril 2013 16:53:55 UTC+2, Arnaud Delobelle a ?crit?: > > You've fallen victim to the fact that CPython is very quick to collect > > garbage. OK, I get it but it's a fairly unexpected behavior. Thanks for the demonstrative snippet of code and the instructive answer. From timothy.c.delaney at gmail.com Fri Apr 5 15:57:01 2013 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Sat, 6 Apr 2013 06:57:01 +1100 Subject: is operator versus id() function In-Reply-To: References: Message-ID: On 6 April 2013 03:40, candide wrote: > Le vendredi 5 avril 2013 16:53:55 UTC+2, Arnaud Delobelle a ?crit : > > > > > > You've fallen victim to the fact that CPython is very quick to collect > > > > garbage. > > > OK, I get it but it's a fairly unexpected behavior. > Thanks for the demonstrative snippet of code and the instructive answer. > If you read the docs for id() < http://docs.python.org/3.3/library/functions.html#id>, you will see that it says: Return the "identity" of an object. This is an integer which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value. If you think it could explain things better, please submit a doc bug. I think part of your confusion here is that bound methods in Python are created when accessed. So A.f and a.f are not the same object - one is a function (an unbound method, but there's no distinction in Python 3.x) and the other is a bound method. For that reason, accessing a.f twice will return two different bound method instances. Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> class A(object): ... def f(self): ... print("A") ... >>> a=A() >>> print(id(a.f) == id(a.f), a.f is a.f) True False >>> Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.com Sat Apr 6 09:35:03 2013 From: nobody at nowhere.com (Nobody) Date: Sat, 06 Apr 2013 14:35:03 +0100 Subject: is operator versus id() function References: Message-ID: On Fri, 05 Apr 2013 06:49:14 -0700, Candide Dandide wrote: > So, could someone please explain what exactly the is operator returns ? > The official doc says : > > The ?is? operator compares the identity of two objects; the id() > function returns an integer representing its identity (currently > implemented as its address). The docs are correct. But an identity is only unique for the lifetime of the object, so "x is y" and "id(x)==id(y)" are only equivalent if the lifetimes of x and y overlap. If the objects have disjoint lifetimes (i.e. one is created after the other has been destroyed), then it's possible for id() to return the same value for both objects, so id(x)==id(y) can return a "false positive" result, as happened in your example. From mattgraves7 at gmail.com Fri Apr 5 10:04:49 2013 From: mattgraves7 at gmail.com (mattgraves7 at gmail.com) Date: Fri, 5 Apr 2013 07:04:49 -0700 (PDT) Subject: Typing letters slowly using sys Message-ID: <44fa9565-c6cd-4a46-ad28-97417b403444@googlegroups.com> I am using sys to give the effect that I am typing letters slowly. Basically what I want to have happen is have it show "Loading......" with the word loading appearing instantly and then the periods appearing slowly, as most loading screens do. This is what I have. dots = ('............') for x in dots: sys.stdout.write(x) sys.stdout.flush() time.sleep(0.2) I cannot for the life of me figure out how to get the dots to appear on the same line as "Loading". Every way that I have attempted, the word "Loading" appears and then the dots appear on the next line. From gordon at panix.com Fri Apr 5 10:31:03 2013 From: gordon at panix.com (John Gordon) Date: Fri, 5 Apr 2013 14:31:03 +0000 (UTC) Subject: Typing letters slowly using sys References: <44fa9565-c6cd-4a46-ad28-97417b403444@googlegroups.com> Message-ID: In <44fa9565-c6cd-4a46-ad28-97417b403444 at googlegroups.com> mattgraves7 at gmail.com writes: > dots = ('............') > for x in dots: > sys.stdout.write(x) > sys.stdout.flush() > time.sleep(0.2) > > I cannot for the life of me figure out how to get the dots to appear on > the same line as "Loading". Every way that I have attempted, the word > "Loading" appears and then the dots appear on the next line. How are you printing the "Loading" text? (It would have helped a lot to show us that code.) -- 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 msirenef at lightbird.net Fri Apr 5 10:52:07 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Fri, 05 Apr 2013 10:52:07 -0400 Subject: Typing letters slowly using sys In-Reply-To: <44fa9565-c6cd-4a46-ad28-97417b403444@googlegroups.com> References: <44fa9565-c6cd-4a46-ad28-97417b403444@googlegroups.com> Message-ID: <515EE517.70801@lightbird.net> On 04/05/2013 10:04 AM, mattgraves7 at gmail.com wrote: > I am using sys to give the effect that I am typing letters slowly. Basically what I want to have happen is have it show "Loading......" with the word loading appearing instantly and then the periods appearing slowly, as most loading screens do. > This is what I have. > > dots = ('............') > for x in dots: > sys.stdout.write(x) > sys.stdout.flush() > time.sleep(0.2) > > I cannot for the life of me figure out how to get the dots to appear on the same line as "Loading". Every way that I have attempted, the word "Loading" appears and then the dots appear on the next line. If you're printing in 2.x, you can do: print "Loading", in 3.x, print("Loading", end='') -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From invalid at invalid.invalid Fri Apr 5 10:50:01 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 5 Apr 2013 14:50:01 +0000 (UTC) Subject: Typing letters slowly using sys References: <44fa9565-c6cd-4a46-ad28-97417b403444@googlegroups.com> Message-ID: On 2013-04-05, mattgraves7 at gmail.com wrote: > dots = ('............') > for x in dots: > sys.stdout.write(x) > sys.stdout.flush() > time.sleep(0.2) That works just fine for me using Python 2.4, 2.6, 2.7 and 3.2. -- Grant Edwards grant.b.edwards Yow! Is it 1974? What's at for SUPPER? Can I spend gmail.com my COLLEGE FUND in one wild afternoon?? From mattgraves7 at gmail.com Fri Apr 5 11:10:53 2013 From: mattgraves7 at gmail.com (Matt) Date: Fri, 5 Apr 2013 08:10:53 -0700 (PDT) Subject: Typing letters slowly using sys In-Reply-To: <44fa9565-c6cd-4a46-ad28-97417b403444@googlegroups.com> References: <44fa9565-c6cd-4a46-ad28-97417b403444@googlegroups.com> Message-ID: On Friday, April 5, 2013 10:04:49 AM UTC-4, Matt wrote: > I am using sys to give the effect that I am typing letters slowly. Basically what I want to have happen is have it show "Loading......" with the word loading appearing instantly and then the periods appearing slowly, as most loading screens do. > > This is what I have. > > > > dots = ('............') > > for x in dots: > > sys.stdout.write(x) > > sys.stdout.flush() > > time.sleep(0.2) > > > > I cannot for the life of me figure out how to get the dots to appear on the same line as "Loading". Every way that I have attempted, the word "Loading" appears and then the dots appear on the next line. Sorry guys, I may have not been clear. The part I pasted does work, but I cannot figure out how to get that to print after the word "Loading". So it will instantly print "Loading", and then the "..........." will appear slowly From gordon at panix.com Fri Apr 5 11:14:20 2013 From: gordon at panix.com (John Gordon) Date: Fri, 5 Apr 2013 15:14:20 +0000 (UTC) Subject: Typing letters slowly using sys References: <44fa9565-c6cd-4a46-ad28-97417b403444@googlegroups.com> Message-ID: In Matt writes: > Sorry guys, I may have not been clear. The part I pasted does work, but > I cannot figure out how to get that to print after the word "Loading". So > it will instantly print "Loading", and then the "..........." will appear > slowly Have you tried: sys.stdout.write('Loading') sys.stdout.flush() -- 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 inq1ltd at inqvista.com Fri Apr 5 11:39:21 2013 From: inq1ltd at inqvista.com (inq1ltd) Date: Fri, 05 Apr 2013 11:39:21 -0400 Subject: Typing letters slowly using sys In-Reply-To: References: <44fa9565-c6cd-4a46-ad28-97417b403444@googlegroups.com> Message-ID: <6866043.IrmzE94Xm3@mach-114-20> On Friday, April 05, 2013 08:10:53 AM Matt wrote: > On Friday, April 5, 2013 10:04:49 AM UTC-4, Matt wrote: > > I am using sys to give the effect that I am typing letters slowly. > > Basically what I want to have happen is have it show "Loading......" > > with the word loading appearing instantly and then the periods > > appearing slowly, as most loading screens do. > > > > This is what I have. > > > > > > > > dots = ('............') > > > > for x in dots: > > sys.stdout.write(x) > > > > sys.stdout.flush() > > > > time.sleep(0.2) > > > > I cannot for the life of me figure out how to get the dots to appear on > > the same line as "Loading". Every way that I have attempted, the word > > "Loading" appears and then the dots appear on the next line. > Sorry guys, I may have not been clear. The part I pasted does work, but I > cannot figure out how to get that to print after the word "Loading". So it > will instantly print "Loading", and then the "..........." will appear > slowly if you can write the dots on one one line, then try writing the word with an additional dot. Loading . Loading . . Loading . . . in other words, over write the word Loading with one additional dot each time a dot is called for. jd inqvista.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From luban.works at gmail.com Fri Apr 5 11:04:43 2013 From: luban.works at gmail.com (LubanWorks) Date: Fri, 5 Apr 2013 23:04:43 +0800 Subject: Run python script with ./ Message-ID: Hi all, I installed two python 2.7.3 into my home directory one is for Linux: /home/luban/*Linux*/Python/2.7.3 another is for Solaris: /home/luban/*SunOS*/Python/2.7.3 then I create a wrapper named "python" in /home/luban/bin to call the different python when I am working on different systems. [luban at lunbanworks 1] ~ > cat /home/luban/bin/python #!/bin/sh CMD=`basename $0` OS=`uname -s` CMD_PATH="/home/luban/$OS/Python/2.7.3/bin" if [ -x "${CMD_PATH}/${CMD}" ];then export PATH="${CMD_PATH}:${PATH}" exec ${CMD_PATH}/${CMD} ${1+"$@"} else echo "${CMD} is not available for ${OS}" 1>&2 exit 1 fi [luban at lunbanworks 2] ls -l /home/luban/bin/python -rwxrwxr-x 1 luban lunban 221 Apr 5 19:11 python* I use below script to test the wrapper /home/luban/bin/python [luban at lunbanworks 3]* ~ > *cat myscript.py #!/home/luban/bin/python myname="lunban" print "myname is %s" % myname [luban at lunbanworks 4]* *chmod +x myscript.py I want to use ./ run myscript.py [luban at lunbanworks 5] ~ >./myscript.py myname=luban: Command not found. lpr: Unable to access "myname" - No such file or directory use /home/luban/bin/python myscript.py can work:* *[luban at lunbanworks 5] ~ > */home/luban/bin/python myscript.py* myname is luban After I *change the shebang line to #!/home/luban/Linux/Python/2.7.3/bin/python, use ./ can execute the script. * [luban at lunbanworks 6] *~ >*cat myscript.py #!/home/luban/Linux/Python/2.7.3/bin/python myname="lunban" print "myname is %s" % myname [luban at lunbanworks 7] *~ >*./myscript.py myname is luban My question is: Why when I use #!/home/luban/Linux/Python/2.7.3/bin/python at the beginning of myscript.py, *./*myscript.py can work, but if I use the wrapper #!/home/luban/bin/python in my python script, use * ./* to run the script, it cannot not work? I had many scripts used #!/home/luban/bin/python when I only installed python under #!/home/luban/ for Linux, they can run with ./, I don't want to change them, so, how to let ./ run the python script If I want to *KEEP* wrapper #!/home/luban/bin/python as the shebang line? Best Regards, Luban -------------- next part -------------- An HTML attachment was scrubbed... URL: From dylan at dje.me Fri Apr 5 11:58:28 2013 From: dylan at dje.me (Dylan Evans) Date: Sat, 6 Apr 2013 01:58:28 +1000 Subject: Run python script with ./ In-Reply-To: References: Message-ID: On Sat, Apr 6, 2013 at 1:04 AM, LubanWorks wrote: > > > > My question is: > > Why when I use #!/home/luban/Linux/Python/2.7.3/bin/python at the > beginning of myscript.py, *./*myscript.py can work, > > but if I use the wrapper #!/home/luban/bin/python in my python script, use > *./* to run the script, it cannot not work? > Your shell will be trying to run your python script. The reason being that when you do #!/bin/sh in the wrapper the shell tries to execute $0 which in this case is the name of your python script. > > > I had many scripts used #!/home/luban/bin/python when I only installed > python under #!/home/luban/ for Linux, they can run with ./, I don't want > to change them, > > so, how to let ./ run the python script If I want to *KEEP* wrapper > #!/home/luban/bin/python as the shebang line? > > Probably easier to use a symlink, or just use #!python and adjust your $PATH. > > Best Regards, > Luban > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- "The UNIX system has a command, nice ... in order to be nice to the other users. Nobody ever uses it." - Andrew S. Tanenbaum -------------- next part -------------- An HTML attachment was scrubbed... URL: From luban.works at gmail.com Sat Apr 6 06:15:01 2013 From: luban.works at gmail.com (LubanWorks) Date: Sat, 6 Apr 2013 18:15:01 +0800 Subject: Run python script with ./ In-Reply-To: References: Message-ID: I have test that wrapper, under Bash 4.1.2, ./myscript.py works, it doesn't work under Bash 3.2.25, seems Bash relative. http://stackoverflow.com/questions/15838183/run-python-script-with-dot-slash On Fri, Apr 5, 2013 at 11:58 PM, Dylan Evans wrote: > > > > On Sat, Apr 6, 2013 at 1:04 AM, LubanWorks wrote: >> >> >> >> My question is: >> >> Why when I use #!/home/luban/Linux/Python/2.7.3/bin/python at the >> beginning of myscript.py, *./*myscript.py can work, >> >> but if I use the wrapper #!/home/luban/bin/python in my python script, use >> *./* to run the script, it cannot not work? >> > > Your shell will be trying to run your python script. The reason being that > when you do #!/bin/sh in the wrapper the shell tries to execute $0 which in > this case is the name of your python script. > > >> >> >> I had many scripts used #!/home/luban/bin/python when I only installed >> python under #!/home/luban/ for Linux, they can run with ./, I don't want >> to change them, >> >> so, how to let ./ run the python script If I want to *KEEP* wrapper >> #!/home/luban/bin/python as the shebang line? >> >> > Probably easier to use a symlink, or just use #!python and adjust your > $PATH. > > >> >> Best Regards, >> Luban >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > > -- > "The UNIX system has a command, nice ... in order to be nice to the other > users. Nobody ever uses it." - Andrew S. Tanenbaum > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris at simplistix.co.uk Fri Apr 5 12:03:44 2013 From: chris at simplistix.co.uk (Chris Withers) Date: Fri, 05 Apr 2013 13:03:44 -0300 Subject: xlutils 1.6.0 released! Message-ID: <515EF5E0.6010703@simplistix.co.uk> Hi All, I'm pleased to announce the release of xlutils 1.6.0: http://pypi.python.org/pypi/xlutils/1.6.0 This release features shiny new Sphinx-based documentation: http://pythonhosted.org/xlutils/ It also has some changes that make xlutils compatible with the upcoming xlrd 0.9.1 release. Details of all things Python and Excel related can be found here: http://www.python-excel.org/ cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From tyler at tysdomain.com Fri Apr 5 14:59:04 2013 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Fri, 05 Apr 2013 12:59:04 -0600 Subject: a couple of questions: pickling objects and strict types Message-ID: <515F1EF8.50304@tysdomain.com> Hello all: I've been using Python for a while now, but I have one larger problem. I come from a c++ background; though it doesn't help in catching runtime errors, being able to compile a program helps catch a lot of syntax errors. I know about pychecker, which is somewhat useful. Do people have other methods for handling this? Also, I'm depickling objects. Is there a way I can force pickle to call the object's ctor? I set up events per object, but when it just deserializes it doesn't set all that up. Thanks, -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. From gordon at panix.com Fri Apr 5 15:27:30 2013 From: gordon at panix.com (John Gordon) Date: Fri, 5 Apr 2013 19:27:30 +0000 (UTC) Subject: a couple of questions: pickling objects and strict types References: Message-ID: In "Littlefield, Tyler" writes: > Hello all: > I've been using Python for a while now, but I have one larger problem. > I come from a c++ background; though it doesn't help in catching runtime > errors, being able to compile a program helps catch a lot of syntax > errors. I know about pychecker, which is somewhat useful. Do people have > other methods for handling this? The py_compile module can catch some obvious syntax errors, such as incorrect indentation levels or a missing colon at the end of an if statement. But it won't catch other errors such as using a variable name before it's defined. For that, you can use an external program such as pylint or pyflakes. -- 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 steve+comp.lang.python at pearwood.info Fri Apr 5 16:30:18 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 05 Apr 2013 20:30:18 GMT Subject: a couple of questions: pickling objects and strict types References: Message-ID: <515f345a$0$29995$c3e8da3$5496439d@news.astraweb.com> On Fri, 05 Apr 2013 12:59:04 -0600, Littlefield, Tyler wrote: > Hello all: > I've been using Python for a while now, but I have one larger problem. I > come from a c++ background; though it doesn't help in catching runtime > errors, being able to compile a program helps catch a lot of syntax > errors. I know about pychecker, which is somewhat useful. Do people have > other methods for handling this? Do you tend to make a lot of syntax errors? Python also catches syntax errors at compile-time. I won't speak for others, but I hardly ever make syntax errors: between Python's simple, surprise-free syntax, and modern, syntax-colouring editors, I find that I rarely make syntax errors. > Also, I'm depickling objects. Is there a way I can force pickle to call > the object's ctor? I set up events per object, but when it just > deserializes it doesn't set all that up. Thanks, What's the object's ctor? What sort of objects are you dealing with? -- Steven From tyler at tysdomain.com Fri Apr 5 20:18:51 2013 From: tyler at tysdomain.com (Littlefield, Tyler) Date: Fri, 05 Apr 2013 18:18:51 -0600 Subject: a couple of questions: pickling objects and strict types In-Reply-To: <515f345a$0$29995$c3e8da3$5496439d@news.astraweb.com> References: <515f345a$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: <515F69EB.4090504@tysdomain.com> On 4/5/2013 2:30 PM, Steven D'Aprano wrote: > On Fri, 05 Apr 2013 12:59:04 -0600, Littlefield, Tyler wrote: > >> Hello all: >> I've been using Python for a while now, but I have one larger problem. I >> come from a c++ background; though it doesn't help in catching runtime >> errors, being able to compile a program helps catch a lot of syntax >> errors. I know about pychecker, which is somewhat useful. Do people have >> other methods for handling this? > > Do you tend to make a lot of syntax errors? Not a -lot-, but there are things I don't catch sometimes. > Python also catches syntax errors at compile-time. I won't speak for > others, but I hardly ever make syntax errors: between Python's simple, > surprise-free syntax, and modern, syntax-colouring editors, I find that I > rarely make syntax errors. I am blind, so colorful editors don't really work all that well for me. >> Also, I'm depickling objects. Is there a way I can force pickle to call >> the object's ctor? I set up events per object, but when it just >> deserializes it doesn't set all that up. Thanks, > What's the object's ctor? What sort of objects are you dealing with? > > > def __init__(self): self.events = {} self.components = [] self.contents = [] self.uid = uuid4().int self.events['OnLook'] = teventlet() Basically events don't get initialized like I'd like after I depickle objects. -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave. From steve+comp.lang.python at pearwood.info Fri Apr 5 22:37:31 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Apr 2013 02:37:31 GMT Subject: a couple of questions: pickling objects and strict types References: <515f345a$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: <515f8a6b$0$29995$c3e8da3$5496439d@news.astraweb.com> On Fri, 05 Apr 2013 18:18:51 -0600, Littlefield, Tyler wrote: > On 4/5/2013 2:30 PM, Steven D'Aprano wrote: >> On Fri, 05 Apr 2013 12:59:04 -0600, Littlefield, Tyler wrote: >> >>> Hello all: >>> I've been using Python for a while now, but I have one larger problem. >>> I come from a c++ background; though it doesn't help in catching >>> runtime errors, being able to compile a program helps catch a lot of >>> syntax errors. I know about pychecker, which is somewhat useful. Do >>> people have other methods for handling this? >> >> Do you tend to make a lot of syntax errors? > > Not a -lot-, but there are things I don't catch sometimes. As we all do. But fortunately the Python compiler catches syntax errors. >> Python also catches syntax errors at compile-time. I won't speak for >> others, but I hardly ever make syntax errors: between Python's simple, >> surprise-free syntax, and modern, syntax-colouring editors, I find that >> I rarely make syntax errors. > > I am blind, so colorful editors don't really work all that well for me. Fair point. >>> Also, I'm depickling objects. Is there a way I can force pickle to >>> call the object's ctor? I set up events per object, but when it just >>> deserializes it doesn't set all that up. Thanks, >> What's the object's ctor? What sort of objects are you dealing with? >> >> >> > def __init__(self): > self.events = {} > self.components = [] > self.contents = [] > self.uid = uuid4().int > self.events['OnLook'] = teventlet() > > > Basically events don't get initialized like I'd like after I depickle > objects. Did you mean "constructor" rather than C T O R ? Perhaps your voice-to- text software (if you are using such) misheard you. Correct, by default pickle does not call the __init__ method, it just reconstructs the instance. Basically, it takes a snapshot of the instance's internal state (the __dict__) and reconstructs from the snapshot. This is explained in the documentation here: http://docs.python.org/2/library/pickle.html#the-pickle-protocol You can force the __init__ method to be called in a couple of different ways. Perhaps this is the most straight-forward. Add a __setstate__ method to your class: def __setstate__(self, state): self.__dict__.update(state) self.events['OnLook'] = teventlet() -- Steven From rosuav at gmail.com Fri Apr 5 22:49:50 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Apr 2013 13:49:50 +1100 Subject: a couple of questions: pickling objects and strict types In-Reply-To: <515f8a6b$0$29995$c3e8da3$5496439d@news.astraweb.com> References: <515f345a$0$29995$c3e8da3$5496439d@news.astraweb.com> <515f8a6b$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Apr 6, 2013 at 1:37 PM, Steven D'Aprano wrote: > Did you mean "constructor" rather than C T O R ? Perhaps your voice-to- > text software (if you are using such) misheard you. Side point: "ctor" is a common abbreviation for "constructor". ChrisA From davea at davea.name Fri Apr 5 23:22:22 2013 From: davea at davea.name (Dave Angel) Date: Fri, 05 Apr 2013 23:22:22 -0400 Subject: a couple of questions: pickling objects and strict types In-Reply-To: References: <515f345a$0$29995$c3e8da3$5496439d@news.astraweb.com> <515f8a6b$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: <515F94EE.4090502@davea.name> On 04/05/2013 10:49 PM, Chris Angelico wrote: > On Sat, Apr 6, 2013 at 1:37 PM, Steven D'Aprano > wrote: >> Did you mean "constructor" rather than C T O R ? Perhaps your voice-to- >> text software (if you are using such) misheard you. > > Side point: "ctor" is a common abbreviation for "constructor". > > ChrisA > But neither term applies to the __init__() method, which is an initializer. The constructor is __new__() -- DaveA From foobar at invalid.invalid Sat Apr 6 06:30:29 2013 From: foobar at invalid.invalid (mblume) Date: Sat, 6 Apr 2013 10:30:29 +0000 (UTC) Subject: a couple of questions: pickling objects and strict types References: <515f345a$0$29995$c3e8da3$5496439d@news.astraweb.com> <515f8a6b$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am Sat, 06 Apr 2013 02:37:31 +0000 schrieb Steven D'Aprano: >>> [...] >> def __init__(self): >> self.events = {} >> self.components = [] >> self.contents = [] >> self.uid = uuid4().int >> self.events['OnLook'] = teventlet() >> >> >> Basically events don't get initialized like I'd like after I depickle >> objects. > > > Correct, by default pickle does not call the __init__ method, it just > reconstructs the instance. Basically, it takes a snapshot of the > instance's internal state (the __dict__) and reconstructs from the > snapshot. > > [...] > To the OP: Did you really mean self.events['OnLook'] = teventlet() as opposed to: self.events['OnLook'] = teventlet The first one executes teventlet and then assigns the result of the function to self.events['OnLook']. The second one assigns the function teventlet to the dict entry (presumably so that it will be called when the objct detects the 'OnLook' event). Unless the teventlet() function returns itself a function, an 'OnLook' event won't do anything useful during the remaining life time of the object, I think. Regards Martin From rosuav at gmail.com Fri Apr 5 20:31:35 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Apr 2013 11:31:35 +1100 Subject: a couple of questions: pickling objects and strict types In-Reply-To: <515F1EF8.50304@tysdomain.com> References: <515F1EF8.50304@tysdomain.com> Message-ID: On Sat, Apr 6, 2013 at 5:59 AM, Littlefield, Tyler wrote: > I come from a c++ background; though it doesn't help in catching runtime > errors, being able to compile a program helps catch a lot of syntax errors. Syntax errors you'll still catch just by attempting to load up the module in any way: def foo(): if True # oops, no colon pass You don't need to execute that particular line of code to get the error. But there are a whole lot of errors that a C++ compiler would catch that Python leaves until run-time, such as variable name misspellings, data type mismatches, etc, etc... however, this is part of what gives Python its flexibility. In fact, a lot of things that would be errors in C/C++ are actually quite legal and useful in Python. The one area that I would prefer the C model, though, is declared variables vs freely-usable names. I prefer the Python notion of "names" rather than "variables" (the difference takes a lot of words to explain, but it makes VERY good sense - in a high level language), but I do like the infinite nesting of scopes and simple catching of misspellings that the declarations give. Effectively, what I'd like to see is a declaration "local foo" instead of Python's choice of "global foo" - with the caveat that globals can be read, but not written, without that declaration. I think it's clearer and cleaner to declare all locals. But that's a small matter. ChrisA From terminatorul at gmail.com Fri Apr 5 17:41:19 2013 From: terminatorul at gmail.com (terminatorul at gmail.com) Date: Fri, 5 Apr 2013 14:41:19 -0700 (PDT) Subject: I hate you all Message-ID: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> Hello I just tried python 3.3 with some simple script meant for unit test. How can python authors be so arrogant to impose their tabs and spaces options on me ? It should be my choice if I want to use tabs or not ! I know people have all goten into this frenzy of using either tabs, either spaces for indentation, but using a hard-tab of 8 spaces and a soft tab of 4 spaces has worked fine long before python 3 showed up. And if they decided to throw a TabError, they should have at least created an option to specify tab size, so I can work around that. I am aware that so many editors use a tab stop of 4 spaces instead of 8 (which by the way started as a cheap way to work around their initial lack of a "soft tab stop" option, and then was kept at 4 for "compatibility"). But the rest of us who always use a tab stop of 8 should not be forced to change preferences because python reached version 3. Timothy Madden From rosuav at gmail.com Fri Apr 5 17:53:35 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Apr 2013 08:53:35 +1100 Subject: I hate you all In-Reply-To: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> Message-ID: On Sat, Apr 6, 2013 at 8:41 AM, wrote: > Hello > > I just tried python 3.3 with some simple script meant for unit test. > > How can python authors be so arrogant to impose their tabs and spaces options on me ? It should be my choice if I want to use tabs or not ! It is. As long as you're consistent, you can use tabs or spaces without problems. You're also most welcome to continue using Python 3.2, or 2.1, or 0.1 (if you're Steven D'Aprano), which might have the semantics you want. And hey, if you dig into the source, I'm sure you could find how to make it configurable. ChrisA From gordon at panix.com Fri Apr 5 17:55:29 2013 From: gordon at panix.com (John Gordon) Date: Fri, 5 Apr 2013 21:55:29 +0000 (UTC) Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> Message-ID: In <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb at googlegroups.com> terminatorul at gmail.com writes: > How can python authors be so arrogant to impose their tabs and spaces > options on me ? It should be my choice if I want to use tabs or not ! You are free to use tabs, but you must be consistent. You can't mix tabs and spaces for lines of code at the same indentation level. -- 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 terminatorul at gmail.com Fri Apr 5 18:04:52 2013 From: terminatorul at gmail.com (terminatorul at gmail.com) Date: Fri, 5 Apr 2013 15:04:52 -0700 (PDT) Subject: I hate you all In-Reply-To: References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> Message-ID: <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> On Saturday, April 6, 2013 12:55:29 AM UTC+3, John Gordon wrote: > In <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb at googlegroups.com> terminatorul at gmail.com writes: > > > How can python authors be so arrogant to impose their tabs and spaces > > options on me ? It should be my choice if I want to use tabs or not ! > > You are free to use tabs, but you must be consistent. You can't mix > tabs and spaces for lines of code at the same indentation level. They say so, but python does not work that way. This is a simple script: from unittest import TestCase class SvnExternalCmdTests(TestCase) : def test_parse_svn_external(self) : for sample_external in sample_svn_externals : self.assertEqual(parse_svn_externals(sample_external[0][0], sample_external[0][1]), [ sample_external[1] ]) And at the `for` statement at line 5 I get: C:\Documents and Settings\Adrian\Projects>python sample-py3.py File "sample-py3.py", line 5 for sample_external in sample_svn_externals : ^ TabError: inconsistent use of tabs and spaces in indentation Line 5 is the only line in the file that starts at col 9 (after a tab). Being the only line in the file with that indent level, how can it be inconsistent ? You can try the script as it is, and see python 3.3 will not run it From bahamutzero8825 at gmail.com Fri Apr 5 18:28:43 2013 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Fri, 05 Apr 2013 17:28:43 -0500 Subject: I hate you all In-Reply-To: <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> Message-ID: <515F501B.30102@gmail.com> On 2013.04.05 17:04, terminatorul at gmail.com wrote: > Line 5 is the only line in the file that starts at col 9 (after a tab). Being the only line in the file with that indent level, how can it be inconsistent ? The first indent level is done with spaces on the second line (for def) and then with a tab on the third (and another tab to indent again). Remember that your for loop is inside the class definition. -- CPython 3.3.0 | Windows NT 6.2.9200 / FreeBSD 9.1 From ian.g.kelly at gmail.com Fri Apr 5 18:42:15 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 5 Apr 2013 16:42:15 -0600 Subject: I hate you all In-Reply-To: <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> Message-ID: On Fri, Apr 5, 2013 at 4:04 PM, wrote: > They say so, but python does not work that way. This is a simple script: > > from unittest import TestCase > > class SvnExternalCmdTests(TestCase) : > def test_parse_svn_external(self) : > for sample_external in sample_svn_externals : > self.assertEqual(parse_svn_externals(sample_external[0][0], sample_external[0][1]), [ sample_external[1] ]) > > And at the `for` statement at line 5 I get: > > C:\Documents and Settings\Adrian\Projects>python sample-py3.py > File "sample-py3.py", line 5 > for sample_external in sample_svn_externals : > ^ > TabError: inconsistent use of tabs and spaces in indentation > > > Line 5 is the only line in the file that starts at col 9 (after a tab). Being the only line in the file with that indent level, how can it be inconsistent ? The "def" line has four spaces. The "for" line then has a hard tab. This is ambiguous. If the hard tab is assumed to have a width of four spaces, then they are at the same indentation level. If it is assumed to have a width of eight spaces, then they are not. Python 2 resolved this ambiguity by assuming that a hard tab was simply equivalent to four or eight spaces (I don't remember which). The problem with assuming this is that the assumption made by Python does not necessarily match the tab width selected by the user, with the result that lines that *look* like they are at the same indentation level might actually be different (and vice-versa), leading to hard-to-find bugs. Python 3 instead resolves this ambiguity by not allowing it. In the code above, because the "def" line has four spaces, the indentation of the "for" line that is subordinate to it needs to also start with four spaces (and then you can continue the indentation with tabs or spaces as you prefer). Because the line after the "for" line is subordinate to it, it also then needs to begin with the same exact indentation used by the "for" line (in the sample provided, it currently does). My suggestion: choose to use either all tabs or all spaces within a file, and then you won't have this problem. From ian.g.kelly at gmail.com Fri Apr 5 19:00:23 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 5 Apr 2013 17:00:23 -0600 Subject: I hate you all In-Reply-To: References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> Message-ID: On Fri, Apr 5, 2013 at 4:42 PM, Ian Kelly wrote: > Python 2 resolved this ambiguity by assuming that a hard tab was > simply equivalent to four or eight spaces (I don't remember which). In fact, neither is correct. Per the docs: ...tabs are replaced (from left to right) by one to eight spaces such that the total number of characters up to and including the replacement is a multiple of eight... From isaac.to at gmail.com Fri Apr 5 18:35:42 2013 From: isaac.to at gmail.com (Isaac To) Date: Sat, 6 Apr 2013 06:35:42 +0800 Subject: I hate you all In-Reply-To: <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> Message-ID: You underestimated the arrogance of Python. Python 3 tab doesn't map to 4 spaces. It doesn't map to any number of spaces. Tabs and spaces are completely unrelated. If you have a function having the first indentation level with 4 (or any number of) spaces, the next line starting not with 4 spaces but instead with a tab always lead you to the TabError exception. If you like to play tricks, you can use "4 spaces plus a tab" as the next indentation level. I'd rather not do this kind of things, and forget about use using tabs at all. You are out of luck if you want to play the tab-space tricks, but if you follow the lead, you'll soon find that code will be more reliable without tabs, especially if you cut-and-paste code of others. On Sat, Apr 6, 2013 at 6:04 AM, wrote: > On Saturday, April 6, 2013 12:55:29 AM UTC+3, John Gordon wrote: > > In <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb at googlegroups.com> > terminatorul at gmail.com writes: > > > > > How can python authors be so arrogant to impose their tabs and spaces > > > options on me ? It should be my choice if I want to use tabs or not ! > > > > You are free to use tabs, but you must be consistent. You can't mix > > tabs and spaces for lines of code at the same indentation level. > > They say so, but python does not work that way. This is a simple script: > > from unittest import TestCase > > class SvnExternalCmdTests(TestCase) : > def test_parse_svn_external(self) : > for sample_external in sample_svn_externals : > self.assertEqual(parse_svn_externals(sample_external[0][0], > sample_external[0][1]), [ sample_external[1] ]) > > And at the `for` statement at line 5 I get: > > C:\Documents and Settings\Adrian\Projects>python sample-py3.py > File "sample-py3.py", line 5 > for sample_external in sample_svn_externals : > ^ > TabError: inconsistent use of tabs and spaces in indentation > > > Line 5 is the only line in the file that starts at col 9 (after a tab). > Being the only line in the file with that indent level, how can it be > inconsistent ? > > You can try the script as it is, and see python 3.3 will not run it > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From terminatorul at gmail.com Fri Apr 5 20:22:19 2013 From: terminatorul at gmail.com (terminatorul at gmail.com) Date: Fri, 5 Apr 2013 17:22:19 -0700 (PDT) Subject: I hate you all In-Reply-To: References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> Message-ID: <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> On Saturday, April 6, 2013 1:42:15 AM UTC+3, Ian wrote: [...] > The "def" line has four spaces. The "for" line then has a hard tab. > This is ambiguous. If the hard tab is assumed to have a width of four > spaces, then they are at the same indentation level. If it is assumed > to have a width of eight spaces, then they are not. [...] The correct tab stop positions have always been at 8 character columns apart. The "ambiguity" was introduced by editors that do not follow the default value set in hardware like printers or used by consoles and terminal emulators. And now python forces me out of using any tab characters at all. I believe I should still have a choice, python should at lest give an option to set tab size, if the default of 8 is ambiguous now. Thank you, Timothy Madden From terminatorul at gmail.com Fri Apr 5 20:22:19 2013 From: terminatorul at gmail.com (terminatorul at gmail.com) Date: Fri, 5 Apr 2013 17:22:19 -0700 (PDT) Subject: I hate you all In-Reply-To: References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> Message-ID: <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> On Saturday, April 6, 2013 1:42:15 AM UTC+3, Ian wrote: [...] > The "def" line has four spaces. The "for" line then has a hard tab. > This is ambiguous. If the hard tab is assumed to have a width of four > spaces, then they are at the same indentation level. If it is assumed > to have a width of eight spaces, then they are not. [...] The correct tab stop positions have always been at 8 character columns apart. The "ambiguity" was introduced by editors that do not follow the default value set in hardware like printers or used by consoles and terminal emulators. And now python forces me out of using any tab characters at all. I believe I should still have a choice, python should at lest give an option to set tab size, if the default of 8 is ambiguous now. Thank you, Timothy Madden From rosuav at gmail.com Fri Apr 5 20:35:04 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Apr 2013 11:35:04 +1100 Subject: I hate you all In-Reply-To: <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> Message-ID: On Sat, Apr 6, 2013 at 11:22 AM, wrote: > On Saturday, April 6, 2013 1:42:15 AM UTC+3, Ian wrote: > [...] >> The "def" line has four spaces. The "for" line then has a hard tab. >> This is ambiguous. If the hard tab is assumed to have a width of four >> spaces, then they are at the same indentation level. If it is assumed >> to have a width of eight spaces, then they are not. > [...] > > The correct tab stop positions have always been at 8 character columns apart. > The "ambiguity" was introduced by editors that do not follow the default value set in hardware like printers or used by consoles and terminal emulators. > > And now python forces me out of using any tab characters at all. I believe I should still have a choice, python should at lest give an option to set tab size, if the default of 8 is ambiguous now. If you're indenting four spaces per level, then indent four spaces per level. The code you posted would work perfectly if the indentation is four spaces, then eight spaces, then twelve spaces. The problem is that you have a stupid editor that's enforcing tabs instead of certain multiples of spaces - get one that'll keep them all as spaces and you won't have a problem. Or use actual tabs, and set the displayed tab width to whatever you feel like. That works, too. Neither option causes any problems with any sane tools. ChrisA From bahamutzero8825 at gmail.com Fri Apr 5 20:50:36 2013 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Fri, 05 Apr 2013 19:50:36 -0500 Subject: I hate you all In-Reply-To: <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> Message-ID: <515F715C.5040402@gmail.com> On 2013.04.05 19:22, terminatorul at gmail.com wrote: > And now python forces me out of using any tab characters at all. I believe I should still have a choice, python should at lest give an option to set tab size, if the default of 8 is ambiguous now. Python (at least Python 3) has no concept of tab size. A tab is one character, and how an editor or terminal or whatever chooses to display it has nothing to do with Python. If you want to convert tabs to a specific number of spaces or vice versa, there are multiple tools out there you can use. In fact, many editors have the functionality built in. Use all tabs or use all spaces. Any editor that isn't broken will let you do either without problems. -- CPython 3.3.0 | Windows NT 6.2.9200 / FreeBSD 9.1 From steve+comp.lang.python at pearwood.info Fri Apr 5 22:07:34 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Apr 2013 02:07:34 GMT Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> Message-ID: <515f8365$0$29995$c3e8da3$5496439d@news.astraweb.com> On Fri, 05 Apr 2013 17:22:19 -0700, terminatorul wrote: > On Saturday, April 6, 2013 1:42:15 AM UTC+3, Ian wrote: [...] >> The "def" line has four spaces. The "for" line then has a hard tab. >> This is ambiguous. If the hard tab is assumed to have a width of four >> spaces, then they are at the same indentation level. If it is assumed >> to have a width of eight spaces, then they are not. > [...] > > The correct tab stop positions have always been at 8 character columns > apart. The "ambiguity" was introduced by editors that do not follow the > default value set in hardware like printers or used by consoles and > terminal emulators. This is incorrect. Tab stops come from *typewriters*, where they are user- configurable to any position on the page without limit. There is no requirement for them to be 8 character columns apart, or even a fixed number of columns apart. Word processors like OpenOffice and Microsoft Word get the behaviour of tab stops right. Any editor which forces tabs to be exactly 8 columns apart gets them wrong. > And now python forces me out of using any tab characters at all. That is simply not true, and you have been told repeatedly by numerous people that Python 3 supports tabs. You can use spaces for indentation, and you can use tabs for indentation. You can even mix spaces and tabs in the same file. What you cannot do is mix spaces and tabs in the same block. If you don't believe us, and you don't believe the documentation, then believe the actual behaviour of the Python 3 compiler. Test it for yourself. Run this code under Python 3: === cut === code = """ def spam(): print("indented with five spaces") def eggs(): \t\tprint("indented with two tabs") spam() eggs() """ exec(code) === cut === If it were my language, I would be even stricter about indentation than Python 3. I would require that each file use *only* tabs, or *only* spaces, and not allow both in the same file. -- Steven From ian.g.kelly at gmail.com Fri Apr 5 23:53:40 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 5 Apr 2013 21:53:40 -0600 Subject: I hate you all In-Reply-To: <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> Message-ID: On Fri, Apr 5, 2013 at 6:22 PM, wrote: > The correct tab stop positions have always been at 8 character columns apart. > The "ambiguity" was introduced by editors that do not follow the default value set in hardware like printers or used by consoles and terminal emulators. 8 characters is common, but no more "correct" than any other, as tab width has never been standardized. You talk of not wanting tab options imposed on you, but consider that treating tabs as 8-character stops imposes that setting on anybody who needs to work with your mixed-indentation code. > And now python forces me out of using any tab characters at all. I believe I should still have a choice, python should at lest give an option to set tab size, if the default of 8 is ambiguous now. And then changing that setting could change the meaning of the code, which would be a disaster for code that you want to distribute. From terminatorul at gmail.com Sat Apr 6 01:07:07 2013 From: terminatorul at gmail.com (Timothy Madden) Date: Sat, 06 Apr 2013 08:07:07 +0300 Subject: I hate you all In-Reply-To: References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> Message-ID: <515fad75$0$32109$14726298@news.sunsite.dk> On 06.04.2013 03:35, Chris Angelico wrote: > On Sat, Apr 6, 2013 at 11:22 AM, wrote: >> On Saturday, April 6, 2013 1:42:15 AM UTC+3, Ian wrote: >> [...] >>> The "def" line has four spaces. The "for" line then has a hard tab. >>> This is ambiguous. If the hard tab is assumed to have a width of four >>> spaces, then they are at the same indentation level. If it is assumed >>> to have a width of eight spaces, then they are not. >> [...] >> >> The correct tab stop positions have always been at 8 character columns apart. >> The "ambiguity" was introduced by editors that do not follow the default value set in hardware like printers or used by consoles and terminal emulators. >> >> And now python forces me out of using any tab characters at all. I believe I should still have a choice, python should at lest give an option to set tab size, if the default of 8 is ambiguous now. > > If you're indenting four spaces per level, then indent four spaces per > level. The code you posted would work perfectly if the indentation is > four spaces, then eight spaces, then twelve spaces. The problem is > that you have a stupid editor that's enforcing tabs instead of certain > multiples of spaces - get one that'll keep them all as spaces and you > won't have a problem. My editor is not the problem, of course, this is about what I think is right. I think I should be given the option to use tabs as I always have, and at least to use them with the default tab size, as python 2 used to. > Or use actual tabs, and set the displayed tab width to whatever you > feel like. That works, too. Neither option causes any problems with > any sane tools. Well this is the problem, the tab size is not "whatever I like", tab stops are 8 character columns apart (default). Changing the tab size from this default is what makes the code incompatible, not the tabs themselves. So the solution is simple: do not change tab size from the default. People say I can use tabs all the way, just set them to the indent I want. Well, I always had my indent independent of the tab size. Which is the way it should be, after all, since one can indent with or without tabs, so indent should not be tied to them. But now I can not; python no longer lets me do that. Tab size should be 8, so now python 3 says: either indent at 8 with tabs, either drop tabs and indent with spaces (just the same as if tabs are not allowed). But that is so wrong. I can indent at 4 (or any value), and still use tabs, as long as the interpreter knows tab stops are 8 columns apart. There is no "ambiguity" and no way to change the meaning of the code. So as a comparison we have: - the good old rules - python has use the default tab stops of 8 columns - indent is independent of tab stops - the new rules - python is independent of the tab stops - indent is now tied to the tab stop, so users have to : - use non-default tab size (8 is too much), or - drop tabs altogether The new rules may look flexible at first sight, but the net effect they have is they push me to use non-default tab size (which is not good), or drop the tabs, which I could have used before python 3 just fine. Thank you, Timothy Madden From benjamin.kaplan at case.edu Sat Apr 6 01:28:52 2013 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 5 Apr 2013 22:28:52 -0700 Subject: I hate you all In-Reply-To: <515fad75$0$32109$14726298@news.sunsite.dk> References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <515fad75$0$32109$14726298@news.sunsite.dk> Message-ID: On Fri, Apr 5, 2013 at 10:07 PM, Timothy Madden wrote: > > On 06.04.2013 03:35, Chris Angelico wrote: >> >> On Sat, Apr 6, 2013 at 11:22 AM, wrote: >>> >>> On Saturday, April 6, 2013 1:42:15 AM UTC+3, Ian wrote: >>> [...] >>>> >>>> The "def" line has four spaces. The "for" line then has a hard tab. >>>> This is ambiguous. If the hard tab is assumed to have a width of four >>>> spaces, then they are at the same indentation level. If it is assumed >>>> to have a width of eight spaces, then they are not. >>> >>> [...] >>> >>> The correct tab stop positions have always been at 8 character columns apart. >>> The "ambiguity" was introduced by editors that do not follow the default value set in hardware like printers or used by consoles and terminal emulators. >>> >>> And now python forces me out of using any tab characters at all. I believe I should still have a choice, python should at lest give an option to set tab size, if the default of 8 is ambiguous now. >> >> >> If you're indenting four spaces per level, then indent four spaces per >> level. The code you posted would work perfectly if the indentation is >> four spaces, then eight spaces, then twelve spaces. The problem is >> that you have a stupid editor that's enforcing tabs instead of certain >> multiples of spaces - get one that'll keep them all as spaces and you >> won't have a problem. > > > My editor is not the problem, of course, this is about what I think is right. I think I should be given the option to use tabs as I always have, and at least to use them with the default tab size, as python 2 used to. > > >> Or use actual tabs, and set the displayed tab width to whatever you >> feel like. That works, too. Neither option causes any problems with >> any sane tools. > > > Well this is the problem, the tab size is not "whatever I like", tab stops are 8 character columns apart (default). > > Changing the tab size from this default is what makes the code incompatible, not the tabs themselves. So the solution is simple: do not change tab size from the default. > > People say I can use tabs all the way, just set them to the indent I want. > > Well, I always had my indent independent of the tab size. Which is the way it should be, after all, since one can indent with or without tabs, so indent should not be tied to them. > > But now I can not; python no longer lets me do that. > > Tab size should be 8, so now python 3 says: either indent at 8 with tabs, either drop tabs and indent with spaces (just the same as if tabs are not allowed). > > But that is so wrong. I can indent at 4 (or any value), and still use tabs, as long as the interpreter knows tab stops are 8 columns apart. There is no "ambiguity" and no way to change the meaning of the code. > > So as a comparison we have: > > - the good old rules > - python has use the default tab stops of 8 columns > - indent is independent of tab stops > > - the new rules > - python is independent of the tab stops > - indent is now tied to the tab stop, so users have to : > - use non-default tab size (8 is too much), or > - drop tabs altogether > > The new rules may look flexible at first sight, but the net effect they have is they push me to use non-default tab size (which is not good), or drop the tabs, which I could have used before python 3 just fine. > > > Thank you, > Timothy Madden http://www.xkcd.com/1172/ From torriem at gmail.com Sat Apr 6 01:49:29 2013 From: torriem at gmail.com (Michael Torrie) Date: Fri, 05 Apr 2013 23:49:29 -0600 Subject: I hate you all In-Reply-To: References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <515fad75$0$32109$14726298@news.sunsite.dk> Message-ID: <515FB769.3050607@gmail.com> On 04/05/2013 11:28 PM, Benjamin Kaplan wrote: > http://www.xkcd.com/1172/ How did I ever miss this before? That is truly awesome. From ian.g.kelly at gmail.com Sat Apr 6 01:53:09 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 5 Apr 2013 23:53:09 -0600 Subject: I hate you all In-Reply-To: <515fad75$0$32109$14726298@news.sunsite.dk> References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <515fad75$0$32109$14726298@news.sunsite.dk> Message-ID: On Fri, Apr 5, 2013 at 11:07 PM, Timothy Madden wrote: > Changing the tab size from this default is what makes the code incompatible, > not the tabs themselves. So the solution is simple: do not change tab size > from the default. So in other words, everybody must be forced to use 8-character tabs because you want to be able to mix tabs and spaces. > People say I can use tabs all the way, just set them to the indent I want. > > Well, I always had my indent independent of the tab size. Which is the way > it should be, after all, since one can indent with or without tabs, so > indent should not be tied to them. > > But now I can not; python no longer lets me do that. Honestly, I really don't understand why you *want* to do that. If your indentation is 4 characters, then that would be the natural tab width to use. If you're not going to tie your indent to your tabs, then why even use tabs in the first place? > The new rules may look flexible at first sight, but the net effect they have > is they push me to use non-default tab size (which is not good), What makes that not good? There is no law anywhere that says tabs are 8 characters. That's just an arbitrary amount that looked appropriate to the people designing the first teletypes. From torriem at gmail.com Sat Apr 6 01:59:18 2013 From: torriem at gmail.com (Michael Torrie) Date: Fri, 05 Apr 2013 23:59:18 -0600 Subject: I hate you all In-Reply-To: References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <515fad75$0$32109$14726298@news.sunsite.dk> Message-ID: <515FB9B6.4080805@gmail.com> On 04/05/2013 11:53 PM, Ian Kelly wrote: >> The new rules may look flexible at first sight, but the net effect they have >> is they push me to use non-default tab size (which is not good), > > What makes that not good? There is no law anywhere that says tabs are > 8 characters. That's just an arbitrary amount that looked appropriate > to the people designing the first teletypes. Ahh but assuming tabs are the equivalent of 8 spaces can save 7 bytes per tab character in the source code! Think of the savings. From steve+comp.lang.python at pearwood.info Sat Apr 6 02:19:53 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Apr 2013 06:19:53 GMT Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <515fad75$0$32109$14726298@news.sunsite.dk> Message-ID: <515fbe89$0$29995$c3e8da3$5496439d@news.astraweb.com> On Fri, 05 Apr 2013 23:59:18 -0600, Michael Torrie wrote: > On 04/05/2013 11:53 PM, Ian Kelly wrote: >>> The new rules may look flexible at first sight, but the net effect >>> they have is they push me to use non-default tab size (which is not >>> good), >> >> What makes that not good? There is no law anywhere that says tabs are >> 8 characters. That's just an arbitrary amount that looked appropriate >> to the people designing the first teletypes. > > Ahh but assuming tabs are the equivalent of 8 spaces can save 7 bytes > per tab character in the source code! Think of the savings. If we standardize on 1025 spaces per indent, and use tabs, we can save 1KiB per indent. Let's see now... looking at a typical piece of code in my code base, I make it that the average line of code is indented about 1.75 levels. (I use a lot of top-level functions, and few classes). With an average line length of 50 characters, plus indentation, we can reduce the size of a typical Python module by ninety-seven percent! Of course, what we save in disk space, we lose in monitor size, but I'm sure that the price of 300 inch monitors will soon become quite affordable. -- Steven From terminatorul at gmail.com Sat Apr 6 02:56:51 2013 From: terminatorul at gmail.com (Timothy Madden) Date: Sat, 06 Apr 2013 09:56:51 +0300 Subject: I hate you all In-Reply-To: References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <515fad75$0$32109$14726298@news.sunsite.dk> Message-ID: <515fc72c$0$32106$14726298@news.sunsite.dk> On 06.04.2013 08:53, Ian Kelly wrote: > On Fri, Apr 5, 2013 at 11:07 PM, Timothy Madden wrote: [...] > So in other words, everybody must be forced to use 8-character tabs > because you want to be able to mix tabs and spaces. > >> People say I can use tabs all the way, just set them to the indent I want. >> >> Well, I always had my indent independent of the tab size. Which is the way >> it should be, after all, since one can indent with or without tabs, so >> indent should not be tied to them. >> >> But now I can not; python no longer lets me do that. > > Honestly, I really don't understand why you *want* to do that. If > your indentation is 4 characters, then that would be the natural tab > width to use. If you're not going to tie your indent to your tabs, > then why even use tabs in the first place? > >> The new rules may look flexible at first sight, but the net effect they have >> is they push me to use non-default tab size (which is not good), > > What makes that not good? There is no law anywhere that says tabs are > 8 characters. That's just an arbitrary amount that looked appropriate > to the people designing the first teletypes. I am aware that 7 bytes per tab character (or 14/28, in UTF-16, UTF-32!) will not justify the time spent debating. The reason I want to use tabs is that I think there is nothing wrong with them. The reason why everybody should use 8-character tabs is so that I and the rest of the world can use `grep` / `findstr` on their code, and still see lines of code properly aligned in the terminal. Or to be able to print fragments of code as plain text only, and get the proper alignment. But most importantly, the reason that tab size should be 8 is so that all of us people in this world can freely exchange formatted text like source code without having to first consider if "will it look the same in their editor ? What tab size do they use ?" In other words, the solution to "different people's definition of tabs" is not to drop them, but only to get a common default. Which is already there: 8 columns between every tab stop. What python 3 does is a different attitude, and that is: everyone likes their own indent. Although I personally find it annoying, I am aware that many people use an indent of 2 spaces, some use even 3. Moreover, many C programers still like 8 spaces per indent. So some development environments find it an advantage to use tabs only for indentation, and every programmer is then free to set the tab stop to their liking. Everyone will see the indent they like, with no changes in the byte stream for the file. Why I think this is wrong is a little difficult for me explain. First, I admit this approach toward tabs has some value and is tempting for me, too. But it assumes everything, everywhere can configure tab sizes. Consoles and printers usually do not. Next, even if they can, most people, including all non-technical personal, never bother to change settings. Then this also assumes I change settings to my liking on several computers I use (maybe I work for several clients each with their computers, most people have a work computer and a home computer, maybe also a laptop and a tablet/smart device). Last, this is also not helpful if two sometimes use the same computer from time to time, and do not want to switch users all the time. So this is not a very good approach, and I have the feeling that most python programmers and development environment prefer to use only spaces than to use variable tab sizes. So the right solution remains a proper default setting for the tab size, and then we no longer have to drop tabs from source code files. Thank you, Timothy Madden From joshua.landau.ws at gmail.com Sat Apr 6 06:17:00 2013 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Sat, 6 Apr 2013 11:17:00 +0100 Subject: I hate you all In-Reply-To: <515fc72c$0$32106$14726298@news.sunsite.dk> References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <515fad75$0$32109$14726298@news.sunsite.dk> <515fc72c$0$32106$14726298@news.sunsite.dk> Message-ID: On 6 April 2013 07:56, Timothy Madden wrote: > On 06.04.2013 08:53, Ian Kelly wrote: > >> On Fri, Apr 5, 2013 at 11:07 PM, Timothy Madden >> wrote: >> > [...] > >> So in other words, everybody must be forced to use 8-character tabs >> because you want to be able to mix tabs and spaces. >> >> People say I can use tabs all the way, just set them to the indent I >>> want. >>> >>> Well, I always had my indent independent of the tab size. Which is the >>> way >>> it should be, after all, since one can indent with or without tabs, so >>> indent should not be tied to them. >>> >>> But now I can not; python no longer lets me do that. >>> >> >> Honestly, I really don't understand why you *want* to do that. If >> your indentation is 4 characters, then that would be the natural tab >> width to use. If you're not going to tie your indent to your tabs, >> then why even use tabs in the first place? >> >> The new rules may look flexible at first sight, but the net effect they >>> have >>> is they push me to use non-default tab size (which is not good), >>> >> >> What makes that not good? There is no law anywhere that says tabs are >> 8 characters. That's just an arbitrary amount that looked appropriate >> to the people designing the first teletypes. >> > > I am aware that 7 bytes per tab character (or 14/28, in UTF-16, UTF-32!) > will not justify the time spent debating. > > The reason I want to use tabs is that I think there is nothing wrong with > them. > So use them > The reason why everybody should use 8-character tabs is so that I and the > rest of the world can use `grep` / `findstr` on their code, and still see > lines of code properly aligned in the terminal. Or to be able to print > fragments of code as plain text only, and get the proper alignment. > Oh thanks. I liked using my four character tabs, but I guess you *are* so important that I'm going to have to change everything I do just for you. It's obviously not good enough for you just to not mix tabs and spaces so that we can both enjoy ourselves because that would make *you*, the holiest of all, have to put some effort in. No, I totally understand and will now go and change everything after Python is changed to break hundreds of files of codes for you. > But most importantly, the reason that tab size should be 8 is so that all > of us people in this world can freely exchange formatted text like source > code without having to first consider if "will it look the same in their > editor ? What tab size do they use ?" > Hrm. Hrm. Hrrrrmmm. Hrrrrmmmm. No, you're right: spaces are totally not for this in any way and that no-one has ever made this point before and who the hell cares if you're reading code with a different indent size anyway it's not like it affects the actual code. Yours frustratedly, Joshua Landau ---------------------------------------------------------------------------------------------------------------- But seriously, please at least look like you've read other people's posts. It doesn't matter what tabstop you use as long as you don't mix. If your code depends on tab size then it's categorically wrong. Other people's tab sizes are as valid. I use tabs because of the variation it lets me have - I can switch tab sizes on the fly - and it's faster on "dumb" editors. So let me do that. But let us assume we were going to standardise on TAB == 8 SPACES. It would *still* be bad to mix tabs and spaces. Hence you'd change Python in exactly 0 ways. So *what do you want from us*? -------------- next part -------------- An HTML attachment was scrubbed... URL: From terminatorul at gmail.com Sat Apr 6 10:22:47 2013 From: terminatorul at gmail.com (Timothy Madden) Date: Sat, 06 Apr 2013 17:22:47 +0300 Subject: I hate you all In-Reply-To: References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <515fad75$0$32109$14726298@news.sunsite.dk> <515fc72c$0$32106$14726298@news.sunsite.dk> Message-ID: <51602fb8$0$32114$14726298@news.sunsite.dk> On 06.04.2013 13:17, Joshua Landau wrote: [...] > > Yours frustratedly, > > Joshua Landau > > ---------------------------------------------------------------------------------------------------------------- > > But seriously, please at least look like you've read other people's > posts. It doesn't matter what tabstop you use as long as you don't mix. When the default tab size is 8, than tab size does matter. Because it is too much to use as indent size. If you still want to use tabs, you are now supposed to change tab size from the default. I believe using non-default tab size in a public environment like open-source code is bound to cause formatting problems for someone at some point. > If your code depends on tab size then it's categorically wrong. Other > people's tab sizes are as valid. I use tabs because of the variation it > lets me have - I can switch tab sizes on the fly - and it's faster on > "dumb" editors. So let me do that. > > But let us assume we were going to standardise on TAB == 8 SPACES. It > would *still* be bad to mix tabs and spaces. Hence you'd change Python > in exactly 0 ways. So *what do you want from us*? Well all previous (python 2) code is meant to work for a tab size of 8. You may call this "categorically wrong", but it has been there a long while, is is still in use, and it sticks to the default. Spaces-only can achieve compatibility between different people settings for formatted text like source code. But so does a common default for the tab size, and with that we do not have to limit ourselves to spaces only. Now I understand python 3 people may already use tabs with a size of 4, as you said. Although I tried to show this is not good practice, (and that not many people do that, really, since most of them prefer to use all-spaces instead), still I do not expect the people to change their settings. What I would expect is some option in python to make tabs work the way they used to. I want a choice for me to preserve my settings, the same way you want to preserve yours. What I want should not be much to ask, since this is how python 2 used to do things. I admit such a '--fixed-tabs' option, that will make tab stops be 8 columns apart, and allow any number of spaces like in python 2, makes the code I write dependent on that option. But the option will run all code written for the new "python 3 way", and brings back some compatibility, so it is not that bad. And some people might actually want it. Timothy Madden From invalid at invalid.invalid Sat Apr 6 11:30:47 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 6 Apr 2013 15:30:47 +0000 (UTC) Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <515fad75$0$32109$14726298@news.sunsite.dk> <515fc72c$0$32106$14726298@news.sunsite.dk> <51602fb8$0$32114$14726298@news.sunsite.dk> Message-ID: On 2013-04-06, Timothy Madden wrote: > When the default tab size is 8, than tab size does matter. There is no default size. The size of a tab isn't even constant across a line -- they're individually adjustable. The tabs "default" to wherever they were left by the last person who used the typewriter. All assumptions about the size or predictabilty of tabs are erroneous. -- Grant From r.koebler at yahoo.de Sun Apr 7 18:52:58 2013 From: r.koebler at yahoo.de (Roland Koebler) Date: Mon, 8 Apr 2013 00:52:58 +0200 Subject: I hate you all In-Reply-To: <51602fb8$0$32114$14726298@news.sunsite.dk> References: <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <515fad75$0$32109$14726298@news.sunsite.dk> <515fc72c$0$32106$14726298@news.sunsite.dk> <51602fb8$0$32114$14726298@news.sunsite.dk> Message-ID: <20130407225258.GA14752@localhost> Hi, > Well all previous (python 2) code is meant to work for a tab size of > 8. yes, but even in Python 2, mixing spaces and tabs is considered bad style and should be avoided. And code-checkers like pylint (which I can recommend to everyone) create a warning. > You may call this "categorically wrong", but it has been there a > long while, is is still in use, and it sticks to the default. As I said, mixing tabs and spaces for indentation was *always* a bad idea, and is discouraged also in Python 2. > Spaces-only can achieve compatibility between different people > settings for formatted text like source code. But so does a common > default for the tab size, But there's no such thing as "default tab size". Configuring the tab-size is quite common among programmers. But why do you insist on using tabs at all? The best way -- in my opinion -- is to use the tab- and backspace-key for indentation, and let the editor convert it to spaces. (And use some tool to convert all tabs in the old code.) I don't see *any* advantage of mixed spaces and tabs, but quite some disadvantages/problems. > What I would expect is some option in python to make tabs work the > way they used to. I want a choice for me to preserve my settings, > the same way you want to preserve yours. > > What I want should not be much to ask, since this is how python 2 > used to do things. > > I admit such a '--fixed-tabs' option, that will make tab stops be 8 > columns apart, and allow any number of spaces like in python 2, > makes the code I write dependent on that option. There's no need to add this to Python 3, since you already have what you want. Simply use: expand yourscript.py | python3 regards Roland From terminatorul at gmail.com Sat Apr 6 01:36:23 2013 From: terminatorul at gmail.com (Timothy Madden) Date: Sat, 06 Apr 2013 08:36:23 +0300 Subject: I hate you all In-Reply-To: References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> Message-ID: <515fb451$0$32114$14726298@news.sunsite.dk> On 06.04.2013 06:53, Ian Kelly wrote: > On Fri, Apr 5, 2013 at 6:22 PM, wrote: >> The correct tab stop positions have always been at 8 character columns apart. >> The "ambiguity" was introduced by editors that do not follow the default value set in hardware like printers or used by consoles and terminal emulators. > > 8 characters is common, but no more "correct" than any other, as tab > width has never been standardized. You talk of not wanting tab > options imposed on you, but consider that treating tabs as 8-character > stops imposes that setting on anybody who needs to work with your > mixed-indentation code. > >> And now python forces me out of using any tab characters at all. I believe I should still have a choice, python should at lest give an option to set tab size, if the default of 8 is ambiguous now. > > And then changing that setting could change the meaning of the code, > which would be a disaster for code that you want to distribute. > 8-character tab stops should be the default. Debating that is I believe another topic, and compatibility with python2 should be enough to make that debate unnecessary. You are right, to change the tab size means to change the meaning of the code, and that would be wrong. Can't argue with that. What I want is an option to use the tabs as I have used them in the past, with the default size. Since "ambiguity" about the tab size appears to be the cause for new python 3 rules, I though of an option the make that size explicit. I still think users should somehow have a way to use a tab stop of their choice, but how this could be achieved properly is another problem. I guess a discussion like this thread is the price to be paid for relying solely on white space to delimit code blocks, like the python syntax does. Thank you, Timothy Madden From rosuav at gmail.com Sat Apr 6 01:44:11 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Apr 2013 16:44:11 +1100 Subject: I hate you all In-Reply-To: <515fb451$0$32114$14726298@news.sunsite.dk> References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <515fb451$0$32114$14726298@news.sunsite.dk> Message-ID: On Sat, Apr 6, 2013 at 4:36 PM, Timothy Madden wrote: > I guess a discussion like this thread is the price to be paid for relying > solely on white space to delimit code blocks, like the python syntax does. Absolutely. Bring on Python 5000, where all such stupidities are abolished and we can argue about really important matters, like whether chr(7) should be allowed in identifiers. ChrisA From torriem at gmail.com Sat Apr 6 01:58:03 2013 From: torriem at gmail.com (Michael Torrie) Date: Fri, 05 Apr 2013 23:58:03 -0600 Subject: I hate you all In-Reply-To: <515fb451$0$32114$14726298@news.sunsite.dk> References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <515fb451$0$32114$14726298@news.sunsite.dk> Message-ID: <515FB96B.1000002@gmail.com> On 04/05/2013 11:36 PM, Timothy Madden wrote: > I guess a discussion like this thread is the price to be paid for > relying solely on white space to delimit code blocks, like the python > syntax does. I've always been taught that in Python using tabs, particularly in the way that you use them (which, by the way, is the default way vim uses them when in C++ mode) is fraught with difficulty. So years ago I dropped in c couple of lines in my vimrc file to use spaces instead of tabs and use the PEP standard of 4 spaces. Have never had any problem. As for your problems, perhaps instead of coming on the list with a poorly-thought-out subject line, and desire to simply argue, perhaps you could run your code through a reformatter that would translate your tabs into spaces using the tab stop that you desired. Open the file in vim, enter the following commands: set sw=4 set ts=8 set et set softtabstop=4 set ai :retab Then save the file. Now it's pep-formatted with spaces and no tabs. Problem solved. Yes it doesn't address your concerns, but it is the recommended solution for Python given the difficulties in mixing tabs and spaces and different people's definition of tabs. From ethan at stoneleaf.us Sat Apr 6 02:00:20 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 05 Apr 2013 23:00:20 -0700 Subject: I hate you all In-Reply-To: <515fb451$0$32114$14726298@news.sunsite.dk> References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <515fb451$0$32114$14726298@news.sunsite.dk> Message-ID: <515FB9F4.3040901@stoneleaf.us> On 04/05/2013 10:36 PM, Timothy Madden wrote: > > 8-character tab stops should be the default. Debating that is I believe another topic, and compatibility with python2 > should be enough to make that debate unnecessary. Python 3 broke a lot of things. Pull on your big-boy underwear and deal with it. > Thank you, Saying 'thank you' does not mitigate you acting like an ass. -- ~Ethan~ From steve+comp.lang.python at pearwood.info Sat Apr 6 02:55:05 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Apr 2013 06:55:05 GMT Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <515fb451$0$32114$14726298@news.sunsite.dk> Message-ID: <515fc6c8$0$29995$c3e8da3$5496439d@news.astraweb.com> On Sat, 06 Apr 2013 08:36:23 +0300, Timothy Madden wrote: > 8-character tab stops should be the default. Debating that is I believe > another topic, and compatibility with python2 should be enough to make > that debate unnecessary. Compatibility with Python 2 is not a requirement. Python 3 exists to fix a bunch of design flaws and mistakes in Python 2. Among the changes: - print and exec are now functions, not statements - the dangerous input function is gone - raw_input is renamed input - the distinction between int and long is gone - the second-string "classic classes" are gone - strings are Unicode, not bytes - division is done correctly - the error-prone syntax of the "except" statement is fixed - inconsistently named modules are fixed - the plethora of similar dict methods is cleaned up - map, filter, zip operate lazily rather than eagerly and of course - mixed spaces and tabs for indentation is gone > You are right, to change the tab size means to change the meaning of the > code, and that would be wrong. Can't argue with that. I can argue with that. Changing tab size does *not* change the meaning of code, provided you *only* use tabs for indentation. Using only tabs for indentation is fine. Whether you set your editor to display tabs as 2 columns, 4 columns, 8 columns, or a thousand columns will make not a whit of difference to the meaning of the code or the number of indent levels. This is the Killer Feature of tabs, and it is the primary reason why tabs rule and spaces suck for indentation. (Alas, too many broken tools that can't handle tabs mean that the less- good standard won.) Using only spaces for indentation is also fine. Not as good as tabs, because if I use spaces, you're stuck reading my code in whatever poorly- thought out indent I might choose. I've seen developers use *one* space. But using only spaces does work. What does not work in general, is mixing the two. Don't mix them for indents, and you'll be fine. > What I want is an option to use the tabs as I have used them in the > past, with the default size. You can continue to use tabs, so long as you don't mix them with spaces. > Since "ambiguity" about the tab size > appears to be the cause for new python 3 rules, I though of an option > the make that size explicit. I still think users should somehow have a > way to use a tab stop of their choice, but how this could be achieved > properly is another problem. Unnecessary complexity to solve a non-problem. Just pick one, tabs or spaces, and consistently use it in any one block of code. You don't even have to be consistent over an entire file. > I guess a discussion like this thread is the price to be paid for > relying solely on white space to delimit code blocks, like the python > syntax does. Mixing spaces and tabs for indentation is bad in brace languages too. http://mailman.linuxchix.org/pipermail/programming/2004-August/001433.html Maybe if we had smarter editors and smarter diffs and smarter tools in general, it wouldn't be a problem. But we don't, so it is. -- Steven From terminatorul at gmail.com Sat Apr 6 03:07:06 2013 From: terminatorul at gmail.com (Timothy Madden) Date: Sat, 06 Apr 2013 10:07:06 +0300 Subject: I hate you all In-Reply-To: References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <515fb451$0$32114$14726298@news.sunsite.dk> Message-ID: <515fc994$0$32113$14726298@news.sunsite.dk> On 06.04.2013 08:58, Michael Torrie wrote: [...] > As for your problems, perhaps instead of coming on the list with a > poorly-thought-out subject line, and desire to simply argue, perhaps you > could run your code through a reformatter [...] Hey, I was feeling frustrated ... ! It is how people feel when they no longer have a choice they used to have. But I hear programmers should get used to the feeling: using code that you did not write is bound to trigger that reaction every so often. Timothy Madden From invalid at invalid.invalid Sat Apr 6 11:37:14 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 6 Apr 2013 15:37:14 +0000 (UTC) Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <515fb451$0$32114$14726298@news.sunsite.dk> Message-ID: On 2013-04-06, Ethan Furman wrote: > On 04/05/2013 10:36 PM, Timothy Madden wrote: >> >> 8-character tab stops should be the default. Debating that is I believe another topic, and compatibility with python2 >> should be enough to make that debate unnecessary. > > Python 3 broke a lot of things. Pull on your big-boy underwear and > deal with it. Python 3 requires that you wear _underwear_? That seems entirely arbitrary, and violates the god-given rights of telecommuters to write code wearing nothing but a bathrobe! Hell, for all I know, there may be people who go into the office without underwear. Though I think the lonely, unbathed, unshaven, robe-wearing telecommuter will be the poster-child for the worldwide campaign against the undwearist fascists trying to impose their sartorial dictates on Python users. Next, we need to pick a song... -- Grant From roy at panix.com Sat Apr 6 11:49:24 2013 From: roy at panix.com (Roy Smith) Date: Sat, 06 Apr 2013 11:49:24 -0400 Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <515fb451$0$32114$14726298@news.sunsite.dk> Message-ID: In article , Grant Edwards wrote: > On 2013-04-06, Ethan Furman wrote: > > On 04/05/2013 10:36 PM, Timothy Madden wrote: > >> > >> 8-character tab stops should be the default. Debating that is I believe > >> another topic, and compatibility with python2 > >> should be enough to make that debate unnecessary. > > > > Python 3 broke a lot of things. Pull on your big-boy underwear and > > deal with it. > > Python 3 requires that you wear _underwear_? Only at PyCon. From orgnut at yahoo.com Sat Apr 6 16:17:12 2013 From: orgnut at yahoo.com (Larry Hudson) Date: Sat, 06 Apr 2013 13:17:12 -0700 Subject: I hate you all In-Reply-To: <515fb451$0$32114$14726298@news.sunsite.dk> References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <515fb451$0$32114$14726298@news.sunsite.dk> Message-ID: On 04/05/2013 10:36 PM, Timothy Madden wrote: [snip...] > 8-character tab stops should be the default. Debating that is I believe another topic, and > compatibility with python2 should be enough to make that debate unnecessary. > As everyone keeps telling you -- there is NO default tab size. Default implies there is an OFFICIAL definition, there is none. There is, however, convention -- which is merely a common suggestion, without any force implied. > What I want is an option to use the tabs as I have used them in the past, with the default size. > Since "ambiguity" about the tab size appears to be the cause for new python 3 rules, I though of > an option the make that size explicit. I still think users should somehow have a way to use a > tab stop of their choice, but how this could be achieved properly is another problem. > What you want and what you think are irrelevant. The Python language (whatever version) is already defined. If you want to use it, you have to accept it and adapt to what it is. Live with it and move on. Complaining about it is a complete waste of time -- it's NOT going to change just because YOU don't like it. Frankly, with your continuing to rant about this subject is simply making yourself look like an obstinate fool. I've enjoyed following this thread because I find your attitude so ridiculously amusing.[1] > I guess a discussion like this thread is the price to be paid for relying solely on white space > to delimit code blocks, like the python syntax does. > And in actual practice, that has been shown to be a Good Thing. > Thank you, > Timothy Madden -=- Larry -=- [1]. I just turned 76 and definitely tend to be a curmudgeon, so sorry if I sound too insulting, but it is the way I feel. From terminatorul at gmail.com Sun Apr 7 07:37:40 2013 From: terminatorul at gmail.com (Timothy Madden) Date: Sun, 07 Apr 2013 14:37:40 +0300 Subject: I hate you all In-Reply-To: References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <515fb451$0$32114$14726298@news.sunsite.dk> Message-ID: <51615a8b$0$32104$14726298@news.sunsite.dk> On 06.04.2013 23:17, Larry Hudson wrote: [...] > What you want and what you think are irrelevant. The Python language > (whatever version) is already defined. If you want to use it, you have > to accept it and adapt to what it is. Live with it and move on. > Complaining about it is a complete waste of time -- it's NOT going to > change just because YOU don't like it. Adding an option for fixed size tabs will not change the language (and someone even suggested I patch my own copy, but this discussion is not about me, is about tabs). >> I guess a discussion like this thread is the price to be paid for >> relying solely on white space >> to delimit code blocks, like the python syntax does. >> > And in actual practice, that has been shown to be a Good Thing. Yes, I agree, it is. It just could have been better. Timothy Madden From nobody at nowhere.com Sat Apr 6 09:52:45 2013 From: nobody at nowhere.com (Nobody) Date: Sat, 06 Apr 2013 14:52:45 +0100 Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> Message-ID: On Fri, 05 Apr 2013 21:53:40 -0600, Ian Kelly wrote: > 8 characters is common, but no more "correct" than any other, This is pure revisionism. 8-column tabs may never have been a significant /de jure/ standard (although they have been that in many specific domains), but they have been a significant /de facto/ standard for almost as long as computers have existed. Historically, software and hardware which assigns a meaning to a tab character has come in two flavours: 1. Tab stops are every 8 columns; this cannot be changed. 2. Tab stops are configurable, defaulting to every 8 columns. Creating software which, in the absence of both a good reason and an explicit mechanism for communicating the configured value, treats them as configurable is usually a consequence of a "code now, think later" mentality (although there may have be a few cases where it was a deliberate "embrace, extend, extinguish" tactic). From rosuav at gmail.com Sat Apr 6 10:20:32 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 7 Apr 2013 01:20:32 +1100 Subject: I hate you all In-Reply-To: References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> Message-ID: On Sun, Apr 7, 2013 at 12:52 AM, Nobody wrote: > Historically, software and hardware which assigns a meaning to a tab > character has come in two flavours: > > 1. Tab stops are every 8 columns; this cannot be changed. > 2. Tab stops are configurable, defaulting to every 8 columns. 3. Tab stops are measured in something other than characters. With variable-width fonts, it's illogical to set tab stops in characters. DeScribe Word Processor defined them in centimeters, way back in the early... well, I didn't meet it till the 90s, but I don't know how long it had been around before that. ChrisA From terminatorul at gmail.com Sat Apr 6 10:37:02 2013 From: terminatorul at gmail.com (Timothy Madden) Date: Sat, 06 Apr 2013 17:37:02 +0300 Subject: I hate you all In-Reply-To: References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> Message-ID: <51603307$0$32106$14726298@news.sunsite.dk> On 06.04.2013 17:20, Chris Angelico wrote: > On Sun, Apr 7, 2013 at 12:52 AM, Nobody wrote: >> Historically, software and hardware which assigns a meaning to a tab >> character has come in two flavours: >> >> 1. Tab stops are every 8 columns; this cannot be changed. >> 2. Tab stops are configurable, defaulting to every 8 columns. > > 3. Tab stops are measured in something other than characters. > > With variable-width fonts, it's illogical to set tab stops in > characters. DeScribe Word Processor defined them in centimeters, way > back in the early... well, I didn't meet it till the 90s, but I don't > know how long it had been around before that. Yes, but systems with variable-width fonts do not make the default for the tab size now. From roy at panix.com Sat Apr 6 11:01:04 2013 From: roy at panix.com (Roy Smith) Date: Sat, 06 Apr 2013 11:01:04 -0400 Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> Message-ID: In article , Chris Angelico wrote: > On Sun, Apr 7, 2013 at 12:52 AM, Nobody wrote: > > Historically, software and hardware which assigns a meaning to a tab > > character has come in two flavours: > > > > 1. Tab stops are every 8 columns; this cannot be changed. > > 2. Tab stops are configurable, defaulting to every 8 columns. > > 3. Tab stops are measured in something other than characters. > > With variable-width fonts, it's illogical to set tab stops in > characters. DeScribe Word Processor defined them in centimeters, way > back in the early... well, I didn't meet it till the 90s, but I don't > know how long it had been around before that. What makes sense for a word processor and what makes sense for a programming language are two very different things. Word processors are almost always working with blocks of running text, set in proportional fonts, often with multiple font sizes and styles. It is usually assumed that line breaks are ephemeral, i.e. as the text gets edited and reformatted, lines will re-flow. Program text is almost always(*) displayed in a fixed-width font. No font information is carried along with the program text at all; it is assumed the reader will pick a font and size of their own preference, with the only requirement being that it's monospaced. (*) There was a fad about 10 or 15 years ago to print code samples in books in proportional fonts. Prentice-Hall seemed to be particularly guilty of this. Fortunately, common sense prevailed and everybody has gone back to monotype. From neilc at norwich.edu Sat Apr 6 11:15:36 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 6 Apr 2013 15:15:36 GMT Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> Message-ID: On 2013-04-06, Roy Smith wrote: > (*) There was a fad about 10 or 15 years ago to print code > samples in books in proportional fonts. Prentice-Hall seemed > to be particularly guilty of this. Fortunately, common sense > prevailed and everybody has gone back to monotype. Bjarne Stroustrup likes it, and I agree with him that code is even easier to read that way, especially in hard-copy. But most tools have not caught up with the idea. I'll switch as soon as vim supports it. -- Neil Cerutti From invalid at invalid.invalid Sat Apr 6 11:41:43 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 6 Apr 2013 15:41:43 +0000 (UTC) Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> Message-ID: On 2013-04-06, Neil Cerutti wrote: > On 2013-04-06, Roy Smith wrote: >> (*) There was a fad about 10 or 15 years ago to print code >> samples in books in proportional fonts. Prentice-Hall seemed >> to be particularly guilty of this. Fortunately, common sense >> prevailed and everybody has gone back to monotype. > > Bjarne Stroustrup likes it, and I agree with him that code is > even easier to read that way, especially in hard-copy. I'd have to disagree. There are too many times when things are easier to read/maintain by visually aligning columns: * struct/array initializers * constant definitions * parallel/identical operations on multiple different variables * vertical alignment of a parameter lists in multi-line function calls -- Grant From rustompmody at gmail.com Sat Apr 6 12:00:59 2013 From: rustompmody at gmail.com (rusi) Date: Sat, 6 Apr 2013 09:00:59 -0700 (PDT) Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> Message-ID: On Apr 6, 8:41?pm, Grant Edwards wrote: > On 2013-04-06, Neil Cerutti wrote: > > > On 2013-04-06, Roy Smith wrote: > >> (*) There was a fad about 10 or 15 years ago to print code > >> samples in books in proportional fonts. ?Prentice-Hall seemed > >> to be particularly guilty of this. ?Fortunately, common sense > >> prevailed and everybody has gone back to monotype. > > > Bjarne Stroustrup likes it, and I agree with him that code is > > even easier to read that way, especially in hard-copy. > > I'd have to disagree. ?There are too many times when things are easier > to read/maintain by visually aligning columns: > > ?* struct/array initializers > > ?* constant definitions > > ?* parallel/identical operations on multiple different variables > > ?* vertical alignment of a parameter lists in multi-line function calls > > -- > Grant I believe that it is at least possible to wish for the best of all worlds. http://nickgravgaard.com/elastictabstops/ (browser needs java) Pragmatically I continue to use emacs with a fixed-width font. Not claiming I am too happy with this choice. That includes a whole lot of stuff, not just fonts From roy at panix.com Sat Apr 6 11:59:41 2013 From: roy at panix.com (Roy Smith) Date: Sat, 06 Apr 2013 11:59:41 -0400 Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> Message-ID: In article , Neil Cerutti wrote: > Bjarne Stroustrup likes it This is supposed to impress me? Yeah, most of the books I recall that used this were C++ books. From neilc at norwich.edu Sat Apr 6 14:48:31 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 6 Apr 2013 18:48:31 GMT Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> Message-ID: On 2013-04-06, Roy Smith wrote: > In article , > Neil Cerutti wrote: > >> Bjarne Stroustrup likes it > > This is supposed to impress me? Hehe. No! But he's got enough clout to give the notion some traction. > Yeah, most of the books I recall that used this were C++ books. Yes, that would be why I bet. -- Neil Cerutti From rustompmody at gmail.com Sat Apr 6 11:31:08 2013 From: rustompmody at gmail.com (rusi) Date: Sat, 6 Apr 2013 08:31:08 -0700 (PDT) Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> Message-ID: <3ae55204-1d32-4d7c-a1e6-51456845d4b8@q3g2000pbv.googlegroups.com> On Apr 6, 8:01?pm, Roy Smith wrote: > What makes sense for a word processor and what makes sense for a > programming language are two very different things. > > Word processors are almost always working with blocks of running text, > set in proportional fonts, often with multiple font sizes and styles. > It is usually assumed that line breaks are ephemeral, i.e. as the text > gets edited and reformatted, lines will re-flow. > > Program text is almost always(*) displayed in a fixed-width font. ?No > font information is carried along with the program text at all; it is > assumed the reader will pick a font and size of their own preference, > with the only requirement being that it's monospaced. > > (*) There was a fad about 10 or 15 years ago to print code samples in > books in proportional fonts. ?Prentice-Hall seemed to be particularly > guilty of this. ?Fortunately, common sense prevailed and everybody has > gone back to monotype. Hmm? One of my favourite books on programming is Intro to functional programming by Bird and Wadler (1st edition Prentice Hall). I always knew that part of why I liked the book was the beautifully typeset code. Now I know how this choice dates me!! [It was published in 1988; I used it to teach from '89 onwards] From rosuav at gmail.com Sat Apr 6 17:29:59 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 7 Apr 2013 07:29:59 +1000 Subject: I hate you all In-Reply-To: References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> Message-ID: On Sun, Apr 7, 2013 at 2:01 AM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> On Sun, Apr 7, 2013 at 12:52 AM, Nobody wrote: >> > Historically, software and hardware which assigns a meaning to a tab >> > character has come in two flavours: >> > >> > 1. Tab stops are every 8 columns; this cannot be changed. >> > 2. Tab stops are configurable, defaulting to every 8 columns. >> >> 3. Tab stops are measured in something other than characters. >> >> With variable-width fonts, it's illogical to set tab stops in >> characters. DeScribe Word Processor defined them in centimeters, way >> back in the early... well, I didn't meet it till the 90s, but I don't >> know how long it had been around before that. > > What makes sense for a word processor and what makes sense for a > programming language are two very different things. Yes. I was just completing the set, since the heading didn't specify *for programming languages*. ChrisA From steve+comp.lang.python at pearwood.info Sat Apr 6 21:38:48 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Apr 2013 01:38:48 GMT Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> Message-ID: <5160ce27$0$29995$c3e8da3$5496439d@news.astraweb.com> On Sat, 06 Apr 2013 11:01:04 -0400, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> On Sun, Apr 7, 2013 at 12:52 AM, Nobody wrote: >> > Historically, software and hardware which assigns a meaning to a tab >> > character has come in two flavours: >> > >> > 1. Tab stops are every 8 columns; this cannot be changed. 2. Tab >> > stops are configurable, defaulting to every 8 columns. >> >> 3. Tab stops are measured in something other than characters. >> >> With variable-width fonts, it's illogical to set tab stops in >> characters. DeScribe Word Processor defined them in centimeters, way >> back in the early... well, I didn't meet it till the 90s, but I don't >> know how long it had been around before that. > > What makes sense for a word processor and what makes sense for a > programming language are two very different things. > > Word processors are almost always working with blocks of running text, > set in proportional fonts, often with multiple font sizes and styles. It > is usually assumed that line breaks are ephemeral, i.e. as the text gets > edited and reformatted, lines will re-flow. Word processors mostly use tabs for aligning text, e.g. in tables and lists. Exactly the same thing that tabs are used for in source code. Large blocks of running text are irrelevant, because tabs are rarely used inside large blocks of running text. > Program text is almost always(*) displayed in a fixed-width font. No > font information is carried along with the program text at all; it is > assumed the reader will pick a font and size of their own preference, And tab settings. If you're going to complain that changing the tab settings will break the layout of the source code, so will changing the font and size. -- Steven From steve+comp.lang.python at pearwood.info Sat Apr 6 21:30:45 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Apr 2013 01:30:45 GMT Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> Message-ID: <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> On Sun, 07 Apr 2013 01:20:32 +1100, Chris Angelico wrote: > On Sun, Apr 7, 2013 at 12:52 AM, Nobody wrote: >> Historically, software and hardware which assigns a meaning to a tab >> character has come in two flavours: >> >> 1. Tab stops are every 8 columns; this cannot be changed. 2. Tab stops >> are configurable, defaulting to every 8 columns. > > 3. Tab stops are measured in something other than characters. > > With variable-width fonts, it's illogical to set tab stops in > characters. DeScribe Word Processor defined them in centimeters, way > back in the early... well, I didn't meet it till the 90s, but I don't > know how long it had been around before that. Am I the only one here who has used a typewriter? Tab stops were set manually, to a physical distance into the page, using a mechanical stop. This long predates the "rule" that tab stops are every 8 characters. If your editor doesn't support setting tab stops to at least single pixel resolution, it's not supporting tabs, it's supporting something else that it merely calls "tabs". -- Steven From roy at panix.com Sat Apr 6 22:15:51 2013 From: roy at panix.com (Roy Smith) Date: Sat, 06 Apr 2013 22:15:51 -0400 Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <5160cc44$0$29995$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > On Sun, 07 Apr 2013 01:20:32 +1100, Chris Angelico wrote: > > > On Sun, Apr 7, 2013 at 12:52 AM, Nobody wrote: > >> Historically, software and hardware which assigns a meaning to a tab > >> character has come in two flavours: > >> > >> 1. Tab stops are every 8 columns; this cannot be changed. 2. Tab stops > >> are configurable, defaulting to every 8 columns. > > > > 3. Tab stops are measured in something other than characters. > > > > With variable-width fonts, it's illogical to set tab stops in > > characters. DeScribe Word Processor defined them in centimeters, way > > back in the early... well, I didn't meet it till the 90s, but I don't > > know how long it had been around before that. > > > Am I the only one here who has used a typewriter? > > Tab stops were set manually, to a physical distance into the page, using > a mechanical stop. This long predates the "rule" that tab stops are every > 8 characters. Yup. I learned on a good old manual, with mechanical "Tab Set" and "Tab Clear" function. Of course, on an 029, you set the tab stops by punching a drum card. > If your editor doesn't support setting tab stops to at least single pixel > resolution, it's not supporting tabs, it's supporting something else that > it merely calls "tabs". Yup. I use emacs. "M-X edit tab stops" does that. Like so much else about emacs, I haven't used that feature in years (gee, maybe decades), but it's nice to know it's there. From jsf80238 at gmail.com Sat Apr 6 22:42:25 2013 From: jsf80238 at gmail.com (Jason Friedman) Date: Sat, 6 Apr 2013 20:42:25 -0600 Subject: I hate you all In-Reply-To: <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: > Am I the only one here who has used a typewriter? > > I used one. And http://en.wikipedia.org/wiki/White-Out. And http://en.wikipedia.org/wiki/Correction_tape. My wife typed her dissertation on this: http://en.wikipedia.org/wiki/File:Hardwarewordprocessor.png. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.com Mon Apr 8 14:43:51 2013 From: nobody at nowhere.com (Nobody) Date: Mon, 08 Apr 2013 19:43:51 +0100 Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, 07 Apr 2013 01:30:45 +0000, Steven D'Aprano wrote: > Am I the only one here who has used a typewriter? > > Tab stops were set manually, to a physical distance into the page, using > a mechanical stop. This long predates the "rule" that tab stops are every > 8 characters. And your point is? Typewriters don't have a tab "character". The information regarding tab stops is conveyed out-of-band from the typist to the typewriter, and doesn't need to persist beyond the time taken to type the document. From invalid at invalid.invalid Mon Apr 8 15:48:58 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 8 Apr 2013 19:48:58 +0000 (UTC) Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-04-08, Nobody wrote: > On Sun, 07 Apr 2013 01:30:45 +0000, Steven D'Aprano wrote: > >> Am I the only one here who has used a typewriter? >> >> Tab stops were set manually, to a physical distance into the page, using >> a mechanical stop. This long predates the "rule" that tab stops are every >> 8 characters. > > And your point is? The point is that there is little historical precedent for assuming that tab stops are evenly and equally spaced across the page (let alone one particular fixed, even spacing) -- and people who mix spaces and tabs based on such false assumptions are responsible for their own bleeding foot. > Typewriters don't have a tab "character". The information regarding tab > stops is conveyed out-of-band from the typist to the typewriter, and > doesn't need to persist beyond the time taken to type the document. And the same is true when you don't mix tabs and spaces when indenting Python code. If you use tabs alone when indenting Python code it doesn't matter where the tabs are set -- they don't even have to be equally spaced -- the meaning of the source file is unambiguous. If you mix tabs and spaces, then you've got to provide out-of-band information regarding the position of the tab stops in order to make the source code unambiguous. Since there's no mechanism to provide that OOB tab stop info, mixed tabs and spaces isn't accepted. -- Grant Edwards grant.b.edwards Yow! I am covered with at pure vegetable oil and I am gmail.com writing a best seller! From walterhurry at lavabit.com Mon Apr 8 17:25:08 2013 From: walterhurry at lavabit.com (Walter Hurry) Date: Mon, 8 Apr 2013 21:25:08 +0000 (UTC) Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, 08 Apr 2013 19:48:58 +0000, Grant Edwards wrote: > On 2013-04-08, Nobody wrote: >> On Sun, 07 Apr 2013 01:30:45 +0000, Steven D'Aprano wrote: >> >>> Am I the only one here who has used a typewriter? >>> >>> Tab stops were set manually, to a physical distance into the page, >>> using a mechanical stop. This long predates the "rule" that tab stops >>> are every 8 characters. >> >> And your point is? > > The point is that there is little historical precedent for assuming that > tab stops are evenly and equally spaced across the page (let alone one > particular fixed, even spacing) -- and people who mix spaces and tabs > based on such false assumptions are responsible for their own bleeding > foot. > >> Typewriters don't have a tab "character". The information regarding tab >> stops is conveyed out-of-band from the typist to the typewriter, and >> doesn't need to persist beyond the time taken to type the document. > > And the same is true when you don't mix tabs and spaces when indenting > Python code. If you use tabs alone when indenting Python code it > doesn't matter where the tabs are set -- they don't even have to be > equally spaced -- the meaning of the source file is unambiguous. > > If you mix tabs and spaces, then you've got to provide out-of-band > information regarding the position of the tab stops in order to make the > source code unambiguous. Since there's no mechanism to provide that OOB > tab stop info, mixed tabs and spaces isn't accepted. Personally I have always used 4 spaces. I use it in SQL, shell scripts and Python. It makes code simple to read, and unambiguous. The fact of Python enforcing it (or all tabs; a poor second choice) is *a good thing*, easy and natural IMHO. No need for "end if" or "end loop" or "fi". One wonders whether OP is simply trolling. From invalid at invalid.invalid Mon Apr 8 17:29:11 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 8 Apr 2013 21:29:11 +0000 (UTC) Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-04-08, Walter Hurry wrote: > Personally I have always used 4 spaces. I use it in SQL, shell > scripts and Python. It makes code simple to read, and unambiguous. Same here -- mostly because that's what the emacs "Python-mode" does by default, and it seems to be commonly accepted "right way". All things being equal, I'd pobably pick 2 or 3, but 4 is fine. > The fact of Python enforcing it (or all tabs; a poor second choice) > is *a good thing*, easy and natural IMHO. No need for "end if" or > "end loop" or "fi". One wonders whether OP is simply trolling. If he was trolling, he certainly deserves a prize. -- Grant Edwards grant.b.edwards Yow! Here we are in America at ... when do we collect gmail.com unemployment? From rosuav at gmail.com Mon Apr 8 18:00:06 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 9 Apr 2013 08:00:06 +1000 Subject: I hate you all In-Reply-To: References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Apr 9, 2013 at 7:29 AM, Grant Edwards wrote: > On 2013-04-08, Walter Hurry wrote: >> The fact of Python enforcing it (or all tabs; a poor second choice) >> is *a good thing*, easy and natural IMHO. No need for "end if" or >> "end loop" or "fi". One wonders whether OP is simply trolling. > > If he was trolling, he certainly deserves a prize. I don't think he was trolling. It was a classic-model rant: "I upgraded my dependency to a newer version and all my stuff broke". Commonly provokes anger, largely because many such upgrades do NOT break stuff (eg if I were to switch from gcc 4.5 to gcc 4.7 right now, I doubt anything would break, and my code would be able to use the new iterator syntax in c++11 - pity 4.7 isn't packaged for Debian Squeeze). The OP upgraded across an openly-non-backward-compatible boundary, and got angry over one particular aspect of backward compat that wasn't there. ChrisA From walterhurry at lavabit.com Mon Apr 8 18:51:58 2013 From: walterhurry at lavabit.com (Walter Hurry) Date: Mon, 8 Apr 2013 22:51:58 +0000 (UTC) Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, 09 Apr 2013 08:00:06 +1000, Chris Angelico wrote: > On Tue, Apr 9, 2013 at 7:29 AM, Grant Edwards > wrote: >> On 2013-04-08, Walter Hurry wrote: >>> The fact of Python enforcing it (or all tabs; a poor second choice) >>> is *a good thing*, easy and natural IMHO. No need for "end if" or "end >>> loop" or "fi". One wonders whether OP is simply trolling. >> >> If he was trolling, he certainly deserves a prize. > > I don't think he was trolling. It was a classic-model rant: "I upgraded > my dependency to a newer version and all my stuff broke". > Commonly provokes anger, largely because many such upgrades do NOT break > stuff (eg if I were to switch from gcc 4.5 to gcc 4.7 right now, > I doubt anything would break, and my code would be able to use the new > iterator syntax in c++11 - pity 4.7 isn't packaged for Debian Squeeze). > The OP upgraded across an openly-non-backward-compatible boundary, and > got angry over one particular aspect of backward compat that wasn't > there. But wouldn't it have been easier simply to do do a quick sed or whatever rather than to spend hours here arguing? From rosuav at gmail.com Mon Apr 8 18:57:22 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 9 Apr 2013 08:57:22 +1000 Subject: I hate you all In-Reply-To: References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Apr 9, 2013 at 8:51 AM, Walter Hurry wrote: > On Tue, 09 Apr 2013 08:00:06 +1000, Chris Angelico wrote: > >> On Tue, Apr 9, 2013 at 7:29 AM, Grant Edwards >> wrote: >>> On 2013-04-08, Walter Hurry wrote: >>>> The fact of Python enforcing it (or all tabs; a poor second choice) >>>> is *a good thing*, easy and natural IMHO. No need for "end if" or "end >>>> loop" or "fi". One wonders whether OP is simply trolling. >>> >>> If he was trolling, he certainly deserves a prize. >> >> I don't think he was trolling. It was a classic-model rant: "I upgraded >> my dependency to a newer version and all my stuff broke". >> Commonly provokes anger, largely because many such upgrades do NOT break >> stuff (eg if I were to switch from gcc 4.5 to gcc 4.7 right now, >> I doubt anything would break, and my code would be able to use the new >> iterator syntax in c++11 - pity 4.7 isn't packaged for Debian Squeeze). >> The OP upgraded across an openly-non-backward-compatible boundary, and >> got angry over one particular aspect of backward compat that wasn't >> there. > > But wouldn't it have been easier simply to do do a quick sed or whatever > rather than to spend hours here arguing? Probably. I don't profess to understand the OP's brain *that* much! ChrisA From breamoreboy at yahoo.co.uk Tue Apr 9 04:33:25 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 09 Apr 2013 09:33:25 +0100 Subject: I hate you all In-Reply-To: References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 08/04/2013 23:51, Walter Hurry wrote: > On Tue, 09 Apr 2013 08:00:06 +1000, Chris Angelico wrote: > >> On Tue, Apr 9, 2013 at 7:29 AM, Grant Edwards >> wrote: >>> On 2013-04-08, Walter Hurry wrote: >>>> The fact of Python enforcing it (or all tabs; a poor second choice) >>>> is *a good thing*, easy and natural IMHO. No need for "end if" or "end >>>> loop" or "fi". One wonders whether OP is simply trolling. >>> >>> If he was trolling, he certainly deserves a prize. >> >> I don't think he was trolling. It was a classic-model rant: "I upgraded >> my dependency to a newer version and all my stuff broke". >> Commonly provokes anger, largely because many such upgrades do NOT break >> stuff (eg if I were to switch from gcc 4.5 to gcc 4.7 right now, >> I doubt anything would break, and my code would be able to use the new >> iterator syntax in c++11 - pity 4.7 isn't packaged for Debian Squeeze). >> The OP upgraded across an openly-non-backward-compatible boundary, and >> got angry over one particular aspect of backward compat that wasn't >> there. > > But wouldn't it have been easier simply to do do a quick sed or whatever > rather than to spend hours here arguing? > Where's the fun in that? :) -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From invalid at invalid.invalid Tue Apr 9 09:39:20 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 9 Apr 2013 13:39:20 +0000 (UTC) Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-04-09, Mark Lawrence wrote: > >> But wouldn't it have been easier simply to do do a quick sed or whatever >> rather than to spend hours here arguing? > > Where's the fun in that? :) What, you don't think sed is fun? -- Grant Edwards grant.b.edwards Yow! Did I say I was at a sardine? Or a bus??? gmail.com From python.list at tim.thechases.com Tue Apr 9 10:17:38 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 9 Apr 2013 09:17:38 -0500 Subject: I hate you all In-Reply-To: References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20130409091738.45df7845@bigbox.christie.dr> On 2013-04-09 13:39, Grant Edwards wrote: > On 2013-04-09, Mark Lawrence wrote: > > > >> But wouldn't it have been easier simply to do do a quick sed or > >> whatever rather than to spend hours here arguing? > > > > Where's the fun in that? :) > > What, you don't think sed is fun? > > -- > Grant Edwards grant.b.edwards Yow! Did I say I > was at a sardine? Or a bus??? > gmail.com | sed -e '/What.*n.t/{s//Sure I/;s/?/!/};/^-- /{r .signature' -e'q}' :-) -tkc From rosuav at gmail.com Tue Apr 9 10:20:14 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Apr 2013 00:20:14 +1000 Subject: I hate you all In-Reply-To: <20130409091738.45df7845@bigbox.christie.dr> References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> <20130409091738.45df7845@bigbox.christie.dr> Message-ID: On Wed, Apr 10, 2013 at 12:17 AM, Tim Chase wrote: > | sed -e '/What.*n.t/{s//Sure I/;s/?/!/};/^-- /{r .signature' -e'q}' > A very apt response. Oh wait, I already have sed on this system, don't need to fire up apt. ChrisA From breamoreboy at yahoo.co.uk Tue Apr 9 11:51:26 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 09 Apr 2013 16:51:26 +0100 Subject: I hate you all In-Reply-To: References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 09/04/2013 14:39, Grant Edwards wrote: > On 2013-04-09, Mark Lawrence wrote: >> >>> But wouldn't it have been easier simply to do do a quick sed or whatever >>> rather than to spend hours here arguing? >> >> Where's the fun in that? :) > > What, you don't think sed is fun? > Having never really used a *nix box in anger how would I know? A substantial portion of my career was spent on a combination of VMS, C with embedded SQL and Ingres. Please don't ask as I don't know the answer :) -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From walterhurry at lavabit.com Tue Apr 9 17:09:34 2013 From: walterhurry at lavabit.com (Walter Hurry) Date: Tue, 9 Apr 2013 21:09:34 +0000 (UTC) Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, 09 Apr 2013 16:51:26 +0100, Mark Lawrence wrote: > On 09/04/2013 14:39, Grant Edwards wrote: >> On 2013-04-09, Mark Lawrence wrote: >>> >>>> But wouldn't it have been easier simply to do do a quick sed or >>>> whatever rather than to spend hours here arguing? >>> >>> Where's the fun in that? :) >> >> What, you don't think sed is fun? >> >> > Having never really used a *nix box in anger how would I know? A > substantial portion of my career was spent on a combination of VMS, C > with embedded SQL and Ingres. Please don't ask as I don't know the > answer :) Anti-virus, anti-malware, defragmenters, registry cleaners, needing to reboot every time I install or update software? No grep, no awk, no sed? No thanks. But never mind; each to his own. I don't want to spark OS wars. From breamoreboy at yahoo.co.uk Tue Apr 9 18:09:19 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 09 Apr 2013 23:09:19 +0100 Subject: I hate you all In-Reply-To: References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 09/04/2013 22:09, Walter Hurry wrote: > On Tue, 09 Apr 2013 16:51:26 +0100, Mark Lawrence wrote: >> Having never really used a *nix box in anger how would I know? A >> substantial portion of my career was spent on a combination of VMS, C >> with embedded SQL and Ingres. Please don't ask as I don't know the >> answer :) > > Anti-virus, anti-malware, defragmenters, registry cleaners, needing to > reboot every time I install or update software? > > No grep, no awk, no sed? > > No thanks. > > But never mind; each to his own. I don't want to spark OS wars. > I haven't the faintest idea what your response means so please explainn. -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From steve+comp.lang.python at pearwood.info Tue Apr 9 19:21:19 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Apr 2013 23:21:19 GMT Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5164a26e$0$30003$c3e8da3$5496439d@news.astraweb.com> On Tue, 09 Apr 2013 23:09:19 +0100, Mark Lawrence wrote: > On 09/04/2013 22:09, Walter Hurry wrote: >> On Tue, 09 Apr 2013 16:51:26 +0100, Mark Lawrence wrote: >>> Having never really used a *nix box in anger how would I know? A >>> substantial portion of my career was spent on a combination of VMS, C >>> with embedded SQL and Ingres. Please don't ask as I don't know the >>> answer :) >> >> Anti-virus, anti-malware, defragmenters, registry cleaners, needing to >> reboot every time I install or update software? >> >> No grep, no awk, no sed? >> >> No thanks. >> >> But never mind; each to his own. I don't want to spark OS wars. >> >> > I haven't the faintest idea what your response means so please explainn. Walter is pointing out that as a Windows user, you probably have to deal with problems that Unix users are barely even aware of, like viruses, the registry, having to reboot after installing software, etc., and you are missing out on oodles of useful and powerful tools like grep. He finds your decision to use Windows curious, but respects your decision to use it and doesn't want to get into an unproductive war over which is the best OS. -- Steven From rosuav at gmail.com Tue Apr 9 19:28:26 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Apr 2013 09:28:26 +1000 Subject: I hate you all In-Reply-To: <5164a26e$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> <5164a26e$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 10, 2013 at 9:21 AM, Steven D'Aprano wrote: > Walter is pointing out that as a Windows user... Walter is also assuming that Mark is a Windows user, which was never actually stated :) ChrisA From breamoreboy at yahoo.co.uk Tue Apr 9 19:41:23 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 10 Apr 2013 00:41:23 +0100 Subject: I hate you all In-Reply-To: References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> <5164a26e$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 10/04/2013 00:28, Chris Angelico wrote: > On Wed, Apr 10, 2013 at 9:21 AM, Steven D'Aprano > wrote: >> Walter is pointing out that as a Windows user... > > Walter is also assuming that Mark is a Windows user, which was never > actually stated :) > > ChrisA > Another unicode error with VMS being transposed to Windows? :) -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From breamoreboy at yahoo.co.uk Tue Apr 9 19:39:19 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 10 Apr 2013 00:39:19 +0100 Subject: I hate you all In-Reply-To: <5164a26e$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> <5164a26e$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 10/04/2013 00:21, Steven D'Aprano wrote: > On Tue, 09 Apr 2013 23:09:19 +0100, Mark Lawrence wrote: > >> On 09/04/2013 22:09, Walter Hurry wrote: >>> On Tue, 09 Apr 2013 16:51:26 +0100, Mark Lawrence wrote: >>>> Having never really used a *nix box in anger how would I know? A >>>> substantial portion of my career was spent on a combination of VMS, C >>>> with embedded SQL and Ingres. Please don't ask as I don't know the >>>> answer :) >>> >>> Anti-virus, anti-malware, defragmenters, registry cleaners, needing to >>> reboot every time I install or update software? >>> >>> No grep, no awk, no sed? >>> >>> No thanks. >>> >>> But never mind; each to his own. I don't want to spark OS wars. >>> >>> >> I haven't the faintest idea what your response means so please explainn. > > > Walter is pointing out that as a Windows user, you probably have to deal > with problems that Unix users are barely even aware of, like viruses, the > registry, having to reboot after installing software, etc., and you are > missing out on oodles of useful and powerful tools like grep. He finds > your decision to use Windows curious, but respects your decision to use > it and doesn't want to get into an unproductive war over which is the > best OS. > How did VMS get translated into Windows? :) -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From walterhurry at lavabit.com Tue Apr 9 19:50:20 2013 From: walterhurry at lavabit.com (Walter Hurry) Date: Tue, 9 Apr 2013 23:50:20 +0000 (UTC) Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> <5164a26e$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 10 Apr 2013 09:28:26 +1000, Chris Angelico wrote: > On Wed, Apr 10, 2013 at 9:21 AM, Steven D'Aprano > wrote: >> Walter is pointing out that as a Windows user... > > Walter is also assuming that Mark is a Windows user, which was never > actually stated :) >From Mark's reply to me: User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 From rosuav at gmail.com Tue Apr 9 20:31:44 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Apr 2013 10:31:44 +1000 Subject: I hate you all In-Reply-To: References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> <5164a26e$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 10, 2013 at 9:50 AM, Walter Hurry wrote: > On Wed, 10 Apr 2013 09:28:26 +1000, Chris Angelico wrote: > >> On Wed, Apr 10, 2013 at 9:21 AM, Steven D'Aprano >> wrote: >>> Walter is pointing out that as a Windows user... >> >> Walter is also assuming that Mark is a Windows user, which was never >> actually stated :) > > From Mark's reply to me: > User-Agent: Mozilla/5.0 (Windows NT 6.0; > rv:17.0) Gecko/20130328 Thunderbird/17.0.5 My headers say I use Windows, too, but I actually use Linux. ChrisA From steve+comp.lang.python at pearwood.info Tue Apr 9 22:00:46 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Apr 2013 02:00:46 GMT Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> <5164a26e$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5164c7cd$0$30003$c3e8da3$5496439d@news.astraweb.com> On Wed, 10 Apr 2013 10:31:44 +1000, Chris Angelico wrote: > On Wed, Apr 10, 2013 at 9:50 AM, Walter Hurry > wrote: >> On Wed, 10 Apr 2013 09:28:26 +1000, Chris Angelico wrote: >> >>> On Wed, Apr 10, 2013 at 9:21 AM, Steven D'Aprano >>> wrote: >>>> Walter is pointing out that as a Windows user... >>> >>> Walter is also assuming that Mark is a Windows user, which was never >>> actually stated :) >> >> From Mark's reply to me: >> User-Agent: Mozilla/5.0 (Windows NT 6.0; >> rv:17.0) Gecko/20130328 Thunderbird/17.0.5 > > My headers say I use Windows, too, but I actually use Linux. Actually, no they don't. They don't say anything about your OS, and there is no User-Agent string. Since Mark claims to have not seriously used Unix, that rules out Linux, FreeBSD, OpenBSD, and modern Apple Mac. It's just barely possible that he's still using VMS or Hurd, but really, by a process of elimination the most likely answer is that he's using Windows. -- Steven From rosuav at gmail.com Tue Apr 9 22:14:30 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Apr 2013 12:14:30 +1000 Subject: I hate you all In-Reply-To: <5164c7cd$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> <5164a26e$0$30003$c3e8da3$5496439d@news.astraweb.com> <5164c7cd$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 10, 2013 at 12:00 PM, Steven D'Aprano wrote: > On Wed, 10 Apr 2013 10:31:44 +1000, Chris Angelico wrote: > >> On Wed, Apr 10, 2013 at 9:50 AM, Walter Hurry >> wrote: >>> From Mark's reply to me: >>> User-Agent: Mozilla/5.0 (Windows NT 6.0; >>> rv:17.0) Gecko/20130328 Thunderbird/17.0.5 >> >> My headers say I use Windows, too, but I actually use Linux. > > Actually, no they don't. They don't say anything about your OS, and there > is no User-Agent string. > > Since Mark claims to have not seriously used Unix, that rules out Linux, > FreeBSD, OpenBSD, and modern Apple Mac. It's just barely possible that > he's still using VMS or Hurd, but really, by a process of elimination the > most likely answer is that he's using Windows. Heh, I didn't actually check. But if my user-agent _were_ being recorded anywhere, it would make it seem that I use Windows. ChrisA From invalid at invalid.invalid Tue Apr 9 17:43:59 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 9 Apr 2013 21:43:59 +0000 (UTC) Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-04-09, Mark Lawrence wrote: > On 09/04/2013 14:39, Grant Edwards wrote: >> On 2013-04-09, Mark Lawrence wrote: >>> >>>> But wouldn't it have been easier simply to do do a quick sed or whatever >>>> rather than to spend hours here arguing? >>> >>> Where's the fun in that? :) >> >> What, you don't think sed is fun? > > Having never really used a *nix box in anger how would I know? A > substantial portion of my career was spent on a combination of VMS, That's no excuse -- DECShell for VMS included sed! :) I spent many months months writing a set of shell-scripts and makefiles that used awk, sed, and their brethren to do automated testing and building of an 1100 page document that was written in LaTeX. It was all on a VMS system. Unfortunately, the massive process-creation overhead of VMS hit shell-scripts pretty hard -- a full V&V run and document build took something like 7 hours. We usually only ran it overnight. > C with embedded SQL and Ingres. Please don't ask as I don't know the > answer :) -- Grant Edwards grant.b.edwards Yow! FROZEN ENTREES may at be flung by members of gmail.com opposing SWANSON SECTS ... From steve+comp.lang.python at pearwood.info Mon Apr 8 22:51:22 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Apr 2013 02:51:22 GMT Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51638229$0$30003$c3e8da3$5496439d@news.astraweb.com> On Mon, 08 Apr 2013 19:43:51 +0100, Nobody wrote: > On Sun, 07 Apr 2013 01:30:45 +0000, Steven D'Aprano wrote: > >> Am I the only one here who has used a typewriter? >> >> Tab stops were set manually, to a physical distance into the page, >> using a mechanical stop. This long predates the "rule" that tab stops >> are every 8 characters. > > And your point is? > > Typewriters don't have a tab "character". The information regarding tab > stops is conveyed out-of-band from the typist to the typewriter, and > doesn't need to persist beyond the time taken to type the document. Both text editors and typewriters encode information about tab settings out of band. Editors encode that information in some combination of program configuration, command-line switches, environment variables, and embedded mode lines in the document itself. Typewriters encode that information in the typists' memory, or failing that, in the actual physical space left on the page. That's a difference that makes no difference. My point is that there were well-established semantics for what a tab should do, and the "8 character tab" is not that. Pressing the tab key on a keyboard while entering text ought to instruct the editor to advance to a specified tab stop capable of being set anywhere on the page. Word processors use that model: the word processor stores the positions of the tab stops out of band, usually in the "paragraph formatting" or "style sheet", but in principle they could keep the position of the tab stops global to the document or even global to the application. Good text editors also support this model. Some versions of Vim, for example, include a feature called "variable tabstops". Emacs includes a variable called tab-stop-list which can set variable tab stops[1]. Even the Linux command "less" supports variable width tabs, with the -x option. In case you think this is only for Unix editors, the Windows "Boxer Text Editor" also supports variable tab stops. There may, or may not be, good reasons for an eight character default setting for tab stops. But eight characters is not, and never has been, the One True Way of setting tab stops. [1] Although what happens when you press the tab key in Emacs is so complicated that only three people in the world have ever understood it fully. The first is Richard Stallman, then second is dead, and the third has gone mad. -- Steven From rustompmody at gmail.com Tue Apr 9 00:06:42 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 8 Apr 2013 21:06:42 -0700 (PDT) Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> <51638229$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Apr 9, 7:51?am, Steven D'Aprano wrote: > On Mon, 08 Apr 2013 19:43:51 +0100, Nobody wrote: > > On Sun, 07 Apr 2013 01:30:45 +0000, Steven D'Aprano wrote: > > >> Am I the only one here who has used a typewriter? > > >> Tab stops were set manually, to a physical distance into the page, > >> using a mechanical stop. This long predates the "rule" that tab stops > >> are every 8 characters. > > > And your point is? > > > Typewriters don't have a tab "character". The information regarding tab > > stops is conveyed out-of-band from the typist to the typewriter, and > > doesn't need to persist beyond the time taken to type the document. > > Both text editors and typewriters encode information about tab settings > out of band. Editors encode that information in some combination of > program configuration, command-line switches, environment variables, and > embedded mode lines in the document itself. Typewriters encode that > information in the typists' memory, or failing that, in the actual > physical space left on the page. That's a difference that makes no > difference. > > My point is that there were well-established semantics for what a tab > should do, and the "8 character tab" is not that. Pressing the tab key on > a keyboard while entering text ought to instruct the editor to advance to > a specified tab stop capable of being set anywhere on the page. Word > processors use that model: the word processor stores the positions of the > tab stops out of band, usually in the "paragraph formatting" or "style > sheet", but in principle they could keep the position of the tab stops > global to the document or even global to the application. Dunno what you mean by 'out-of-band' If I set tabstops for a para to say 4-13-25-36 in a wordprocessor, save the file and look inside, I will find the tuple (4,13,25,36) in some encoded form. For a typewritten page, if the margin seems to be at 11th col, the reader cannot know from the page alone whether the typist 1. set the tab at 11 2. set the tab at 8 and pressed TAB followed by 3 SPC 3. Started with 2 and switched to 1 From rustompmody at gmail.com Tue Apr 9 00:52:51 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 8 Apr 2013 21:52:51 -0700 (PDT) Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> <51638229$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4a02dda8-ec54-467a-8ebb-555f1b291597@k6g2000pbq.googlegroups.com> On Apr 9, 9:06?am, rusi wrote: > Dunno what you mean by 'out-of-band' > If I set tabstops for a para to say 4-13-25-36 in a wordprocessor, > save the file and look inside, I will find the tuple (4,13,25,36) in > some encoded form. To make this conform to current practices, I should use some length- unit not characters which I had in mind. From steve+comp.lang.python at pearwood.info Tue Apr 9 01:19:11 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Apr 2013 05:19:11 GMT Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> <5160cc44$0$29995$c3e8da3$5496439d@news.astraweb.com> <51638229$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5163a4cf$0$29977$c3e8da3$5496439d@news.astraweb.com> On Mon, 08 Apr 2013 21:06:42 -0700, rusi wrote: > On Apr 9, 7:51?am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> On Mon, 08 Apr 2013 19:43:51 +0100, Nobody wrote: >> > On Sun, 07 Apr 2013 01:30:45 +0000, Steven D'Aprano wrote: >> >> >> Am I the only one here who has used a typewriter? >> >> >> Tab stops were set manually, to a physical distance into the page, >> >> using a mechanical stop. This long predates the "rule" that tab >> >> stops are every 8 characters. >> >> > And your point is? >> >> > Typewriters don't have a tab "character". The information regarding >> > tab stops is conveyed out-of-band from the typist to the typewriter, >> > and doesn't need to persist beyond the time taken to type the >> > document. >> >> Both text editors and typewriters encode information about tab settings >> out of band. Editors encode that information in some combination of >> program configuration, command-line switches, environment variables, >> and embedded mode lines in the document itself. Typewriters encode that >> information in the typists' memory, or failing that, in the actual >> physical space left on the page. That's a difference that makes no >> difference. >> >> My point is that there were well-established semantics for what a tab >> should do, and the "8 character tab" is not that. Pressing the tab key >> on a keyboard while entering text ought to instruct the editor to >> advance to a specified tab stop capable of being set anywhere on the >> page. Word processors use that model: the word processor stores the >> positions of the tab stops out of band, usually in the "paragraph >> formatting" or "style sheet", but in principle they could keep the >> position of the tab stops global to the document or even global to the >> application. > > Dunno what you mean by 'out-of-band' I mean that the information about the tab stops are not inherent to the tab itself. > If I set tabstops for a para to say 4-13-25-36 in a wordprocessor, save > the file and look inside, I will find the tuple (4,13,25,36) in some > encoded form. There's nothing about the *tab character itself* that says "jump to column 25". That information is metadata, stored external to the tab. That doesn't necessarily mean external to the file. A word-processing file carries a lot of metadata about the document. A plain text file is a better example. If I type up a document in (say) OpenOffice and use tabs to align a table, I might manually set the tabs to 4cm, 9cm, 18cm. When I hit tab, the cursor will jump to (say) 18cm, but if I save the document as plain text, that information is not stored anywhere in the document. It may be encoded in the OpenOffice config, e.g. in the "Normal" stylesheet. The same applies for documents created in a text editor, say Vim or Emacs. They may store the metadata about tab settings as mode lines in the document, or in an environment variable, or in a config file, or perhaps nowhere at all. Just like a typewriter. > For a typewritten page, if the margin seems to be at 11th col, the > reader cannot know from the page alone whether the typist 1. set the tab > at 11 > 2. set the tab at 8 and pressed TAB followed by 3 SPC 3. Started with 2 > and switched to 1 Very true. Manual typewriters are not identical to text editors. Typewriters can do both more *and* less than text editors. E.g. you can compose extra symbols by backspacing and overtyping, but you cannot usually distinguish between space-tab and space-space-tab. But from the perspective of "duplicate what you see on the page", the difference between space-tab and space-space-tab does not matter. What matters is where you end up, not how you get there. -- Steven From gd.usenet at spamfence.net Sat Apr 6 08:55:50 2013 From: gd.usenet at spamfence.net (=?ISO-8859-1?Q?G=FCnther?= Dietrich) Date: Sat, 06 Apr 2013 14:55:50 +0200 Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <906d8c05-99dc-4209-854c-7988ca7c78e3@googlegroups.com> <95b2bc1c-57a2-48c9-85ea-cf1004c9e26c@googlegroups.com> Message-ID: terminatorul at gmail.com wrote: >[...] >> The "def" line has four spaces. The "for" line then has a hard tab. >> This is ambiguous. If the hard tab is assumed to have a width of four >> spaces, then they are at the same indentation level. If it is assumed >> to have a width of eight spaces, then they are not. >[...] > >The correct tab stop positions have always been at 8 character columns apart. >The "ambiguity" was introduced by editors that do not follow the default value >set in hardware like printers or used by consoles and terminal emulators. > >And now python forces me out of using any tab characters at all. I believe I >should still have a choice, python should at lest give an option to set tab >size, if the default of 8 is ambiguous now. You know the Unix command 'expand'? If you used tabs representing eight columns consequently, use expand on your python scripts to convert tabs to spaces before running them. Best regards, G?nther From dylan at dje.me Sat Apr 6 00:28:55 2013 From: dylan at dje.me (Dylan Evans) Date: Sat, 6 Apr 2013 14:28:55 +1000 Subject: I hate you all In-Reply-To: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> Message-ID: On Sat, Apr 6, 2013 at 7:41 AM, wrote: > Hello > > I just tried python 3.3 with some simple script meant for unit test. > > How can python authors be so arrogant to impose their tabs and spaces > options on me ? It should be my choice if I want to use tabs or not ! > > Don't like it? Use ruby. > I know people have all goten into this frenzy of using either tabs, either > spaces for indentation, but using a hard-tab of 8 spaces and a soft tab of > 4 spaces has worked fine long before python 3 showed up. > > And if they decided to throw a TabError, they should have at least created > an option to specify tab size, so I can work around that. > > I am aware that so many editors use a tab stop of 4 spaces instead of 8 > (which by the way started as a cheap way to work around their initial lack > of a "soft tab stop" option, and then was kept at 4 for "compatibility"). > But the rest of us who always use a tab stop of 8 should not be forced to > change preferences because python reached version 3. > > Timothy Madden > -- > http://mail.python.org/mailman/listinfo/python-list > -- "The UNIX system has a command, nice ... in order to be nice to the other users. Nobody ever uses it." - Andrew S. Tanenbaum -------------- next part -------------- An HTML attachment was scrubbed... URL: From terminatorul at gmail.com Sat Apr 6 01:13:39 2013 From: terminatorul at gmail.com (terminatorul at gmail.com) Date: Fri, 5 Apr 2013 22:13:39 -0700 (PDT) Subject: I hate you all In-Reply-To: References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> Message-ID: <00fd714f-c513-48c9-89a6-74887cb962bd@googlegroups.com> On Saturday, April 6, 2013 7:28:55 AM UTC+3, Dylan Evans wrote: > On Sat, Apr 6, 2013 at 7:41 AM, wrote: > > Hello > > > I just tried python 3.3 with some simple script meant for unit test. > > How can python authors be so arrogant to impose their tabs and spaces options on me ? It should be my choice if I want to use tabs or not ! > > > Don't like it? Use ruby. Actually next on my list is perl. I know ruby is sexy, but taming the wild beast is what makes me feel like the real cowboy. From terminatorul at gmail.com Sat Apr 6 01:13:39 2013 From: terminatorul at gmail.com (terminatorul at gmail.com) Date: Fri, 5 Apr 2013 22:13:39 -0700 (PDT) Subject: I hate you all In-Reply-To: References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> Message-ID: <00fd714f-c513-48c9-89a6-74887cb962bd@googlegroups.com> On Saturday, April 6, 2013 7:28:55 AM UTC+3, Dylan Evans wrote: > On Sat, Apr 6, 2013 at 7:41 AM, wrote: > > Hello > > > I just tried python 3.3 with some simple script meant for unit test. > > How can python authors be so arrogant to impose their tabs and spaces options on me ? It should be my choice if I want to use tabs or not ! > > > Don't like it? Use ruby. Actually next on my list is perl. I know ruby is sexy, but taming the wild beast is what makes me feel like the real cowboy. From dylan at dje.me Sat Apr 6 23:00:19 2013 From: dylan at dje.me (Dylan Evans) Date: Sun, 7 Apr 2013 13:00:19 +1000 Subject: I hate you all In-Reply-To: <00fd714f-c513-48c9-89a6-74887cb962bd@googlegroups.com> References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <00fd714f-c513-48c9-89a6-74887cb962bd@googlegroups.com> Message-ID: Then you see my point, unless you are being told what to use by a boss then there are plenty of other languages you can choose from. Python is rigid about it's format, that's just what it is and a lot of people like it but if it's not your thing then some other language will probably suit you better. However, if you are working for a company, or OSS project, you are probably going to have your style dictated whatever language you use, for example the 2 space indents (*shudder*) that google uses in c++ http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml?showone=Spaces_vs._Tabs#Spaces_vs._Tabs (Interestingly google use 4 space indents in python for compatibility with PEP-8 http://google-styleguide.googlecode.com/svn/trunk/pyguide.html?showone=Indentation#Indentation ) You probably won't like everything in a project style but it's not about being tyrannical, and it's not a bad thing to have restrictions at the language level. I work for a company with a load of lagacy c formatted as follows: int many_many_globals; int func(int iFoo,int iBar) { int var = 10; if(iBar>1) { var=iFoo+many_many_globals; } return var; } So i am pretty happy to adopt a language which defines a sane style. This is a nice flame war you have stirred up. On Sat, Apr 6, 2013 at 3:13 PM, wrote: > On Saturday, April 6, 2013 7:28:55 AM UTC+3, Dylan Evans wrote: > > On Sat, Apr 6, 2013 at 7:41 AM, wrote: > > > > Hello > > > > > > I just tried python 3.3 with some simple script meant for unit test. > > > > How can python authors be so arrogant to impose their tabs and spaces > options on me ? It should be my choice if I want to use tabs or not ! > > > > > > Don't like it? Use ruby. > > > Actually next on my list is perl. I know ruby is sexy, but taming the wild > beast is what makes me feel like the real cowboy. > -- > http://mail.python.org/mailman/listinfo/python-list > -- "The UNIX system has a command, nice ... in order to be nice to the other users. Nobody ever uses it." - Andrew S. Tanenbaum -------------- next part -------------- An HTML attachment was scrubbed... URL: From terminatorul at gmail.com Sun Apr 7 07:44:02 2013 From: terminatorul at gmail.com (Timothy Madden) Date: Sun, 07 Apr 2013 14:44:02 +0300 Subject: I hate you all In-Reply-To: References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <00fd714f-c513-48c9-89a6-74887cb962bd@googlegroups.com> Message-ID: <51615c02$0$32104$14726298@news.sunsite.dk> On 07.04.2013 06:00, Dylan Evans wrote: > Then you see my point, unless you are being told what to use by a boss > then there are plenty of other languages you can choose from. Python is > rigid about it's format, that's just what it is and a lot of people like > it but if it's not your thing then some other language will probably > suit you better. However, if you are working for a company, or OSS > project, you are probably going to have your style dictated whatever > language you use [...] I am ok with the people that like python the way it is. But an option from python authors to make tabs work the way they used to would have been nice. Just my opinion, I do see other people here think otherwise... Timothy Madden From ethan at stoneleaf.us Sun Apr 7 14:12:11 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 07 Apr 2013 11:12:11 -0700 Subject: I hate you all In-Reply-To: <51615c02$0$32104$14726298@news.sunsite.dk> References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <00fd714f-c513-48c9-89a6-74887cb962bd@googlegroups.com> <51615c02$0$32104$14726298@news.sunsite.dk> Message-ID: <5161B6FB.7080902@stoneleaf.us> On 04/07/2013 04:44 AM, Timothy Madden wrote: > > I am ok with the people that like python the way it is. Really? 'Cause I totally missed that from the subject line... -- ~Ethan~ From roy at panix.com Sun Apr 7 14:33:47 2013 From: roy at panix.com (Roy Smith) Date: Sun, 07 Apr 2013 14:33:47 -0400 Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> <00fd714f-c513-48c9-89a6-74887cb962bd@googlegroups.com> <51615c02$0$32104$14726298@news.sunsite.dk> Message-ID: In article , Ethan Furman wrote: > On 04/07/2013 04:44 AM, Timothy Madden wrote: > > > > I am ok with the people that like python the way it is. > > Really? 'Cause I totally missed that from the subject line... > > -- > ~Ethan~ Take this logically... 1) Ethan hates all clp readers 2) Ethan does not hate people who "like python the way it is" I therefore deduce that Ethan believes there are no clp readers who "like python the way it is". This may be a mistaken belief, but at least there's no logical contradiction. From invalid at invalid.invalid Sat Apr 6 11:27:34 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 6 Apr 2013 15:27:34 +0000 (UTC) Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> Message-ID: On 2013-04-05, terminatorul at gmail.com wrote: [Mad that in 3.3 you can no longer use ambiguous mixtures of spaces and tabs within a single indent level.] My boss would refer to this as a failure to be "bug-compatible" with the previous version. Whether or not to maintain bug-compatibility when you bring out a new version is one of the eternal debates. No matter what you do, it's going to annoy somebody... -- Grant From roy at panix.com Sat Apr 6 11:58:31 2013 From: roy at panix.com (Roy Smith) Date: Sat, 06 Apr 2013 11:58:31 -0400 Subject: I hate you all References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> Message-ID: In article , Grant Edwards wrote: > On 2013-04-05, terminatorul at gmail.com wrote: > > [Mad that in 3.3 you can no longer use ambiguous mixtures of spaces > and tabs within a single indent level.] > > My boss would refer to this as a failure to be "bug-compatible" with > the previous version. > > Whether or not to maintain bug-compatibility when you bring out a new > version is one of the eternal debates. No matter what you do, it's > going to annoy somebody... I remember the first VAX was got. We used some third-party serial card because it cost a small fraction of the official DEC version. We had all sorts of trouble with it. Eventually it turned out that the third-party card was operating correctly according to the DEC specs, but the driver had been written to work against genuine DEC hardware, which didn't follow their own published spec! I vaguely remember it had to do with how the DMA processor dealt with odd-sized block transfers. As I recall, there was a software patch to the driver which allowed it to work with the correctly implemented hardware, but I could be messing up most of the details. Great machine, that VAX. For only $100k, three or four people could play rogue at the same time! From breamoreboy at yahoo.co.uk Sun Apr 7 14:25:11 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 07 Apr 2013 19:25:11 +0100 Subject: I hate you all In-Reply-To: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> References: <64d4fb7c-6a75-4b5f-b5c8-06a4b2b5d0cb@googlegroups.com> Message-ID: On 05/04/2013 22:41, terminatorul at gmail.com wrote: snipped as loads of comments already made. > Timothy Madden > The BDFL's view from many moons ago www.python.org/doc/essays/ppt/regrets/PythonRegrets.ppt slide 3. -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From chris at simplistix.co.uk Fri Apr 5 18:22:53 2013 From: chris at simplistix.co.uk (Chris Withers) Date: Fri, 05 Apr 2013 19:22:53 -0300 Subject: xlrd 0.9.1 released! Message-ID: <515F4EBD.4050800@simplistix.co.uk> Hi All, I'm pleased to announce the release of xlrd 0.9.1: http://pypi.python.org/pypi/xlrd/0.9.1 This release includes the following changes: - A tonne of bugs when used with Python 3 were fixed thanks to John Machin. - Extra byte data in hyperlink records now records a warning rather than raising an exception. - Improved handling of aberrant Excel 4.0 Worksheet files - setup.py and MANIFEST simplifaction along with removal of a tonne of code that was needed before we dropped support for Python 2.5 and below. Thanks to Thomas Kluyver to the commits. - Removed vestiges of support for pickleable Book objects. This hasn't worked for some time, so the options to support it have gone. If you find any problems, please ask about them on the python-excel at googlegroups.com list, or submit an issue on GitHub: https://github.com/python-excel/xlrd/issues Full details of all things Python and Excel related can be found here: http://www.python-excel.org/ cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From satamukh at gmail.com Fri Apr 5 18:41:54 2013 From: satamukh at gmail.com (Satabdi Mukherjee) Date: Fri, 5 Apr 2013 15:41:54 -0700 (PDT) Subject: can anyone help me in developing a simple webpage in jinja2 Message-ID: i am a rookie in python and i am trying to develop a simple webpage using jinja2. can anyone please help me how to do that i am trying in this way but showing invalid syntax error My Webpage

My Webpage

{{ a_variable }} From janpeterr at freenet.de Sat Apr 6 03:15:19 2013 From: janpeterr at freenet.de (Jan Riechers) Date: Sat, 06 Apr 2013 10:15:19 +0300 Subject: can anyone help me in developing a simple webpage in jinja2 In-Reply-To: References: Message-ID: <515FCB87.1000103@freenet.de> On 06.04.2013 01:41, Satabdi Mukherjee wrote: > i am a rookie in python and i am trying to develop a simple webpage using jinja2. can anyone please help me how to do that > i am trying in this way but showing invalid syntax error > [...] > > >

My Webpage

> {{ a_variable }} [...] > Hello, the jinja2 syntax is correct that way, see also this for reference for variable naming: http://jinja.pocoo.org/docs/templates/index.html#variables The invalid syntax is raised when? Can you post the error a bit more detailed, this will help giving you any advice. If you know the code part raising the error and you post it, this will also help. Jan From rosuav at gmail.com Sat Apr 6 04:00:45 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Apr 2013 19:00:45 +1100 Subject: can anyone help me in developing a simple webpage in jinja2 In-Reply-To: <515FCB87.1000103@freenet.de> References: <515FCB87.1000103@freenet.de> Message-ID: On Sat, Apr 6, 2013 at 6:15 PM, Jan Riechers wrote: > The invalid syntax is raised when? Can you post the error a bit more > detailed, this will help giving you any advice. > > If you know the code part raising the error and you post it, this will also > help. Agreed. But my guess would be the lack of colon on the for loop... which would be highlighted by the error thrown. ChrisA From cousinstanley at gmail.com Sun Apr 7 15:29:24 2013 From: cousinstanley at gmail.com (Cousin Stanley) Date: Sun, 7 Apr 2013 19:29:24 +0000 (UTC) Subject: can anyone help me in developing a simple webpage in jinja2 References: Message-ID: Satabdi Mukherjee wrote: > i am a rookie in python and i am trying > to develop a simple webpage using jinja2. > > can anyone please help me how to do that You might try using your jinja template with named tuples .... # ------------------------------------------- from jinja2 import Template from collections import namedtuple as NT nt = NT( 'Navigation' , 'href caption' ) n1 = nt( 'http://python.org' , 'python' ) n2 = nt( 'http://cython.org' , 'cython' ) n3 = nt( 'http://jython.org' , 'jython' ) n4 = nt( 'http://pypy.org/' , 'pypy' ) nav = ( n1 , n2 , n3 , n4 ) tmpl = Template( '''\ My Webpage

My Webpage

{{ a_variable }} ''' ) print tmpl.render( variable = 'Navigation' , navigation = nav ) -- Stanley C. Kitching Human Being Phoenix, Arizona From jhunter.dunefsky at gmail.com Fri Apr 5 20:16:05 2013 From: jhunter.dunefsky at gmail.com (Jake D) Date: Fri, 5 Apr 2013 17:16:05 -0700 (PDT) Subject: im.py: a python communications tool Message-ID: Hey Usenetites! I have a horrible Python program to allow two people to chat with each other. It has horribly any functionality, but it is meant for the public to work on, not necessarily me. Anyways, here's a quick FAQ. What does this do that IRC can't? What does this do that AIM can't? --It allows direct communication between two computers, whereas IRC doesn't. And AIM and similar services require a username, etc. This is made specifically for two users on a network to chat. What version of Python is this written in? --Python 2.7.3. What is the licence? --It's released under a special FOSS licence. Here it is: ----You can do whatever you want with this program. Alright, now, here's the code: #!/usr/bin/python #An instant messaging program implemented in Python. #Created on Sunday, December 30, 2012 (long before it's Usenet publication) import socket import sys import threading def server_listen(): while True: r = c.recv(8192) if r == "\quit": c.close() s.close() sys.exit(0) print con_addr[0], ": " + r def client_listen(): while True: r = s.recv(8192) if r == "\quit": s.close() sys.exit(0) print sys.argv[1], ": " + r s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) if sys.argv[1] == "-l": s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind(('', 5067)) s.listen(5) c, con_addr = s.accept() while True: r = c.recv(8192) if r == "\quit": c.close() s.close() sys.exit(0) print con_addr[0], ": " + r i = raw_input("You: ") if i == "\quit": c.send("\quit") c.close() s.close() sys.exit(0) c.send(i) else: s.connect((socket.gethostbyname(sys.argv[1]), 5067)) print "Chat initiated with " + sys.argv[1] + "!" while True: i = raw_input("You: ") if i == "\quit": s.send("\quit") s.close() sys.exit(0) s.send(i) r = s.recv(8192) if r == "\quit": s.close() sys.exit(0) print sys.argv[1] + ": " + r I encourage people to modify this code, because really, it sucks. Enjoy! From demianbrecht at gmail.com Fri Apr 5 20:52:47 2013 From: demianbrecht at gmail.com (Demian Brecht) Date: Fri, 5 Apr 2013 17:52:47 -0700 Subject: im.py: a python communications tool In-Reply-To: References: Message-ID: Thanks for sharing some of your work with the community. However... Speaking to the sharing aspect: Why would you post a block of code in an email? If you're looking for people to contribute, it would likely be a much better idea to post it on github (which was built for collaborative work). As for the code itself, if you /know/ it sucks and are advertising it as such, you're not really enticing people to work on it. In its current state, it looks like a non-extensible prototype, just poking around to see how you can achieve a p2p connectivity, without doing /any/ research (supporting modules, etc) or design before just starting to throw something together. I'd venture to say that the chances of actually getting anyone to contribute to this in its current state (especially purely over a mailing list) would be slim to none. People generally tend to want to see that there's actually effort and thought put into something before they put /their/ own time into it. -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Fri Apr 5 21:07:21 2013 From: roy at panix.com (Roy Smith) Date: Fri, 05 Apr 2013 21:07:21 -0400 Subject: im.py: a python communications tool References: Message-ID: In article , Jake D wrote: > What is the licence? > --It's released under a special FOSS licence. Here it is: > ----You can do whatever you want with this program. I know this is off-topic, but I encourage people to NOT invent their own licenses. Take your pick of any of the well-known (Berkeley, MIT, GPL, etc) licenses, and use that. I used to work for a very large corporation. The legal department was (quite reasonably) concerned about use of FOSS, and all open source software we used needed to pass legal review. They were looking for two things. First, that the license didn't obligate the company to anything it didn't want to be obligated to (i.e. they wouldn't allow GPL3). Second, that YOU understood the terms of the license and had a plan in place to comply with all the requirements. The lawyers knew all the major licenses. If you showed up with something that was known (and acceptable) to them, the process was quick and (relatively) painless. If you showed up with some license they had no experience with, they would go off into a huddle and not come out until they were sure they understood it. The usual result was that anything that came with a one-off license was probably more trouble to get approved than it was worth. From dreamingforward at gmail.com Fri Apr 5 21:13:30 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Fri, 5 Apr 2013 18:13:30 -0700 Subject: im.py: a python communications tool In-Reply-To: References: Message-ID: On Fri, Apr 5, 2013 at 6:07 PM, Roy Smith wrote: > In article > , > Jake D wrote: > >> What is the licence? >> --It's released under a special FOSS licence. Here it is: >> ----You can do whatever you want with this program. > > I know this is off-topic, but I encourage people to NOT invent their own > licenses. Take your pick of any of the well-known (Berkeley, MIT, GPL, > etc) licenses, and use that. [...] That all being said, and excellent policy and commentary in general, no one should have trouble interpreting "do whatever you want with it", legally or otherwise. Mark From bahamutzero8825 at gmail.com Fri Apr 5 21:26:01 2013 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Fri, 05 Apr 2013 20:26:01 -0500 Subject: im.py: a python communications tool In-Reply-To: References: Message-ID: <515F79A9.1090100@gmail.com> On 2013.04.05 20:07, Roy Smith wrote: > I know this is off-topic, but I encourage people to NOT invent their own > licenses. Perhaps he meant this existing license: http://www.wtfpl.net/about/ -- CPython 3.3.0 | Windows NT 6.2.9200 / FreeBSD 9.1 From jhunter.dunefsky at gmail.com Sat Apr 6 10:54:28 2013 From: jhunter.dunefsky at gmail.com (Jake D) Date: Sat, 6 Apr 2013 07:54:28 -0700 (PDT) Subject: im.py: a python communications tool References: Message-ID: <1eaf6b81-276f-4662-ab85-2cdb7eae0150@y12g2000vbh.googlegroups.com> On Apr 5, 9:26?pm, Andrew Berg wrote: > On 2013.04.05 20:07, Roy Smith wrote:> I know this is off-topic, but I encourage people to NOT invent their own > > licenses. > > Perhaps he meant this existing license:http://www.wtfpl.net/about/ > -- > CPython 3.3.0 | Windows NT 6.2.9200 / FreeBSD 9.1 Yep. As a matter of fact, I did. From garabik-news-2005-05 at kassiopeia.juls.savba.sk Sun Apr 7 04:59:10 2013 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Sun, 7 Apr 2013 08:59:10 +0000 (UTC) Subject: im.py: a python communications tool References: Message-ID: Andrew Berg wrote: > On 2013.04.05 20:07, Roy Smith wrote: >> I know this is off-topic, but I encourage people to NOT invent their own >> licenses. > Perhaps he meant this existing license: http://www.wtfpl.net/about/ I like the Python Powered Logo license by Just van Rossum (Guido's brother, in case someone doesn't know..) http://mail.python.org/pipermail/python-list/1999-December/013413.html -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From jhunter.dunefsky at gmail.com Sun Apr 7 17:47:11 2013 From: jhunter.dunefsky at gmail.com (jhunter.dunefsky at gmail.com) Date: Sun, 7 Apr 2013 14:47:11 -0700 (PDT) Subject: im.py: a python communications tool In-Reply-To: References: Message-ID: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> On Sunday, April 7, 2013 4:59:10 AM UTC-4, garabik-ne... at kassiopeia.juls.savba.sk wrote: > Andrew Berg wrote: > > > On 2013.04.05 20:07, Roy Smith wrote: > > >> I know this is off-topic, but I encourage people to NOT invent their own > > >> licenses. > > > Perhaps he meant this existing license: http://www.wtfpl.net/about/ > > > > I like the Python Powered Logo license by Just van Rossum (Guido's > > brother, in case someone doesn't know..) > > > > http://mail.python.org/pipermail/python-list/1999-December/013413.html > > > > -- > > ----------------------------------------------------------- > > | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | > > | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | > > ----------------------------------------------------------- > > Antivirus alert: file .signature infected by signature virus. > > Hi! I'm a signature virus! Copy me into your signature file to help me spread! Actually, my current licence can be found here: https://github.com/jhunter-d/im.py/blob/master/LICENCE. Whaddaya think about this, Useneters? From steve+comp.lang.python at pearwood.info Sun Apr 7 18:36:57 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Apr 2013 22:36:57 GMT Subject: im.py: a python communications tool References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> Message-ID: <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> On Sun, 07 Apr 2013 14:47:11 -0700, jhunter.dunefsky wrote: > Actually, my current licence can be found here: > https://github.com/jhunter-d/im.py/blob/master/LICENCE. Whaddaya think > about this, Useneters? I think you're looking for a world of pain, when somebody uses your software, it breaks something, and they sue you. Your licence currently means that you are responsible for the performance of your software. Why don't you use a recognised, tested, legally-correct licence, like the MIT licence, instead of trying to be clever and/or lazy with a one-liner? E.g. http://opensource.org/licenses/MIT Software licencing is a solved problem. Do you really think that people write three or four paragraph licences because they *like* legal boilerplate? Did you imagine that you were the first person to think, "I know! I'll write a one-liner telling people they can do whatever they want with my software! Nothing can possibly go wrong!"? Use a known, tested, working solution, and save yourself the pain. -- Steven From rosuav at gmail.com Sun Apr 7 23:00:09 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 8 Apr 2013 13:00:09 +1000 Subject: im.py: a python communications tool In-Reply-To: <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Apr 8, 2013 at 8:36 AM, Steven D'Aprano wrote: > On Sun, 07 Apr 2013 14:47:11 -0700, jhunter.dunefsky wrote: > >> Actually, my current licence can be found here: >> https://github.com/jhunter-d/im.py/blob/master/LICENCE. Whaddaya think >> about this, Useneters? > > > I think you're looking for a world of pain, when somebody uses your > software, it breaks something, and they sue you. Your licence currently > means that you are responsible for the performance of your software. > > Why don't you use a recognised, tested, legally-correct licence, like the > MIT licence, instead of trying to be clever and/or lazy with a one-liner? > > E.g. http://opensource.org/licenses/MIT Plus there's the whole brevity thing. If I see something that says "MIT license", I don't need to read the details. Compare the README for one of my projects: https://github.com/Rosuav/Gypsum/blob/master/README (Actually, I need to update that; there are a few solved problems listed there as still open.) You read "Licensed under the BSD Open Source license" and then you can stop reading - you know what your rights are. The lawyers at Roy Smith's company would have no trouble comprehending this, and no trouble deciding whether or not it's allowed - they either do or do not (there is no try). License proliferation is actually a major problem. If I were to lift code from your program and incorporate it into something GPL3, am I violating either's terms? What if I want to put that code into something BSD 2-clause? Am I allowed? At least if you use a well-known license, I can do a quick web search, coming up with something like [1], but a custom or unusual license would require careful analysis of terms. [1] http://www.dwheeler.com/essays/floss-license-slide.html ChrisA From jhunter.dunefsky at gmail.com Mon Apr 8 06:48:42 2013 From: jhunter.dunefsky at gmail.com (Jake D) Date: Mon, 8 Apr 2013 03:48:42 -0700 (PDT) Subject: im.py: a python communications tool References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Apr 7, 6:36?pm, Steven D'Aprano wrote: > On Sun, 07 Apr 2013 14:47:11 -0700, jhunter.dunefsky wrote: > > Actually, my current licence can be found here: > >https://github.com/jhunter-d/im.py/blob/master/LICENCE. ?Whaddaya think > > about this, Useneters? > > I think you're looking for a world of pain, when somebody uses your > software, it breaks something, and they sue you. Your licence currently > means that you are responsible for the performance of your software. > > Why don't you use a recognised, tested, legally-correct licence, like the > MIT licence, instead of trying to be clever and/or lazy with a one-liner? > > E.g.http://opensource.org/licenses/MIT > > Software licencing is a solved problem. Do you really think that people > write three or four paragraph licences because they *like* legal > boilerplate? Did you imagine that you were the first person to think, "I > know! I'll write a one-liner telling people they can do whatever they > want with my software! Nothing can possibly go wrong!"? > > Use a known, tested, working solution, and save yourself the pain. > > -- > Steven MIT is actually the best one I've seen so far. I'm updating LICENCE. From dreamingforward at gmail.com Mon Apr 8 19:16:54 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Mon, 8 Apr 2013 16:16:54 -0700 Subject: im.py: a python communications tool In-Reply-To: <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Apr 7, 2013 at 3:36 PM, Steven D'Aprano wrote: > On Sun, 07 Apr 2013 14:47:11 -0700, jhunter.dunefsky wrote: > >> Actually, my current licence can be found here: >> https://github.com/jhunter-d/im.py/blob/master/LICENCE. Whaddaya think >> about this, Useneters? > > > I think you're looking for a world of pain, when somebody uses your > software, it breaks something, and they sue you. Your licence currently > means that you are responsible for the performance of your software. Steven, they can't sue you for something they didn't pay for, because they never entered into an agreement, not did you. Mark Janssen Tacoma, Washington. From davea at davea.name Mon Apr 8 22:05:45 2013 From: davea at davea.name (Dave Angel) Date: Mon, 08 Apr 2013 22:05:45 -0400 Subject: im.py: a python communications tool In-Reply-To: References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51637779.7020209@davea.name> On 04/08/2013 07:16 PM, Mark Janssen wrote: > On Sun, Apr 7, 2013 at 3:36 PM, Steven D'Aprano > wrote: >> On Sun, 07 Apr 2013 14:47:11 -0700, jhunter.dunefsky wrote: >> >>> Actually, my current licence can be found here: >>> https://github.com/jhunter-d/im.py/blob/master/LICENCE. Whaddaya think >>> about this, Useneters? >> >> >> I think you're looking for a world of pain, when somebody uses your >> software, it breaks something, and they sue you. Your licence currently >> means that you are responsible for the performance of your software. > > Steven, they can't sue you for something they didn't pay for, because > they never entered into an agreement, not did you. > That's a common misconception. No prior agreement is necessary to institute a lawsuit, at least in the United States. I'm not a lawyer, but I've been advised that the best you can hope for is to minimize the likelihood that a lawsuit will be successful, not to somehow guarantee that a lawsuit cannot be filed and prosecuted. Besides, an open-ended license might be acted on anywhere in the world, and who knows what some other jurisdictions might permit/require. -- DaveA From dreamingforward at gmail.com Mon Apr 8 23:37:46 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Mon, 8 Apr 2013 20:37:46 -0700 Subject: im.py: a python communications tool In-Reply-To: <51637779.7020209@davea.name> References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> Message-ID: On Mon, Apr 8, 2013 at 7:05 PM, Dave Angel wrote: > On 04/08/2013 07:16 PM, Mark Janssen wrote: >> >> On Sun, Apr 7, 2013 at 3:36 PM, Steven D'Aprano >> wrote: >>> >>> On Sun, 07 Apr 2013 14:47:11 -0700, jhunter.dunefsky wrote: >>> >>>> Actually, my current licence can be found here: >>>> https://github.com/jhunter-d/im.py/blob/master/LICENCE. Whaddaya think >>>> about this, Useneters? >>> >>> >>> >>> I think you're looking for a world of pain, when somebody uses your >>> software, it breaks something, and they sue you. Your licence currently >>> means that you are responsible for the performance of your software. >> >> >> Steven, they can't sue you for something they didn't pay for, because >> they never entered into an agreement, not did you. >> > > That's a common misconception. No prior agreement is necessary to institute > a lawsuit, at least in the United States. I'm not a lawyer, but I've been > advised that the best you can hope for is to minimize the likelihood that a > lawsuit will be successful, not to somehow guarantee that a lawsuit cannot > be filed and prosecuted. Clearly anyone can file a lawsuit, I could file one against you for offending me, for example. The issue I was poorly raising is whether such a case would have merit. In the case of free (libre) open source software, such a case would have no merit, because such software never promises anyone *anything*. But someone would have to make the case and "train" the court. The court simply has not become appraised of what free, libre, open source software is. Really, one shouldn't be so afraid of such things and intimidated of our own system of law -- this is why the republic has degraded to lawyers, not representatives of the People. If a hospital takes your open source code and someone dies, the hospital must be held responsible, because the open source developer is not posing as an expert of anything, nor has she made it for some explicit purpose for you like in a commercial agreement. Mark From davea at davea.name Tue Apr 9 02:04:27 2013 From: davea at davea.name (Dave Angel) Date: Tue, 09 Apr 2013 02:04:27 -0400 Subject: im.py: a python communications tool In-Reply-To: References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> Message-ID: <5163AF6B.7040104@davea.name> On 04/08/2013 11:37 PM, Mark Janssen wrote: > On Mon, Apr 8, 2013 at 7:05 PM, Dave Angel wrote: >> On 04/08/2013 07:16 PM, Mark Janssen wrote: >>> >>> On Sun, Apr 7, 2013 at 3:36 PM, Steven D'Aprano >>> wrote: >>>> >>>> On Sun, 07 Apr 2013 14:47:11 -0700, jhunter.dunefsky wrote: >>>> >>>>> Actually, my current licence can be found here: >>>>> https://github.com/jhunter-d/im.py/blob/master/LICENCE. Whaddaya think >>>>> about this, Useneters? >>>> >>>> >>>> >>>> I think you're looking for a world of pain, when somebody uses your >>>> software, it breaks something, and they sue you. Your licence currently >>>> means that you are responsible for the performance of your software. >>> >>> >>> Steven, they can't sue you for something they didn't pay for, because >>> they never entered into an agreement, not did you. >>> >> >> That's a common misconception. No prior agreement is necessary to institute >> a lawsuit, at least in the United States. I'm not a lawyer, but I've been >> advised that the best you can hope for is to minimize the likelihood that a >> lawsuit will be successful, not to somehow guarantee that a lawsuit cannot >> be filed and prosecuted. > > Clearly anyone can file a lawsuit, I could file one against you for > offending me, for example. The issue I was poorly raising is whether > such a case would have merit. In the case of free (libre) open source > software, such a case would have no merit, because such software never > promises anyone *anything*. I'm not a lawyer, and I suspect you're not either. If a burglar climbs up my trellis to try to attain a second floor window, and comes crashing to the ground, he may very well successfully sue me for not having a warning sign. Especially if "I" am a company. And especially if I have an "attractive nuisance" around. There are lots of implied agreements that have been successfully used by the opposing lawyers. But someone would have to make the case > and "train" the court. The court simply has not become appraised of > what free, libre, open source software is. Now you're assuming that there is such a definition, and that the court could be convinced to follow your interpretation. I claim that no amateur should try to word his own agreement. Either get an expert to help, or refer to an agreement that was prepared by such experts. Don't make the assumption that because something is free, it's somehow immune from liability. I expect it's safer to have no agreement at all, than to have one that gives away privileges without explicitly declaring or disclaiming any responsibilities. > Really, one shouldn't be > so afraid of such things and intimidated of our own system of law -- > this is why the republic has degraded to lawyers, not representatives > of the People. If a hospital takes your open source code and someone > dies, the hospital must be No, *should* *be* > held responsible, because the open source > developer is not posing as an expert of anything, nor has she made it > for some explicit purpose for you like in a commercial agreement. > > Mark > > -- DaveA From dreamingforward at gmail.com Tue Apr 9 02:20:54 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Mon, 8 Apr 2013 23:20:54 -0700 Subject: im.py: a python communications tool In-Reply-To: <5163AF6B.7040104@davea.name> References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> <5163AF6B.7040104@davea.name> Message-ID: > I'm not a lawyer, and I suspect you're not either. If a burglar climbs up > my trellis to try to attain a second floor window, and comes crashing to the > ground, he may very well successfully sue me for not having a warning sign. No, I understand these cases are common lore, but it's this bullshit which is ruining everything that was balanced by the Constitution. By propagating such ideas, it continues the idea that we're all victims to our own system of law, but we are the tacit *creators* of it by our own negligence, and frankly, pessimism. This is a system of, by and for the People -- those are the words of the Constitution of the United States which is the highest law of the land. People need to fight this "enabler" creep, that allows it to continually be co-opted by fear-story, like the one that was being propagated earlier. We're not victims here. The story of a burglar suing a homeowner is either urban myth and a hoax, or a gross default somewhere in the judicial system. It should not be considered case history or "de facto" law and left at that. >> If a hospital takes your open source code and someone >> dies, the hospital must be > > No, *should* *be* > >> held responsible, because the open source >> developer is not posing as an expert of anything, nor has she made it >> for some explicit purpose for you like in a commercial agreement. (re: must vs. should) Legally, you are right, but I was speaking from the point of view of a judge, rather than a lawyer. Like the sheriff says: "I make the law around here!" lol. Mark From demianbrecht at gmail.com Tue Apr 9 02:42:06 2013 From: demianbrecht at gmail.com (Demian Brecht) Date: Mon, 8 Apr 2013 23:42:06 -0700 Subject: im.py: a python communications tool In-Reply-To: References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> <5163AF6B.7040104@davea.name> Message-ID: We're /definitely/ on topic for this list. Just saying. On Mon, Apr 8, 2013 at 11:20 PM, Mark Janssen wrote: >> I'm not a lawyer, and I suspect you're not either. If a burglar climbs up >> my trellis to try to attain a second floor window, and comes crashing to the >> ground, he may very well successfully sue me for not having a warning sign. > > No, I understand these cases are common lore, but it's this bullshit > which is ruining everything that was balanced by the Constitution. By > propagating such ideas, it continues the idea that we're all victims > to our own system of law, but we are the tacit *creators* of it by our > own negligence, and frankly, pessimism. > > This is a system of, by and for the People -- those are the words of > the Constitution of the United States which is the highest law of the > land. People need to fight this "enabler" creep, that allows it to > continually be co-opted by fear-story, like the one that was being > propagated earlier. We're not victims here. The story of a burglar > suing a homeowner is either urban myth and a hoax, or a gross default > somewhere in the judicial system. It should not be considered case > history or "de facto" law and left at that. > >>> If a hospital takes your open source code and someone >>> dies, the hospital must be >> >> No, *should* *be* >> >>> held responsible, because the open source >>> developer is not posing as an expert of anything, nor has she made it >>> for some explicit purpose for you like in a commercial agreement. > > (re: must vs. should) Legally, you are right, but I was speaking from > the point of view of a judge, rather than a lawyer. Like the sheriff > says: "I make the law around here!" lol. > > Mark > -- > http://mail.python.org/mailman/listinfo/python-list -- Demian Brecht http://demianbrecht.github.com From davea at davea.name Tue Apr 9 02:42:30 2013 From: davea at davea.name (Dave Angel) Date: Tue, 09 Apr 2013 02:42:30 -0400 Subject: im.py: a python communications tool In-Reply-To: References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> <5163AF6B.7040104@davea.name> Message-ID: <5163B856.90107@davea.name> On 04/09/2013 02:20 AM, Mark Janssen wrote: >> I'm not a lawyer, and I suspect you're not either. If a burglar climbs up >> my trellis to try to attain a second floor window, and comes crashing to the >> ground, he may very well successfully sue me for not having a warning sign. > > No, I understand these cases are common lore, but it's this bullshit > which is ruining everything that was balanced by the Constitution. By > propagating such ideas, it continues the idea that we're all victims > to our own system of law, but we are the tacit *creators* of it by our > own negligence, and frankly, pessimism. I like to be pessimistic when signing the documents that might ruin my own future. In my last job, I told the company lawyers I would not accept the NDA as they supplied it, and they claimed I was the first one to successfully force a new version. As HR put it, most people don't even read it, they figure it's a requirement to work. > > This is a system of, by and for the People -- those are the words of > the Constitution of the United States which is the highest law of the > land. People need to fight this "enabler" creep, that allows it to > continually be co-opted by fear-story, like the one that was being > propagated earlier. We're not victims here. The story of a burglar > suing a homeowner is either urban myth and a hoax, or a gross default > somewhere in the judicial system. It should not be considered case > history or "de facto" law and left at that. > >>> If a hospital takes your open source code and someone >>> dies, the hospital must be >> >> No, *should* *be* >> >>> held responsible, because the open source >>> developer is not posing as an expert of anything, nor has she made it >>> for some explicit purpose for you like in a commercial agreement. > > (re: must vs. should) Legally, you are right, but I was speaking from > the point of view of a judge, rather than a lawyer. Like the sheriff > says: "I make the law around here!" lol. > I can't really argue your points, and once a challenge is made, I'm thoroughly in agreement. But it's much easier to keep things clear from the beginning, and I've been assuming our job here was to advise the OP on whether his plan for a license agreement is good. Years ago I managed to get our company lawyers to approve the use of "free" software for internal use, but getting the custom license agreement past them was like pulling teeth. -- DaveA From steve+comp.lang.python at pearwood.info Tue Apr 9 02:47:50 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Apr 2013 06:47:50 GMT Subject: im.py: a python communications tool References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> <5163AF6B.7040104@davea.name> Message-ID: <5163b996$0$29977$c3e8da3$5496439d@news.astraweb.com> On Mon, 08 Apr 2013 23:20:54 -0700, Mark Janssen wrote: >> I'm not a lawyer, and I suspect you're not either. If a burglar climbs >> up my trellis to try to attain a second floor window, and comes >> crashing to the ground, he may very well successfully sue me for not >> having a warning sign. > > No, I understand these cases are common lore, but it's this bullshit > which is ruining everything that was balanced by the Constitution. Which Constitution is that? The Russian Constitution? Italian? Japanese? Brazilian? New Zealand? Serbian? South African? > By > propagating such ideas, it continues the idea that we're all victims to > our own system of law, but we are the tacit *creators* of it by our own > negligence, and frankly, pessimism. > > This is a system of, by and for the People -- those are the words of the > Constitution of the United States which is the highest law of the land. Speak for yourself. Not everyone here is a Yankie. > People need to fight this "enabler" creep, that allows it to continually > be co-opted by fear-story, like the one that was being propagated > earlier. We're not victims here. The story of a burglar suing a > homeowner is either urban myth and a hoax, Maybe, maybe not, but it's irrelevant. We're not talking about somebody breaking into your home to steal your DVD, and on the way in, being injured by your software. We're talking about somebody using your software, *with your explicit permission*, and then having it cause them harm by being unfit for the purpose advertised. If you don't disclaim warranty, and even sometimes if you do, there is an implicit warranty that your goods will be fit for their purpose in many jurisdictions. In some places that may only apply if money changes hands; in other places it will apply regardless. -- Steven From dreamingforward at gmail.com Tue Apr 9 04:15:04 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Tue, 9 Apr 2013 01:15:04 -0700 Subject: im.py: a python communications tool In-Reply-To: <5163AF6B.7040104@davea.name> References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> <5163AF6B.7040104@davea.name> Message-ID: > I'm not a lawyer, and I suspect you're not either. By the way, here's where part of the problem stems, right here. This notion of that you have to be a lawyer -- as if their some other race or something. Lawyers are people, that have been trained into a historical system of conventions. That doesn't necessarily make them good counselors, and conversely non-lawyers can be better defenders than "lawyers". As long as this (US) is a constitutional republic, it is of, by and for, the people. There is legally no grounds to deprive a citizen of a fair trial even if they don't have lawyer. The Establishment has been intimidating people for too long. I'm just calling it out, so my crowd (can I call it that?) doesn't give away it's power. Mark. From steve+comp.lang.python at pearwood.info Tue Apr 9 04:45:50 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Apr 2013 08:45:50 GMT Subject: im.py: a python communications tool References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> <5163AF6B.7040104@davea.name> Message-ID: <5163d53d$0$29977$c3e8da3$5496439d@news.astraweb.com> On Tue, 09 Apr 2013 01:15:04 -0700, Mark Janssen wrote: >> I'm not a lawyer, and I suspect you're not either. > > By the way, here's where part of the problem stems, right here. This > notion of that you have to be a lawyer -- as if their some other race or > something. You wouldn't go to a lawyer for advice on the best way to program. You wouldn't go to a car mechanic to ask for the best way to set a broken leg. You wouldn't go to a professional gardener to ask how to fight a land war in Asia. Sure, Mike the Personal Injury Lawyer happens to also be a hotshot programmer with 35 years of experience in C, Fortran, Lisp, Python, Perl, Java, Ruby, PHP, Smalltalk and Haskell. Good for him, and if you know him, then maybe you would ask him programming questions in preference to a lot of programmers. But that's Mike. 99% of lawyers have no idea about the difference between a hash table and a linked list, and 30% think that cloud computing has something to do with real clouds. Dave might be an awesome car mechanic who can fix anything with an engine, but that doesn't mean he knows shit about what sort of licence and warranty disclaimer is best. It's just damn common sense that, when faced with a legal issue, you ask a legal expert, not a programmer or a butcher or a candle-stick maker. http://demotivationalblog.com/demotivational/2010/03/common-sense.jpg -- Steven From dreamingforward at gmail.com Tue Apr 9 05:00:47 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Tue, 9 Apr 2013 02:00:47 -0700 Subject: im.py: a python communications tool In-Reply-To: <5163d53d$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> <5163AF6B.7040104@davea.name> <5163d53d$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: >> By the way, here's where part of the problem stems, right here. This >> notion of that you have to be a lawyer -- as if their some other race or >> something. > > You wouldn't go to a lawyer for advice on the best way to program. You > wouldn't go to a car mechanic to ask for the best way to set a broken > leg. You wouldn't go to a professional gardener to ask how to fight a > land war in Asia. Yeah and a programmer wouldn't go to a lawyer to GIVE SOMETHING AWAY FOR FREE! I mean I couldn't brainwash this kind of common sense into a person. Mark From davea at davea.name Tue Apr 9 05:18:59 2013 From: davea at davea.name (Dave Angel) Date: Tue, 09 Apr 2013 05:18:59 -0400 Subject: im.py: a python communications tool In-Reply-To: References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> <5163AF6B.7040104@davea.name> <5163d53d$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5163DD03.1050608@davea.name> On 04/09/2013 05:00 AM, Mark Janssen wrote: >>> By the way, here's where part of the problem stems, right here. This >>> notion of that you have to be a lawyer -- as if their some other race or >>> something. >> >> You wouldn't go to a lawyer for advice on the best way to program. You >> wouldn't go to a car mechanic to ask for the best way to set a broken >> leg. You wouldn't go to a professional gardener to ask how to fight a >> land war in Asia. > > Yeah and a programmer wouldn't go to a lawyer to GIVE SOMETHING AWAY > FOR FREE! I mean I couldn't brainwash this kind of common sense into > a person. > And the same thinking would say that there's no need to ever change the oil in a car, just add more when the dipstick gets too low. And no need to kill the weeds in a lawn, just keep spreading more grass seed. And no need to call a plumber for a leak, just wrap it in lots of duct tape. And no need for liability insurance for your house, as nobody's gotten hurt yet. And no need to hire a programmer for a payroll program, just let Jimmy the receptionist write it in his spare time. I recently talked to a small business entrepreneur who thought she didn't have to charge or file sales tax, because her business was still small. Her accountant told her that was fine. I told her to ask a lawyer. Lots of obvious generalizations out there which are wrong, at least some of the time. -- DaveA From dreamingforward at gmail.com Tue Apr 9 05:32:21 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Tue, 9 Apr 2013 02:32:21 -0700 Subject: im.py: a python communications tool In-Reply-To: <5163DD03.1050608@davea.name> References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> <5163AF6B.7040104@davea.name> <5163d53d$0$29977$c3e8da3$5496439d@news.astraweb.com> <5163DD03.1050608@davea.name> Message-ID: > Lots of obvious generalizations out there which are wrong, at least some of > the time. You know, Dave.... funny thing is, right there is one of them. -- MarkJ Tacoma, Washington From rosuav at gmail.com Tue Apr 9 03:14:53 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 9 Apr 2013 17:14:53 +1000 Subject: im.py: a python communications tool In-Reply-To: References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> Message-ID: On Tue, Apr 9, 2013 at 1:37 PM, Mark Janssen wrote: > In the case of free (libre) open source > software, such a case would have no merit, because such software never > promises anyone *anything*. If that is the case, it's because the software license explicitly says so - which is the reason for all those uppercase words in those licenses. Which brings us right back to where we started. ChrisA From dreamingforward at gmail.com Tue Apr 9 03:20:27 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Tue, 9 Apr 2013 00:20:27 -0700 Subject: im.py: a python communications tool In-Reply-To: References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> Message-ID: On Tue, Apr 9, 2013 at 12:14 AM, Chris Angelico wrote: > On Tue, Apr 9, 2013 at 1:37 PM, Mark Janssen wrote: >> In the case of free (libre) open source >> software, such a case would have no merit, because such software never >> promises anyone *anything*. > > If that is the case, it's because the software license explicitly says > so - which is the reason for all those uppercase words in those > licenses. Which brings us right back to where we started. It doesn't have to say so, if it's not charging any money -- there's no expectation that you're getting anything at all! Where does everyone come up with these bullshit ideas? And them let them stand as de facto law? Mark From rosuav at gmail.com Tue Apr 9 03:21:42 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 9 Apr 2013 17:21:42 +1000 Subject: im.py: a python communications tool In-Reply-To: References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> Message-ID: On Tue, Apr 9, 2013 at 5:20 PM, Mark Janssen wrote: > On Tue, Apr 9, 2013 at 12:14 AM, Chris Angelico wrote: >> On Tue, Apr 9, 2013 at 1:37 PM, Mark Janssen wrote: >>> In the case of free (libre) open source >>> software, such a case would have no merit, because such software never >>> promises anyone *anything*. >> >> If that is the case, it's because the software license explicitly says >> so - which is the reason for all those uppercase words in those >> licenses. Which brings us right back to where we started. > > It doesn't have to say so, if it's not charging any money -- there's > no expectation that you're getting anything at all! Where does > everyone come up with these bullshit ideas? And them let them stand > as de facto law? Where do YOU come up with the idea that you can't be sued if money didn't change hands? In what jurisdiction is that true? Unless it's true in every jurisdiction that the internet touches, I wouldn't trust it to protect me. ChrisA From dreamingforward at gmail.com Tue Apr 9 03:39:21 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Tue, 9 Apr 2013 00:39:21 -0700 Subject: im.py: a python communications tool In-Reply-To: References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> Message-ID: > Where do YOU come up with the idea that you can't be sued if money > didn't change hands? In what jurisdiction is that true? Unless it's > true in every jurisdiction that the internet touches, I wouldn't trust > it to protect me. I know, the legal system has us all under their thumbs. If I hand you a rose, will you sue me because it doesn't smell like one? If no money changed hands? I don't have to cite anything! This is argument of the absurd and should be inadmissible. Honestly, it's all because of this Novus Ordo Seclorum bullshit. Mark From steve+comp.lang.python at pearwood.info Tue Apr 9 04:31:12 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Apr 2013 08:31:12 GMT Subject: im.py: a python communications tool References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> Message-ID: <5163d1d0$0$29977$c3e8da3$5496439d@news.astraweb.com> On Tue, 09 Apr 2013 00:39:21 -0700, Mark Janssen wrote: >> Where do YOU come up with the idea that you can't be sued if money >> didn't change hands? In what jurisdiction is that true? Unless it's >> true in every jurisdiction that the internet touches, I wouldn't trust >> it to protect me. > > I know, the legal system has us all under their thumbs. If I hand you a > rose, will you sue me because it doesn't smell like one? Are you harmed by the fact that the rose doesn't have a scent? If there is no harm, there is no grounds for a lawsuit. What counts as harm will depend on the jurisdiction, but I'm not aware of any place where "I was disappointed that it didn't smell nice" counts as harm. Is there an implied promise that the rose I gave you will have a scent? I don't think so, there are many roses that don't have a scent. There is, however, an implied promise that the rose is safe. If I lace the rose with a toxic chemical, and you get sick after handling it, you probably could sue me even if the rose was a free gift. And so you should -- if I am stupid, careless or malicious enough to hand out toxic products that cause harm, I ought to take responsibility for my actions. If I won't take responsibility, then the law enforcement and legal systems ought to force me to take responsibility. > If no money > changed hands? I don't have to cite anything! This is argument of the > absurd and should be inadmissible. I love a good fantasy as much as the next guy, but I live in reality. In reality, people do have the expectation that products are fit for their purpose, and if they don't, some percentage of them will attempt to sue. For the sake of an extra dozen or so lines giving an explicit disclaimer, you can protect yourself from all but the most ignorant or malicious plaintiffs. Why would anyone rely on *wishful thinking* instead of a short, proven, effective legal licence? > Honestly, it's all because of this Novus Ordo Seclorum bullshit. You've dropped your tinfoil hat. Watch out, the CIA will start beaming thoughts into your head. -- Steven From dreamingforward at gmail.com Tue Apr 9 04:58:25 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Tue, 9 Apr 2013 01:58:25 -0700 Subject: im.py: a python communications tool In-Reply-To: <5163d1d0$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> <5163d1d0$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: >>> Where do YOU come up with the idea that you can't be sued if money >>> didn't change hands? In what jurisdiction is that true? Unless it's >>> true in every jurisdiction that the internet touches, I wouldn't trust >>> it to protect me. >> >> I know, the legal system has us all under their thumbs. If I hand you a >> rose, will you sue me because it doesn't smell like one? > > Are you harmed by the fact that the rose doesn't have a scent? If there > is no harm, there is no grounds for a lawsuit. What counts as harm will > depend on the jurisdiction, but I'm not aware of any place where "I was > disappointed that it didn't smell nice" counts as harm. What if my thumb gets pricked by a thorn on the rose? Let's see.... > There is, however, an implied promise that the rose is safe. > I love a good fantasy as much as the next guy, but I live in reality. Okay. > In > reality, people do have the expectation that products are fit for their > purpose, and if they don't, some percentage of them will attempt to sue. To the extent that Free Software isn't sold, it's not a product. To the extent that the software is taken at the effort of the user, rather than *given* by the programmer, there is no purpose -- neither explicitly or *implicitly* implied. Just like if I were to pick off a teddybear on a table sitting on a curb with a sign that says "free". Ask yourself, tin-foil-hatless man, why don't you suggest a sign that says "take at your own risk, no warranty implied"? Because you don't want to make a society that is that stupid about things, that's why. Now stop pandering to the bar association. You've accepted the market mentality and applied it to our world of free and open source software. It's supposed to be about community and having fun. > For the sake of an extra dozen or so lines giving an explicit disclaimer, > you can protect yourself from all but the most ignorant or malicious > plaintiffs. That might be, but if you include such a wily lawyer could suggest that by the very act of including a legal disclaimer you're moved yourself into a contract negotiation and are expected to be more strict in your terms. > Why would anyone rely on *wishful thinking* instead of a short, proven, > effective legal licence? I told you above. I don't want a world like you're suggesting where people can't just say "you can do what you want with this software", but should be lawyers instead. >> Honestly, it's all because of this Novus Ordo Seclorum bullshit. > > You've dropped your tinfoil hat. Watch out, the CIA will start beaming > thoughts into your head. I know. It got you didn't it. But you'll note that Latin is also used as a language of the court. If you want tin foil hats, though, you'll have to notice what's right in front of your face -- you already have voodoo right on your currency that YOU have accepted. Egyptian pyramids on the U.S. dollar? All seeing eye? It's you who have the burden of explanation brother, because it doesn't make any sense without going to outer space. Mark From rosuav at gmail.com Tue Apr 9 05:40:24 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 9 Apr 2013 19:40:24 +1000 Subject: im.py: a python communications tool In-Reply-To: References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> <5163d1d0$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Apr 9, 2013 at 6:58 PM, Mark Janssen wrote: > If you want tin foil hats, though, > you'll have to notice what's right in front of your face -- you > already have voodoo right on your currency that YOU have accepted. > Egyptian pyramids on the U.S. dollar? All seeing eye? I'm sorry, I'm somewhat lost here. The dollar I have here has a mob of animals on one side and someone's face on the other - no pyramids, no all-seeing-eye. ChrisA (And yeah, a mob of animals. You'll either know or not know why it's a mob.) From dreamingforward at gmail.com Tue Apr 9 05:46:43 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Tue, 9 Apr 2013 02:46:43 -0700 Subject: im.py: a python communications tool In-Reply-To: References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> <5163d1d0$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Apr 9, 2013 at 2:40 AM, Chris Angelico wrote: > On Tue, Apr 9, 2013 at 6:58 PM, Mark Janssen wrote: >> If you want tin foil hats, though, >> you'll have to notice what's right in front of your face -- you >> already have voodoo right on your currency that YOU have accepted. >> Egyptian pyramids on the U.S. dollar? All seeing eye? > > I'm sorry, I'm somewhat lost here. The dollar I have here has a mob of > animals on one side and someone's face on the other - no pyramids, no > all-seeing-eye. Please pardon the implicit Americanism, I didn't disclaim my speech because I think all G8-20? countries are somewhat accountable for basing their currency or referencing their currency upon it (is this true from European views?). In any case, trading with America, they entangle themselves with its history -- including the Native American near-genocide that happened here and the human rights abuses that continue to this day. Is it not strange that no one notices this while the talking heads on TV go on about human rights in some far-away land that they hardly know? Mark From rosuav at gmail.com Tue Apr 9 05:48:41 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 9 Apr 2013 19:48:41 +1000 Subject: im.py: a python communications tool In-Reply-To: References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> <5163d1d0$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Apr 9, 2013 at 7:46 PM, Mark Janssen wrote: > On Tue, Apr 9, 2013 at 2:40 AM, Chris Angelico wrote: >> On Tue, Apr 9, 2013 at 6:58 PM, Mark Janssen wrote: >>> If you want tin foil hats, though, >>> you'll have to notice what's right in front of your face -- you >>> already have voodoo right on your currency that YOU have accepted. >>> Egyptian pyramids on the U.S. dollar? All seeing eye? >> >> I'm sorry, I'm somewhat lost here. The dollar I have here has a mob of >> animals on one side and someone's face on the other - no pyramids, no >> all-seeing-eye. > > Please pardon the implicit Americanism, I didn't disclaim my speech > because I think all G8-20? countries are somewhat accountable for > basing their currency or referencing their currency upon it (is this > true from European views?). In any case, trading with America, they > entangle themselves with its history -- including the Native American > near-genocide that happened here and the human rights abuses that > continue to this day. Is it not strange that no one notices this > while the talking heads on TV go on about human rights in some > far-away land that they hardly know? Okay. I've read your post. Read it again. Rubbed my eyes in case there was something in them and gone back for another read. And I can't conjure any response but this: Wut? ChrisA From jhunter.dunefsky at gmail.com Tue Apr 9 07:09:08 2013 From: jhunter.dunefsky at gmail.com (Jake D) Date: Tue, 9 Apr 2013 04:09:08 -0700 (PDT) Subject: im.py: a python communications tool References: <51637779.7020209@davea.name> <5163d1d0$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <085be1f6-8871-48c2-bfd1-0ca97819fcea@z4g2000vbz.googlegroups.com> I just put out a new version of im.py on GitHub. You can find it here: https://github.com/jhunter-d/im.py/blob/master/im.py From steve+comp.lang.python at pearwood.info Tue Apr 9 09:03:32 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Apr 2013 13:03:32 GMT Subject: im.py: a python communications tool References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> <5163d1d0$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <516411a4$0$30003$c3e8da3$5496439d@news.astraweb.com> On Tue, 09 Apr 2013 19:40:24 +1000, Chris Angelico wrote: > On Tue, Apr 9, 2013 at 6:58 PM, Mark Janssen > wrote: >> If you want tin foil hats, though, >> you'll have to notice what's right in front of your face -- you already >> have voodoo right on your currency that YOU have accepted. Egyptian >> pyramids on the U.S. dollar? All seeing eye? > > I'm sorry, I'm somewhat lost here. The dollar I have here has a mob of > animals on one side and someone's face on the other - no pyramids, no > all-seeing-eye. It must be counterfeit! Send it to me, I'll dispose of it safely. -- Steven From rosuav at gmail.com Tue Apr 9 09:23:40 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 9 Apr 2013 23:23:40 +1000 Subject: im.py: a python communications tool In-Reply-To: <516411a4$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> <5163d1d0$0$29977$c3e8da3$5496439d@news.astraweb.com> <516411a4$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Apr 9, 2013 at 11:03 PM, Steven D'Aprano wrote: > On Tue, 09 Apr 2013 19:40:24 +1000, Chris Angelico wrote: > >> I'm sorry, I'm somewhat lost here. The dollar I have here has a mob of >> animals on one side and someone's face on the other - no pyramids, no >> all-seeing-eye. > > It must be counterfeit! > > Send it to me, I'll dispose of it safely. Ahh, you studied counterfeit-recognition under the tutelage of Dennis Bloodnok, I see. ChrisA From invalid at invalid.invalid Tue Apr 9 10:41:29 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 9 Apr 2013 14:41:29 +0000 (UTC) Subject: im.py: a python communications tool References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> <5163d1d0$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-04-09, Mark Janssen wrote: >>>> Where do YOU come up with the idea that you can't be sued if money >>>> didn't change hands? In what jurisdiction is that true? Unless it's >>>> true in every jurisdiction that the internet touches, I wouldn't trust >>>> it to protect me. >>> >>> I know, the legal system has us all under their thumbs. If I hand you a >>> rose, will you sue me because it doesn't smell like one? >> >> Are you harmed by the fact that the rose doesn't have a scent? If there >> is no harm, there is no grounds for a lawsuit. What counts as harm will >> depend on the jurisdiction, but I'm not aware of any place where "I was >> disappointed that it didn't smell nice" counts as harm. > > What if my thumb gets pricked by a thorn on the rose? Let's see.... [In the US] 1) You've got to show that the prick was harmful enough to you that it merits legal remedy. 2) You've got to show that you had a reasonable expectation that roses didn't have thorns. 3) You've got to show that whoever gave you the rose should have forseen that would be harmed. 4) For extra bonus points, you try to show that whoever gave you the rose knew you would be harmed or indended to harm you. [In some areas of civil law, you can cash in your bonus points from step four for treble damages!] Are there that many people in the country who have no clue how the legal system works? -- Grant Edwards grant.b.edwards Yow! UH-OH!! I put on at "GREAT HEAD-ON TRAIN gmail.com COLLISIONS of the 50's" by mistake!!! From dreamingforward at gmail.com Tue Apr 9 12:36:39 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Tue, 9 Apr 2013 09:36:39 -0700 Subject: im.py: a python communications tool In-Reply-To: References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> <5163d1d0$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: > Are there that many people in the country who have no clue how the > legal system works? Gads. I'm trying to show you how the legal system *doesn't* work. All your points may be valid under court history, but that history is tainted. It doesn't mean the system is working, only that cases have been decided. And the court should not be ruling on issues of such accidents because guilt cannot established ("accidents" where there was no intention of harm, nor tacit agreement made between any parties) like a person giving a rose to their neighbor in an act of good will. Such events should use mediators, not judges because their is no *law* to be decided. The judges, or course, can act as mediators, but the court system seems bogged down enough already. I mean really, a good-will act? The Good Samaritan rules already establish that you can't sue people for good faith acts. Do you really want a world where *good intentions* are penalized? Come on -- that's why the system is broken and shame on every citizen that continues this error in system of the People. It doesn't matter if people get harmed, as long as good faith is in place before and after the event. The "system" shouldn't get dragged in because you want to act like a child and get your daddy to help you. Mark From invalid at invalid.invalid Tue Apr 9 10:30:13 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 9 Apr 2013 14:30:13 +0000 (UTC) Subject: im.py: a python communications tool References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> Message-ID: On 2013-04-09, Mark Janssen wrote: >> Where do YOU come up with the idea that you can't be sued if money >> didn't change hands? In what jurisdiction is that true? Unless it's >> true in every jurisdiction that the internet touches, I wouldn't trust >> it to protect me. > > I know, the legal system has us all under their thumbs. If I hand you > a rose, will you sue me because it doesn't smell like one? He might. To win, he'd first have to show standing: he'd have to prove that he was harmed (directly or indirectly by your action). > If no money changed hands? [As usual: IANAL so consule a real lawyer before giving away roses that don't smell like roses.] Doesn't matter. What matters first is harm. Once he establishes that he was harmed because the rose didn't smell, then the question of responsibility for that harm arises. Did you intend the harm? Did you forsee (or should have forseen) the harm? Did you warn him about the possibility of harm or take any other actions to prevent forseeable harm? > I don't have to cite anything! This is argument of the absurd and > should be inadmissible. Absurdity has nothing to with it, we're talking about the law. :) -- Grant Edwards grant.b.edwards Yow! But they went to MARS at around 1953!! gmail.com From breamoreboy at yahoo.co.uk Tue Apr 9 12:10:43 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 09 Apr 2013 17:10:43 +0100 Subject: im.py: a python communications tool In-Reply-To: References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> Message-ID: On 09/04/2013 08:21, Chris Angelico wrote: > On Tue, Apr 9, 2013 at 5:20 PM, Mark Janssen wrote: >> On Tue, Apr 9, 2013 at 12:14 AM, Chris Angelico wrote: >>> On Tue, Apr 9, 2013 at 1:37 PM, Mark Janssen wrote: >>>> In the case of free (libre) open source >>>> software, such a case would have no merit, because such software never >>>> promises anyone *anything*. >>> >>> If that is the case, it's because the software license explicitly says >>> so - which is the reason for all those uppercase words in those >>> licenses. Which brings us right back to where we started. >> >> It doesn't have to say so, if it's not charging any money -- there's >> no expectation that you're getting anything at all! Where does >> everyone come up with these bullshit ideas? And them let them stand >> as de facto law? > > Where do YOU come up with the idea that you can't be sued if money > didn't change hands? In what jurisdiction is that true? Unless it's > true in every jurisdiction that the internet touches, I wouldn't trust > it to protect me. > > ChrisA > The same place that he came up with this thread "Message passing syntax for objects" on Python ideas? What the BDFL thought of it here http://code.activestate.com/lists/python-ideas/20043/ -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From steve+comp.lang.python at pearwood.info Tue Apr 9 03:38:32 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Apr 2013 07:38:32 GMT Subject: im.py: a python communications tool References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> Message-ID: <5163c578$0$29977$c3e8da3$5496439d@news.astraweb.com> On Tue, 09 Apr 2013 00:20:27 -0700, Mark Janssen wrote: > On Tue, Apr 9, 2013 at 12:14 AM, Chris Angelico > wrote: >> On Tue, Apr 9, 2013 at 1:37 PM, Mark Janssen >> wrote: >>> In the case of free (libre) open source software, such a case would >>> have no merit, because such software never promises anyone *anything*. >> >> If that is the case, it's because the software license explicitly says >> so - which is the reason for all those uppercase words in those >> licenses. Which brings us right back to where we started. > > It doesn't have to say so, if it's not charging any money -- there's no > expectation that you're getting anything at all! Of course there is. If Oprah Winfrey stands up and publicly says that she's giving you a car, FOR FREE, no strings attached, and then gives you a piece of old bubblegum, you have standing to sue for breach of promise. If she gives you the car, but puts it down as a *prize* rather than a gift, then there is a big, hefty string attached: income tax. http://money.cnn.com/2004/09/22/news/newsmakers/oprah_car_tax/index.htm And if she gives you a car, only the brake lines have been disconnected and you're seriously injured the first time you drive it, you also have standing to sue that she gave you a car that was unfit for the purpose it was designed. > Where does everyone > come up with these bullshit ideas? I've been wondering exactly the same thing... -- Steven From dreamingforward at gmail.com Tue Apr 9 04:02:14 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Tue, 9 Apr 2013 01:02:14 -0700 Subject: im.py: a python communications tool In-Reply-To: <5163c578$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> <5163c578$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: >> It doesn't have to say so, if it's not charging any money -- there's no >> expectation that you're getting anything at all! > > Of course there is. If Oprah Winfrey stands up and publicly says that > she's giving you a car, FOR FREE, no strings attached, and then gives you > a piece of old bubblegum, you have standing to sue for breach of promise. > If she gives you the car, but puts it down as a *prize* rather than a > gift, then there is a big, hefty string attached: income tax. But you see, there's the critical difference. First of all you're making two errors in your comparison. Firstly, a *person* is saying that she's going to *do something for you*. She's making a promise. If I put a piece of software online -- you're taking it! That's #1 (!) Number 2, you used Oprah, a public figure, to make you're argument. Legally, the issue is not so much that she's a public figure, but that she's making a *published* claim. It could be Joe Blow posting a notice around town making the claim. Now such claims don't have much legal standing, because a lawyer could argue that Joe Blow is a nut job and such offers can't be trusted. If you want grounds for breach of a promise you better get it in writing and counter-signed. > And if she gives you a car, only the brake lines have been disconnected > and you're seriously injured the first time you drive it, you also have > standing to sue that she gave you a car that was unfit for the purpose it > was designed. Okay, if the TV show disconnected the brake lines, there could be argument of criminal negligence on her production, but otherwise the car company could be sued. You don't sue Oprah because she's not the one who designed it. Mark From ramit.prasad at jpmorgan.com Fri Apr 12 15:46:13 2013 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 12 Apr 2013 19:46:13 +0000 Subject: im.py: a python communications tool In-Reply-To: References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> <5163c578$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5B80DD153D7D744689F57F4FB69AF474182F6BDD@SCACMX008.exchad.jpmchase.net> Mark Janssen wrote: > >> It doesn't have to say so, if it's not charging any money -- there's no > >> expectation that you're getting anything at all! > > > > Of course there is. If Oprah Winfrey stands up and publicly says that > > she's giving you a car, FOR FREE, no strings attached, and then gives you > > a piece of old bubblegum, you have standing to sue for breach of promise. > > If she gives you the car, but puts it down as a *prize* rather than a > > gift, then there is a big, hefty string attached: income tax. > > But you see, there's the critical difference. First of all you're > making two errors in your comparison. Firstly, a *person* is saying > that she's going to *do something for you*. She's making a promise. > If I put a piece of software online -- you're taking it! That's #1 > (!) Theoretically isn't putting a piece of software "online" akin to publishing it? Following that logic, then there is the possibility of arguing an implicit promise that the software does what it is supposed to. Any bugs would be the responsibility of the developer. On a separate note, even if the judgment supports your view and the developer is never responsible for damages, will you still not be responsible for any court/lawyer fees? And getting those fees paid by suitor will likely be another court case. ~Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From dreamingforward at gmail.com Fri Apr 12 15:57:59 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Fri, 12 Apr 2013 12:57:59 -0700 Subject: im.py: a python communications tool In-Reply-To: <5B80DD153D7D744689F57F4FB69AF474182F6BDD@SCACMX008.exchad.jpmchase.net> References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> <5163c578$0$29977$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF474182F6BDD@SCACMX008.exchad.jpmchase.net> Message-ID: On Fri, Apr 12, 2013 at 12:46 PM, Prasad, Ramit wrote: > Mark Janssen wrote: >> But you see, there's the critical difference. First of all you're >> making two errors in your comparison. Firstly, a *person* is saying >> that she's going to *do something for you*. She's making a promise. >> If I put a piece of software online -- you're taking it! That's #1 >> (!) > > Theoretically isn't putting a piece of software "online" akin to > publishing it? Following that logic, then there is the possibility > of arguing an implicit promise that the software does what it is > supposed to. Any bugs would be the responsibility of the developer. It is akin to publishing it. The law has not made a good distinction about responsibility in this area. But I'm telling you that unless money is exchanged THERE IS NO AGREEMENT MADE, implicit or otherwise. If there is no agreement, then another party can't blame you for something you didn't promise. Otherwise, I can blame you for insulting my fashion sense. > On a separate note, even if the judgment supports your view > and the developer is never responsible for damages, will you > still not be responsible for any court/lawyer fees? If someone brings you to court and fails to make their case, they've inconvenienced everyone. The fair thing would be for the court to require them to pay for your fees. >And > getting those fees paid by suitor will likely be another court case. Possibily, but don't accept this view of the legal system. Judges can be quite reasonable. They don't want more time taken for bullshit cases and would much prefer for things to be settled (that is what their duty is -- to settle matters, not to make lawyers wealthy). Mark From neilc at norwich.edu Fri Apr 12 16:05:40 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 12 Apr 2013 20:05:40 GMT Subject: im.py: a python communications tool References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> <5163c578$0$29977$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF474182F6BDD@SCACMX008.exchad.jpmchase.net> Message-ID: On 2013-04-12, Mark Janssen wrote: > Possibily, but don't accept this view of the legal system. > Judges can be quite reasonable. They don't want more time > taken for bullshit cases and would much prefer for things to be > settled (that is what their duty is -- to settle matters, not > to make lawyers wealthy). Wishful thinking is the wrong way to approach any legal matter. -- Neil Cerutti From ramit.prasad at jpmorgan.com Fri Apr 12 17:48:52 2013 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 12 Apr 2013 21:48:52 +0000 Subject: im.py: a python communications tool In-Reply-To: References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> <5163c578$0$29977$c3e8da3$5496439d@news.astraweb.com> <5B80DD153D7D744689F57F4FB69AF474182F6BDD@SCACMX008.exchad.jpmchase.net> Message-ID: <5B80DD153D7D744689F57F4FB69AF474182F6FF8@SCACMX008.exchad.jpmchase.net> Neil Cerutti wrote: > On 2013-04-12, Mark Janssen wrote: > > Possibily, but don't accept this view of the legal system. > > Judges can be quite reasonable. They don't want more time > > taken for bullshit cases and would much prefer for things to be > > settled (that is what their duty is -- to settle matters, not > > to make lawyers wealthy). > > Wishful thinking is the wrong way to approach any legal matter. > He is not completely wishful (for USA). http://www.macrumors.com/2013/04/11/u-s-judge-expresses-frustration-at-apples-and-googles-use-of-litigation-as-business-strategy/ Of course, not sure if the frustration will actually lead to an action or is just idle talk. ~Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From steve+comp.lang.python at pearwood.info Tue Apr 9 05:08:41 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Apr 2013 09:08:41 GMT Subject: im.py: a python communications tool References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> <5163c578$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5163da98$0$29977$c3e8da3$5496439d@news.astraweb.com> On Tue, 09 Apr 2013 01:02:14 -0700, Mark Janssen wrote: >>> It doesn't have to say so, if it's not charging any money -- there's >>> no expectation that you're getting anything at all! >> >> Of course there is. If Oprah Winfrey stands up and publicly says that >> she's giving you a car, FOR FREE, no strings attached, and then gives >> you a piece of old bubblegum, you have standing to sue for breach of >> promise. If she gives you the car, but puts it down as a *prize* rather >> than a gift, then there is a big, hefty string attached: income tax. > > But you see, there's the critical difference. First of all you're > making two errors in your comparison. Firstly, a *person* is saying > that she's going to *do something for you*. She's making a promise. If > I put a piece of software online -- you're taking it! That's #1 (!) And by putting it online for free download, IN THE ABSENCE OF AN EXPLICIT DISCLAIMER, you are implying that it is fit for its purpose, and that you have a duty of care to make sure that it does do what you say it does. If you go into a restaurant, and they have bowls of breadsticks free for people to eat, and you eat one, and it had a needle in it and you stabbed yourself and got infected, don't you think that the restaurant ought to take responsibility for their carelessness? Don't you think that it is pretty shitty, weaselly behaviour for them to say "But you didn't pay for the breadstick! We never promised that it wouldn't contain an AIDS- infected needle!" The principle is the same. There is an implied warranty that a breadstick will not contain infected needles, and that software will do what you say it does. If it doesn't, and people are harmed by that, then you ought to live up to your responsibility. Or, *you warn them ahead of time* that you take no responsibility, with an explicit warranty disclaimer. WARNING: Breadsticks in this restaurant may contain infected needles. Eat at your own risk! > Number 2, you used Oprah, a public figure, to make you're argument. The fact that she's a public figure is irrelevant. [...] >> And if she gives you a car, only the brake lines have been disconnected >> and you're seriously injured the first time you drive it, you also have >> standing to sue that she gave you a car that was unfit for the purpose >> it was designed. > > Okay, if the TV show disconnected the brake lines, there could be > argument of criminal negligence on her production, but otherwise the car > company could be sued. You don't sue Oprah because she's not the one > who designed it. That will surely depend on the jurisdiction. Some places may reason that your relationship was with Oprah (to be precise, her production company that actually gave you the car), that she had a duty of care, and so it is her that you should sue. It is then Oprah's responsibility to sue the manufacturer. Other places might decide that Oprah's company had no duty of care to ensure that the car was in a fit state, and responsibility was entirely on the car manufacturer. Some places might reason that you can sue both, and it is up to the court to decide what percentage of responsibility each party must take. Which case it is will depend on the laws of whichever place has legal jurisdiction. -- Steven From dreamingforward at gmail.com Tue Apr 9 05:29:43 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Tue, 9 Apr 2013 02:29:43 -0700 Subject: im.py: a python communications tool In-Reply-To: <5163da98$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> <5163c578$0$29977$c3e8da3$5496439d@news.astraweb.com> <5163da98$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: > And by putting it online for free download, IN THE ABSENCE OF AN EXPLICIT > DISCLAIMER, you are implying that it is fit for its purpose, and that you > have a duty of care to make sure that it does do what you say it does. No, there is no requirement for a disclaimer. In the US, what is not explicitly restricted by the law is withheld by the citizen. I don't have to give a disclaimer if my intentions are in good faith. And further, I'm not saying that it's fit for a purpose in some trade-like agreement. So I'm not in possible breach of any agreement whatsoever. > If you go into a restaurant, and they have bowls of breadsticks free for > people to eat, and you eat one, and it had a needle in it and you stabbed > yourself and got infected, don't you think that the restaurant ought to > take responsibility for their carelessness? If I go to a freebiebox placed outside a restaurant with such, no, I'm taking responsibility. "Caveat emptor" as they say and here's there's no buyer. If I go to a table and there are free breadstix on the table and start eating them without intentions to pay, then I'm the shithole. If I get infected from some food at a restaurant which I paid for, then each side will have to argue their case. The court may find negligence on the side of the restaurant, or it may not. > Don't you think that it is > pretty shitty, weaselly behaviour for them to say "But you didn't pay for > the breadstick! We never promised that it wouldn't contain an AIDS- > infected needle!" Hey, you know it's expected that if someone gets hurt from something you provided, but you didnt' intend it on them and didn't make any money off of them, that you still say you're sorry. Each person in a government of the people is expected to do their fair part in using commonsense. The courts can't deal with every little squabble. > The principle is the same. There is an implied warranty that a breadstick > will not contain infected needles, and that software will do what you say > it does. No to the latter. As for the former, if I'm at a restaurant I'm entering a business relationship. The cost of the breadsticks are already bundled in the other food you are *expected* to order. > WARNING: Breadsticks in this restaurant may contain infected needles. > Eat at your own risk! Here again your letting the Novus Ordo "market mentality" dominate your thinking when it should be on about person-to-person simple interactions. Unless of course, you've allowed corporations to be people, and your in a corporate restaurant, please no. >> Okay, if the TV show disconnected the brake lines, there could be >> argument of criminal negligence on her production, but otherwise the car >> company could be sued. You don't sue Oprah because she's not the one >> who designed it. > > That will surely depend on the jurisdiction. Some places may reason that > your relationship was with Oprah (to be precise, her production company > that actually gave you the car), that she had a duty of care, and so it > is her that you should sue. It is then Oprah's responsibility to sue the > manufacturer. Well, out here in the good ol' USA, there no "duty of care", because you're not a child being taken care of and Oprah is not someone acting "in loco parentis". The 14th(?) amendment give equal treatment under the law, there's no duty of care unless you can argue that it's expected of your adult ass getting on TV. MarkJ From steve+comp.lang.python at pearwood.info Tue Apr 9 09:05:23 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Apr 2013 13:05:23 GMT Subject: im.py: a python communications tool References: <48f984a0-7702-4cba-9021-06c3985646da@googlegroups.com> <5161f508$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637779.7020209@davea.name> <5163c578$0$29977$c3e8da3$5496439d@news.astraweb.com> <5163da98$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51641212$0$30003$c3e8da3$5496439d@news.astraweb.com> On Tue, 09 Apr 2013 02:29:43 -0700, Mark Janssen wrote: > Well, out here in the good ol' USA, there no "duty of care" That explains a lot. -- Steven From jhunter.dunefsky at gmail.com Sat Apr 6 11:35:11 2013 From: jhunter.dunefsky at gmail.com (Jake D) Date: Sat, 6 Apr 2013 08:35:11 -0700 (PDT) Subject: im.py: a python communications tool References: Message-ID: <7fe0e77d-efe1-4663-aec0-3301f0d1d629@a3g2000vbr.googlegroups.com> On Apr 5, 8:52?pm, Demian Brecht wrote: > Thanks for sharing some of your work with the community. However... > > Speaking to the sharing aspect: Why would you post a block of code in an > email? If you're looking for people to contribute, it would likely be a > much better idea to post it on github (which was built for collaborative > work). > > As for the code itself, if you /know/ it sucks and are advertising it as > such, you're not really enticing people to work on it. In its current > state, it looks like a non-extensible prototype, just poking around to see > how you can achieve a p2p connectivity, without doing /any/ research > (supporting modules, etc) or design before just starting to throw something > together. > > I'd venture to say that the chances of actually getting anyone to > contribute to this in its current state (especially purely over a mailing > list) would be slim to none. People generally tend to want to see that > there's actually effort and thought put into something before they put > /their/ own time into it. Jeez, harsh. I __am__ putting this on github, and I __am__ coming back to this program and working on it now. From chris at simplistix.co.uk Fri Apr 5 20:41:51 2013 From: chris at simplistix.co.uk (Chris Withers) Date: Fri, 05 Apr 2013 21:41:51 -0300 Subject: xlwt 0.7.5 released! Message-ID: <515F6F4F.6060405@simplistix.co.uk> Hi All, I'm pleased to announce the release of xlwt 0.7.5. This release contains the following: - Fixes a bug that could cause a corrupt SST in .xls files written by a wide-unicode Python build. - A ValueError is now raised immediately if an attempt is made to set column width to other than an int in range(65536) - Added the ability to set a custom RGB colour in the palette to use for colours. Thanks to Alan Rotman for the work, although this could really use an example in the examples folder... - Fixed an issue trying to set a diagonal border using easyxf. Thanks to Neil Etheridge for the fix. - Fixed a regression from 0.7.2 when writing sheets with frozen panes. If you find any problems, please ask about them on the python-excel at googlegroups.com list, or submit an issue on GitHub: https://github.com/python-excel/xlwt/issues There's also details of all things Python and Excel related here: http://www.python-excel.org/ cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From usmani.kashif9957 at gmail.com Fri Apr 5 23:20:05 2013 From: usmani.kashif9957 at gmail.com (usmani.kashif9957 at gmail.com) Date: Fri, 5 Apr 2013 20:20:05 -0700 (PDT) Subject: mock django cache Message-ID: <66eb7077-77ab-434b-aa19-a7a6d8bc687a@googlegroups.com> In my settings.py , I have specified my cache as : CACHES = { 'default': { ...... } } In my views.py, I have import requests from django.core.cache import cache, get_cache def aview(): #check cache if not get_cache('default').get('key'): #make request and save in cache result = request.get('some_url') get_cache('default').set('key', result) return result else: return get_cache('default').get('key') Now in my tests.py, I have been able to mock requests.get('aurl'), so that makes sure that no external requests are made. But the test code still hits the cache and gets/sets from it. So if my prod has already set the cache, then test is failing because it gets the data from same cache. Or if I run my tests first, then the test case is setting the cache with test data and I see that same reflected when I run prod website. How can I mock the calls to get_cache('default').set('key', result) and get_cache('default').get('key') so that the set call does not sets the real cache ( return None?) and get does not return anything in actual cache. Please provide me with code sample to how to get this done. Here is how I have mocked my requests.get def test_get_aview(self): with mock.patch('requests.get') as mymock: mymock.side_effect = (lambda url: MOCKED_DATA[url]) What code can I put after this to make it work? I tried something like class MockCacheValue(mock.MagicMock): def get(self, key): print 'here' return None def set(self, key, value): print 'here 2' pass def test_get_aview(self): with mock.patch('requests.get') as mymock: mymock.side_effect = (lambda url: MOCKED_DATA[url]) mock.patch('django.core.cache.get_cache', new=MockCacheValue) but it does not work and putting a print statement inside get/set above does not print anything giving me an idea that its not mocked properly From jeanmichel at sequans.com Mon Apr 8 04:56:53 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 8 Apr 2013 10:56:53 +0200 (CEST) Subject: mock django cache In-Reply-To: <66eb7077-77ab-434b-aa19-a7a6d8bc687a@googlegroups.com> Message-ID: <1128545288.7616578.1365411413808.JavaMail.root@sequans.com> ----- Original Message ----- > In my settings.py , I have specified my cache as : > CACHES = { > 'default': { > ...... > } > } > > In my views.py, I have > > import requests > from django.core.cache import cache, get_cache > > def aview(): > #check cache > if not get_cache('default').get('key'): > #make request and save in cache > result = request.get('some_url') > get_cache('default').set('key', result) > return result > else: > return get_cache('default').get('key') > > > Now in my tests.py, I have been able to mock requests.get('aurl'), so > that makes sure that no external requests are made. > > But the test code still hits the cache and gets/sets from it. So if > my prod has already set the cache, then test is failing because it > gets the data from same cache. Or if I run my tests first, then the > test case is setting the cache with test data and I see that same > reflected when I run prod website. > > How can I mock the calls to get_cache('default').set('key', result) > and get_cache('default').get('key') so that the set call does not > sets the real cache ( return None?) and get does not return anything > in actual cache. > > Please provide me with code sample to how to get this done. > > Here is how I have mocked my requests.get > > def test_get_aview(self): > with mock.patch('requests.get') as mymock: > mymock.side_effect = (lambda url: MOCKED_DATA[url]) > > What code can I put after this to make it work? I tried something > like > > > class MockCacheValue(mock.MagicMock): > def get(self, key): > print 'here' > return None > def set(self, key, value): > print 'here 2' > pass > > def test_get_aview(self): > with mock.patch('requests.get') as mymock: > mymock.side_effect = (lambda url: MOCKED_DATA[url]) > mock.patch('django.core.cache.get_cache', > new=MockCacheValue) > > but it does not work and putting a print statement inside get/set > above does not print anything giving me an idea that its not mocked > properly Having a quick look at django doc, get_cache() returns a cache which has get set methods, so you need get_cache to return a Mock object that mock the get and set method. Try something like : mock.patch('django.core.cache.get_cache',Mock(return_value=MockCacheValue()) JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From 1248283536 at qq.com Sat Apr 6 01:11:52 2013 From: 1248283536 at qq.com (=?gb18030?B?y66+ssH3ye4=?=) Date: Sat, 6 Apr 2013 13:11:52 +0800 Subject: parse the file Message-ID: I have an xml file. http://s.yunio.com/bmCS5h It is the list of my files in Google-blogger, how can I parse it in python to get every article?please give me the right code,which can get exact result. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dylan at dje.me Sun Apr 7 04:45:49 2013 From: dylan at dje.me (Dylan Evans) Date: Sun, 7 Apr 2013 18:45:49 +1000 Subject: parse the file In-Reply-To: References: Message-ID: You can read the fantastic manual at http://docs.python.org/2/library/xml.etree.elementtree.html or i'm sure someone will do it for a modest fee. On Sat, Apr 6, 2013 at 3:11 PM, ???? <1248283536 at qq.com> wrote: > I have an xml file . http://s.yunio.com/bmCS5h > > It is the list of my files in Google-blogger, how can I parse it in python > to get every article?please give me the right code,which can get exact > result. > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- "The UNIX system has a command, nice ... in order to be nice to the other users. Nobody ever uses it." - Andrew S. Tanenbaum -------------- next part -------------- An HTML attachment was scrubbed... URL: From phatbuckett at gmail.com Sat Apr 6 01:49:26 2013 From: phatbuckett at gmail.com (Darren Spruell) Date: Fri, 5 Apr 2013 22:49:26 -0700 Subject: Library to work with SSH public keys Message-ID: I'd like to work with user submitted/uploaded SSH public keys from Python. I'm trying to solve what I'd thought might be a simple need: given a user's OpenSSH formatted _public_ key (RSA, or DSA, or whatever), how do you obtain information about it such as: key type (e.g. ssh-rsa, etc.); bit length (e.g. 2048); key comment (e.g. user at hostname); key fingerprint? I've been fiddling with the Paramiko API and looked at PyCrypto (supports OpenSSH keys) and Twisted Conch but didn't see anything that looked like it did this. I'm looking for the equivalent to this: $ ssh-keygen -l -f tmp.key.pub 2048 9b:31:06:6a:a4:79:97:33:d7:20:15:1f:cd:b4:86:4d dspruell at Sydney.local (RSA) ...to get the attributes of the public key: key type, bit length, fingerprint and comment. Is there an SSH library capable of doing this from Python? Can break out to shell commands to parse them but I'd prefer not to. -- Darren Spruell phatbuckett at gmail.com From roy at panix.com Sat Apr 6 08:49:09 2013 From: roy at panix.com (Roy Smith) Date: Sat, 06 Apr 2013 08:49:09 -0400 Subject: Library to work with SSH public keys References: Message-ID: In article , Darren Spruell wrote: > I'd like to work with user submitted/uploaded SSH public keys from > Python. I'm trying to solve what I'd thought might be a simple need: > given a user's OpenSSH formatted _public_ key (RSA, or DSA, or > whatever), how do you obtain information about it such as: key type > (e.g. ssh-rsa, etc.); bit length (e.g. 2048); key comment (e.g. > user at hostname); key fingerprint? I've been fiddling with the Paramiko > API and looked at PyCrypto (supports OpenSSH keys) and Twisted Conch > but didn't see anything that looked like it did this. > > I'm looking for the equivalent to this: > > $ ssh-keygen -l -f tmp.key.pub > 2048 9b:31:06:6a:a4:79:97:33:d7:20:15:1f:cd:b4:86:4d dspruell at Sydney.local > (RSA) > > ...to get the attributes of the public key: key type, bit length, > fingerprint and comment. > > Is there an SSH library capable of doing this from Python? Can break > out to shell commands to parse them but I'd prefer not to. The first hit on googling "paramiko fingerprint" got me this: http://www.lag.net/paramiko/docs/paramiko.PKey-class.html From phatbuckett at gmail.com Sun Apr 7 03:51:48 2013 From: phatbuckett at gmail.com (Darren Spruell) Date: Sun, 7 Apr 2013 00:51:48 -0700 Subject: Library to work with SSH public keys In-Reply-To: References: Message-ID: On Sat, Apr 6, 2013 at 5:49 AM, Roy Smith wrote: > In article , > Darren Spruell wrote: > >> I'd like to work with user submitted/uploaded SSH public keys from >> Python. I'm trying to solve what I'd thought might be a simple need: >> given a user's OpenSSH formatted _public_ key (RSA, or DSA, or >> whatever), how do you obtain information about it such as: key type >> (e.g. ssh-rsa, etc.); bit length (e.g. 2048); key comment (e.g. >> user at hostname); key fingerprint? I've been fiddling with the Paramiko >> API and looked at PyCrypto (supports OpenSSH keys) and Twisted Conch >> but didn't see anything that looked like it did this. >> >> I'm looking for the equivalent to this: >> >> $ ssh-keygen -l -f tmp.key.pub >> 2048 9b:31:06:6a:a4:79:97:33:d7:20:15:1f:cd:b4:86:4d dspruell at Sydney.local >> (RSA) >> >> ...to get the attributes of the public key: key type, bit length, >> fingerprint and comment. >> >> Is there an SSH library capable of doing this from Python? Can break >> out to shell commands to parse them but I'd prefer not to. > > The first hit on googling "paramiko fingerprint" got me this: > > http://www.lag.net/paramiko/docs/paramiko.PKey-class.html Indeed, and I seem to find it's not suited for the need. Many of the methods appear to assume deriving information about public key parts from private key input or for handling public keys sent by server when connecting from client. I can't manage to wrangle desired or accurate data out of passing in OpenSSH format public keys from a user keypair (authentication key, not host key). -- Darren Spruell phatbuckett at gmail.com From breamoreboy at yahoo.co.uk Sat Apr 6 10:51:57 2013 From: breamoreboy at yahoo.co.uk (breamoreboy at yahoo.co.uk) Date: Sat, 6 Apr 2013 07:51:57 -0700 (PDT) Subject: [OT?]gmane not updating Message-ID: <9ef3499f-a063-49fc-aebc-7abea0232b07@googlegroups.com> The gmane site is online but none of the Python lists I subscribe to have been updated for over 24 hours. I fired off an email yesterday evening to larsi + gmane at gnus dot org but I've no idea whether there's anybody to read it, or even if it's actually been delivered :( Is there anybody lurking who could stir the embers to get things rolling? TIA. Mark Lawrence From breamoreboy at yahoo.co.uk Sat Apr 6 14:46:27 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 06 Apr 2013 19:46:27 +0100 Subject: [OT?]gmane not updating In-Reply-To: <9ef3499f-a063-49fc-aebc-7abea0232b07@googlegroups.com> References: <9ef3499f-a063-49fc-aebc-7abea0232b07@googlegroups.com> Message-ID: On 06/04/2013 15:51, breamoreboy at yahoo.co.uk wrote: > The gmane site is online but none of the Python lists I subscribe to have been updated for over 24 hours. I fired off an email yesterday evening to larsi + gmane at gnus dot org but I've no idea whether there's anybody to read it, or even if it's actually been delivered :( Is there anybody lurking who could stir the embers to get things rolling? > > TIA. > > Mark Lawrence > Forget it normal service has been resumed :) -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From ndbecker2 at gmail.com Sat Apr 6 15:01:51 2013 From: ndbecker2 at gmail.com (Neal Becker) Date: Sat, 06 Apr 2013 15:01:51 -0400 Subject: [OT?]gmane not updating References: <9ef3499f-a063-49fc-aebc-7abea0232b07@googlegroups.com> Message-ID: breamoreboy at yahoo.co.uk wrote: > The gmane site is online but none of the Python lists I subscribe to have been > updated for over 24 hours. I fired off an email yesterday evening to larsi + > gmane at gnus dot org but I've no idea whether there's anybody to read it, or > even if it's actually been delivered :( Is there anybody lurking who could > stir the embers to get things rolling? > > TIA. > > Mark Lawrence Working again. Funny how you come to rely on these things. There is no alternative to gmane. From kwpolska at gmail.com Sun Apr 7 10:41:45 2013 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Sun, 7 Apr 2013 16:41:45 +0200 Subject: [OT?]gmane not updating In-Reply-To: References: <9ef3499f-a063-49fc-aebc-7abea0232b07@googlegroups.com> Message-ID: On Sat, Apr 6, 2013 at 9:01 PM, Neal Becker wrote: > breamoreboy at yahoo.co.uk wrote: > >> The gmane site is online but none of the Python lists I subscribe to have been >> updated for over 24 hours. I fired off an email yesterday evening to larsi + >> gmane at gnus dot org but I've no idea whether there's anybody to read it, or >> even if it's actually been delivered :( Is there anybody lurking who could >> stir the embers to get things rolling? >> >> TIA. >> >> Mark Lawrence > > Working again. Funny how you come to rely on these things. There is no > alternative to gmane. > > -- > http://mail.python.org/mailman/listinfo/python-list There is: http://mail.python.org/mailman/listinfo/python-list ? it?s the official (as in PSF) mirror of comp.lang.python. Much more fun than gmane or usenet. -- Kwpolska | GPG KEY: 5EAAEA16 stop html mail | always bottom-post http://asciiribbon.org | http://caliburn.nl/topposting.html From invalid at invalid.invalid Sat Apr 6 16:53:29 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 6 Apr 2013 20:53:29 +0000 (UTC) Subject: [OT?]gmane not updating References: <9ef3499f-a063-49fc-aebc-7abea0232b07@googlegroups.com> Message-ID: On 2013-04-06, Neal Becker wrote: > Working again. Funny how you come to rely on these things. There is no > alternative to gmane. I try not to think about that. I read this "list" via Usenet, but there are a good dozen or so mailing lists for which I rely completely on gmane. -- Grant Edwards grant.b.edwards Yow! Those people look at exactly like Donnie and gmail.com Marie Osmond!! From subhabangalore at gmail.com Sat Apr 6 15:56:19 2013 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Sat, 6 Apr 2013 12:56:19 -0700 (PDT) Subject: Error in Python NLTK Message-ID: <8dd5cddd-792a-489f-bc1a-46026a227aa8@googlegroups.com> Dear Group, I was using a package named NLTK in Python. I was trying to write a code given in section 3.8 of http://docs.huihoo.com/nltk/0.9.5/guides/tag.html. Here, in the >>> test = ['up', 'down', 'up'] if I put more than 3 values and trying to write the reciprocal codes, like, sequence = [(t, None) for t in test] and print '%.3f' % (model.probability(sequence)) I am getting an error as, Traceback (most recent call last): File "", line 1, in model.probability(sequence) File "C:\Python27\lib\site-packages\nltk\tag\hmm.py", line 228, in probability return 2**(self.log_probability(self._transform.transform(sequence))) File "C:\Python27\lib\site-packages\nltk\tag\hmm.py", line 259, in log_probability alpha = self._forward_probability(sequence) File "C:\Python27\lib\site-packages\nltk\tag\hmm.py", line 694, in _forward_probability alpha[0, i] = self._priors.logprob(state) + \ File "C:\Python27\lib\site-packages\nltk\probability.py", line 689, in logprob elif self._prob_dict[sample] == 0: return _NINF ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() If any learned member may kindly assist me how may I solve the issue. Regards, Subhabrata. From davea at davea.name Sat Apr 6 16:44:41 2013 From: davea at davea.name (Dave Angel) Date: Sat, 06 Apr 2013 16:44:41 -0400 Subject: Error in Python NLTK In-Reply-To: <8dd5cddd-792a-489f-bc1a-46026a227aa8@googlegroups.com> References: <8dd5cddd-792a-489f-bc1a-46026a227aa8@googlegroups.com> Message-ID: <51608939.2070700@davea.name> On 04/06/2013 03:56 PM, subhabangalore at gmail.com wrote: > Dear Group, > > I was using a package named NLTK in Python. > > I was trying to write a code given in section 3.8 of > > http://docs.huihoo.com/nltk/0.9.5/guides/tag.html. > > Here, in the >>> test = ['up', 'down', 'up'] if I put more than 3 values and trying to write the reciprocal codes, like, > > sequence = [(t, None) for t in test] and print '%.3f' % (model.probability(sequence)) This 'and' operator is going to try to interpret the previous list as a boolean. Could that be your problem? Why aren't you putting these two statements on separate lines? And what version of Python are you using? If 2.x, you should get a syntax error because print is a statement. If 3.x, you should get a different error because you don't put parens around the preint expression. > > I am getting an error as, > > Traceback (most recent call last): File "", line 1, in model.probability(sequence) File "C:\Python27\lib\site-packages\nltk\tag\hmm.py", line 228, in probability return 2**(self.log_probability(self._transform.transform(sequence))) File "C:\Python27\lib\site-packages\nltk\tag\hmm.py", line 259, in log_probability alpha = self._forward_probability(sequence) File "C:\Python27\lib\site-packages\nltk\tag\hmm.py", line 694, in _forward_probability alpha[0, i] = self._priors.logprob(state) + \ File "C:\Python27\lib\site-packages\nltk\probability.py", line 689, in logprob elif self._prob_dict[sample] == 0: return _NINF ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() > > If any learned member may kindly assist me how may I solve the issue. > Your error display has been trashed, thanks to googlegroups. http://wiki.python.org/moin/GoogleGroupsPython Try posting with a text email message, since this is a text forum. Your code is also sparse. Why do you point us to fragments on the net, when you could show us the exact code you were running when it failed? I'm guessing you're running it from the interpreter, which can be very confusing once you have to ask for help. Please put a sample of code into a file, run it, and paste into your text email both the contents of that file and the full traceback. thanks. The email address to post on this forum is python-list at python.org -- DaveA From subhabangalore at gmail.com Sat Apr 6 17:13:57 2013 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Sat, 6 Apr 2013 14:13:57 -0700 (PDT) Subject: Error in Python NLTK In-Reply-To: References: <8dd5cddd-792a-489f-bc1a-46026a227aa8@googlegroups.com> Message-ID: <73d6289a-945d-4d1b-8a0c-9895ce7d6253@googlegroups.com> On Sunday, April 7, 2013 2:14:41 AM UTC+5:30, Dave Angel wrote: > On 04/06/2013 03:56 PM, subhabangalore at gmail.com wrote: > > > Dear Group, > > > > > > I was using a package named NLTK in Python. > > > > > > I was trying to write a code given in section 3.8 of > > > > > > http://docs.huihoo.com/nltk/0.9.5/guides/tag.html. > > > > > > Here, in the >>> test = ['up', 'down', 'up'] if I put more than 3 values and trying to write the reciprocal codes, like, > > > > > > sequence = [(t, None) for t in test] and print '%.3f' % (model.probability(sequence)) > > > > This 'and' operator is going to try to interpret the previous list as a > > boolean. Could that be your problem? Why aren't you putting these two > > statements on separate lines? And what version of Python are you using? > > If 2.x, you should get a syntax error because print is a statement. > > If 3.x, you should get a different error because you don't put parens > > around the preint expression. > > > > > > > > I am getting an error as, > > > > > > Traceback (most recent call last): File "", line 1, in model.probability(sequence) File "C:\Python27\lib\site-packages\nltk\tag\hmm.py", line 228, in probability return 2**(self.log_probability(self._transform.transform(sequence))) File "C:\Python27\lib\site-packages\nltk\tag\hmm.py", line 259, in log_probability alpha = self._forward_probability(sequence) File "C:\Python27\lib\site-packages\nltk\tag\hmm.py", line 694, in _forward_probability alpha[0, i] = self._priors.logprob(state) + \ File "C:\Python27\lib\site-packages\nltk\probability.py", line 689, in logprob elif self._prob_dict[sample] == 0: return _NINF ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() > > > > > > If any learned member may kindly assist me how may I solve the issue. > > > > > > > Your error display has been trashed, thanks to googlegroups. > > http://wiki.python.org/moin/GoogleGroupsPython > > Try posting with a text email message, since this is a text forum. > > > > Your code is also sparse. Why do you point us to fragments on the net, > > when you could show us the exact code you were running when it failed? > > I'm guessing you're running it from the interpreter, which can be very > > confusing once you have to ask for help. Please put a sample of code > > into a file, run it, and paste into your text email both the contents of > > that file and the full traceback. thanks. > > > > The email address to post on this forum is python-list at python.org > > > > > > -- > > DaveA Thanks Dave for your kind suggestions. I am checking on them and if I get any questions I am sending the room in detailed manner. Regards,Subhabrata. From subhabangalore at gmail.com Sat Apr 6 17:13:57 2013 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Sat, 6 Apr 2013 14:13:57 -0700 (PDT) Subject: Error in Python NLTK In-Reply-To: References: <8dd5cddd-792a-489f-bc1a-46026a227aa8@googlegroups.com> Message-ID: <73d6289a-945d-4d1b-8a0c-9895ce7d6253@googlegroups.com> On Sunday, April 7, 2013 2:14:41 AM UTC+5:30, Dave Angel wrote: > On 04/06/2013 03:56 PM, subhabangalore at gmail.com wrote: > > > Dear Group, > > > > > > I was using a package named NLTK in Python. > > > > > > I was trying to write a code given in section 3.8 of > > > > > > http://docs.huihoo.com/nltk/0.9.5/guides/tag.html. > > > > > > Here, in the >>> test = ['up', 'down', 'up'] if I put more than 3 values and trying to write the reciprocal codes, like, > > > > > > sequence = [(t, None) for t in test] and print '%.3f' % (model.probability(sequence)) > > > > This 'and' operator is going to try to interpret the previous list as a > > boolean. Could that be your problem? Why aren't you putting these two > > statements on separate lines? And what version of Python are you using? > > If 2.x, you should get a syntax error because print is a statement. > > If 3.x, you should get a different error because you don't put parens > > around the preint expression. > > > > > > > > I am getting an error as, > > > > > > Traceback (most recent call last): File "", line 1, in model.probability(sequence) File "C:\Python27\lib\site-packages\nltk\tag\hmm.py", line 228, in probability return 2**(self.log_probability(self._transform.transform(sequence))) File "C:\Python27\lib\site-packages\nltk\tag\hmm.py", line 259, in log_probability alpha = self._forward_probability(sequence) File "C:\Python27\lib\site-packages\nltk\tag\hmm.py", line 694, in _forward_probability alpha[0, i] = self._priors.logprob(state) + \ File "C:\Python27\lib\site-packages\nltk\probability.py", line 689, in logprob elif self._prob_dict[sample] == 0: return _NINF ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() > > > > > > If any learned member may kindly assist me how may I solve the issue. > > > > > > > Your error display has been trashed, thanks to googlegroups. > > http://wiki.python.org/moin/GoogleGroupsPython > > Try posting with a text email message, since this is a text forum. > > > > Your code is also sparse. Why do you point us to fragments on the net, > > when you could show us the exact code you were running when it failed? > > I'm guessing you're running it from the interpreter, which can be very > > confusing once you have to ask for help. Please put a sample of code > > into a file, run it, and paste into your text email both the contents of > > that file and the full traceback. thanks. > > > > The email address to post on this forum is python-list at python.org > > > > > > -- > > DaveA Thanks Dave for your kind suggestions. I am checking on them and if I get any questions I am sending the room in detailed manner. Regards,Subhabrata. From subhabangalore at gmail.com Sun Apr 7 16:20:38 2013 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Sun, 7 Apr 2013 13:20:38 -0700 (PDT) Subject: Error in Python NLTK In-Reply-To: References: <8dd5cddd-792a-489f-bc1a-46026a227aa8@googlegroups.com> Message-ID: On Sunday, April 7, 2013 2:14:41 AM UTC+5:30, Dave Angel wrote: > On 04/06/2013 03:56 PM, subhabangalore at gmail.com wrote: > > > Dear Group, > > > > > > I was using a package named NLTK in Python. > > > > > > I was trying to write a code given in section 3.8 of > > > > > > http://docs.huihoo.com/nltk/0.9.5/guides/tag.html. > > > > > > Here, in the >>> test = ['up', 'down', 'up'] if I put more than 3 values and trying to write the reciprocal codes, like, > > > > > > sequence = [(t, None) for t in test] and print '%.3f' % (model.probability(sequence)) > > > > This 'and' operator is going to try to interpret the previous list as a > > boolean. Could that be your problem? Why aren't you putting these two > > statements on separate lines? And what version of Python are you using? > > If 2.x, you should get a syntax error because print is a statement. > > If 3.x, you should get a different error because you don't put parens > > around the preint expression. > > > > > > > > I am getting an error as, > > > > > > Traceback (most recent call last): File "", line 1, in model.probability(sequence) File "C:\Python27\lib\site-packages\nltk\tag\hmm.py", line 228, in probability return 2**(self.log_probability(self._transform.transform(sequence))) File "C:\Python27\lib\site-packages\nltk\tag\hmm.py", line 259, in log_probability alpha = self._forward_probability(sequence) File "C:\Python27\lib\site-packages\nltk\tag\hmm.py", line 694, in _forward_probability alpha[0, i] = self._priors.logprob(state) + \ File "C:\Python27\lib\site-packages\nltk\probability.py", line 689, in logprob elif self._prob_dict[sample] == 0: return _NINF ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() > > > > > > If any learned member may kindly assist me how may I solve the issue. > > > > > > > Your error display has been trashed, thanks to googlegroups. > > http://wiki.python.org/moin/GoogleGroupsPython > > Try posting with a text email message, since this is a text forum. > > > > Your code is also sparse. Why do you point us to fragments on the net, > > when you could show us the exact code you were running when it failed? > > I'm guessing you're running it from the interpreter, which can be very > > confusing once you have to ask for help. Please put a sample of code > > into a file, run it, and paste into your text email both the contents of > > that file and the full traceback. thanks. > > > > The email address to post on this forum is python-list at python.org > > > > > > -- > > DaveA Dear Sir, I generally solved this problem from some other angle but I would like to fix this particular issue also so I am posting soon to you. Regards, Subhabrata. From subhabangalore at gmail.com Sun Apr 7 16:20:38 2013 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Sun, 7 Apr 2013 13:20:38 -0700 (PDT) Subject: Error in Python NLTK In-Reply-To: References: <8dd5cddd-792a-489f-bc1a-46026a227aa8@googlegroups.com> Message-ID: On Sunday, April 7, 2013 2:14:41 AM UTC+5:30, Dave Angel wrote: > On 04/06/2013 03:56 PM, subhabangalore at gmail.com wrote: > > > Dear Group, > > > > > > I was using a package named NLTK in Python. > > > > > > I was trying to write a code given in section 3.8 of > > > > > > http://docs.huihoo.com/nltk/0.9.5/guides/tag.html. > > > > > > Here, in the >>> test = ['up', 'down', 'up'] if I put more than 3 values and trying to write the reciprocal codes, like, > > > > > > sequence = [(t, None) for t in test] and print '%.3f' % (model.probability(sequence)) > > > > This 'and' operator is going to try to interpret the previous list as a > > boolean. Could that be your problem? Why aren't you putting these two > > statements on separate lines? And what version of Python are you using? > > If 2.x, you should get a syntax error because print is a statement. > > If 3.x, you should get a different error because you don't put parens > > around the preint expression. > > > > > > > > I am getting an error as, > > > > > > Traceback (most recent call last): File "", line 1, in model.probability(sequence) File "C:\Python27\lib\site-packages\nltk\tag\hmm.py", line 228, in probability return 2**(self.log_probability(self._transform.transform(sequence))) File "C:\Python27\lib\site-packages\nltk\tag\hmm.py", line 259, in log_probability alpha = self._forward_probability(sequence) File "C:\Python27\lib\site-packages\nltk\tag\hmm.py", line 694, in _forward_probability alpha[0, i] = self._priors.logprob(state) + \ File "C:\Python27\lib\site-packages\nltk\probability.py", line 689, in logprob elif self._prob_dict[sample] == 0: return _NINF ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() > > > > > > If any learned member may kindly assist me how may I solve the issue. > > > > > > > Your error display has been trashed, thanks to googlegroups. > > http://wiki.python.org/moin/GoogleGroupsPython > > Try posting with a text email message, since this is a text forum. > > > > Your code is also sparse. Why do you point us to fragments on the net, > > when you could show us the exact code you were running when it failed? > > I'm guessing you're running it from the interpreter, which can be very > > confusing once you have to ask for help. Please put a sample of code > > into a file, run it, and paste into your text email both the contents of > > that file and the full traceback. thanks. > > > > The email address to post on this forum is python-list at python.org > > > > > > -- > > DaveA Dear Sir, I generally solved this problem from some other angle but I would like to fix this particular issue also so I am posting soon to you. Regards, Subhabrata. From subhabangalore at gmail.com Sun Apr 7 18:11:36 2013 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Sun, 7 Apr 2013 15:11:36 -0700 (PDT) Subject: Error in Python NLTK In-Reply-To: References: <8dd5cddd-792a-489f-bc1a-46026a227aa8@googlegroups.com> Message-ID: <880e60a6-71a8-40c3-9887-f494924b8401@googlegroups.com> On Monday, April 8, 2013 1:50:38 AM UTC+5:30, subhaba... at gmail.com wrote: > On Sunday, April 7, 2013 2:14:41 AM UTC+5:30, Dave Angel wrote: > > > On 04/06/2013 03:56 PM, subhabangalore at gmail.com wrote: > > > > > > > Dear Group, > > > > > > > > > > > > > > I was using a package named NLTK in Python. > > > > > > > > > > > > > > I was trying to write a code given in section 3.8 of > > > > > > > > > > > > > > http://docs.huihoo.com/nltk/0.9.5/guides/tag.html. > > > > > > > > > > > > > > Here, in the >>> test = ['up', 'down', 'up'] if I put more than 3 values and trying to write the reciprocal codes, like, > > > > > > > > > > > > > > sequence = [(t, None) for t in test] and print '%.3f' % (model.probability(sequence)) > > > > > > > > > > > > This 'and' operator is going to try to interpret the previous list as a > > > > > > boolean. Could that be your problem? Why aren't you putting these two > > > > > > statements on separate lines? And what version of Python are you using? > > > > > > If 2.x, you should get a syntax error because print is a statement. > > > > > > If 3.x, you should get a different error because you don't put parens > > > > > > around the preint expression. > > > > > > > > > > > > > > > > > > > > I am getting an error as, > > > > > > > > > > > > > > Traceback (most recent call last): File "", line 1, in model.probability(sequence) File "C:\Python27\lib\site-packages\nltk\tag\hmm.py", line 228, in probability return 2**(self.log_probability(self._transform.transform(sequence))) File "C:\Python27\lib\site-packages\nltk\tag\hmm.py", line 259, in log_probability alpha = self._forward_probability(sequence) File "C:\Python27\lib\site-packages\nltk\tag\hmm.py", line 694, in _forward_probability alpha[0, i] = self._priors.logprob(state) + \ File "C:\Python27\lib\site-packages\nltk\probability.py", line 689, in logprob elif self._prob_dict[sample] == 0: return _NINF ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() > > > > > > > > > > > > > > If any learned member may kindly assist me how may I solve the issue. > > > > > > > > > > > > > > > > > > > Your error display has been trashed, thanks to googlegroups. > > > > > > http://wiki.python.org/moin/GoogleGroupsPython > > > > > > Try posting with a text email message, since this is a text forum. > > > > > > > > > > > > Your code is also sparse. Why do you point us to fragments on the net, > > > > > > when you could show us the exact code you were running when it failed? > > > > > > I'm guessing you're running it from the interpreter, which can be very > > > > > > confusing once you have to ask for help. Please put a sample of code > > > > > > into a file, run it, and paste into your text email both the contents of > > > > > > that file and the full traceback. thanks. > > > > > > > > > > > > The email address to post on this forum is python-list at python.org > > > > > > > > > > > > > > > > > > -- > > > > > > DaveA > > > > Dear Sir, > > I generally solved this problem from some other angle but I would like to fix this particular issue also so I am posting soon to you. > > Regards, > > Subhabrata. Dear Sir, I was trying to give wrong input. I was making an input error. Regards, Subhabrata. From subhabangalore at gmail.com Sun Apr 7 18:11:36 2013 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Sun, 7 Apr 2013 15:11:36 -0700 (PDT) Subject: Error in Python NLTK In-Reply-To: References: <8dd5cddd-792a-489f-bc1a-46026a227aa8@googlegroups.com> Message-ID: <880e60a6-71a8-40c3-9887-f494924b8401@googlegroups.com> On Monday, April 8, 2013 1:50:38 AM UTC+5:30, subhaba... at gmail.com wrote: > On Sunday, April 7, 2013 2:14:41 AM UTC+5:30, Dave Angel wrote: > > > On 04/06/2013 03:56 PM, subhabangalore at gmail.com wrote: > > > > > > > Dear Group, > > > > > > > > > > > > > > I was using a package named NLTK in Python. > > > > > > > > > > > > > > I was trying to write a code given in section 3.8 of > > > > > > > > > > > > > > http://docs.huihoo.com/nltk/0.9.5/guides/tag.html. > > > > > > > > > > > > > > Here, in the >>> test = ['up', 'down', 'up'] if I put more than 3 values and trying to write the reciprocal codes, like, > > > > > > > > > > > > > > sequence = [(t, None) for t in test] and print '%.3f' % (model.probability(sequence)) > > > > > > > > > > > > This 'and' operator is going to try to interpret the previous list as a > > > > > > boolean. Could that be your problem? Why aren't you putting these two > > > > > > statements on separate lines? And what version of Python are you using? > > > > > > If 2.x, you should get a syntax error because print is a statement. > > > > > > If 3.x, you should get a different error because you don't put parens > > > > > > around the preint expression. > > > > > > > > > > > > > > > > > > > > I am getting an error as, > > > > > > > > > > > > > > Traceback (most recent call last): File "", line 1, in model.probability(sequence) File "C:\Python27\lib\site-packages\nltk\tag\hmm.py", line 228, in probability return 2**(self.log_probability(self._transform.transform(sequence))) File "C:\Python27\lib\site-packages\nltk\tag\hmm.py", line 259, in log_probability alpha = self._forward_probability(sequence) File "C:\Python27\lib\site-packages\nltk\tag\hmm.py", line 694, in _forward_probability alpha[0, i] = self._priors.logprob(state) + \ File "C:\Python27\lib\site-packages\nltk\probability.py", line 689, in logprob elif self._prob_dict[sample] == 0: return _NINF ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() > > > > > > > > > > > > > > If any learned member may kindly assist me how may I solve the issue. > > > > > > > > > > > > > > > > > > > Your error display has been trashed, thanks to googlegroups. > > > > > > http://wiki.python.org/moin/GoogleGroupsPython > > > > > > Try posting with a text email message, since this is a text forum. > > > > > > > > > > > > Your code is also sparse. Why do you point us to fragments on the net, > > > > > > when you could show us the exact code you were running when it failed? > > > > > > I'm guessing you're running it from the interpreter, which can be very > > > > > > confusing once you have to ask for help. Please put a sample of code > > > > > > into a file, run it, and paste into your text email both the contents of > > > > > > that file and the full traceback. thanks. > > > > > > > > > > > > The email address to post on this forum is python-list at python.org > > > > > > > > > > > > > > > > > > -- > > > > > > DaveA > > > > Dear Sir, > > I generally solved this problem from some other angle but I would like to fix this particular issue also so I am posting soon to you. > > Regards, > > Subhabrata. Dear Sir, I was trying to give wrong input. I was making an input error. Regards, Subhabrata. From steve+comp.lang.python at pearwood.info Sun Apr 7 18:40:50 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Apr 2013 22:40:50 GMT Subject: Error in Python NLTK References: <8dd5cddd-792a-489f-bc1a-46026a227aa8@googlegroups.com> <880e60a6-71a8-40c3-9887-f494924b8401@googlegroups.com> Message-ID: <5161f5f2$0$29995$c3e8da3$5496439d@news.astraweb.com> On Sun, 07 Apr 2013 15:11:36 -0700, subhabangalore wrote: [snip 200+ lines of irrelevant quoted text] > Dear Sir, > I was trying to give wrong input. I was making an input error. Please, use the delete key to remove unnecessary text from your messages. We shouldn't have to scroll past THREE AND A HALF PAGES of quoted text to see a two line response. Thank you. -- Steven From benjamin at python.org Sat Apr 6 16:04:38 2013 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 6 Apr 2013 16:04:38 -0400 Subject: [RELEASE] Python 2.7.4 Message-ID: I'm thrilled to announce the release of Python 2.7.4. 2.7.4 is the latest maintenance release in the Python 2.7 series. It includes hundreds of bugfixes to the core language and standard library. Downloads are at http://python.org/download/releases/2.7.4/ As always, please report bugs to http://bugs.python.org/ Several regressions found in the release candidate have been fixed. Many thanks to those who tested the preview release. There has recently been a lot of discussion about XML-based denial of service attacks. Specifically, certain XML files can cause XML parsers, including ones in the Python stdlib, to consume gigabytes of RAM and swamp the CPU. 2.7.4 does not include any changes in Python XML code to address these issues. Interested parties should examine the defusedxml package on PyPI: https://pypi.python.org/pypi/defusedxml This is a production release. Best wishes, Benjamin Peterson 2.7 Release Manager (on behalf of all of Python 2.7's contributors) From georg at python.org Sat Apr 6 16:43:11 2013 From: georg at python.org (Georg Brandl) Date: Sat, 06 Apr 2013 22:43:11 +0200 Subject: [RELEASED] Python 3.2.4 and Python 3.3.1 Message-ID: <516088DF.5050303@python.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On behalf of the Python development team, I am pleased to announce the final releases of Python 3.2.4 and 3.3.1. Python 3.2.4 is the final regular maintenance release for the Python 3.2 series, while Python 3.3.1 is the first maintenance release for the 3.3 series. Both releases include hundreds of bugfixes. There has recently been a lot of discussion about XML-based denial of service attacks. Specifically, certain XML files can cause XML parsers, including ones in the Python stdlib, to consume gigabytes of RAM and swamp the CPU. These releases do not include any changes in Python XML code to address these issues. Interested parties should examine the defusedxml package on PyPI: https://pypi.python.org/pypi/defusedxml To download Python 3.2.4 or Python 3.3.1, visit: http://www.python.org/download/releases/3.2.4/ or http://www.python.org/download/releases/3.3.1/ respectively. As always, please report bugs to http://bugs.python.org/ Enjoy! - -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and all contributors) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) iEYEARECAAYFAlFgiN8ACgkQN9GcIYhpnLAXxQCdHAd2lECpYfmYM4Wbd3I01es4 898AoKBDvHtgecD/PeVRKUrdQRSWGPJg =K8RQ -----END PGP SIGNATURE----- From mcphail_colin at hotmail.com Sat Apr 6 16:48:56 2013 From: mcphail_colin at hotmail.com (cmcp) Date: Sat, 6 Apr 2013 13:48:56 -0700 (PDT) Subject: [RELEASED] Python 3.2.4 and Python 3.3.1 In-Reply-To: References: Message-ID: <7cbf1c26-83a4-4511-8ce1-8f9879795bb8@googlegroups.com> On Saturday, 6 April 2013 21:43:11 UTC+1, Georg Brandl wrote: > -----BEGIN PGP SIGNED MESSAGE----- > > Hash: SHA1 > > > > On behalf of the Python development team, I am pleased to announce the > > final releases of Python 3.2.4 and 3.3.1. > The Python 3.3.1 Release page on python.org still says "This is a preview release, and its use is not recommended in production settings." I'm assuming this is just an oversight? From mcphail_colin at hotmail.com Sat Apr 6 16:48:56 2013 From: mcphail_colin at hotmail.com (cmcp) Date: Sat, 6 Apr 2013 13:48:56 -0700 (PDT) Subject: [RELEASED] Python 3.2.4 and Python 3.3.1 In-Reply-To: References: Message-ID: <7cbf1c26-83a4-4511-8ce1-8f9879795bb8@googlegroups.com> On Saturday, 6 April 2013 21:43:11 UTC+1, Georg Brandl wrote: > -----BEGIN PGP SIGNED MESSAGE----- > > Hash: SHA1 > > > > On behalf of the Python development team, I am pleased to announce the > > final releases of Python 3.2.4 and 3.3.1. > The Python 3.3.1 Release page on python.org still says "This is a preview release, and its use is not recommended in production settings." I'm assuming this is just an oversight? From g.brandl at gmx.net Sat Apr 6 17:03:43 2013 From: g.brandl at gmx.net (Georg Brandl) Date: Sat, 06 Apr 2013 23:03:43 +0200 Subject: [RELEASED] Python 3.2.4 and Python 3.3.1 In-Reply-To: <7cbf1c26-83a4-4511-8ce1-8f9879795bb8@googlegroups.com> References: <7cbf1c26-83a4-4511-8ce1-8f9879795bb8@googlegroups.com> Message-ID: Am 06.04.2013 22:48, schrieb cmcp: > On Saturday, 6 April 2013 21:43:11 UTC+1, Georg Brandl wrote: >> -----BEGIN PGP SIGNED MESSAGE----- >> >> Hash: SHA1 >> >> >> >> On behalf of the Python development team, I am pleased to announce the >> >> final releases of Python 3.2.4 and 3.3.1. >> > The Python 3.3.1 Release page on python.org still says "This is a preview > release, and its use is not recommended in production settings." I'm > assuming this is just an oversight? Yes. Thanks for the report, it's fixed now. Georg From hossamalagmy at gmail.com Sat Apr 6 17:22:59 2013 From: hossamalagmy at gmail.com (23alagmy) Date: Sat, 6 Apr 2013 14:22:59 -0700 (PDT) Subject: Finding The Best Deals For Hair Care Message-ID: Finding The Best Deals For Hair Care http://natigtas7ab.blogspot.com/2013/03/finding-best-deals-for-hair-care.html From bv8bv8bv8 at gmail.com Sat Apr 6 17:35:50 2013 From: bv8bv8bv8 at gmail.com (BV BV) Date: Sat, 6 Apr 2013 14:35:50 -0700 (PDT) Subject: The Story of Jesus and Mary in the Holy Quran Message-ID: <04e8e8e7-2fc9-4986-95b0-05ee4c45dd97@he10g2000vbb.googlegroups.com> The Story of Jesus and Mary in the Holy Quran The following three part series consists entirely of verses from the Holy Quran about Mary (Mother of Jesus) including her birth, childhood, personal qualities, and the miraculous birth of Jesus. This part explores the life of the Prophet Jesus, his message, miracles, his disciples and what is mentioned about them in the Holy Quran. This part explores the verses of the Holy Quran that talk about God?s protection of Jesus, his followers, his second coming in this world and what will happen to him on the day of resurrection. http://www.islamhouse.com/p/409136 thank you From spacebuoy at gmail.com Sat Apr 6 20:24:28 2013 From: spacebuoy at gmail.com (Gene) Date: Sat, 06 Apr 2013 20:24:28 -0400 Subject: Cannot install readline in pythonbrew install of 3.3.0 Message-ID: <5160BCBC.3030002@gmail.com> Hi, I hope someone can help with this problem with pythonbrew on my mac running OS X 10.8.3 with updated Xcode and CLT. $PATH = /Users/Gene/.pythonbrew/bin:/Users/Gene/.pythonbrew/pythons/Python-3.3.0/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin $PYTHONPATH = /Users/Gene/.pythonbrew/pythons/Python-3.3.0/lib The python 3.3.0 install using pythonbrew was made with default options and seems to be working okay but when I easy_install readline per ipython recommend: BTW, readline has been installed for the system python 2.7.3 on this Mac for over a year and works fine. Switched to Python-3.3.0 easy_install readline Searching for readline Reading http://pypi.python.org/simple/readline/ Reading http://github.com/ludwigschwardt/python-readline Reading http://www.python.org/ Best match: readline 6.2.4.1 Downloading http://pypi.python.org/packages/source/r/readline/readline-6.2.4.1.tar.gz#md5=578237939c81fdbc2c8334d168b17907 Processing readline-6.2.4.1.tar.gz Writing /var/folders/51/k4qphs517k3c9dv55_23b6j80000gp/T/easy_install-ypwvg6/readline-6.2.4.1/setup.cfg Running readline-6.2.4.1/setup.py -q bdist_egg --dist-dir /var/folders/51/k4qphs517k3c9dv55_23b6j80000gp/T/easy_install-ypwvg6/readline-6.2.4.1/egg-dist-tmp-9hwdkl In file included from /Users/Ceti/.pythonbrew/pythons/Python-3.3.0/include/python3.3m/Python.h:112:0, from Modules/3.x/readline.c:8: /Users/Ceti/.pythonbrew/pythons/Python-3.3.0/include/python3.3m/modsupport.h:29:1: warning: ?PyArg_ParseTuple? is an unrecognized format function type [-Wformat=] PyAPI_FUNC(int) PyArg_ParseTuple(PyObject *, const char *, ...) Py_FORMAT_PARSETUPLE(PyArg_ParseTuple, 2, 3); ^ /var/folders/51/k4qphs517k3c9dv55_23b6j80000gp/T//ccEk88Hx.s:9:`_begidx(%rip)' is not a valid base/index expression /var/folders/51/k4qphs517k3c9dv55_23b6j80000gp/T//ccEk88Hx.s:10:bad register name `%rax)' /var/folders/51/k4qphs517k3c9dv55_23b6j80000gp/T//ccEk88Hx.s:20:`_endidx(%rip)' is not a valid base/index expression /var/folders/51/k4qphs517k3c9dv55_23b6j80000gp/T//ccEk88Hx.s:21:bad register name `%rax)' /var/folders/51/k4qphs517k3c9dv55_23b6j80000gp/T//ccEk88Hx.s:31:bad register name `%rdi' /var/folders/51/k4qphs517k3c9dv55_23b6j80000gp/T//ccEk88Hx.s:48:bad register name `%r15' These "bad register name" errors stream for many pages then the install fails. Here's the last line of the install: error: Setup script exited with error: command 'gcc' failed with exit status 1 Any ideas? Thanks, Gene From nad at acm.org Sat Apr 6 22:53:23 2013 From: nad at acm.org (Ned Deily) Date: Sat, 06 Apr 2013 19:53:23 -0700 Subject: Cannot install readline in pythonbrew install of 3.3.0 References: <5160BCBC.3030002@gmail.com> Message-ID: In article <5160BCBC.3030002 at gmail.com>, Gene wrote: > I hope someone can help with this problem with pythonbrew on my mac > running OS X 10.8.3 with updated Xcode and CLT. [...] > The python 3.3.0 install using pythonbrew was made with default options > and seems to be working okay but when I easy_install readline per > ipython recommend: [...] > Any ideas? pythonbrew does its own funky things above and beyond standard OS X Python installs. Further, the PyPI readline distribution (which substitutes GNU readline for the OS X default BSD editline library) does its own funky things. I don't use either so I'm copping out here and not going to try to debug what's going wrong when you try to use them together. You *might* be better off just manually building and installing GNU readline in /usr/local and then use pythonbrew to rebuild Python 3.3 (3.3.1 was just released, BTW). Otherwise, you could search the pythonbrew issue list and open an issue there, if necessary. Or use a python.org 3.3 along with PyPI readline. Or install ipython3.3, Python 3.3, and GNU readline from MacPorts or Homebrew. https://github.com/utahta/pythonbrew/issues -- Ned Deily, nad at acm.org From jiewei24 at gmail.com Sat Apr 6 21:03:07 2013 From: jiewei24 at gmail.com (Frank) Date: Sat, 6 Apr 2013 18:03:07 -0700 (PDT) Subject: raw_input that able to do detect multiple input Message-ID: Hi all, I would require advise on this question for function call interact: the desire outcome: interact() Friends File: friends.csv Command: f John Cleese John Cleese: Ministry of Silly Walks, 5555421, 27 October Command: f Michael Palin Unknown friend Michael Palin Command: f Invalid Command: f Command: a Michael Palin Invalid Command: a Michael Palin Command: a John Cleese, Cheese Shop, 5552233, 5 May John Cleese is already a friend Command: a Michael Palin, Cheese Shop, 5552233, 5 May Command: f Michael Palin Michael Palin: Cheese Shop, 5552233, 5 May Command: e Saving changes... Exiting... my code so far for interact: #interact function def interact(*arg): open('friends.csv', 'rU') d = load_friends('friends.csv') print "Friends File: friends.csv" s = raw_input("Please input something: ") command = s.split(" ", 1) if "f" in command: display_friends("command",load_friends('friends.csv')) print command #display friend function def display_friends(name, friends_list): Fname = name[0] for item in friends_list: if item[0] == Fname: print item break else: print False Let say if i type in " f John Cleese " and after the line 6 , my value of "command" should be ['f', 'John Cleese']. Is there ways to extract out John Cleese as a input so that i could use it on my function call "display_friends" ? From davea at davea.name Sat Apr 6 21:41:24 2013 From: davea at davea.name (Dave Angel) Date: Sat, 06 Apr 2013 21:41:24 -0400 Subject: raw_input that able to do detect multiple input In-Reply-To: References: Message-ID: <5160CEC4.1090201@davea.name> On 04/06/2013 09:03 PM, Frank wrote: > Hi all, I would require advise on this question for function call interact: > > the desire outcome: > interact() > Friends File: friends.csv > Command: f John Cleese > John Cleese: Ministry of Silly Walks, 5555421, 27 October > Command: f Michael Palin > Unknown friend Michael Palin > Command: f > Invalid Command: f > Command: a Michael Palin > Invalid Command: a Michael Palin > Command: a John Cleese, Cheese Shop, 5552233, 5 May > John Cleese is already a friend > Command: a Michael Palin, Cheese Shop, 5552233, 5 May > Command: f Michael Palin > Michael Palin: Cheese Shop, 5552233, 5 May > Command: e > Saving changes... > Exiting... > > my code so far for interact: > #interact function > def interact(*arg): > open('friends.csv', 'rU') > d = load_friends('friends.csv') > print "Friends File: friends.csv" > s = raw_input("Please input something: ") > command = s.split(" ", 1) > if "f" in command: > display_friends("command",load_friends('friends.csv')) > print command > > #display friend function > def display_friends(name, friends_list): > Fname = name[0] > for item in friends_list: > if item[0] == Fname: > print item > break > else: > print False > > Let say if i type in " f John Cleese " and after the line 6 , my value of "command" should be ['f', 'John Cleese']. Is there ways to extract out John Cleese as a input so that i could use it on my function call "display_friends" ? > > Nothing about this message makes any sense to me. The function display_friends() has no body. Code for load_friends() is missing. You seem to be confusing variable names with literal strings. You open an input file "friends.csv", but never use the file handle. You store the return value of load_friends() in d, but never use it. The "desire outcome" includes lots of stuff that this code won't be producing. And I cannot understand the question you ask at the end. However, one thing I see that's wrong is the user is apparently typing a leading and trailinb blank on the line. If you want to strip out whitespace before and after, just use strip(). -- DaveA From jiewei24 at gmail.com Sat Apr 6 23:22:42 2013 From: jiewei24 at gmail.com (Frank) Date: Sat, 6 Apr 2013 20:22:42 -0700 (PDT) Subject: raw_input that able to do detect multiple input In-Reply-To: References: Message-ID: Hi Dave, Sorry for my unclear question. I didn't use the d = load_friends('friends.csv') now because I'm going use it for other function later on, I should have remove it first to avoid confusion. This is the code for load_friends , add_info ,display_friends, save_friends function: def load_friends(filename): f = open(filename, 'rU') for row in f: return list (row.strip() for row in f) def add_info(new_info, new_list): # Persons name is the first item of the list name = new_info[0] # Check if we already have an item with that name for item in new_list: if item[0] == name: print "%s is already in the list" % name return False # Insert the item into the list new_list.append(new_info) return True def display_friends(name, friends_list): Fname = name[0] for item in friends_list: if item[0] == Fname: print item break else: print False def save_friends(friend_info, new_list): with open(friend_info, 'w') as f: for line in new_list: f.write(line + '\n') I will elaborate my question further , when the user type the function call interact() this will appear : interact() Friends File: friends.csv so after which the user would type in the command call maybe we call it " F John Cleese", the program need to know if the user input contain a "f" "a" or "e" at the first char and if 'f' it mean it would takes a name as an argument, prints out the information about that friend or prints an error message if the given name is notthe name of a friend in the database(friends.csv). if "a" it would takes four arguments (comma separated) with information about a person and adds that person as a friend. An error message is printed if that person is already a friend. if "e" it would ends the interaction and, if the friends information has been updated, the information is saved to the friends.csv. This is the example output Command: f John Cleese John Cleese: Ministry of Silly Walks, 5555421, 27 October Command: f Michael Palin Unknown friend Michael Palin Command: f Invalid Command: f Command: a Michael Palin Invalid Command: a Michael Palin Command: a John Cleese, Cheese Shop, 5552233, 5 May John Cleese is already a friend Command: a Michael Palin, Cheese Shop, 5552233, 5 May Command: f Michael Palin Michael Palin: Cheese Shop, 5552233, 5 May Command: e Saving changes... Exiting... So currently I think i had my other functions ready but I do not know how do i apply it into interact() my rough idea is : def interact(*arg): open('friends.csv', 'rU') d = load_friends('friends.csv') print "Friends File: friends.csv" s = raw_input() command = s.split(" ", 1) if "f" in command: # invoke display_friends function print result elif "a" in command: # invoke add_info function print result elif "e" in command: # invoke save_friends function print result My idea is to split the user command out to ['f', 'John Cleese'] and use the 'F' to invoke my "f" in the if statement and then i would use the display_friends function to process 'John Cleese' but i'm not sure if i'm able to do it this way From jiewei24 at gmail.com Sat Apr 6 23:22:42 2013 From: jiewei24 at gmail.com (Frank) Date: Sat, 6 Apr 2013 20:22:42 -0700 (PDT) Subject: raw_input that able to do detect multiple input In-Reply-To: References: Message-ID: Hi Dave, Sorry for my unclear question. I didn't use the d = load_friends('friends.csv') now because I'm going use it for other function later on, I should have remove it first to avoid confusion. This is the code for load_friends , add_info ,display_friends, save_friends function: def load_friends(filename): f = open(filename, 'rU') for row in f: return list (row.strip() for row in f) def add_info(new_info, new_list): # Persons name is the first item of the list name = new_info[0] # Check if we already have an item with that name for item in new_list: if item[0] == name: print "%s is already in the list" % name return False # Insert the item into the list new_list.append(new_info) return True def display_friends(name, friends_list): Fname = name[0] for item in friends_list: if item[0] == Fname: print item break else: print False def save_friends(friend_info, new_list): with open(friend_info, 'w') as f: for line in new_list: f.write(line + '\n') I will elaborate my question further , when the user type the function call interact() this will appear : interact() Friends File: friends.csv so after which the user would type in the command call maybe we call it " F John Cleese", the program need to know if the user input contain a "f" "a" or "e" at the first char and if 'f' it mean it would takes a name as an argument, prints out the information about that friend or prints an error message if the given name is notthe name of a friend in the database(friends.csv). if "a" it would takes four arguments (comma separated) with information about a person and adds that person as a friend. An error message is printed if that person is already a friend. if "e" it would ends the interaction and, if the friends information has been updated, the information is saved to the friends.csv. This is the example output Command: f John Cleese John Cleese: Ministry of Silly Walks, 5555421, 27 October Command: f Michael Palin Unknown friend Michael Palin Command: f Invalid Command: f Command: a Michael Palin Invalid Command: a Michael Palin Command: a John Cleese, Cheese Shop, 5552233, 5 May John Cleese is already a friend Command: a Michael Palin, Cheese Shop, 5552233, 5 May Command: f Michael Palin Michael Palin: Cheese Shop, 5552233, 5 May Command: e Saving changes... Exiting... So currently I think i had my other functions ready but I do not know how do i apply it into interact() my rough idea is : def interact(*arg): open('friends.csv', 'rU') d = load_friends('friends.csv') print "Friends File: friends.csv" s = raw_input() command = s.split(" ", 1) if "f" in command: # invoke display_friends function print result elif "a" in command: # invoke add_info function print result elif "e" in command: # invoke save_friends function print result My idea is to split the user command out to ['f', 'John Cleese'] and use the 'F' to invoke my "f" in the if statement and then i would use the display_friends function to process 'John Cleese' but i'm not sure if i'm able to do it this way From davea at davea.name Sun Apr 7 00:36:14 2013 From: davea at davea.name (Dave Angel) Date: Sun, 07 Apr 2013 00:36:14 -0400 Subject: raw_input that able to do detect multiple input In-Reply-To: References: Message-ID: <5160F7BE.5070104@davea.name> On 04/06/2013 11:22 PM, Frank wrote: > Hi Dave, > > > Sorry for my unclear question. > I didn't use the d = load_friends('friends.csv') now because I'm going use it for other function later on, I should have remove it first to avoid confusion. > > This is the code for load_friends , add_info ,display_friends, save_friends function: > > def load_friends(filename): > f = open(filename, 'rU') > for row in f: > return list (row.strip() for row in f) This is a mighty confusing way of skipping the first line. You make it look like a loop, but it only executes once, since you have a return inside. Besides, when you save the data, you don't put an extra header line at the top. So it's not consistent. > > def add_info(new_info, new_list): > # Persons name is the first item of the list > name = new_info[0] > # Check if we already have an item with that name > for item in new_list: > if item[0] == name: > print "%s is already in the list" % name > return False > # Insert the item into the list > new_list.append(new_info) > return True > > def display_friends(name, friends_list): > Fname = name[0] > for item in friends_list: > if item[0] == Fname: > print item > break > else: > print False > > def save_friends(friend_info, new_list): > with open(friend_info, 'w') as f: > for line in new_list: > f.write(line + '\n') Now you've saved the data in a different file. How does the next run of the program find it? > > > I will elaborate my question further , when the user type the function call interact() What user? In what environment can a user enter function calls into your code? > this will appear : > > interact() > Friends File: friends.csv > > so after which the user would type in the command call maybe we call it " F John Cleese", the program need to know if the user input contain a "f" "a" or "e" at the first char and > > if 'f' it mean it would takes a name as an argument, prints out the information about that friend or prints an error message if the given name is notthe name of a friend in the database(friends.csv). > > if "a" it would takes four arguments (comma separated) with information > about a person and adds that person as a friend. An error message is printed > if that person is already a friend. > > if "e" it would ends the interaction and, if the friends information has been > updated, the information is saved to the friends.csv. > > This is the example output > > Command: f John Cleese > John Cleese: Ministry of Silly Walks, 5555421, 27 October > Command: f Michael Palin > Unknown friend Michael Palin > Command: f > Invalid Command: f Why is the command invalid? > Command: a Michael Palin > Invalid Command: a Michael Palin > Command: a John Cleese, Cheese Shop, 5552233, 5 May > John Cleese is already a friend That's not the way the message is worded in the code > Command: a Michael Palin, Cheese Shop, 5552233, 5 May > Command: f Michael Palin > Michael Palin: Cheese Shop, 5552233, 5 May > Command: e > Saving changes... > Exiting... > > So currently I think i had my other functions ready but I do not know how do i apply it into interact() > > my rough idea is : > > def interact(*arg): > open('friends.csv', 'rU') > d = load_friends('friends.csv') > print "Friends File: friends.csv" > s = raw_input() > command = s.split(" ", 1) > if "f" in command: You don't really want "in" here. You just want the first field to match "f" So why not: if "f" == command[0]: > # invoke display_friends function In this function and in save_friends, there is no return value, so not clear what you mean by 'result' > print result > elif "a" in command: > # invoke add_info function > print result > elif "e" in command: > # invoke save_friends function > print result > > My idea is to split the user command out to ['f', 'John Cleese'] and use the 'F' to invoke my "f" in the if statement and then i would use the display_friends function to process 'John Cleese' but i'm not sure if i'm able to do it this way > > It's all over but the debugging. What's the real question? -- DaveA From jiewei24 at gmail.com Sun Apr 7 01:00:51 2013 From: jiewei24 at gmail.com (Frank) Date: Sat, 6 Apr 2013 22:00:51 -0700 (PDT) Subject: raw_input that able to do detect multiple input In-Reply-To: References: Message-ID: Now you've saved the data in a different file. How does the next run of the program find it? What user? In what environment can a user enter function calls into your code? -The user will call the function out from IDLE Why is the command invalid? -Because the user need to type out a name after the "f" That's not the way the message is worded in the code - because if user type in " a John Cleese, Cheese Shop, 5552233, 5 May" it mean it would takes four arguments (comma separated) with information about a person and adds that person to my "friends.csv". An error message is printed if that person is already a friend. Because the name "John Cleese" is already in my friends.csv that why it will prompt out "John Cleese is already a friend" In this function and in save_friends, there is no return value, so not clear what you mean by 'result' e ends the interaction and, if the friends information has been updated, the information is saved to the friends.csv , i think i used the wrong function for this. The question I'm told to work on: interact() is the top-level function that de nes the text-base user interface as described in the introduction. Here is an example of what is expected from your program. The input is everything after Command: on a line (and the initial friends.csv). Every- thing else is output. Your output should be exactly the same as below for the given input. interact() Friends File: friends.csv Command: f John Cleese John Cleese: Ministry of Silly Walks, 5555421, 27 October Command: f Michael Palin Unknown friend Michael Palin Command: f Invalid Command: f Command: a Michael Palin Invalid Command: a Michael Palin Command: a John Cleese, Cheese Shop, 5552233, 5 May John Cleese is already a friend Command: a Michael Palin, Cheese Shop, 5552233, 5 May Command: f Michael Palin Michael Palin: Cheese Shop, 5552233, 5 May Command: e Saving changes... Exiting... From jiewei24 at gmail.com Sun Apr 7 01:00:51 2013 From: jiewei24 at gmail.com (Frank) Date: Sat, 6 Apr 2013 22:00:51 -0700 (PDT) Subject: raw_input that able to do detect multiple input In-Reply-To: References: Message-ID: Now you've saved the data in a different file. How does the next run of the program find it? What user? In what environment can a user enter function calls into your code? -The user will call the function out from IDLE Why is the command invalid? -Because the user need to type out a name after the "f" That's not the way the message is worded in the code - because if user type in " a John Cleese, Cheese Shop, 5552233, 5 May" it mean it would takes four arguments (comma separated) with information about a person and adds that person to my "friends.csv". An error message is printed if that person is already a friend. Because the name "John Cleese" is already in my friends.csv that why it will prompt out "John Cleese is already a friend" In this function and in save_friends, there is no return value, so not clear what you mean by 'result' e ends the interaction and, if the friends information has been updated, the information is saved to the friends.csv , i think i used the wrong function for this. The question I'm told to work on: interact() is the top-level function that de nes the text-base user interface as described in the introduction. Here is an example of what is expected from your program. The input is everything after Command: on a line (and the initial friends.csv). Every- thing else is output. Your output should be exactly the same as below for the given input. interact() Friends File: friends.csv Command: f John Cleese John Cleese: Ministry of Silly Walks, 5555421, 27 October Command: f Michael Palin Unknown friend Michael Palin Command: f Invalid Command: f Command: a Michael Palin Invalid Command: a Michael Palin Command: a John Cleese, Cheese Shop, 5552233, 5 May John Cleese is already a friend Command: a Michael Palin, Cheese Shop, 5552233, 5 May Command: f Michael Palin Michael Palin: Cheese Shop, 5552233, 5 May Command: e Saving changes... Exiting... From davea at davea.name Sun Apr 7 01:25:47 2013 From: davea at davea.name (Dave Angel) Date: Sun, 07 Apr 2013 01:25:47 -0400 Subject: raw_input that able to do detect multiple input In-Reply-To: References: Message-ID: <5161035B.8010007@davea.name> (You forgot to separate the parts of my comments that you were quoting from your responses. Any decent email program will do that for you automatically, inserting "< " in front of each quoted line. Then you just hit enter a couple of times to type the new stuff right after the part you're quoting.) On 04/07/2013 01:00 AM, Frank wrote: > Now you've saved the data in a different file. How does the next run of > the program find it? > > > What user? In what environment can a user enter function calls into > your code? > -The user will call the function out from IDLE So the user is the programmer. No end-user would be using IDLE to run a program. > > Why is the command invalid? > -Because the user need to type out a name after the "f" But that wouldn't be an invalid command, but invalid data > > That's not the way the message is worded in the code > - because if user type in " a John Cleese, Cheese Shop, 5552233, 5 May" > it mean it would takes four arguments (comma separated) with information > about a person and adds that person to my "friends.csv". An error message is printed if that person is already a friend. Because the name "John Cleese" is already in my friends.csv that why it will prompt out "John Cleese is already a friend" So fix the code, I just pointed out that the message was different. The code says print "%s is already in the list" % name Yet you say the message needs to be: > John Cleese is already a friend One or the other is incorrect. > > In this function and in save_friends, there is no return value, so not > clear what you mean by 'result' > > e ends the interaction and, if the friends information has been > updated, the information is saved to the friends.csv , i think i used the wrong function for this. No, just the wrong filename. I assumed you were going to rename it afterwards, tut apparently not. > > The question I'm told to work on: > interact() is the top-level function that de nes the text-base user interface > as described in the introduction. > So if you call interact() in your program at the top-level, then a non-programmer can run the program directly from the terminal window. > Here is an example of what is expected from your program. The input is > everything after Command: on a line (and the initial friends.csv). Every- > thing else is output. Your output should be exactly the same as below for > the given input. > > interact() > Friends File: friends.csv > Command: f John Cleese > John Cleese: Ministry of Silly Walks, 5555421, 27 October > Command: f Michael Palin > Unknown friend Michael Palin > Command: f > Invalid Command: f > Command: a Michael Palin > Invalid Command: a Michael Palin > Command: a John Cleese, Cheese Shop, 5552233, 5 May > John Cleese is already a friend > Command: a Michael Palin, Cheese Shop, 5552233, 5 May > Command: f Michael Palin > Michael Palin: Cheese Shop, 5552233, 5 May > Command: e > Saving changes... > Exiting... > You will also need to add an argument to the raw_input() to have it produce the output specified. -- DaveA From jarausch at skynet.be Sun Apr 7 05:50:35 2013 From: jarausch at skynet.be (Helmut Jarausch) Date: 07 Apr 2013 09:50:35 GMT Subject: new.instancemethod - how to port to Python3 Message-ID: <5161416b$0$3104$ba620e4c@news.skynet.be> Hi, I'm trying to port a class to Python3.3 which contains class Foo : .... def to_binary(self, *varargs, **keys): .... .... self.to_binary = new.instancemethod(to_binary, self, self.__class__) # Finally call it manually return apply(self.to_binary, varargs, keys) ---- The last line has been transformed to return self.to_binary(*varargs, **keys) by 2to3 But how to transform the line with new.instancemethod. I've seen examples where new.instancemethod(to_binary, ....) is replaced by to_binay but this doesn't work here since to_binary isn't known. If I simply delete it, I get an infinite recursion. So, what's a working transcript of this code? Many thanks for a hint, Helmut. P.S. Is there collection of examples of necessary transformations to Python3 which are not managed by 2to3 ? From arnodel at gmail.com Sun Apr 7 06:41:46 2013 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 7 Apr 2013 11:41:46 +0100 Subject: new.instancemethod - how to port to Python3 In-Reply-To: <5161416b$0$3104$ba620e4c@news.skynet.be> References: <5161416b$0$3104$ba620e4c@news.skynet.be> Message-ID: On 7 April 2013 10:50, Helmut Jarausch wrote: > Hi, > > I'm trying to port a class to Python3.3 which contains > > class Foo : > .... > def to_binary(self, *varargs, **keys): > .... > > .... > self.to_binary = new.instancemethod(to_binary, self, self.__class__) `self` isn't bound in this lexical scope (the class scope). Or is your indentation incorrect? However, if this statement was within the `to_binary` method, then `to_binary` wouldn't be bound so I can't make a reasonable guess. > # Finally call it manually > return apply(self.to_binary, varargs, keys) > [...] -- Arnaud From steve+comp.lang.python at pearwood.info Sun Apr 7 06:52:11 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Apr 2013 10:52:11 GMT Subject: new.instancemethod - how to port to Python3 References: <5161416b$0$3104$ba620e4c@news.skynet.be> Message-ID: <51614fda$0$29995$c3e8da3$5496439d@news.astraweb.com> On Sun, 07 Apr 2013 09:50:35 +0000, Helmut Jarausch wrote: > Hi, > > I'm trying to port a class to Python3.3 which contains > > class Foo : > .... > def to_binary(self, *varargs, **keys): > .... > .... > self.to_binary = new.instancemethod(to_binary, self, self.__class__) > # Finally call it manually > return apply(self.to_binary, varargs, keys) I do not understand this code. Can you give a short example that actually works please? As written, your code has a class that defines a to_binary method. Then, *outside* of the method, in the class definition, you refer to "self", and use a return statement. This is not possible -- self does not exist, and return gives a SyntaxError. But, if the indentation is wrong, it looks like you are trying to get the to_binary method to replace itself with a global to_binary function. I do not understand this. > ---- > > The last line has been transformed to > return self.to_binary(*varargs, **keys) > > by 2to3 > > But how to transform the line with new.instancemethod. I've seen > examples where > new.instancemethod(to_binary, ....) > is replaced by to_binay > but this doesn't work here since to_binary isn't known. I cannot answer your question, because I don't understand it. But perhaps this will help: # === Python 2 version === class Spam: pass x = Spam() def method(self, arg): return {arg: self} import new x.method = new.instancemethod(method, x, x.__class__) x.method("hello") => returns {'hello': <__main__.Spam instance at 0xa18bb4c>} Here is the Python 3 version: # === Python 3 === class Spam: pass x = Spam() def method(self, arg): return {arg: self} import types x.method = types.MethodType(method, x) x.method("hello") => returns {'hello': <__main__.Spam object at 0xb7bc59ac>} Does this help? -- Steven From jarausch at skynet.be Sun Apr 7 11:37:13 2013 From: jarausch at skynet.be (Helmut Jarausch) Date: 07 Apr 2013 15:37:13 GMT Subject: new.instancemethod - how to port to Python3 References: <5161416b$0$3104$ba620e4c@news.skynet.be> <51614fda$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: <516192a9$0$3104$ba620e4c@news.skynet.be> On Sun, 07 Apr 2013 10:52:11 +0000, Steven D'Aprano wrote: > On Sun, 07 Apr 2013 09:50:35 +0000, Helmut Jarausch wrote: > >> Hi, >> >> I'm trying to port a class to Python3.3 which contains >> >> class Foo : >> .... >> def to_binary(self, *varargs, **keys): >> .... >> .... >> self.to_binary = new.instancemethod(to_binary, self, self.__class__) >> # Finally call it manually >> return apply(self.to_binary, varargs, keys) > > > I do not understand this code. Can you give a short example that actually > works please? > > As written, your code has a class that defines a to_binary method. Then, > *outside* of the method, in the class definition, you refer to "self", > and use a return statement. This is not possible -- self does not exist, > and return gives a SyntaxError. > > But, if the indentation is wrong, it looks like you are trying to get the > to_binary method to replace itself with a global to_binary function. I do > not understand this. Sorry, the first excerpt was to too short. As noted in the reply to Arnaud, a better excerpt is: class Foo : .... def to_binary(self, *varargs, **keys): .... code= ... args= ... # Add function header code = 'def to_binary(self, %s):\n' % ', '.join(args) + code exec(code) self.to_binary = new.instancemethod(to_binary, self, self.__class__) return self.to_binary(*varargs, **keys) If you'd like to see the full code (not by me) please see the Python package http://python-xlib.sourceforge.net/ file Xlib/protocol/rq.py method to_binary in class Struct > > I cannot answer your question, because I don't understand it. But perhaps > this will help: > > > # === Python 2 version === > class Spam: > pass > > x = Spam() > > def method(self, arg): > return {arg: self} > > import new > x.method = new.instancemethod(method, x, x.__class__) > > x.method("hello") > => returns {'hello': <__main__.Spam instance at 0xa18bb4c>} > > > Here is the Python 3 version: > > > # === Python 3 === > class Spam: > pass > > x = Spam() > > def method(self, arg): > return {arg: self} > > import types > x.method = types.MethodType(method, x) > > x.method("hello") > => returns {'hello': <__main__.Spam object at 0xb7bc59ac>} > > > > Does this help? Yes, From jarausch at skynet.be Sun Apr 7 06:54:46 2013 From: jarausch at skynet.be (Helmut Jarausch) Date: 07 Apr 2013 10:54:46 GMT Subject: new.instancemethod - how to port to Python3 References: <5161416b$0$3104$ba620e4c@news.skynet.be> Message-ID: <51615076$0$3104$ba620e4c@news.skynet.be> On Sun, 07 Apr 2013 11:41:46 +0100, Arnaud Delobelle wrote: > On 7 April 2013 10:50, Helmut Jarausch wrote: >> Hi, >> >> I'm trying to port a class to Python3.3 which contains >> >> class Foo : >> .... >> def to_binary(self, *varargs, **keys): >> .... >> >> .... >> self.to_binary = new.instancemethod(to_binary, self, >> self.__class__) > > `self` isn't bound in this lexical scope (the class scope). Or is your > indentation incorrect? However, if this statement was within the > `to_binary` method, then `to_binary` wouldn't be bound so I can't make a > reasonable guess. > >> # Finally call it manually return apply(self.to_binary, varargs, >> keys) >> > [...] Sorry, the excerpt wasn't complete (it's not my code): Here a more complete excerpt: class Foo : .... def to_binary(self, *varargs, **keys): .... code= ... args= ... # Add function header code = 'def to_binary(self, %s):\n' % ', '.join(args) + code exec(code) self.to_binary = new.instancemethod(to_binary, self, self.__class__) return self.to_binary(*varargs, **keys) From steve+comp.lang.python at pearwood.info Sun Apr 7 07:07:07 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Apr 2013 11:07:07 GMT Subject: new.instancemethod - how to port to Python3 References: <5161416b$0$3104$ba620e4c@news.skynet.be> <51615076$0$3104$ba620e4c@news.skynet.be> Message-ID: <5161535a$0$29995$c3e8da3$5496439d@news.astraweb.com> On Sun, 07 Apr 2013 10:54:46 +0000, Helmut Jarausch wrote: > class Foo : > .... > def to_binary(self, *varargs, **keys): > .... > code= ... > args= ... > # Add function header > code = 'def to_binary(self, %s):\n' % ', '.join(args) + code > exec(code) > self.to_binary = new.instancemethod(to_binary, self, > self.__class__) > return self.to_binary(*varargs, **keys) Self-modifying code! Yuck! Nevertheless, try changing the line with new.instancemethod to this: self.to_binary = types.MethodType(to_binary, self) and see if it works. If it complains about the call to exec, then change that part of the code to this: ns = {} exec(code, ns) to_binary = ns['to_binary'] self.to_binary = types.MethodType(to_binary, self) -- Steven From jarausch at skynet.be Sun Apr 7 11:35:54 2013 From: jarausch at skynet.be (Helmut Jarausch) Date: 07 Apr 2013 15:35:54 GMT Subject: new.instancemethod - how to port to Python3 References: <5161416b$0$3104$ba620e4c@news.skynet.be> <51615076$0$3104$ba620e4c@news.skynet.be> <5161535a$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5161925a$0$3104$ba620e4c@news.skynet.be> On Sun, 07 Apr 2013 11:07:07 +0000, Steven D'Aprano wrote: > On Sun, 07 Apr 2013 10:54:46 +0000, Helmut Jarausch wrote: > >> class Foo : >> .... >> def to_binary(self, *varargs, **keys): >> .... >> code= ... >> args= ... >> # Add function header >> code = 'def to_binary(self, %s):\n' % ', '.join(args) + code >> exec(code) >> self.to_binary = new.instancemethod(to_binary, self, >> self.__class__) >> return self.to_binary(*varargs, **keys) > > > Self-modifying code! Yuck! > > Nevertheless, try changing the line with new.instancemethod to this: > > self.to_binary = types.MethodType(to_binary, self) > > > and see if it works. If it complains about the call to exec, then change > that part of the code to this: Thanks, that worked > > ns = {} > exec(code, ns) I just had to replace this with exec(code,globals(),ns) > to_binary = ns['to_binary'] > self.to_binary = types.MethodType(to_binary, self) Helmut From lalitha.viswanath at gmail.com Sun Apr 7 07:16:27 2013 From: lalitha.viswanath at gmail.com (ReviewBoard User) Date: Sun, 7 Apr 2013 04:16:27 -0700 (PDT) Subject: Newbie to python. Very newbie question Message-ID: Hi I am a newbie to python and am trying to write a program that does a sum of squares of numbers whose squares are odd. For example, for x from 1 to 100, it generates 165 as an output (sum of 1,9,25,49,81) Here is the code I have print reduce(lambda x, y: x+y, filter(lambda x: x%2, map(lambda x: x*x, xrange (10**6)))) = sum(x*x for x in xrange(1, 10**6, 2)) I am getting a syntax error. Can you let me know what the error is? I am new to Python and am also looking for good documentation on python functions. http://www.python.org/doc/ does not provide examples of usage of each function From kruno.saho at gmail.com Sun Apr 7 07:19:32 2013 From: kruno.saho at gmail.com (Kruno Saho) Date: Sun, 7 Apr 2013 04:19:32 -0700 (PDT) Subject: Newbie to python. Very newbie question In-Reply-To: References: Message-ID: On Sunday, April 7, 2013 9:16:27 PM UTC+10, ReviewBoard User wrote: > Hi > > I am a newbie to python and am trying to write a program that does a > > sum of squares of numbers whose squares are odd. > > For example, for x from 1 to 100, it generates 165 as an output (sum > > of 1,9,25,49,81) > > > > Here is the code I have > > print reduce(lambda x, y: x+y, filter(lambda x: x%2, map(lambda x: > > x*x, xrange > > (10**6)))) = sum(x*x for x in xrange(1, 10**6, 2)) > > > > I am getting a syntax error. > > Can you let me know what the error is? > > > > I am new to Python and am also looking for good documentation on > > python functions. http://www.python.org/doc/ does not provide examples > > of usage of each function Are you sure you do not mean '==' instead of '='? From davea at davea.name Sun Apr 7 07:50:29 2013 From: davea at davea.name (Dave Angel) Date: Sun, 07 Apr 2013 07:50:29 -0400 Subject: Newbie to python. Very newbie question In-Reply-To: References: Message-ID: <51615D85.5060604@davea.name> On 04/07/2013 07:16 AM, ReviewBoard User wrote: > Hi > I am a newbie to python Then why are you trying to do 7 or 8 things on one line? > and am trying to write a program that does a > sum of squares of numbers whose squares are odd. > For example, for x from 1 to 100, it generates 165 as an output (sum > of 1,9,25,49,81) > No it doesn't. A small piece of it does, and I'd recommend making that piece a separate line or three, probably making a function out of it. Then if you want to write other code to exercise that function, go right ahead. If you're new to Python, concentrate on the algorithm needed, and keep the program straightforward. After you've got something simple working, and you're comfortable with the algorithm, then you can play code-golf to your heart's content. Perhaps you hadn't realized that any odd number when squared will yield an odd number, and likewise for even. So the stated problem is much simpler than what you're trying to do. 3 lambda's in one line of code? Silly. -- DaveA From rustompmody at gmail.com Sun Apr 7 13:02:29 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 7 Apr 2013 10:02:29 -0700 (PDT) Subject: Newbie to python. Very newbie question References: Message-ID: On Apr 7, 4:16?pm, ReviewBoard User wrote: > Hi > I am a newbie to python and am trying to write a program that does a > sum of squares of numbers whose squares are odd. > For example, for x from 1 to 100, it generates 165 as an output (sum > of 1,9,25,49,81) > > Here is the code I have > print reduce(lambda x, y: x+y, filter(lambda x: x%2, map(lambda x: > x*x, xrange > (10**6)))) = sum(x*x for x in xrange(1, 10**6, 2)) > > I am getting a syntax error. > Can you let me know what the error is? > > I am new to Python and am also looking for good documentation on > python functions.http://www.python.org/doc/does not provide examples > of usage of each function In problems like this it is usually preferable to use list comprehensions over map/filter. Your problem is literally solvable like this: >>> [sq for sq in [x*x for x in range(100)] if sq%2 == 1 and sq <= 100] [1, 9, 25, 49, 81] >>> sum([sq for sq in [x*x for x in range(100)] if sq%2 == 1 and sq <= 100]) 165 Using Dave's observation that odd(x) == odd(x*x) it simplifies to >>> sum([x*x for x in range(100) if x%2==1 and x*x <=100]) 165 Note: Python comprehensions unlike Haskell does not allow local lets so the x*x has to be repeated From miki.tebeka at gmail.com Sun Apr 7 13:04:51 2013 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sun, 7 Apr 2013 10:04:51 -0700 (PDT) Subject: Newbie to python. Very newbie question In-Reply-To: References: Message-ID: <8cf004b8-fa76-4c94-b366-fccbf448c914@googlegroups.com> > I am a newbie to python Welcome! I hope you'll do great things with Python. > and am trying to write a program that does a > sum of squares of numbers whose squares are odd. OK. > For example, for x from 1 to 100, it generates 165 as an output (sum > of 1,9,25,49,81) I don't follow, you seem to be missing a lot of numbers. For example 3^2 = 9 which is odd as well. > Here is the code I have > print reduce(lambda x, y: x+y, filter(lambda x: x%2, map(lambda x: > x*x, xrange > (10**6)))) = sum(x*x for x in xrange(1, 10**6, 2)) print X = Y is a syntax error. Why do you need the 2'nd part. In general, we're moving to list/generator comperhension over map/filter. Something like: print(sum(x*x for x in xrange(10**6) if (x*x)%2)) HTH, Miki From ian at feete.org Sun Apr 7 15:23:49 2013 From: ian at feete.org (Ian Foote) Date: Sun, 07 Apr 2013 20:23:49 +0100 Subject: Newbie to python. Very newbie question In-Reply-To: References: Message-ID: <5161C7C5.6000908@feete.org> On 07/04/13 20:09, Dennis Lee Bieber wrote: > On Sun, 7 Apr 2013 04:16:27 -0700 (PDT), ReviewBoard User > declaimed the following in > gmane.comp.python.general: > >> Hi >> I am a newbie to python and am trying to write a program that does a >> sum of squares of numbers whose squares are odd. >> For example, for x from 1 to 100, it generates 165 as an output (sum >> of 1,9,25,49,81) >> >> Here is the code I have >> print reduce(lambda x, y: x+y, filter(lambda x: x%2, map(lambda x: >> x*x, xrange >> (10**6)))) = sum(x*x for x in xrange(1, 10**6, 2)) >> >> I am getting a syntax error. >> Can you let me know what the error is? >> > I can't even read that mess... three nested lambda? > > Not the most efficient version but... > >>>> sum( x*x for x in range(100/2) if (x*x % 2) and (x*x < 100) ) > 165 >> > > The range(100/2) is a simple reduction to avoid invoking a sqrt > function... the more economical is > >>>> import math >>>> sum( x*x for x in range(int(math.sqrt(100))) if x*x % 2) > 165 >>>> I'm surprised no one has suggested: >>> import math >>> sum( x*x for x in range(1, int(math.sqrt(100)), 2)) Regards, Ian F From arnodel at gmail.com Sun Apr 7 16:16:34 2013 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 7 Apr 2013 21:16:34 +0100 Subject: Newbie to python. Very newbie question In-Reply-To: <5161C7C5.6000908@feete.org> References: <5161C7C5.6000908@feete.org> Message-ID: On 7 April 2013 20:23, Ian Foote wrote: > I'm surprised no one has suggested: > >>>> import math >>>> sum( x*x for x in range(1, int(math.sqrt(100)), 2)) Yeah! And I'm surprised no one came up with: >>> from itertools import count, takewhile >>> sum(takewhile((100).__gt__, filter((2).__rmod__, map((2).__rpow__, count(1))))) 165 :) -- Arnaud From miki.tebeka at gmail.com Sun Apr 7 19:57:20 2013 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sun, 7 Apr 2013 16:57:20 -0700 (PDT) Subject: Newbie to python. Very newbie question In-Reply-To: References: Message-ID: <8fafbd2c-1fe5-4615-b85b-633a7a2a5756@googlegroups.com> > I can't even read that mess... three nested lambda? I have to say this and other answers in this thread seem not that friendly to me. The OP said it's a newbie question, we should be more welcoming to newcomers. From steve+comp.lang.python at pearwood.info Sun Apr 7 23:16:25 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Apr 2013 03:16:25 GMT Subject: Newbie to python. Very newbie question References: Message-ID: <51623687$0$29868$c3e8da3$5496439d@news.astraweb.com> On Sun, 07 Apr 2013 04:16:27 -0700, ReviewBoard User wrote: > Hi > I am a newbie to python and am trying to write a program that does a sum > of squares of numbers whose squares are odd. For example, for x from 1 > to 100, it generates 165 as an output (sum of 1,9,25,49,81) > > Here is the code I have > print reduce(lambda x, y: x+y, filter(lambda x: x%2, map(lambda x: x*x, > xrange(10**6)))) = sum(x*x for x in xrange(1, 10**6, 2)) > > I am getting a syntax error. > Can you let me know what the error is? Python already has told you what the error is. You should read the error message. If you don't understand it, you should copy and paste the full traceback, starting with the line "Traceback", and ask for help. But please do not expect us to *guess* what error you are seeing. I'm now going to guess. I think you are seeing this error: py> len(x) = len(y) File "", line 1 SyntaxError: can't assign to function call In this example, I have a function call, len(x), on the left hand side of an assignment. That is illegal syntax. In your code, you also have a function call reduce(...) on the left hand side of an assignment. If the error message is not clear enough, can you suggest something that would be more understandable? Perhaps you meant to use an equality test == instead of = assignment. > I am new to Python and am also looking for good documentation on python > functions. http://www.python.org/doc/ does not provide examples of usage > of each function No, the reference material does not generally provide examples. Some people like that style, and some don't. However, many pages do have extensive examples: http://docs.python.org/2/library/string.html You should also work through a tutorial or two. Also the "Module of the week" website is very good: http://pymotw.com -- Steven From ngnedin at gmail.com Sun Apr 7 14:02:09 2013 From: ngnedin at gmail.com (Nick Gnedin) Date: Sun, 07 Apr 2013 13:02:09 -0500 Subject: __doc__ string for getset members Message-ID: <5161B4A1.80604@gmail.com> Folks, I am writing an extension where I follow the guide on the web (http://docs.python.org/3.3/extending/newtypes.html#generic-attribute-management). I have an object declared, struct Object { PyObject_HEAD }; and a member set through tp_getset mechanism, PyGetSetDef ObjectGetSet[] = { {"mem", (getter)MemGet, (setter)MemSet, "mem-doc-string", NULL}, {NULL} /* Sentinel */ }; My question is - how do I access the doc string "mem-doc-string" supplied in the PyGetSetDef structure? If I type print(obj.mem.__doc__) then the __doc__ string for the result of a call to MemGet(...) is printed, not the doc string supplied in the PyGetSetDef structure. Many thanks for the advice, Nick Gnedin From arnodel at gmail.com Sun Apr 7 16:21:03 2013 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 7 Apr 2013 21:21:03 +0100 Subject: __doc__ string for getset members In-Reply-To: <5161B4A1.80604@gmail.com> References: <5161B4A1.80604@gmail.com> Message-ID: On 7 April 2013 19:02, Nick Gnedin wrote: > > Folks, > > I am writing an extension where I follow the guide on the web > (http://docs.python.org/3.3/extending/newtypes.html#generic-attribute-management). > I have an object declared, > > struct Object > { > PyObject_HEAD > }; > > and a member set through tp_getset mechanism, > > PyGetSetDef ObjectGetSet[] = > { > {"mem", (getter)MemGet, (setter)MemSet, "mem-doc-string", NULL}, > {NULL} /* Sentinel */ > }; > > My question is - how do I access the doc string "mem-doc-string" supplied in > the PyGetSetDef structure? If I type > > print(obj.mem.__doc__) > > then the __doc__ string for the result of a call to MemGet(...) is printed, > not the doc string supplied in the PyGetSetDef structure. > That's not how Python works. You won't be able to get the docstring of a descriptor this way. You need to do it from the class. The behaviour you observe is normal and cannot be overriden. -- Arnaud From arnodel at gmail.com Sun Apr 7 16:48:02 2013 From: arnodel at gmail.com (Arnaud Delobelle) Date: Sun, 7 Apr 2013 21:48:02 +0100 Subject: __doc__ string for getset members In-Reply-To: <5161D946.7080606@gmail.com> References: <5161B4A1.80604@gmail.com> <5161D946.7080606@gmail.com> Message-ID: On 7 April 2013 21:38, Nick Gnedin wrote: > > Arnaud, > > Thanks for the answer. I understand that I cannot access the docstring as an > attribute of a getter, but what did you mean when you said "You need to do > it from the class"? I am still confused - is there a way to get that > docstring or not? > > Nick > Please reply on-list -- Arnaud From steve+comp.lang.python at pearwood.info Sun Apr 7 17:35:50 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Apr 2013 21:35:50 GMT Subject: __doc__ string for getset members References: <5161B4A1.80604@gmail.com> Message-ID: <5161e6b5$0$29995$c3e8da3$5496439d@news.astraweb.com> On Sun, 07 Apr 2013 21:21:03 +0100, Arnaud Delobelle wrote: > On 7 April 2013 19:02, Nick Gnedin wrote: [...] >> My question is - how do I access the doc string "mem-doc-string" >> supplied in the PyGetSetDef structure? If I type >> >> print(obj.mem.__doc__) >> >> then the __doc__ string for the result of a call to MemGet(...) is >> printed, not the doc string supplied in the PyGetSetDef structure. >> >> > That's not how Python works. You won't be able to get the docstring of > a descriptor this way. You need to do it from the class. The behaviour > you observe is normal and cannot be overriden. All very well and good, but how about putting Nick out of his misery and showing how to do it? print(obj.__class__.mem.__doc__) ought to work. -- Steven From subhabangalore at gmail.com Sun Apr 7 16:25:57 2013 From: subhabangalore at gmail.com (subhabangalore at gmail.com) Date: Sun, 7 Apr 2013 13:25:57 -0700 (PDT) Subject: Splitting of string at an interval Message-ID: Dear Group, I was looking to split a string in a particular interval, like, If I have a string, string="The Sun rises in the east of our earth" I like to see it as, words=["The Sun","rises in","in the","east of","our earth"] If any one of the learned members can kindly suggest. Regards, Subhabrata. From davea at davea.name Sun Apr 7 16:46:44 2013 From: davea at davea.name (Dave Angel) Date: Sun, 07 Apr 2013 16:46:44 -0400 Subject: Splitting of string at an interval In-Reply-To: References: Message-ID: <5161DB34.1070201@davea.name> On 04/07/2013 04:25 PM, subhabangalore at gmail.com wrote: > Dear Group, > > I was looking to split a string in a particular interval, like, > > If I have a string, > string="The Sun rises in the east of our earth" Are you asserting that there is nothing but letters and whitespace in the string, and that any amount of consecutive whitespace may be considered a blank? > > I like to see it as, > words=["The Sun","rises in","in the","east of","our earth"] Those aren't words, they're phrases. But more importantly, you're somehow doubling the word "in" before parsing. > > If any one of the learned members can kindly suggest. > split it into a list, use slices to divide that into even and odd numbered words. Use zip to combine those two list together, and then combine the resultant tuples with a space between. -- DaveA From steve+comp.lang.python at pearwood.info Sun Apr 7 17:48:07 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Apr 2013 21:48:07 GMT Subject: Splitting of string at an interval References: Message-ID: <5161e996$0$29995$c3e8da3$5496439d@news.astraweb.com> On Sun, 07 Apr 2013 13:25:57 -0700, subhabangalore wrote: > Dear Group, > > I was looking to split a string in a particular interval, like, > > If I have a string, > string="The Sun rises in the east of our earth" > > I like to see it as, > words=["The Sun","rises in","in the","east of","our earth"] > > If any one of the learned members can kindly suggest. Like every programming problem, the solution is to break it apart into small, simple steps that even a computer can follow. 1) Split the string into words at whitespace. words = string.split() 2) Search for the word "in", and if found, duplicate it. tmp = [] for word in words: if word == 'in': tmp.append('in') tmp.append(word) words = tmp 3) Take the words two at a time. phrases = [words[i:i+2] for i in range(0, len(words), 2)] 4) Join the phrases into strings. phrases = [' '.join(phrase) for phrase in phrases] -- Steven From rosuav at gmail.com Sun Apr 7 23:01:57 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 8 Apr 2013 13:01:57 +1000 Subject: Splitting of string at an interval In-Reply-To: <5161e996$0$29995$c3e8da3$5496439d@news.astraweb.com> References: <5161e996$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Apr 8, 2013 at 7:48 AM, Steven D'Aprano wrote: > Like every programming problem, the solution is to break it apart into > small, simple steps that even a computer can follow. > ... 5) Shortcut the whole thing, since the problem was underspecified, by using a literal. words = ["The Sun", "rises in", "in the", "east of", "our earth"] *dive for cover against rotten tomatoes* ChrisA From roy at panix.com Mon Apr 8 09:21:56 2013 From: roy at panix.com (Roy Smith) Date: Mon, 08 Apr 2013 09:21:56 -0400 Subject: Splitting of string at an interval References: <5161e996$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Chris Angelico wrote: > On Mon, Apr 8, 2013 at 7:48 AM, Steven D'Aprano > wrote: > > Like every programming problem, the solution is to break it apart into > > small, simple steps that even a computer can follow. > > ... > > 5) Shortcut the whole thing, since the problem was underspecified, by > using a literal. > > words = ["The Sun", "rises in", "in the", "east of", "our earth"] > > *dive for cover against rotten tomatoes* Seems like the right solution to me. For a while, I was rabidly(*) into TDD (Test Driven Development). The cycle I was using was, "Write a specification of a behavior, write a (failing) test for that behavior, then write the least possible amount of code to make the test pass. Lather, Rinse, Repeat, Ship" The "least possible" part is important. It makes sure the cycles stay short (ideally, just a few minutes), and that you don't write any code for which you don't have tests. If you buy into that plan, then I see nothing wrong with your suggested solution. (*) I still believe in TDD, but I don't practice it quite as enthusiastically as I used to. Which probably means my code isn't as good as it used to be. From arnodel at gmail.com Mon Apr 8 11:10:59 2013 From: arnodel at gmail.com (Arnaud Delobelle) Date: Mon, 8 Apr 2013 16:10:59 +0100 Subject: Splitting of string at an interval In-Reply-To: References: <5161e996$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8 April 2013 14:21, Roy Smith wrote: > For a while, I was rabidly(*) into TDD (Test Driven Development). The > cycle I was using was, "Write a specification of a behavior, write a > (failing) test for that behavior, then write the least possible amount > of code to make the test pass. Lather, Rinse, Repeat, Ship" > > The "least possible" part is important. It makes sure the cycles stay > short (ideally, just a few minutes), and that you don't write any code > for which you don't have tests. The least amount of code is often also not the best in terms of time or space complexity. Does this mean you have to write tests for time and space complexity as well? That's interesting, but I don't know of tools to help do that (time complexity seems easy enough, but space complexity seems tougher to me). -- Arnaud From roy at panix.com Mon Apr 8 11:37:28 2013 From: roy at panix.com (Roy Smith) Date: Mon, 8 Apr 2013 11:37:28 -0400 Subject: Splitting of string at an interval In-Reply-To: References: <5161e996$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Apr 8, 2013, at 11:10 AM, Arnaud Delobelle wrote: > On 8 April 2013 14:21, Roy Smith wrote: > >> For a while, I was rabidly(*) into TDD (Test Driven Development). The >> cycle I was using was, "Write a specification of a behavior, write a >> (failing) test for that behavior, then write the least possible amount >> of code to make the test pass. Lather, Rinse, Repeat, Ship" >> >> The "least possible" part is important. It makes sure the cycles stay >> short (ideally, just a few minutes), and that you don't write any code >> for which you don't have tests. > > The least amount of code is often also not the best in terms of time > or space complexity. Does this mean you have to write tests for time > and space complexity as well? That's interesting, but I don't know of > tools to help do that (time complexity seems easy enough, but space > complexity seems tougher to me). If space and time complexity are important, then you need to write a test for those things. If you have no test for them, then it's not important and you shouldn't worry about it. At least according to the TDD catechism :-) From a somewhat less radical point of view, the first thing you want to do is get the code to produce correct results. Once you've got that (and a fully comprehensive test suite to prove it), then you can move on to making it more efficient, and your test suite serves as protection against behavior regressions. And, yes, I agree that testing for time and space complexity are not trivial, because making accurate, repeatable, and isolated measurements of those things is often surprisingly complicated. I can't help point out, however, that if your initial implementation is to have your code return a constant, it's pretty likely to be an optimum solution in both time and space :-) --- Roy Smith roy at panix.com From rosuav at gmail.com Mon Apr 8 12:20:17 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 9 Apr 2013 02:20:17 +1000 Subject: Splitting of string at an interval In-Reply-To: References: <5161e996$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Apr 9, 2013 at 1:37 AM, Roy Smith wrote: > I can't help point out, however, that if your initial implementation is to have your code return a constant, it's pretty likely to be an optimum solution in both time and space :-) Likely, but not certain. # 1 def fifty_stars(): return "**************************************************" # 2 fifty_stars=lambda "*"*50 Okay, that's just getting 2AM stupid now. :) ChrisA From arnodel at gmail.com Mon Apr 8 12:30:26 2013 From: arnodel at gmail.com (Arnaud Delobelle) Date: Mon, 8 Apr 2013 17:30:26 +0100 Subject: Splitting of string at an interval In-Reply-To: References: <5161e996$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 8 April 2013 17:20, Chris Angelico wrote: > On Tue, Apr 9, 2013 at 1:37 AM, Roy Smith wrote: >> I can't help point out, however, that if your initial implementation is to have your code return a constant, it's pretty likely to be an optimum solution in both time and space :-) > > Likely, but not certain. > > # 1 > def fifty_stars(): > return "**************************************************" > > # 2 > fifty_stars=lambda "*"*50 There's a whole competition about writing the smallest program which outputs the song "99 bottles of beer": http://codegolf.com/99-bottles-of-beer Cheers, -- Arnaud From roy at panix.com Mon Apr 8 21:09:08 2013 From: roy at panix.com (Roy Smith) Date: Mon, 08 Apr 2013 21:09:08 -0400 Subject: Splitting of string at an interval References: <5161e996$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Arnaud Delobelle wrote: > On 8 April 2013 17:20, Chris Angelico wrote: > > On Tue, Apr 9, 2013 at 1:37 AM, Roy Smith wrote: > >> I can't help point out, however, that if your initial implementation is to > >> have your code return a constant, it's pretty likely to be an optimum > >> solution in both time and space :-) > > > > Likely, but not certain. > > > > # 1 > > def fifty_stars(): > > return "**************************************************" > > > > # 2 > > fifty_stars=lambda "*"*50 > > There's a whole competition about writing the smallest program which > outputs the song "99 bottles of beer": > > http://codegolf.com/99-bottles-of-beer I see the top 10 entries are all written in Perl. I suppose this says something. From python.list at tim.thechases.com Mon Apr 8 21:42:24 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 8 Apr 2013 20:42:24 -0500 Subject: Splitting of string at an interval In-Reply-To: References: <5161e996$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20130408204224.7451fc4f@bigbox.christie.dr> On 2013-04-08 21:09, Roy Smith wrote: >> http://codegolf.com/99-bottles-of-beer > > I see the top 10 entries are all written in Perl. I suppose this > says something. About the capabilities of Perl for writing such code, or about the drinking habits of Perl programmers? :-) Or-about-how-perl-drives-you-to-drink'ly yours, -tkc From steve+comp.lang.python at pearwood.info Mon Apr 8 22:38:09 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Apr 2013 02:38:09 GMT Subject: Splitting of string at an interval References: <5161e996$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51637f11$0$30003$c3e8da3$5496439d@news.astraweb.com> On Mon, 08 Apr 2013 21:09:08 -0400, Roy Smith wrote: >> There's a whole competition about writing the smallest program which >> outputs the song "99 bottles of beer": >> >> http://codegolf.com/99-bottles-of-beer > > I see the top 10 entries are all written in Perl. I suppose this says > something. When I write my own programming language, it will include a one-character built-in command to perform 99 bottles of beer, just so my language will always be the winner. In fact, I may make it a bare . so that not only will it be the shortest program, but also the smallest program in terms of number of non-white pixels. -- Steven From bahamutzero8825 at gmail.com Mon Apr 8 22:57:36 2013 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Mon, 08 Apr 2013 21:57:36 -0500 Subject: Splitting of string at an interval In-Reply-To: <51637f11$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <5161e996$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637f11$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <516383A0.7050003@gmail.com> On 2013.04.08 21:38, Steven D'Aprano wrote: > In fact, I may make it a bare . so that not only will it be the shortest > program, but also the smallest program in terms of number of non-white > pixels. Until someone implements it in Whitespace. -- CPython 3.3.0 | Windows NT 6.2.9200 / FreeBSD 9.1 From rosuav at gmail.com Tue Apr 9 00:22:35 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 9 Apr 2013 14:22:35 +1000 Subject: Splitting of string at an interval In-Reply-To: <51637f11$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <5161e996$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637f11$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Apr 9, 2013 at 12:38 PM, Steven D'Aprano wrote: > On Mon, 08 Apr 2013 21:09:08 -0400, Roy Smith wrote: > >>> There's a whole competition about writing the smallest program which >>> outputs the song "99 bottles of beer": >>> >>> http://codegolf.com/99-bottles-of-beer >> >> I see the top 10 entries are all written in Perl. I suppose this says >> something. > > > When I write my own programming language, it will include a one-character > built-in command to perform 99 bottles of beer, just so my language will > always be the winner. > > In fact, I may make it a bare . so that not only will it be the shortest > program, but also the smallest program in terms of number of non-white > pixels. Don't be too specific, Steven. Also include a one-character built-in to emit the program's own source, and another to echo "hello, world" to standard output. And one to increment the accumulator, just for completeness. Who knows, it might already exist! http://esolangs.org/wiki/Cliff_L._Biffle ChrisA From davea at davea.name Tue Apr 9 02:28:51 2013 From: davea at davea.name (Dave Angel) Date: Tue, 09 Apr 2013 02:28:51 -0400 Subject: Splitting of string at an interval In-Reply-To: <51637f11$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <5161e996$0$29995$c3e8da3$5496439d@news.astraweb.com> <51637f11$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5163B523.700@davea.name> On 04/08/2013 10:38 PM, Steven D'Aprano wrote: > On Mon, 08 Apr 2013 21:09:08 -0400, Roy Smith wrote: > >>> There's a whole competition about writing the smallest program which >>> outputs the song "99 bottles of beer": >>> >>> http://codegolf.com/99-bottles-of-beer >> >> I see the top 10 entries are all written in Perl. I suppose this says >> something. > > > When I write my own programming language, it will include a one-character > built-in command to perform 99 bottles of beer, just so my language will > always be the winner. > > In fact, I may make it a bare . so that not only will it be the shortest > program, but also the smallest program in terms of number of non-white > pixels. > But do we need a shebang line? If so, then make sure the interpreter name is also one character long. I expect there's a character with fewer pixels than the period, but the utf-8 version of it would be more than one byte long. But you could define your language with a default encoding that happens to map said character to a single byte. The Wang word processor (proprietary hardware and OS) used a single pixel for \x20, and the no pixels for the \xff. This way spaces were "visible" with a faint dot, more or less in the middle of the cell block. It defined other symbols for other control characters like tab and newline. I'm still looking for a similar feature for emacs (on Ubuntu), but so far I've been disappointed by the results. Libreoffice has a similar feature, enabled by View->NonPrintingCharacters, but the dotted space is way too bold, basically a period that's higher in its cell. -- DaveA From musikal.fusion at gmail.com Sun Apr 7 20:40:11 2013 From: musikal.fusion at gmail.com (Barrett Lewis) Date: Sun, 7 Apr 2013 17:40:11 -0700 Subject: with ignored Message-ID: I was recently watching that Raymond Hettinger video on creating Beautiful Python from this years PyCon. He mentioned pushing up the new idiom with ignored(): # do some work I tracked down his commit here http://hg.python.org/cpython/rev/406b47c64480 But am unsure how the yield works in the given situation. I know about creating generators with yield and have read the docs on how it maintains state. I think it works because it is returning control back to the caller while maintaining the try so if the caller throws it is caught by the context. Is this correct? I would love an in depth explanation of how this is working. I am trying to learn as much as possible about the actual python internals. Thanks in advance! -Barrett -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Mon Apr 8 00:53:05 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 7 Apr 2013 22:53:05 -0600 Subject: with ignored In-Reply-To: References: Message-ID: On Sun, Apr 7, 2013 at 6:40 PM, Barrett Lewis wrote: > I was recently watching that Raymond Hettinger video on creating Beautiful > Python from this years PyCon. > He mentioned pushing up the new idiom > > with ignored(): > # do some work > > I tracked down his commit here http://hg.python.org/cpython/rev/406b47c64480 > > But am unsure how the yield works in the given situation. > > I know about creating generators with yield and have read the docs on how it > maintains state. > > I think it works because it is returning control back to the caller while > maintaining the try so if the caller throws it is caught by the context. Is > this correct? I would love an in depth explanation of how this is working. I > am trying to learn as much as possible about the actual python internals. The first thing to understand is that ignored() is a context manager and how context managers work. A context manager is an object with an __enter__ method and an __exit__ method. For example, the ignored() context manager could have been written as: class ignored: def __init__(self, *exceptions): self.__exceptions = exceptions def __enter__(self): return def __exit__(self, exc_type, exc_value, traceback): if exc_type is not None: return issubclass(exc_type, self.__exceptions) The __enter__ method is called when the with block is entered and sets up the context. The __exit__ method is called when the with block is exited and is passed the exception if one was raised. It returns True to suppress the exception, or False to continue propagating it. However, ignored() is actually implemented as a generator function with the @contextmanager decorator shortcut. This decorator takes a generator function and wraps it up as a class with the necessary __enter__ and __exit__ methods. The __enter__ method in this case calls the .next() method of the generator and returns after it yields once. The __exit__ method calls it again -- or it calls the .throw() method if an exception was passed in -- and expects the generator to exit as a result. So from the perspective of the generator it does its context setup (in this case, setting up a try block) prior to the yield, and then does the cleanup (in this case, selectively catching and suppressing the exceptions) after the yield. From musikal.fusion at gmail.com Mon Apr 8 02:38:55 2013 From: musikal.fusion at gmail.com (Barrett Lewis) Date: Sun, 7 Apr 2013 23:38:55 -0700 Subject: with ignored In-Reply-To: References: Message-ID: > > However, ignored() is actually implemented as a generator function > with the @contextmanager decorator shortcut. This decorator takes a > generator function and wraps it up as a class with the necessary > __enter__ and __exit__ methods. The __enter__ method in this case > calls the .next() method of the generator and returns after it yields > once. I looked up the source to the decorator found here:http://hg.python.org/cpython/file/406b47c64480/Lib/contextlib.py for anyone interested. It appears that they are using yield so that they can call it again and force it to throw the stop iteration exception. > The __exit__ method calls it again -- or it calls the .throw() > method if an exception was passed in -- and expects the generator to > exit as a result. > > And here to go with what I said above, they want to be able to use the generators throw ability to capture any exception and throw it to the generator, but then why do they *need* the generator to not iterate again? Or in other words, why when they create the context manager via _GeneratorContextManager on line 33, is there the clause in __exit__ to have stop iteration happen or else throw a runtime error? I am thinking this is because it needs the yield to be over so that it can return the control flow to normal, and that subroutine will be done. But I am new to the whole subroutine paradigm so I could be misunderstanding this. Also, if the value was none, why are they instantiating a new exception with value = type()? How could there be a type for the exception without the exception? (From what I understand type is the error type, and value is the error object). So from the perspective of the generator it does its context setup (in > this case, setting up a try block) prior to the yield, and then does > the cleanup (in this case, selectively catching and suppressing the > exceptions) after the yield. > This part makes sense logically. And I like the simplicity. Now I just need to make sure I understand how the yield semantics are allowing this construct to work. Thanks for the reply Ian! > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From austinmatherne at gmail.com Mon Apr 8 00:06:52 2013 From: austinmatherne at gmail.com (austinmatherne at gmail.com) Date: Sun, 7 Apr 2013 21:06:52 -0700 (PDT) Subject: "pip install PySide" fails from local Python installs Message-ID: <5477e1d1-0bc8-4d31-8690-a22ef3c0b0c2@googlegroups.com> I've used pythonbrew, pythonz, and pyenv to install CPython 3.3.1, but all of them give me the same error when running "pip install PySide": error: Failed to locate the Python library /home/.../lib/libpython3.3m.so Is this a problem with PySide, or with the various local Python installers I've used? If I use the system version of pip, PySide installs just fine. From rosuav at gmail.com Mon Apr 8 03:32:13 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 8 Apr 2013 17:32:13 +1000 Subject: Formatting lost in hg-web (was Re: with ignored) Message-ID: On Mon, Apr 8, 2013 at 4:38 PM, Barrett Lewis wrote: > I looked up the source to the decorator > found here:http://hg.python.org/cpython/file/406b47c64480/Lib/contextlib.py > for anyone interested. Strangely, line indentation seems to be swallowed in the web view of the Mercurial tree. The code directly follows the line numbers, so it goes ragged between (eg) lines 9 and 10. Is this a browser bug? I tried on Chrome 26.0.1410.40 and Firefox 19.0.2 on Windows. ChrisA From musikal.fusion at gmail.com Mon Apr 8 03:36:21 2013 From: musikal.fusion at gmail.com (Barrett Lewis) Date: Mon, 8 Apr 2013 00:36:21 -0700 Subject: Formatting lost in hg-web (was Re: with ignored) In-Reply-To: References: Message-ID: I am viewing it on Chrome Version 26.0.1410.43 m for windows and it works perfectly for me. On Mon, Apr 8, 2013 at 12:32 AM, Chris Angelico wrote: > On Mon, Apr 8, 2013 at 4:38 PM, Barrett Lewis > wrote: > > I looked up the source to the decorator > > found here: > http://hg.python.org/cpython/file/406b47c64480/Lib/contextlib.py > > for anyone interested. > > Strangely, line indentation seems to be swallowed in the web view of > the Mercurial tree. The code directly follows the line numbers, so it > goes ragged between (eg) lines 9 and 10. Is this a browser bug? I > tried on Chrome 26.0.1410.40 and Firefox 19.0.2 on Windows. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Apr 8 03:40:59 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 8 Apr 2013 17:40:59 +1000 Subject: Formatting lost in hg-web (was Re: with ignored) In-Reply-To: References: Message-ID: On Mon, Apr 8, 2013 at 5:36 PM, Barrett Lewis wrote: > I am viewing it on Chrome Version 26.0.1410.43 m for windows and it works > perfectly for me. Huh. Extremely weird. Ctrl-F5 fixed it, and now the source looks different. Either someone's *right now* editing stuff (in which case I'll shut up and let him/her do so), or there's something insanely weird in my system. Which is possible... Windows XP, second-last bastion of real Windows in my control... ChrisA From zeta.convex at gmail.com Mon Apr 8 03:45:57 2013 From: zeta.convex at gmail.com (zeta.convex at gmail.com) Date: Mon, 8 Apr 2013 00:45:57 -0700 (PDT) Subject: How to do a Lispy-esque read? Message-ID: <4ff75708-f8e4-4ec9-8a4b-e71eb1dc2892@googlegroups.com> Suppose I want to read an object from some stream. How do I do it? For example, if the input stream contained the text: [1, # python should ignore this comment 2] and I do a "read" on it, I should obtain the result [1, 2] From musikal.fusion at gmail.com Mon Apr 8 04:17:57 2013 From: musikal.fusion at gmail.com (Barrett Lewis) Date: Mon, 8 Apr 2013 01:17:57 -0700 Subject: How to do a Lispy-esque read? In-Reply-To: <4ff75708-f8e4-4ec9-8a4b-e71eb1dc2892@googlegroups.com> References: <4ff75708-f8e4-4ec9-8a4b-e71eb1dc2892@googlegroups.com> Message-ID: > For example, if the input stream contained the text: > [1, # python should ignore this comment > 2] > > and I do a "read" on it, I should obtain the result > [1, 2] > -- > I don't know much about lisp but given that input and the desired output you can write functions like the following def strtolist(l): if l.startswith('['): l = l[1:] if l.endswith(']'): l = l[:-1] # treat newlines as if they are commas so we can easily split l = l.replace('\n', ',').split(',') # list comprehension # strip to remove whitespace and aggregate all elements without the comment # you can further refine this to create ints by using the int() method return [x for x in l if not x.strip().startswith('#')] you would have to use input() to read the input or open a file. Either way you can pass that value to strtolist and it will convert it to a list of strings. However, this implementation is not very robust and doesn't cover a lot of edge cases (more a demo of how it might be done, I don't know your python experience so forgive me if this is all self evident). The real solution that I would use would be to use the json module. Docs: http://docs.python.org/3.3/library/json.html It allows you to take a string and turn it into a native dict or list in python. The great part is that it is fairly robust and it has a simple interface. You could take input() and send it to loads and it will return an array. The downside is json doesn't allow comments. If you really want comments, you could look into some of the yaml libraries, a quick google search shoes PyYaml is out there. I however don't have any knowledge of that module or other yaml modules as I find json is enough for anything I've ever attempted. I hope that helps -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Mon Apr 8 04:32:55 2013 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 8 Apr 2013 01:32:55 -0700 Subject: How to do a Lispy-esque read? In-Reply-To: <4ff75708-f8e4-4ec9-8a4b-e71eb1dc2892@googlegroups.com> References: <4ff75708-f8e4-4ec9-8a4b-e71eb1dc2892@googlegroups.com> Message-ID: There is no "read in a stream until it's a valid literal" function as far as I know, but ast.literal_eval will turn your string into an object. On Mon, Apr 8, 2013 at 12:45 AM, wrote: > Suppose I want to read an object from some stream. How do I do it? > > For example, if the input stream contained the text: > [1, # python should ignore this comment > 2] > > and I do a "read" on it, I should obtain the result > [1, 2] > -- > http://mail.python.org/mailman/listinfo/python-list From arnodel at gmail.com Mon Apr 8 13:46:22 2013 From: arnodel at gmail.com (Arnaud Delobelle) Date: Mon, 8 Apr 2013 18:46:22 +0100 Subject: How to do a Lispy-esque read? In-Reply-To: <4ff75708-f8e4-4ec9-8a4b-e71eb1dc2892@googlegroups.com> References: <4ff75708-f8e4-4ec9-8a4b-e71eb1dc2892@googlegroups.com> Message-ID: On 8 April 2013 08:45, wrote: > Suppose I want to read an object from some stream. How do I do it? > > For example, if the input stream contained the text: > [1, # python should ignore this comment > 2] > > and I do a "read" on it, I should obtain the result > [1, 2] You might be interested in code.compile_command() (http://docs.python.org/2/library/code.html) -- Arnaud From hossamalagmy at gmail.com Mon Apr 8 03:48:30 2013 From: hossamalagmy at gmail.com (23alagmy) Date: Mon, 8 Apr 2013 00:48:30 -0700 (PDT) Subject: Newer and newer types of mobile Message-ID: <21f75049-a692-4464-9763-dccc9488762c@y9g2000vbb.googlegroups.com> Newer and newer types of mobile Samsung Galaxy Mini http://natigtas7ab.blogspot.com/2012/10/samsung-galaxy-mini.html Motorola Atrix review http://natigtas7ab.blogspot.com/2012/10/motorola-atrix-review.html LG Optimus Black review http://natigtas7ab.blogspot.com/2012/10/lg-optimus-black-review.html Vodafone Smart review http://natigtas7ab.blogspot.com/2012/10/vodafone-smart-review.html HTC ChaCha review http://natigtas7ab.blogspot.com/2012/10/htc-chacha-review.html HTC Sensation review http://natigtas7ab.blogspot.com/2012/10/htc-sensation-review.html HTC Salsa review http://natigtas7ab.blogspot.com/2012/10/htc-salsa-review.html Sony Ericsson Xperia Neo http://natigtas7ab.blogspot.com/2012/10/sony-ericsson-xperia-neo.html Nokia E6 review http://natigtas7ab.blogspot.com/2012/10/nokia-e6-review.html LG Optimus 3D review http://natigtas7ab.blogspot.com/2012/10/lg-optimus-3d-review.html HP Veer http://natigtas7ab.blogspot.com/2012/10/hp-veer.html Samsung Galaxy Pro review http://natigtas7ab.blogspot.com/2012/10/samsung-galaxy-pro-review.html Nokia X7 http://natigtas7ab.blogspot.com/2012/10/nokia-x7.html Samsung Galaxy S review http://natigtas7ab.blogspot.com/2012/10/samsung-galaxy-s-review.html BlackBerry Bold 9900 http://natigtas7ab.blogspot.com/2012/10/blackberry-bold-9900.html Vodafone 555 Blue http://natigtas7ab.blogspot.com/2012/10/vodafone-555-blue.html Sony Ericsson Xperia Mini http://natigtas7ab.blogspot.com/2012/10/sony-ericsson-xperia-mini.html BlackBerry Curve 8520 http://natigtas7ab.blogspot.com/2012/10/blackberry-curve-8520.html HTC Evo 3D http://natigtas7ab.blogspot.com/2012/10/htc-evo-3d.html BlackBerry Curve 9300 http://natigtas7ab.blogspot.com/2012/10/blackberry-curve-9300.html Three MiFi Huawei Wireless Modem E586 http://natigtas7ab.blogspot.com/2012/10/three-mifi-huawei-wireless-modem-e586.html Sony Ericsson Xperia Mini Pro http://natigtas7ab.blogspot.com/2012/10/sony-ericsson-xperia-mini-pro.html BlackBerry Torch 9860 http://natigtas7ab.blogspot.com/2012/10/blackberry-torch-9860.html BlackBerry Torch 9810 http://natigtas7ab.blogspot.com/2012/10/blackberry-torch-9810.html Samsung Galaxy Fit http://natigtas7ab.blogspot.com/2012/09/samsung-galaxy-fit.html Orange Monte Carlo http://natigtas7ab.blogspot.com/2012/09/orange-monte-carlo.html BlackBerry Torch 9810 http://natigtas7ab.blogspot.com/2012/09/blackberry-torch-9810.html Sony Ericsson Xperia Ray http://natigtas7ab.blogspot.com/2012/09/sony-ericsson-xperia-ray.html Sony Ericsson Mix Walkman http://natigtas7ab.blogspot.com/2012/09/sony-ericsson-mix-walkman.html HTC Titan http://natigtas7ab.blogspot.com/2012/09/htc-titan.html Kyocera Hydro C5170 http://natigtas7ab.blogspot.com/2012/09/kyocera-hydro-c5170.html Kyocera Rise http://natigtas7ab.blogspot.com/2012/09/kyocera-rise.html Sony Xperia P http://natigtas7ab.blogspot.com/2012/09/sony-xperia-p.html LG Optimus L7 http://natigtas7ab.blogspot.com/2012/09/lg-optimus-l7.html Sony Xperia S http://natigtas7ab.blogspot.com/2012/09/sony-xperia-s.html Vodafone Smart 2 http://natigtas7ab.blogspot.com/2012/09/vodafone-smart-2.html Samsung Galaxy S Advance http://natigtas7ab.blogspot.com/2012/09/samsung-galaxy-s-advance.html Motorola Droid Razr Maxx http://natigtas7ab.blogspot.com/2012/09/motorola-droid-razr-maxx.html Sony Xperia U http://natigtas7ab.blogspot.com/2012/09/sony-xperia-u.html Motorola MotoSmart http://natigtas7ab.blogspot.com/2012/09/motorola-motosmart.html Sony Xperia Miro http://natigtas7ab.blogspot.com/2012/09/sony-xperia-miro.html Nokia Lumia 900 http://natigtas7ab.blogspot.com/2012/09/nokia-lumia-900_28.html LG Optimus 4X HD http://natigtas7ab.blogspot.com/2012/09/lg-optimus-4x-hd.html HTC Explorer http://natigtas7ab.blogspot.com/2012/09/htc-explorer_28.html Samsung Galaxy Ace 2 http://natigtas7ab.blogspot.com/2012/09/samsung-galaxy-ace-2.html HTC Desire C http://natigtas7ab.blogspot.com/2012/09/htc-desire-c.html Samsung Galaxy Beam http://natigtas7ab.blogspot.com/2012/09/samsung-galaxy-beam.html BlackBerry Curve 9320 http://natigtas7ab.blogspot.com/2012/09/blackberry-curve-9320.html Nokia 808 PureView http://natigtas7ab.blogspot.com/2012/09/nokia-808-pureview.html Samsung Galaxy Note http://natigtas7ab.blogspot.com/2012/09/samsung-galaxy-note.html Samsung Tocco Lite 2 http://natigtas7ab.blogspot.com/2012/09/samsung-tocco-lite-2.html Sony Xperia Go http://natigtas7ab.blogspot.com/2012/09/sony-xperia-go_28.html ZTE Grand X http://natigtas7ab.blogspot.com/2012/09/zte-grand-x.html Huawei Ascend P1 http://natigtas7ab.blogspot.com/2012/09/huawei-ascend-p1.html HTC Explorer http://natigtas7ab.blogspot.com/2012/09/htc-explorer.html iPhone 5 http://natigtas7ab.blogspot.com/2012/09/iphone-5.html Samsung Galaxy Europa i5500 http://natigtas7ab.blogspot.com/2012/09/samsung-galaxy-europa-i5500.html HTC Desire C review http://natigtas7ab.blogspot.com/2012/09/htc-desire-c-review.html Orange San Francisco 2 review http://natigtas7ab.blogspot.com/2012/09/orange-san-francisco-2-review.html Sony Xperia U review http://natigtas7ab.blogspot.com/2012/09/sony-xperia-u-review.html Samsung Galaxy Ace 2 review http://natigtas7ab.blogspot.com/2012/09/samsung-galaxy-ace-2-review.html Nokia Lumia 610 review http://natigtas7ab.blogspot.com/2012/09/nokia-lumia-610-review.html LG Optimus L3 review http://natigtas7ab.blogspot.com/2012/09/lg-optimus-l3-review.html HTC Wildfire S review http://natigtas7ab.blogspot.com/2012/09/htc-wildfire-s-review.html Samsung Galaxy Mini 2 review http://natigtas7ab.blogspot.com/2012/09/samsung-galaxy-mini-2-review.html Sony Xperia Go review http://natigtas7ab.blogspot.com/2012/09/sony-xperia-go-review.html From jeti789 at web.de Mon Apr 8 04:33:13 2013 From: jeti789 at web.de (Bienlein) Date: Mon, 8 Apr 2013 01:33:13 -0700 (PDT) Subject: =?ISO-8859-1?Q?Interactive_development_in_Python_=E0_la_Smalltalk=3F?= Message-ID: Hello, I'm absolutely new to Python, just looked at the language description for the first time. The first thought that came to my mind was whether you can program in Python in an interactive programming style, i.e. I can change code in the debugger which becomes immediately effective (no edit-compile loop) and I can also send messages to objects visible inside the debugger. Then Python could become my replacemenet for my dearly missed Smalltalk, which to my great grief meanwhile really has become quite dead, I fear. In Smalltalk you can open up an inspector window (e.g. you don't have to get into debug mode), inspect objects in it and evaluate code in it, send messaages to objects. I guess this cannot be done in Python out of the box. But if changes made in the debugger became immediately effective, this would be interactive enough for my purposes. Thanks, Bienlein From steve+comp.lang.python at pearwood.info Mon Apr 8 05:27:50 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 08 Apr 2013 09:27:50 GMT Subject: Interactive development in Python =?iso-8859-1?b?4A==?= la Smalltalk? References: Message-ID: <51628d94$0$29868$c3e8da3$5496439d@news.astraweb.com> On Mon, 08 Apr 2013 01:33:13 -0700, Bienlein wrote: > Hello, > > I'm absolutely new to Python, just looked at the language description > for the first time. The first thought that came to my mind was whether > you can program in Python in an interactive programming style, i.e. I > can change code in the debugger which becomes immediately effective (no > edit-compile loop) and I can also send messages to objects visible > inside the debugger. Out of the box, Python comes with an extremely powerful interactive environment. Just launch Python from the command prompt with no arguments, and it will open an interactive interpreter that allows you to enter commands, hit enter, and have them executed. I strongly recommend you work through at least the beginning of the tutorial, and get used to the interactive interpreter. Here's the one for Python 2: http://docs.python.org/2/tutorial/index.html and version 3: http://docs.python.org/3/tutorial/index.html If that's not enough for you, there are third-party Python interpreters that do much more, such as BPython, IPython and DreamPie. http://bpython-interpreter.org/screenshots/ http://ipython.org/index.html http://www.dreampie.org/. IPython will be especially familiar to those used to Mathematica. You can't quite edit code in live objects -- code is compiled to byte- code for a virtual machine, and you cannot edit that -- but you can easily redefine objects, including functions and methods, on the fly. py> class Test(object): ... def method(self, arg): ... print "argument received:", arg ... py> py> t = Test() py> t.method(23) argument received: 23 py> py> def method(self, arg): ... print "argument received:", arg+1000 ... py> Test.method = method py> t.method(23) argument received: 1023 -- Steven From cjw at ncf.ca Mon Apr 8 08:26:40 2013 From: cjw at ncf.ca (Colin J. Williams) Date: Mon, 08 Apr 2013 08:26:40 -0400 Subject: Interactive development in Python =?UTF-8?B?w6AgbGEgU21hbGx0?= =?UTF-8?B?YWxrPw==?= In-Reply-To: References: Message-ID: <5162B780.5050101@ncf.ca> On 08/04/2013 4:33 AM, Bienlein wrote: > Hello, > > I'm absolutely new to Python, just looked at the language description for the first time. The first thought that came to my mind was whether you can program in Python in an interactive programming style, i.e. I can change code in the debugger which becomes immediately effective (no edit-compile loop) and I can also send messages to objects visible inside the debugger. > > Then Python could become my replacemenet for my dearly missed Smalltalk, which to my great grief meanwhile really has become quite dead, I fear. In Smalltalk you can open up an inspector window (e.g. you don't have to get into debug mode), inspect objects in it and evaluate code in it, send messaages to objects. I guess this cannot be done in Python out of the box. But if changes made in the debugger became immediately effective, this would be interactive enough for my purposes. > > Thanks, Bienlein > If you are using Windows, PyScripter is a good choice. I understand that, with Linux, it can also be used with Wine. I haven't tried that. Colin W. From tjreedy at udel.edu Mon Apr 8 15:01:08 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Mon, 08 Apr 2013 15:01:08 -0400 Subject: Interactive development in Python =?ISO-8859-1?Q?=E0_la_?= =?ISO-8859-1?Q?Smalltalk=3F?= In-Reply-To: References: Message-ID: On 4/8/2013 4:33 AM, Bienlein wrote: > Hello, > > I'm absolutely new to Python, just looked at the language description > for the first time. The first thought that came to my mind was > whether you can program in Python in an interactive programming > style, i.e. I can change code in the debugger which becomes > immediately effective (no edit-compile loop) and I can also send > messages to objects visible inside the debugger. The CPython interpreter has both a 'batch' mode (run code in a file) and an interactive mode (run code typed in response to a prompt). It also has a '-i' option to run code in batch mode and then switch to interactive mode so one can interrogate visible objects and call functions. The Idle IDE has editor windows linked to an interactive shell. When you run code in the editor window, it saves and runs it with the -i option so you can interactive with the results in the Shell. Compiling edited text to bytecode is typically so fast (well under a second) as to not be an issue. > Then Python could become my replacemenet for my dearly missed > Smalltalk, which to my great grief meanwhile really has become quite > dead, I fear. In Smalltalk you can open up an inspector window (e.g. > you don't have to get into debug mode), inspect objects in it and > evaluate code in it, send messaages to objects. I guess this cannot > be done in Python out of the box. But if changes made in the debugger > became immediately effective, this would be interactive enough for my > purposes. Idle also has a debugger window that does some of that, though it works better on non-Windows OSes. I have never actually used it. --- Terry Jan Reedy From l.selmi at icloud.com Mon Apr 8 04:01:57 2013 From: l.selmi at icloud.com (leonardo selmi) Date: Mon, 08 Apr 2013 10:01:57 +0200 Subject: help needed Message-ID: <6E5142FB-D0CB-4C7C-B80E-FF0C47E09B82@icloud.com> hello all, i have typed the following program from the book "learn python the hard way": from sys import argv script, first, second, third = argv print "The script is called:", script print "Your first variable is:", first print "Your second variable is:", second print "Your third variable is:", third then i get this error: Traceback (most recent call last): File "/Users/leonardo/Documents/ex13.py", line 3, in script, first, second, third = argv ValueError: need more than 1 value to unpack in the book the author says that i should run the program like this: $ python ex13.py first 2nd 3rd The script is called: ex13.py Your first variable is: first Your second variable is: 2nd Your third variable is: 3rd but how can i do that?? what are the steps? where should i go? thanks! best regards leonardo -------------- next part -------------- An HTML attachment was scrubbed... URL: From musikal.fusion at gmail.com Mon Apr 8 05:15:24 2013 From: musikal.fusion at gmail.com (Barrett Lewis) Date: Mon, 8 Apr 2013 02:15:24 -0700 Subject: help needed In-Reply-To: <6E5142FB-D0CB-4C7C-B80E-FF0C47E09B82@icloud.com> References: <6E5142FB-D0CB-4C7C-B80E-FF0C47E09B82@icloud.com> Message-ID: Do you happen to be on windows? Because if you are then you need to edit the registry. If you are on windows let me know and I will walk you through the fix, but if not then it would be a waste of time for me to explain it. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tampucciolina at libero.it Mon Apr 8 05:29:51 2013 From: tampucciolina at libero.it (leonardo) Date: Mon, 08 Apr 2013 11:29:51 +0200 Subject: help needed In-Reply-To: References: <6E5142FB-D0CB-4C7C-B80E-FF0C47E09B82@icloud.com> Message-ID: <51628E0F.3010109@libero.it> thanks barrett, but i am using a mac.. Il 08/04/2013 11.15, Barrett Lewis ha scritto: > Do you happen to be on windows? Because if you are then you need to > edit the registry. If you are on windows let me know and I will walk > you through the fix, but if not then it would be a waste of time for > me to explain it. > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Apr 8 06:08:00 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 8 Apr 2013 20:08:00 +1000 Subject: help needed In-Reply-To: <51628E0F.3010109@libero.it> References: <6E5142FB-D0CB-4C7C-B80E-FF0C47E09B82@icloud.com> <51628E0F.3010109@libero.it> Message-ID: On Mon, Apr 8, 2013 at 7:29 PM, leonardo wrote: > thanks barrett, but i am using a mac.. Open up Terminal - that'll give you a window with a bash prompt. Proceed from there; it's the same as the default shell on many Linuxes. ChrisA From adam at mesha.org Mon Apr 8 05:25:33 2013 From: adam at mesha.org (Adam Mesha) Date: Mon, 8 Apr 2013 12:25:33 +0300 Subject: help needed In-Reply-To: <6E5142FB-D0CB-4C7C-B80E-FF0C47E09B82@icloud.com> References: <6E5142FB-D0CB-4C7C-B80E-FF0C47E09B82@icloud.com> Message-ID: On Mon, Apr 8, 2013 at 11:01 AM, leonardo selmi wrote: > then i get this error: > > Traceback (most recent call last): > File "/Users/leonardo/Documents/ex13.py", line 3, in > script, first, second, third = argv > ValueError: need more than 1 value to unpack > You didn't provide any arguments to the script. > in the book the author says that i should run the program like this: > > $ python ex13.py first 2nd 3rdThe script is called: ex13.pyYour first variable is: firstYour second variable is: 2ndYour third variable is: 3rd > > but how can i do that?? what are the steps? where should i go? > You need to open a command line terminal and type the first line (without the dollar sign). You will need to change your directory to the directory that contains your exercise script, probably by doing "cd /path/to/exercise/directory". If you're on Windows it's the same idea, you run the "cmd" program, but you would have to specify the full path to the python interpreter instead of just "python", or follow the directions that have been offered for fixing Windows. Adam www.mesha.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From tampucciolina at libero.it Mon Apr 8 07:24:26 2013 From: tampucciolina at libero.it (leonardo) Date: Mon, 8 Apr 2013 13:24:26 +0200 Subject: help needed In-Reply-To: References: <6E5142FB-D0CB-4C7C-B80E-FF0C47E09B82@icloud.com> Message-ID: <32049FE6-8017-4811-A701-B7CA81621807@libero.it> thanks adam, but it is not clear to me yet. if i open the terminal how do i work on it? what should i type in? thanks Il giorno 08/apr/2013, alle ore 11:25, Adam Mesha ha scritto: > On Mon, Apr 8, 2013 at 11:01 AM, leonardo selmi wrote: > then i get this error: > > Traceback (most recent call last): > File "/Users/leonardo/Documents/ex13.py", line 3, in > script, first, second, third = argv > ValueError: need more than 1 value to unpack > > You didn't provide any arguments to the script. > > in the book the author says that i should run the program like this: > > $ python ex13.py first 2nd 3rd > The script is called: ex13.py > Your first variable is: first > Your second variable is: 2nd > Your third variable is: 3rd > but how can i do that?? what are the steps? where should i go? > > You need to open a command line terminal and type the first line (without the dollar sign). You will need to change your directory to the directory that contains your exercise script, probably by doing "cd /path/to/exercise/directory". If you're on Windows it's the same idea, you run the "cmd" program, but you would have to specify the full path to the python interpreter instead of just "python", or follow the directions that have been offered for fixing Windows. > > Adam > www.mesha.org > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Mon Apr 8 07:41:44 2013 From: davea at davea.name (Dave Angel) Date: Mon, 08 Apr 2013 07:41:44 -0400 Subject: help needed In-Reply-To: <32049FE6-8017-4811-A701-B7CA81621807@libero.it> References: <6E5142FB-D0CB-4C7C-B80E-FF0C47E09B82@icloud.com> <32049FE6-8017-4811-A701-B7CA81621807@libero.it> Message-ID: <5162ACF8.9030500@davea.name> On 04/08/2013 07:24 AM, leonardo wrote: > > thanks adam, but it is not clear to me yet. > if i open the terminal how do i work on it? what should i type in? Please don't top-post. It kills off the context. Go back to the previous message and you'll see Adam tells you exactly what to type at the terminal. But to be more literal: python ex13.py first 2nd 3rd -- DaveA From rustompmody at gmail.com Mon Apr 8 07:56:31 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 8 Apr 2013 04:56:31 -0700 (PDT) Subject: help needed References: <6E5142FB-D0CB-4C7C-B80E-FF0C47E09B82@icloud.com> <32049FE6-8017-4811-A701-B7CA81621807@libero.it> Message-ID: <7b36c3ef-89fa-4f50-b003-d49f7fdd7d29@v8g2000yqe.googlegroups.com> On Apr 8, 4:41?pm, Dave Angel wrote: > Go back to the previous message and you'll see Adam tells you exactly > what to type at the terminal. ?But to be more literal: > > python ex13.py ?first 2nd 3rd followed by RET (also called ENTER) key From tampucciolina at libero.it Mon Apr 8 11:26:53 2013 From: tampucciolina at libero.it (leonardo) Date: Mon, 8 Apr 2013 17:26:53 +0200 Subject: help needed In-Reply-To: <7b36c3ef-89fa-4f50-b003-d49f7fdd7d29@v8g2000yqe.googlegroups.com> References: <6E5142FB-D0CB-4C7C-B80E-FF0C47E09B82@icloud.com> <32049FE6-8017-4811-A701-B7CA81621807@libero.it> <7b36c3ef-89fa-4f50-b003-d49f7fdd7d29@v8g2000yqe.googlegroups.com> Message-ID: <303B70AC-96B9-4CD9-9A4B-90145C38EE3D@libero.it> thanks i did it! Il giorno 08/apr/2013, alle ore 13:56, rusi ha scritto: > On Apr 8, 4:41 pm, Dave Angel wrote: > >> Go back to the previous message and you'll see Adam tells you exactly >> what to type at the terminal. But to be more literal: >> >> python ex13.py first 2nd 3rd > > > followed by RET (also called ENTER) key > -- > http://mail.python.org/mailman/listinfo/python-list From antoon.pardon at rece.vub.ac.be Mon Apr 8 05:44:51 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 08 Apr 2013 11:44:51 +0200 Subject: How to subclass a family Message-ID: <51629193.6050301@rece.vub.ac.be> Here is the idea. I have a number of classes with the same interface. Something like the following: class Foo1: def bar(self, ...): work def boo(self, ...): do something self.bar(...) What I want is the equivallent of: class Far1(Foo1): def boo(self, ...) do something different if whatever: self.bar(...) else: Foo1.boo(self, ...) Now of course I could subclass every class from the original family from Foo1 to Foon but that would mean a lot of duplicated code. Is there a way to reduce the use of duplicated code in such circumstances? -- Antoon Pardon From arnodel at gmail.com Mon Apr 8 17:17:03 2013 From: arnodel at gmail.com (Arnaud Delobelle) Date: Mon, 8 Apr 2013 22:17:03 +0100 Subject: How to subclass a family In-Reply-To: <51629193.6050301@rece.vub.ac.be> References: <51629193.6050301@rece.vub.ac.be> Message-ID: On 8 April 2013 10:44, Antoon Pardon wrote: > Here is the idea. I have a number of classes with the same interface. > Something like the following: > > class Foo1: > def bar(self, ...): > work > def boo(self, ...): > do something > self.bar(...) > > What I want is the equivallent of: > > class Far1(Foo1): > def boo(self, ...) > do something different > if whatever: > self.bar(...) > else: > Foo1.boo(self, ...) > > Now of course I could subclass every class from the original family > from Foo1 to Foon but that would mean a lot of duplicated code. Is > there a way to reduce the use of duplicated code in such circumstances? > (Python 3) ------------------------------ class Foo1: def bar(self): print('Foo1.bar') def boo(self, whatever): print('Foo1.boo', whatever) self.bar() # class Foo2: ...(I'll let you define this one) class DifferentBoo: def boo(self, whatever): print('DifferentBoo.boo', whatever) if whatever: self.bar() else: super().boo(whatever) class Far1(DifferentBoo, Foo1): pass # class Far2(DifferentBoo, Foo2): pass ------------------------------ >>> foo = Foo1() >>> foo.bar() Foo1.bar >>> foo.boo(1) Foo1.boo 1 Foo1.bar >>> far = Far1() >>> far.bar() Foo1.bar >>> far.boo(0) DifferentBoo.boo 0 Foo1.boo 0 Foo1.bar >>> far.boo(1) DifferentBoo.boo 1 Foo1.bar HTH, -- Arnaud From jeanpierreda at gmail.com Mon Apr 8 19:22:16 2013 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Mon, 8 Apr 2013 19:22:16 -0400 Subject: How to subclass a family In-Reply-To: <51629193.6050301@rece.vub.ac.be> References: <51629193.6050301@rece.vub.ac.be> Message-ID: On Mon, Apr 8, 2013 at 5:44 AM, Antoon Pardon wrote: > Now of course I could subclass every class from the original family > from Foo1 to Foon but that would mean a lot of duplicated code. Is > there a way to reduce the use of duplicated code in such circumstances? As a rule, if there's duplicate code you can stuff it in a function. def create_subclass(Foo): class Far(Foo): def boo(self, ...) do something different if whatever: self.bar(...) else: super(Far, self).boo(self, ...) return Far Far1 = create_subclass(Foo1) Far2 = create_subclass(Foo2) ... Of course, this doesn't preserve the names of the subclasses properly. To do that you can add a parameter, for the name, although this is a little repetitive. Alternatively you can subclass yet again, as in: class Far1(create_subclass(Foo1)): pass Or you can even change the approach to a class decorator that adds a method: def add_method(cls): def boo(self, ...): do something different if whatever: self.bar(...) else: super(cls, self).boo(...) @add_method class Far1(Foo1): pass @add_method class Far2(Foo2): pass As a wise man once said, TIMTOWTDI. :( -- Devin From steve+comp.lang.python at pearwood.info Mon Apr 8 22:52:33 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Apr 2013 02:52:33 GMT Subject: How to subclass a family References: Message-ID: <51638271$0$30003$c3e8da3$5496439d@news.astraweb.com> On Mon, 08 Apr 2013 11:44:51 +0200, Antoon Pardon wrote: > Here is the idea. I have a number of classes with the same interface. > Something like the following: > > class Foo1: > def bar(self, ...): > work > def boo(self, ...): > do something > self.bar(...) > > What I want is the equivallent of: > > class Far1(Foo1): > def boo(self, ...) > do something different > if whatever: > self.bar(...) > else: > Foo1.boo(self, ...) What do you mean, "the equivalent of"? What's wrong with the code as given? > Now of course I could subclass every class from the original family from > Foo1 to Foon but that would mean a lot of duplicated code. Is there a > way to reduce the use of duplicated code in such circumstances? I don't understand your question. The reason for using inheritance is to reduce the amount of duplicated code. If you're ending up with more code, you're doing something wrong. You're probably badly designing your methods, or your classes, or both. If you give a less contrived example, perhaps we can help. -- Steven From bhk755 at gmail.com Mon Apr 8 06:07:38 2013 From: bhk755 at gmail.com (bhk755 at gmail.com) Date: Mon, 8 Apr 2013 03:07:38 -0700 (PDT) Subject: Can anyone please help me in resolving the error => AttributeError: Array instance has no attribute '__trunc__' Message-ID: I am trying to create 2D arrays without using advanced features like numpy, for this I have created 2 separate modules arrays.py and array2D.py. Here's the code for that: arrays.py module: ================== import ctypes class Array: #Creates an array with size elements. def __init__( self, size ): assert size > 0, "Array size must be > 0" self._size = size print "sixe is %s" %self._size # Create the array structure using the ctypes module. PyArrayType = ctypes.c_int * size self._elements = PyArrayType() print "type is e", type(self._elements) #self._elements = ctypes.c_int * size print "Elements are self.element %s" % self._elements # Initialize each element. #for i in range(self._size): # self.clear( i ) # Returns the size of the array. def __len__( self ): return self._size # Gets the contents of the index element. def __getitem__( self, index ): assert index >= 0 and index < len(self), "Array subscript out of range" return self._elements[ index ] # Puts the value in the array element at index position. def __setitem__( self, index, value ): assert index >= 0 and index < len(self), "Array subscript out of range" print "Type is ", type(index) self._elements[ index ] = value # Clears the array by setting each element to the given value. def clear( self, value ): for i in range( len(self) ) : self._elements[i] = value # Printing the arrays: def __str__(self): return self._elements array2D.py module ================== import arrays class Array2D : # Creates a 2-D array of size numRows x numCols. def __init__( self, numRows, numCols ): # Create a 1-D array to store an array reference for each row. self._theRows = arrays.Array( numRows ) # Create the 1-D arrays for each row of the 2-D array. print "Num of Cloumns is", numCols for i in range( numRows ) : self._theRows[i] = arrays.Array( numCols ) # Returns the number of rows in the 2-D array. def numRows( self ): return len( self._theRows ) # Returns the number of columns in the 2-D array. def numCols( self ): return len( self._theRows[0] ) # Clears the array by setting every element to the given value. def clear( self, value ): for row in range( self.numRows() ): row.clear( value ) # Gets the contents of the element at position [i, j] def __getitem__( self, ndxTuple ): assert len(ndxTuple) == 2, "Invalid number of array subscripts." row = ndxTuple[0] col = ndxTuple[1] assert row >= 0 and row < self.numRows() \ and col >= 0 and col < self.numCols(), \ "Array subscript out of range." the1dArray = self._theRows[row] return the1dArray[col] # Sets the contents of the element at position [i,j] to value. def __setitem__( self, ndxTuple, value ): #assert len(ndxTuple) == 3, "Invalid number of array subscripts." row = ndxTuple[0] col = ndxTuple[1] assert row >= 0 and row < self.numRows() \ and col >= 0 and col < self.numCols(), \ "Array subscript out of range." the1dArray = self._theRows[row] the1dArray[col] = value arr = Array2D(2,4) print "arr is %s" %arr Traceback is : sixe is 2 type is e Elements are self.element Cols in 4 Num of Cloumns is 4 !!!!!!!!!!!!!! i is 0 sixe is 4 type is e Elements are self.element Type is Traceback (most recent call last): File "C:\Python27\Lib\array2D.py", line 53, in arr = Array2D(2,4) File "C:\Python27\Lib\array2D.py", line 16, in __init__ self._theRows[i] = arrays.Array( numCols ) File "C:\Python27\Lib\arrays.py", line 36, in __setitem__ self._elements[ index ] = value AttributeError: Array instance has no attribute '__trunc__' From dylan at dje.me Mon Apr 8 08:40:58 2013 From: dylan at dje.me (Dylan Evans) Date: Mon, 8 Apr 2013 22:40:58 +1000 Subject: Can anyone please help me in resolving the error => AttributeError: Array instance has no attribute '__trunc__' In-Reply-To: References: Message-ID: On Mon, Apr 8, 2013 at 8:07 PM, wrote: > I am trying to create 2D arrays without using advanced features like > numpy, for this I have created 2 separate modules arrays.py and array2D.py. > Here's the code for that: > > arrays.py module: > ================== > import ctypes > > class Array: > > #Creates an array with size elements. > def __init__( self, size ): > assert size > 0, "Array size must be > 0" > self._size = size > print "sixe is %s" %self._size > > # Create the array structure using the ctypes module. > PyArrayType = ctypes.c_int * size > self._elements = PyArrayType() > print "type is e", type(self._elements) > #self._elements = ctypes.c_int * size > > print "Elements are self.element %s" % self._elements > # Initialize each element. > #for i in range(self._size): > # self.clear( i ) > > > # Returns the size of the array. > def __len__( self ): > return self._size > > # Gets the contents of the index element. > def __getitem__( self, index ): > assert index >= 0 and index < len(self), "Array subscript out of > range" > return self._elements[ index ] > > # Puts the value in the array element at index position. > def __setitem__( self, index, value ): > assert index >= 0 and index < len(self), "Array subscript out of > range" > print "Type is ", type(index) > self._elements[ index ] = value > > # Clears the array by setting each element to the given value. > def clear( self, value ): > for i in range( len(self) ) : > self._elements[i] = value > > # Printing the arrays: > def __str__(self): > return self._elements > > > > array2D.py module > ================== > > > import arrays > > class Array2D : > # Creates a 2-D array of size numRows x numCols. > def __init__( self, numRows, numCols ): > # Create a 1-D array to store an array reference for each row. > > self._theRows = arrays.Array( numRows ) > # Create the 1-D arrays for each row of the 2-D array. > print "Num of Cloumns is", numCols > > for i in range( numRows ) : > self._theRows[i] = arrays.Array( numCols ) > > # Returns the number of rows in the 2-D array. > def numRows( self ): > return len( self._theRows ) > > # Returns the number of columns in the 2-D array. > def numCols( self ): > return len( self._theRows[0] ) > > # Clears the array by setting every element to the given value. > def clear( self, value ): > for row in range( self.numRows() ): > row.clear( value ) > > # Gets the contents of the element at position [i, j] > def __getitem__( self, ndxTuple ): > assert len(ndxTuple) == 2, "Invalid number of array subscripts." > row = ndxTuple[0] > col = ndxTuple[1] > assert row >= 0 and row < self.numRows() \ > and col >= 0 and col < self.numCols(), \ > "Array subscript out of range." > the1dArray = self._theRows[row] > return the1dArray[col] > > # Sets the contents of the element at position [i,j] to value. > def __setitem__( self, ndxTuple, value ): > #assert len(ndxTuple) == 3, "Invalid number of array subscripts." > row = ndxTuple[0] > col = ndxTuple[1] > assert row >= 0 and row < self.numRows() \ > and col >= 0 and col < self.numCols(), \ > "Array subscript out of range." > the1dArray = self._theRows[row] > the1dArray[col] = value > > > arr = Array2D(2,4) > > print "arr is %s" %arr > > > Traceback is : > > sixe is 2 > type is e > Elements are self.element > Cols in 4 > Num of Cloumns is 4 > !!!!!!!!!!!!!! i is 0 > sixe is 4 > type is e > Elements are self.element > Type is > Traceback (most recent call last): > File "C:\Python27\Lib\array2D.py", line 53, in > arr = Array2D(2,4) > File "C:\Python27\Lib\array2D.py", line 16, in __init__ > self._theRows[i] = arrays.Array( numCols ) > File "C:\Python27\Lib\arrays.py", line 36, in __setitem__ > self._elements[ index ] = value > AttributeError: Array instance has no attribute '__trunc__' > -- > http://mail.python.org/mailman/listinfo/python-list > Not sure about the __trunc__ problem but i can suggest this alternative which is a bit simpler def array2D(x, y, val=None): return [[val for col in xrange(x)] for row in xrange(y)] -- "The UNIX system has a command, nice ... in order to be nice to the other users. Nobody ever uses it." - Andrew S. Tanenbaum -------------- next part -------------- An HTML attachment was scrubbed... URL: From bhk755 at gmail.com Tue Apr 9 00:01:04 2013 From: bhk755 at gmail.com (bhk755 at gmail.com) Date: Mon, 8 Apr 2013 21:01:04 -0700 (PDT) Subject: Can anyone please help me in resolving the error => AttributeError: Array instance has no attribute '__trunc__' In-Reply-To: References: Message-ID: <2ebc5368-8a73-41ed-b6f4-a2a39aae642f@googlegroups.com> On Monday, April 8, 2013 3:37:38 PM UTC+5:30, bhk... at gmail.com wrote: > I am trying to create 2D arrays without using advanced features like numpy, for this I have created 2 separate modules arrays.py and array2D.py. Here's the code for that: > > > > arrays.py module: > > ================== > > import ctypes > > > > class Array: > > > > #Creates an array with size elements. > > def __init__( self, size ): > > assert size > 0, "Array size must be > 0" > > self._size = size > > print "sixe is %s" %self._size > > > > # Create the array structure using the ctypes module. > > PyArrayType = ctypes.c_int * size > > self._elements = PyArrayType() > > print "type is e", type(self._elements) > > #self._elements = ctypes.c_int * size > > > > print "Elements are self.element %s" % self._elements > > # Initialize each element. > > #for i in range(self._size): > > # self.clear( i ) > > > > > > # Returns the size of the array. > > def __len__( self ): > > return self._size > > > > # Gets the contents of the index element. > > def __getitem__( self, index ): > > assert index >= 0 and index < len(self), "Array subscript out of range" > > return self._elements[ index ] > > > > # Puts the value in the array element at index position. > > def __setitem__( self, index, value ): > > assert index >= 0 and index < len(self), "Array subscript out of range" > > print "Type is ", type(index) > > self._elements[ index ] = value > > > > # Clears the array by setting each element to the given value. > > def clear( self, value ): > > for i in range( len(self) ) : > > self._elements[i] = value > > > > # Printing the arrays: > > def __str__(self): > > return self._elements > > > > > > > > array2D.py module > > ================== > > > > > > import arrays > > > > class Array2D : > > # Creates a 2-D array of size numRows x numCols. > > def __init__( self, numRows, numCols ): > > # Create a 1-D array to store an array reference for each row. > > > > self._theRows = arrays.Array( numRows ) > > # Create the 1-D arrays for each row of the 2-D array. > > print "Num of Cloumns is", numCols > > > > for i in range( numRows ) : > > self._theRows[i] = arrays.Array( numCols ) > > > > # Returns the number of rows in the 2-D array. > > def numRows( self ): > > return len( self._theRows ) > > > > # Returns the number of columns in the 2-D array. > > def numCols( self ): > > return len( self._theRows[0] ) > > > > # Clears the array by setting every element to the given value. > > def clear( self, value ): > > for row in range( self.numRows() ): > > row.clear( value ) > > > > # Gets the contents of the element at position [i, j] > > def __getitem__( self, ndxTuple ): > > assert len(ndxTuple) == 2, "Invalid number of array subscripts." > > row = ndxTuple[0] > > col = ndxTuple[1] > > assert row >= 0 and row < self.numRows() \ > > and col >= 0 and col < self.numCols(), \ > > "Array subscript out of range." > > the1dArray = self._theRows[row] > > return the1dArray[col] > > > > # Sets the contents of the element at position [i,j] to value. > > def __setitem__( self, ndxTuple, value ): > > #assert len(ndxTuple) == 3, "Invalid number of array subscripts." > > row = ndxTuple[0] > > col = ndxTuple[1] > > assert row >= 0 and row < self.numRows() \ > > and col >= 0 and col < self.numCols(), \ > > "Array subscript out of range." > > the1dArray = self._theRows[row] > > the1dArray[col] = value > > > > > > arr = Array2D(2,4) > > > > print "arr is %s" %arr > > > > > > Traceback is : > > > > sixe is 2 > > type is e > > Elements are self.element > > Cols in 4 > > Num of Cloumns is 4 > > !!!!!!!!!!!!!! i is 0 > > sixe is 4 > > type is e > > Elements are self.element > > Type is > > Traceback (most recent call last): > > File "C:\Python27\Lib\array2D.py", line 53, in > > arr = Array2D(2,4) > > File "C:\Python27\Lib\array2D.py", line 16, in __init__ > > self._theRows[i] = arrays.Array( numCols ) > > File "C:\Python27\Lib\arrays.py", line 36, in __setitem__ > > self._elements[ index ] = value > > AttributeError: Array instance has no attribute '__trunc__' Hi Dylan, Thank you for the alternative solution. I will look into that. From steve+comp.lang.python at pearwood.info Tue Apr 9 01:14:06 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Apr 2013 05:14:06 GMT Subject: Can anyone please help me in resolving the error => AttributeError: Array instance has no attribute '__trunc__' References: <2ebc5368-8a73-41ed-b6f4-a2a39aae642f@googlegroups.com> Message-ID: <5163a39e$0$29977$c3e8da3$5496439d@news.astraweb.com> On Mon, 08 Apr 2013 21:01:04 -0700, bhk755 wrote: [snip over 260 lines of unnecessary quoted text] > Hi Dylan, > > Thank you for the alternative solution. I will look into that. Please trim your replies. There's absolutely no reason to expect people to scroll through almost FOUR PAGES of quoted text just to get to a two line response. Thank you. -- Steven From bhk755 at gmail.com Tue Apr 9 02:21:01 2013 From: bhk755 at gmail.com (bhk755 at gmail.com) Date: Mon, 8 Apr 2013 23:21:01 -0700 (PDT) Subject: Can anyone please help me in resolving the error => AttributeError: Array instance has no attribute '__trunc__' In-Reply-To: <5163a39e$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <2ebc5368-8a73-41ed-b6f4-a2a39aae642f@googlegroups.com> <5163a39e$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: Thanks Steven for pointing that out. This is my first topic in Google Groups. So, I did not notice that the previous contents will also be taken in the new post. From bhk755 at gmail.com Tue Apr 9 02:15:54 2013 From: bhk755 at gmail.com (bhk755 at gmail.com) Date: Mon, 8 Apr 2013 23:15:54 -0700 (PDT) Subject: Can anyone please help me in resolving the error => AttributeError: Array instance has no attribute '__trunc__' In-Reply-To: References: Message-ID: Hi Dylan, Thank you for the alternative solution. I will look into that. From bhk755 at gmail.com Tue Apr 9 02:15:54 2013 From: bhk755 at gmail.com (bhk755 at gmail.com) Date: Mon, 8 Apr 2013 23:15:54 -0700 (PDT) Subject: Can anyone please help me in resolving the error => AttributeError: Array instance has no attribute '__trunc__' In-Reply-To: References: Message-ID: Hi Dylan, Thank you for the alternative solution. I will look into that. From __peter__ at web.de Tue Apr 9 03:57:23 2013 From: __peter__ at web.de (Peter Otten) Date: Tue, 09 Apr 2013 09:57:23 +0200 Subject: Can anyone please help me in resolving the error => AttributeError: Array instance has no attribute '__trunc__' References: Message-ID: bhk755 at gmail.com wrote: > I am trying to create 2D arrays without using advanced features like > numpy, I'd say that using ctypes is a bit more "advanced" than *using* numpy because with ctypes it helps to know C. > for this I have created 2 separate modules arrays.py and > array2D.py. Here's the code for that: - You should absolutely go with numpy - If you insist on building your own use lists of lists as suggested - If you need something more space efficient than lists have a look at http://docs.python.org/2/library/array.html rather than ctypes. Now on to some debugging, without looking into the details. > import arrays > > class Array2D : > # Creates a 2-D array of size numRows x numCols. > def __init__( self, numRows, numCols ): > # Create a 1-D array to store an array reference for each row. > > self._theRows = arrays.Array( numRows ) Here you create an instance of your array of integers... > # Create the 1-D arrays for each row of the 2-D array. > print "Num of Cloumns is", numCols > > for i in range( numRows ) : > self._theRows[i] = arrays.Array( numCols ) ...and here you are stuffing arrays.Array instances into that array of integers. In nuce: >>> import ctypes >>> class C: pass # classic class ... >>> items = (ctypes.c_int * 3)() >>> items[0] = C() Traceback (most recent call last): File "", line 1, in AttributeError: C instance has no attribute '__trunc__' ctypes unhelpfully tries to truncate the value to convert it into an integer. As an aside here's an example of a successful conversion: >>> class C2: ... def __trunc__(self): return 42 ... >>> items[0] = C2() >>> items[0] 42 There are basically two resolutions: - adjust the type of the outer array or - use a single 1D array internally and calculate the index as row * width + column (for example). From bhk755 at gmail.com Tue Apr 9 04:48:39 2013 From: bhk755 at gmail.com (bhk755 at gmail.com) Date: Tue, 9 Apr 2013 01:48:39 -0700 (PDT) Subject: Can anyone please help me in resolving the error => AttributeError: Array instance has no attribute '__trunc__' In-Reply-To: References: Message-ID: <3db23f44-218d-4a09-b28a-bca304b363c9@googlegroups.com> Awesome!!! Thanks a lot Peter. From bhk755 at gmail.com Tue Apr 9 04:50:35 2013 From: bhk755 at gmail.com (bhk755 at gmail.com) Date: Tue, 9 Apr 2013 01:50:35 -0700 (PDT) Subject: Can anyone please help me in resolving the error => AttributeError: Array instance has no attribute '__trunc__' In-Reply-To: References: Message-ID: <716e69a5-4e11-4b15-8e6b-40fd5cd09a0a@googlegroups.com> Awesome Peter!!!. Thanks a lot for detailed explanation... From bhk755 at gmail.com Tue Apr 9 04:50:35 2013 From: bhk755 at gmail.com (bhk755 at gmail.com) Date: Tue, 9 Apr 2013 01:50:35 -0700 (PDT) Subject: Can anyone please help me in resolving the error => AttributeError: Array instance has no attribute '__trunc__' In-Reply-To: References: Message-ID: <716e69a5-4e11-4b15-8e6b-40fd5cd09a0a@googlegroups.com> Awesome Peter!!!. Thanks a lot for detailed explanation... From boru4781 at gmail.com Mon Apr 8 06:32:40 2013 From: boru4781 at gmail.com (Casperb) Date: Mon, 8 Apr 2013 03:32:40 -0700 (PDT) Subject: Displaying colours in saved script Message-ID: <6899601e-4a24-4ef1-b848-864e471739eb@googlegroups.com> Hi all, I'm new to Python and have a pretty basic question, explained in the following screendump: http://i.imgur.com/oaCuKp5.jpg After I save my script, the nice colours that make the code easier to read disappear. How do I stop that from happening? Any help much appreciated. From davea at davea.name Mon Apr 8 06:55:05 2013 From: davea at davea.name (Dave Angel) Date: Mon, 08 Apr 2013 06:55:05 -0400 Subject: Displaying colours in saved script In-Reply-To: <6899601e-4a24-4ef1-b848-864e471739eb@googlegroups.com> References: <6899601e-4a24-4ef1-b848-864e471739eb@googlegroups.com> Message-ID: <5162A209.5030809@davea.name> On 04/08/2013 06:32 AM, Casperb wrote: > Hi all, > > I'm new to Python and have a pretty basic question, explained in the following screendump: > > http://i.imgur.com/oaCuKp5.jpg > > After I save my script, the nice colours that make the code easier to read disappear. How do I stop that from happening? > > Any help much appreciated. > Python source code is a plain text file, which has no colors. The colors are used by your Python Shell only for displaying to the screen. When Python Shell reloads Python source, it presumably reparses the text and shows it with colors. My guess is that by naming the file without a .py extension, you convinced Python Shell that it was NOT source code, and therefore shouldn't be colorized. -- DaveA From jldunn2000 at gmail.com Mon Apr 8 07:00:12 2013 From: jldunn2000 at gmail.com (loial) Date: Mon, 8 Apr 2013 04:00:12 -0700 (PDT) Subject: subprocess question re waiting Message-ID: I want to call a child process to run a shell script and wait for that script to finish. Will the code below wait for the script to finish? If not then how do I make it wait? Any help appreciated. import subprocess command = "/home/john/myscript" process = subprocess.Popen(command, stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True, shell=True) out, err = process.communicate() returncode = process.returncode From alain at dpt-info.u-strasbg.fr Mon Apr 8 07:48:56 2013 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Mon, 08 Apr 2013 13:48:56 +0200 Subject: subprocess question re waiting References: Message-ID: <8761zxdyzb.fsf@dpt-info.u-strasbg.fr> loial writes: > I want to call a child process to run a shell script and wait for that > script to finish. Will the code below wait for the script to finish? > If not then how do I make it wait? [...] > process = subprocess.Popen(command, stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True, shell=True) process.wait() -- Alain. From dylan at dje.me Mon Apr 8 08:01:52 2013 From: dylan at dje.me (Dylan Evans) Date: Mon, 8 Apr 2013 22:01:52 +1000 Subject: subprocess question re waiting In-Reply-To: <8761zxdyzb.fsf@dpt-info.u-strasbg.fr> References: <8761zxdyzb.fsf@dpt-info.u-strasbg.fr> Message-ID: On Mon, Apr 8, 2013 at 9:48 PM, Alain Ketterlin wrote: > loial writes: > > > I want to call a child process to run a shell script and wait for that > > script to finish. Will the code below wait for the script to finish? > > If not then how do I make it wait? > [...] > > process = subprocess.Popen(command, > stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE, > close_fds=True, shell=True) > > process.wait() > Or use subprocess.call instead which does what you want. > -- Alain. > -- > http://mail.python.org/mailman/listinfo/python-list > -- "The UNIX system has a command, nice ... in order to be nice to the other users. Nobody ever uses it." - Andrew S. Tanenbaum -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Mon Apr 8 08:22:53 2013 From: davea at davea.name (Dave Angel) Date: Mon, 08 Apr 2013 08:22:53 -0400 Subject: subprocess question re waiting In-Reply-To: References: <8761zxdyzb.fsf@dpt-info.u-strasbg.fr> Message-ID: <5162B69D.90908@davea.name> On 04/08/2013 08:01 AM, Dylan Evans wrote: > On Mon, Apr 8, 2013 at 9:48 PM, Alain Ketterlin > wrote: > >> loial writes: >> >>> I want to call a child process to run a shell script and wait for that >>> script to finish. Will the code below wait for the script to finish? >>> If not then how do I make it wait? >> [...] >>> process = subprocess.Popen(command, >> stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE, >> close_fds=True, shell=True) >> >> process.wait() >> > > Or use subprocess.call instead which does what you want. > > >> -- Alain. >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > http://docs.python.org/2/library/subprocess.html#popen-objects or use communicate(), which is what the OP had in the first place. -- DaveA From dylan at dje.me Mon Apr 8 08:58:20 2013 From: dylan at dje.me (Dylan Evans) Date: Mon, 8 Apr 2013 22:58:20 +1000 Subject: subprocess question re waiting In-Reply-To: <5162B69D.90908@davea.name> References: <8761zxdyzb.fsf@dpt-info.u-strasbg.fr> <5162B69D.90908@davea.name> Message-ID: On Mon, Apr 8, 2013 at 10:22 PM, Dave Angel wrote: > On 04/08/2013 08:01 AM, Dylan Evans wrote: > >> On Mon, Apr 8, 2013 at 9:48 PM, Alain Ketterlin < >> alain at dpt-info.u-strasbg.fr >> >>> wrote: >>> >> >> loial writes: >>> >>> I want to call a child process to run a shell script and wait for that >>>> script to finish. Will the code below wait for the script to finish? >>>> If not then how do I make it wait? >>>> >>> [...] >>> >>>> process = subprocess.Popen(command, >>>> >>> stdin=subprocess.PIPE,stdout=**subprocess.PIPE, stderr=subprocess.PIPE, >>> close_fds=True, shell=True) >>> >>> process.wait() >>> >>> >> Or use subprocess.call instead which does what you want. >> >> Actually after having a look through the manual i like check_output for this since it simplifies the code, but some extra exception handling would be required if the output is still required when the script exits with a non zero value, so it's a bit of a trade off. > -- Alain. >>> -- >>> http://mail.python.org/**mailman/listinfo/python-list >>> >>> >> > http://docs.python.org/2/**library/subprocess.html#popen-**objects > > or use communicate(), which is what the OP had in the first place. > > > -- > DaveA > -- > http://mail.python.org/**mailman/listinfo/python-list > -- "The UNIX system has a command, nice ... in order to be nice to the other users. Nobody ever uses it." - Andrew S. Tanenbaum -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Mon Apr 8 08:25:24 2013 From: davea at davea.name (Dave Angel) Date: Mon, 08 Apr 2013 08:25:24 -0400 Subject: subprocess question re waiting In-Reply-To: References: Message-ID: <5162B734.7040200@davea.name> On 04/08/2013 07:00 AM, loial wrote: > I want to call a child process to run a shell script and wait for that script to finish. Will the code below wait for the script to finish? If not then how do I make it wait? > > Any help appreciated. > > > import subprocess > > command = "/home/john/myscript" > > process = subprocess.Popen(command, stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True, shell=True) > > out, err = process.communicate() > returncode = process.returncode > Yes, communicate() will block until the child process is complete. http://docs.python.org/2/library/subprocess.html#popen-objects Note the phrase: "Wait for process to terminate." That's referring to the shell in your case. -- DaveA From dineshbvadhia at hotmail.com Mon Apr 8 09:12:02 2013 From: dineshbvadhia at hotmail.com (dbv) Date: Mon, 8 Apr 2013 06:12:02 -0700 (PDT) Subject: is "_io.py" missing from 2.7.4 ? Message-ID: In 2.7.4, io.py shows: import _io import abc from _io import (DEFAULT_BUFFER_SIZE, BlockingIOError, UnsupportedOperation, open, FileIO, BytesIO, StringIO, BufferedReader, BufferedWriter, BufferedRWPair, BufferedRandom, IncrementalNewlineDecoder, TextIOWrapper) but, cannot find _io.py, though there is the old _pyio.py in the //Python27//Lib folder. From dylan at dje.me Mon Apr 8 09:29:07 2013 From: dylan at dje.me (Dylan Evans) Date: Mon, 8 Apr 2013 23:29:07 +1000 Subject: is "_io.py" missing from 2.7.4 ? In-Reply-To: References: Message-ID: On Mon, Apr 8, 2013 at 11:12 PM, dbv wrote: > In 2.7.4, io.py shows: > > import _io > import abc > > from _io import (DEFAULT_BUFFER_SIZE, BlockingIOError, > UnsupportedOperation, > open, FileIO, BytesIO, StringIO, BufferedReader, > BufferedWriter, BufferedRWPair, BufferedRandom, > IncrementalNewlineDecoder, TextIOWrapper) > > but, cannot find _io.py, though there is the old _pyio.py in the > //Python27//Lib folder. > > >>> _io.__file__ '/usr/lib/python2.7/lib-dynload/_io.so' Looks like it's implemented in C. > -- > http://mail.python.org/mailman/listinfo/python-list > -- "The UNIX system has a command, nice ... in order to be nice to the other users. Nobody ever uses it." - Andrew S. Tanenbaum -------------- next part -------------- An HTML attachment was scrubbed... URL: From dineshbvadhia at hotmail.com Mon Apr 8 09:42:55 2013 From: dineshbvadhia at hotmail.com (dbv) Date: Mon, 8 Apr 2013 06:42:55 -0700 (PDT) Subject: is "_io.py" missing from 2.7.4 ? In-Reply-To: References: Message-ID: <4af0c0a6-4a5f-4738-a529-e7338fddd7c2@googlegroups.com> Ah, okay. Then on Windows, _io.pyd should be in the /DLLs folder but it isn't there ? From dineshbvadhia at hotmail.com Mon Apr 8 09:59:59 2013 From: dineshbvadhia at hotmail.com (dbv) Date: Mon, 8 Apr 2013 06:59:59 -0700 (PDT) Subject: is "_io.py" missing from 2.7.4 ? In-Reply-To: <4af0c0a6-4a5f-4738-a529-e7338fddd7c2@googlegroups.com> References: <4af0c0a6-4a5f-4738-a529-e7338fddd7c2@googlegroups.com> Message-ID: _io is a builtin module From dineshbvadhia at hotmail.com Mon Apr 8 09:59:59 2013 From: dineshbvadhia at hotmail.com (dbv) Date: Mon, 8 Apr 2013 06:59:59 -0700 (PDT) Subject: is "_io.py" missing from 2.7.4 ? In-Reply-To: <4af0c0a6-4a5f-4738-a529-e7338fddd7c2@googlegroups.com> References: <4af0c0a6-4a5f-4738-a529-e7338fddd7c2@googlegroups.com> Message-ID: _io is a builtin module From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Mon Apr 8 11:02:27 2013 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Mon, 08 Apr 2013 17:02:27 +0200 Subject: is "_io.py" missing from 2.7.4 ? In-Reply-To: <4af0c0a6-4a5f-4738-a529-e7338fddd7c2@googlegroups.com> References: <4af0c0a6-4a5f-4738-a529-e7338fddd7c2@googlegroups.com> Message-ID: Am 08.04.2013 15:42 schrieb dbv: > Ah, okay. Then on Windows, _io.pyd should be in the /DLLs folder but it isn't there ? > It seems to be a built-in module: >>> import _io >>> _io alike to >>> import __builtin__ >>> __builtin__ as opposed to >>> import win32ui >>> win32ui and >>> import os >>> os Thomas From dineshbvadhia at hotmail.com Mon Apr 8 09:42:55 2013 From: dineshbvadhia at hotmail.com (dbv) Date: Mon, 8 Apr 2013 06:42:55 -0700 (PDT) Subject: is "_io.py" missing from 2.7.4 ? In-Reply-To: References: Message-ID: <4af0c0a6-4a5f-4738-a529-e7338fddd7c2@googlegroups.com> Ah, okay. Then on Windows, _io.pyd should be in the /DLLs folder but it isn't there ? From steve+comp.lang.python at pearwood.info Mon Apr 8 20:20:33 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Apr 2013 00:20:33 GMT Subject: is "_io.py" missing from 2.7.4 ? References: Message-ID: <51635ed1$0$30003$c3e8da3$5496439d@news.astraweb.com> On Mon, 08 Apr 2013 06:12:02 -0700, dbv wrote: > In 2.7.4, io.py shows: > > import _io > import abc > > from _io import (DEFAULT_BUFFER_SIZE, BlockingIOError, > UnsupportedOperation, > open, FileIO, BytesIO, StringIO, BufferedReader, > BufferedWriter, BufferedRWPair, BufferedRandom, > IncrementalNewlineDecoder, TextIOWrapper) > > but, cannot find _io.py, though there is the old _pyio.py in the > //Python27//Lib folder. If "from _io import ..." succeeds with no error, then it is physically impossible for it to be missing. To find where the _io module lives, at the interactive interpreter run this: import _io _io.__file__ Under Linux, you should get something like this: '/usr/local/lib/python2.7/lib-dynload/_io.so' and the equivalent under Windows. Note that in Python 3.3, the _io module is now built-in into the compiler, so _io.__file__ no longer exists. -- Steven From svenito at gmail.com Mon Apr 8 11:21:36 2013 From: svenito at gmail.com (Sven) Date: Mon, 8 Apr 2013 16:21:36 +0100 Subject: USBLock : lock/unlock your computer with a USB key Message-ID: I've been working on a little project and have a working Linux implementation so far. Basically it allows a user to use any USB stick as a key to lock and unlock their computer. More info in the repo or PyPi https://pypi.python.org/pypi/USBLock Basically run the program with -a to add a device (added once you insert it), then run it without any arguments. Insert the key again, and when you remove it your computer will lock. Insert the key again and it will unlock. It's not intended to provide military grade security, it's more of a convenience tool to launch built in screen locking software. Currently it locks a Linux box with xlock, pending a better solution. I wrote it as an exercise in playing around with USB media and events, and also because I needed a use for these old USB keys I have lying around :) Always looking for contributions, suggestions and improvements. Especially OS X and Win support. Repo: https://github.com/Svenito/usblock Thanks for your time. -- ./Sven -------------- next part -------------- An HTML attachment was scrubbed... URL: From dylan at dje.me Thu Apr 11 05:20:07 2013 From: dylan at dje.me (Dylan Evans) Date: Thu, 11 Apr 2013 19:20:07 +1000 Subject: USBLock : lock/unlock your computer with a USB key In-Reply-To: References: Message-ID: This looks cool, would actual be pretty useful. I see you did it as a usb project but probably bluetooth would be better so you could just pair it to your phone and know that your PC will lock when you walk away. On Tue, Apr 9, 2013 at 1:21 AM, Sven wrote: > I've been working on a little project and have a working Linux > implementation so far. Basically it allows a user to use any USB stick as a > key to lock and unlock their computer. More info in the repo or PyPi > https://pypi.python.org/pypi/USBLock > > Basically run the program with -a to add a device (added once you insert > it), then run it without any arguments. Insert the key again, and when you > remove it your computer will lock. Insert the key again and it will unlock. > It's not intended to provide military grade security, it's more of a > convenience tool to launch built in screen locking software. > > Currently it locks a Linux box with xlock, pending a better solution. > > I wrote it as an exercise in playing around with USB media and events, and > also because I needed a use for these old USB keys I have lying around :) > > Always looking for contributions, suggestions and improvements. Especially > OS X and Win support. > > Repo: > https://github.com/Svenito/usblock > > Thanks for your time. > > -- > ./Sven > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- "The UNIX system has a command, nice ... in order to be nice to the other users. Nobody ever uses it." - Andrew S. Tanenbaum -------------- next part -------------- An HTML attachment was scrubbed... URL: From svenito at gmail.com Thu Apr 11 07:13:25 2013 From: svenito at gmail.com (Sven) Date: Thu, 11 Apr 2013 12:13:25 +0100 Subject: USBLock : lock/unlock your computer with a USB key In-Reply-To: References: Message-ID: Thanks for taking an interest. Yes, I had the idea to add bluetooth too, removes the whole plugging and unplugging spiel. I might start work on that, and if anyone else wants to dive in and help, feel free. I will probably need to refactor the Listener a little, or create a USB and BT listener class. Cheers On 11 April 2013 10:20, Dylan Evans wrote: > This looks cool, would actual be pretty useful. I see you did it as a usb > project but probably bluetooth would be better so you could just pair it to > your phone and know that your PC will lock when you walk away. > > > > On Tue, Apr 9, 2013 at 1:21 AM, Sven wrote: > >> I've been working on a little project and have a working Linux >> implementation so far. Basically it allows a user to use any USB stick as a >> key to lock and unlock their computer. More info in the repo or PyPi >> https://pypi.python.org/pypi/USBLock >> >> Basically run the program with -a to add a device (added once you insert >> it), then run it without any arguments. Insert the key again, and when you >> remove it your computer will lock. Insert the key again and it will unlock. >> It's not intended to provide military grade security, it's more of a >> convenience tool to launch built in screen locking software. >> >> Currently it locks a Linux box with xlock, pending a better solution. >> >> I wrote it as an exercise in playing around with USB media and events, >> and also because I needed a use for these old USB keys I have lying around >> :) >> >> Always looking for contributions, suggestions and improvements. >> Especially OS X and Win support. >> >> Repo: >> https://github.com/Svenito/usblock >> >> Thanks for your time. >> >> -- >> ./Sven >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > > -- > "The UNIX system has a command, nice ... in order to be nice to the other > users. Nobody ever uses it." - Andrew S. Tanenbaum > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- ./Sven -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Thu Apr 11 11:23:49 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 11 Apr 2013 08:23:49 -0700 Subject: USBLock : lock/unlock your computer with a USB key In-Reply-To: References: Message-ID: <5166D585.8020905@stoneleaf.us> On 04/11/2013 04:13 AM, Sven wrote: > Yes, I had the idea to add bluetooth too, removes the whole plugging and unplugging spiel. I might start work on that, > and if anyone else wants to dive in and help, feel free. I will probably need to refactor the Listener a little, or > create a USB and BT listener class. Doesn't BlueTooth have a 30 foot range? For locking I'd rather be at 10 or even 5 feet away. -- ~Ethan~ From ian.g.kelly at gmail.com Thu Apr 11 16:16:26 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 11 Apr 2013 14:16:26 -0600 Subject: USBLock : lock/unlock your computer with a USB key In-Reply-To: <5166D585.8020905@stoneleaf.us> References: <5166D585.8020905@stoneleaf.us> Message-ID: On Thu, Apr 11, 2013 at 9:23 AM, Ethan Furman wrote: > On 04/11/2013 04:13 AM, Sven wrote: >> >> Yes, I had the idea to add bluetooth too, removes the whole plugging and >> unplugging spiel. I might start work on that, >> and if anyone else wants to dive in and help, feel free. I will probably >> need to refactor the Listener a little, or >> create a USB and BT listener class. > > > Doesn't BlueTooth have a 30 foot range? For locking I'd rather be at 10 or > even 5 feet away. Pair it with a Google Glass and have it lock after you've stopped looking at the screen for 30 seconds. From dylan at dje.me Fri Apr 12 07:26:08 2013 From: dylan at dje.me (Dylan Evans) Date: Fri, 12 Apr 2013 21:26:08 +1000 Subject: USBLock : lock/unlock your computer with a USB key In-Reply-To: References: <5166D585.8020905@stoneleaf.us> Message-ID: On Fri, Apr 12, 2013 at 6:16 AM, Ian Kelly wrote: > On Thu, Apr 11, 2013 at 9:23 AM, Ethan Furman wrote: > > On 04/11/2013 04:13 AM, Sven wrote: > >> > >> Yes, I had the idea to add bluetooth too, removes the whole plugging and > >> unplugging spiel. I might start work on that, > >> and if anyone else wants to dive in and help, feel free. I will probably > >> need to refactor the Listener a little, or > >> create a USB and BT listener class. > > > > > > Doesn't BlueTooth have a 30 foot range? For locking I'd rather be at 10 > or > > even 5 feet away. > > I guess it depends on your needs, I'd want it locked when i wander out of the office. > Pair it with a Google Glass and have it lock after you've stopped > looking at the screen for 30 seconds. > That would be awesome. > -- > http://mail.python.org/mailman/listinfo/python-list > -- "The UNIX system has a command, nice ... in order to be nice to the other users. Nobody ever uses it." - Andrew S. Tanenbaum -------------- next part -------------- An HTML attachment was scrubbed... URL: From js at globe.de Fri Apr 12 09:46:31 2013 From: js at globe.de (Schneider) Date: Fri, 12 Apr 2013 15:46:31 +0200 Subject: USBLock : lock/unlock your computer with a USB key In-Reply-To: References: <5166D585.8020905@stoneleaf.us> Message-ID: <51681037.6000500@globe.de> On 11.04.2013 22:16, Ian Kelly wrote: > On Thu, Apr 11, 2013 at 9:23 AM, Ethan Furman wrote: >> On 04/11/2013 04:13 AM, Sven wrote: >>> Yes, I had the idea to add bluetooth too, removes the whole plugging and >>> unplugging spiel. I might start work on that, >>> and if anyone else wants to dive in and help, feel free. I will probably >>> need to refactor the Listener a little, or >>> create a USB and BT listener class. >> >> Doesn't BlueTooth have a 30 foot range? For locking I'd rather be at 10 or >> even 5 feet away. > Pair it with a Google Glass and have it lock after you've stopped > looking at the screen for 30 seconds. Maybe not with Google Glass, but with a web cam placed on top of the screen. Like Samsung does since the Galaxy S III. There it just happens the other way round: no lock as long as you have your face in front of the phone. bg, Johannes -- GLOBE Development GmbH K?nigsberger Strasse 260 48157 M?nsterGLOBE Development GmbH K?nigsberger Strasse 260 48157 M?nster 0251/5205 390 From invalid at invalid.invalid Mon Apr 8 11:20:15 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 8 Apr 2013 15:20:15 +0000 (UTC) Subject: Interactrive Python under Cygwin in Win7 Message-ID: I just installed ActiveState 2.7 64-bit on a Windows 7 machine running a current version of Cygwin. While python programs (both GUI and text-mode) run fine, I'm unable to use Python interactively from either the Cygwin terminal or in an ssh session. I tried adding the "-u" option, but that makes no difference. Interactive C-Python just hangs on startup. Is this bug specific to ActiveState Python, or is it also present in the vanilla C-Python build for Windows? -- Grant Edwards grant.b.edwards Yow! I want you to MEMORIZE at the collected poems of gmail.com EDNA ST VINCENT MILLAY ... BACKWARDS!! From drobinow at gmail.com Mon Apr 8 16:30:57 2013 From: drobinow at gmail.com (David Robinow) Date: Mon, 8 Apr 2013 16:30:57 -0400 Subject: Interactrive Python under Cygwin in Win7 In-Reply-To: References: Message-ID: On Mon, Apr 8, 2013 at 11:20 AM, Grant Edwards wrote: > I just installed ActiveState 2.7 64-bit on a Windows 7 machine running > a current version of Cygwin. While python programs (both GUI and > text-mode) run fine, I'm unable to use Python interactively from > either the Cygwin terminal or in an ssh session. I tried adding the > "-u" option, but that makes no difference. Interactive C-Python just > hangs on startup. > > Is this bug specific to ActiveState Python, or is it also present in > the vanilla C-Python build for Windows? > > It's present in the "vanilla" build. I assume you're running mintty as I do. I just use the cygwin build for fooling around with python, and [WARNING: hold your nose] the cmd shell when I need Windows Python. You can also use the (old-fashioned?) cygwin.bat do start cygwin which doesn't give you as nice a terminal but does allow you to run bash and "/c/Python27/Python" interactively. Another option, which I just discovered, is bash under msys. It's been a while since I've used it so I can't remember the pro and con but you can run an interactive Windows python. -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Mon Apr 8 16:39:21 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 8 Apr 2013 20:39:21 +0000 (UTC) Subject: Interactrive Python under Cygwin in Win7 References: Message-ID: On 2013-04-08, David Robinow wrote: > On Mon, Apr 8, 2013 at 11:20 AM, Grant Edwards wrote: > >> I just installed ActiveState 2.7 64-bit on a Windows 7 machine running >> a current version of Cygwin. While python programs (both GUI and >> text-mode) run fine, I'm unable to use Python interactively from >> either the Cygwin terminal or in an ssh session. I tried adding the >> "-u" option, but that makes no difference. Interactive C-Python just >> hangs on startup. >> >> Is this bug specific to ActiveState Python, or is it also present in >> the vanilla C-Python build for Windows? > > It's present in the "vanilla" build. I assume you're running mintty > as I do. That's what I usually run when I'm not ssh'ed in. > I just use the cygwin build for fooling around with python, and > [WARNING: hold your nose] the cmd shell when I need Windows Python. Yea, that's what I finally fell back on. At least it has command line recall/editing, so it could be worse. I do almost all of my development on Linux and rarely do anything interactive under Windows, but once in a while it would be handy. > You can also use the (old-fashioned?) cygwin.bat do start cygwin > which doesn't give you as nice a terminal but does allow you to run > bash and "/c/Python27/Python" interactively. > > Another option, which I just discovered, is bash under msys. It's been a > while since I've used it so I can't remember the pro and con but you can > run an interactive Windows python. Oh yea, I had forgotten about msys. -- Grant Edwards grant.b.edwards Yow! I'm having an at emotional outburst!! gmail.com From morten.guldager at gmail.com Tue Apr 9 01:50:11 2013 From: morten.guldager at gmail.com (Morten Guldager) Date: Tue, 9 Apr 2013 07:50:11 +0200 Subject: classes and sub classes? Message-ID: 'Aloha Friends! I'm about to write an API against a huge propitiatory Oracle based network inventory database. The database have many different concepts stored in it's tables, can one concept can span over multiple tables. I would like to write a class for accessing each concept, but only have a single database connection throughout the whole program. I imagine some code along these lines, but cant figure out how to declare the classes that will make it work: # create a connection to the database and perform come basic login and initialization nib = NwInvDb("scott/tiger at ora") # find a device by ip interesting_device = nib.Device.lookup_by_ip("192.168.1.1") In this example I access the concept Device. Should I make the Device class inherit from NwInvDb? Or should I keep them separate? Later on I think I will even have to make some sort of sub-concepts, but lets postpone that game until I really have really seen the need! -- /Morten %-) -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Tue Apr 9 03:08:02 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Apr 2013 07:08:02 GMT Subject: classes and sub classes? References: Message-ID: <5163be52$0$29977$c3e8da3$5496439d@news.astraweb.com> On Tue, 09 Apr 2013 07:50:11 +0200, Morten Guldager wrote: > 'Aloha Friends! > > I'm about to write an API against a huge propitiatory Oracle based > network inventory database. The database have many different concepts > stored in it's tables, can one concept can span over multiple tables. > > I would like to write a class for accessing each concept, but only have > a single database connection throughout the whole program. Sounds reasonable. > I imagine some code along these lines, but cant figure out how to > declare the classes that will make it work: > > # create a connection to the database and perform come basic login and > initialization > nib = NwInvDb("scott/tiger at ora") > # find a device by ip > interesting_device = nib.Device.lookup_by_ip("192.168.1.1") What's "nib" mean? And "NwInvDb"? I can imagine that the "Db" at the end stands for Database, but the rest is just word-salad. I can guess that NwInvDb is some sort of database connection. Am I close? > In this example I access the concept Device. > > Should I make the Device class inherit from NwInvDb? Or should I keep > them separate? Why are you asking us? We don't know what functionality you expect NwInvDb and Device to have, what they represent, or whether a Device can be meaningfully considered an instance of a NwInvDb, whatever that is. But given my *guess* that NwInvDb represents a database connection, and that Device represents data fetched from that database, then no of course you should not inherit. Inheritance implies an "is-a" relationship. If you inherit from NwInvDb for Device, that implies: - interesting_device Is-A database; - anywhere you can use a NwInvDb database object, you can use a Device object. And the same would apply to every other concept in the database. That does not sound like a clean and useful design to me. -- Steven From morten.guldager at gmail.com Tue Apr 9 03:38:21 2013 From: morten.guldager at gmail.com (Morten Guldager) Date: Tue, 9 Apr 2013 09:38:21 +0200 Subject: classes and sub classes? In-Reply-To: <5163be52$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <5163be52$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Apr 9, 2013 at 9:08 AM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > On Tue, 09 Apr 2013 07:50:11 +0200, Morten Guldager wrote: > > > I'm about to write an API against a huge propitiatory Oracle based > > network inventory database. The database have many different concepts > > stored in it's tables, can one concept can span over multiple tables. > > > > I would like to write a class for accessing each concept, but only have > > a single database connection throughout the whole program. > > Sounds reasonable. > > > I imagine some code along these lines, but cant figure out how to > > declare the classes that will make it work: > > > > # create a connection to the database and perform come basic login and > > initialization > > nib = NwInvDb("scott/tiger at ora") > > # find a device by ip > > interesting_device = nib.Device.lookup_by_ip("192.168.1.1") > > What's "nib" mean? And "NwInvDb"? I can imagine that the "Db" at the end > stands for Database, but the rest is just word-salad. I can guess that > NwInvDb is some sort of database connection. Am I close? > NwInvDb = NetworkInventoryDatabase, yes you are correct, it creates the database handle and makes it ready for use. > In this example I access the concept Device. > > > > Should I make the Device class inherit from NwInvDb? Or should I keep > > them separate? > > Why are you asking us? We don't know what functionality you expect NwInvDb > and Device to have, what they represent, or whether a Device can be > meaningfully considered an instance of a NwInvDb, whatever that is. > > But given my *guess* that NwInvDb represents a database connection, and > that Device represents data fetched from that database, then no of course > you should not inherit. Inheritance implies an "is-a" relationship. If > you inherit from NwInvDb for Device, that implies: > > - interesting_device Is-A database; > which it is not. - anywhere you can use a NwInvDb database object, you can use > a Device object. > which you can not. And the same would apply to every other concept in the database. > > That does not sound like a clean and useful design to me. > Good. I think I agree with you so far. Maybe that's why I'm asking, because I'm not perfectly sure which path to follow to achieve what I want. Yes, I need some sort of database connection instance, if it wasn't because I later on will be needing to access both test and production database I _could_ have made it global, even if we easily could agree that globals suck most of the time! The concept classes like the Device one, will be using the database instance, I just don't know how to pass db into the concept class. - should I do it explicit making constructors accept an argument? Like: nib = NwInvDb("scott/tiger at ora") dev = NwInvDb.Device(nib) interesting_device = dev.lookup_by_ip("192.168.1.1") -- /Morten %-) -------------- next part -------------- An HTML attachment was scrubbed... URL: From jsf80238 at gmail.com Sun Apr 14 21:38:37 2013 From: jsf80238 at gmail.com (Jason Friedman) Date: Sun, 14 Apr 2013 19:38:37 -0600 Subject: classes and sub classes? In-Reply-To: References: <5163be52$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: > NwInvDb = NetworkInventoryDatabase, yes you are correct, it creates the database handle and makes it ready for use. I am interested in opinions. I for one dislike abbreviations on the theory that programs are read more than they are written. I would probably use this variable name: network_inventory_db_connection = ... And yes, I'm aware that "db" is an abbreviation. I believe I am following a few Zen principles: Beautiful is better than ugly. Explicit is better than implicit. Readability counts. Special cases aren't special enough to break the rules, Although practicality beats purity. What would others use? -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Sun Apr 14 22:07:19 2013 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 15 Apr 2013 03:07:19 +0100 Subject: classes and sub classes? In-Reply-To: References: <5163be52$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <516B60D7.1090906@mrabarnett.plus.com> On 15/04/2013 02:38, Jason Friedman wrote: > > NwInvDb = NetworkInventoryDatabase, yes you are correct, it creates > the database handle and makes it ready for use. > > I am interested in opinions. I for one dislike abbreviations on the > theory that programs are read more than they are written. I would > probably use this variable name: > > network_inventory_db_connection = ... > > And yes, I'm aware that "db" is an abbreviation. I believe I am > following a few Zen principles: > > Beautiful is better than ugly. > Explicit is better than implicit. > Readability counts. > Special cases aren't special enough to break the rules, Although practicality beats purity. > > What would others use? > "network" could be abbreviated to "net", "inventory" to "inv" (maybe OK in this context; in another context it could an abbreviation for "inverse"), and "connection" to "con" (maybe), giving "net_inv_db_con", or "net_inv_db_connection". The trick, of course, is to make it clear, but not annoyingly long. Python itself has "def", "len", and "lstrip", not "define", "length" and "left_strip". From __peter__ at web.de Mon Apr 15 03:21:25 2013 From: __peter__ at web.de (Peter Otten) Date: Mon, 15 Apr 2013 09:21:25 +0200 Subject: classes and sub classes? References: <5163be52$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: Jason Friedman wrote: >> NwInvDb = NetworkInventoryDatabase, yes you are correct, it creates the > database handle and makes it ready for use. > > I am interested in opinions. I for one dislike abbreviations on the > theory > that programs are read more than they are written. I would probably use > this variable name: > > network_inventory_db_connection = ... > > And yes, I'm aware that "db" is an abbreviation. I believe I am following > a few Zen principles: > > Beautiful is better than ugly. > Explicit is better than implicit. > Readability counts. > Special cases aren't special enough to break the rules, Although > practicality beats purity. > > What would others use? inventory_db The rest should be clear from the context. From neilc at norwich.edu Mon Apr 15 08:22:21 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 15 Apr 2013 12:22:21 GMT Subject: classes and sub classes? References: <5163be52$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-04-15, Peter Otten <__peter__ at web.de> wrote: > Jason Friedman wrote: >>> NwInvDb = NetworkInventoryDatabase, yes you are correct, it >>> creates the database handle and makes it ready for use. >> >> I am interested in opinions. I for one dislike abbreviations >> on the theory that programs are read more than they are >> written. I would probably use this variable name: >> >> network_inventory_db_connection = ... >> >> And yes, I'm aware that "db" is an abbreviation. I believe I am following >> a few Zen principles: >> >> Beautiful is better than ugly. >> Explicit is better than implicit. >> Readability counts. >> Special cases aren't special enough to break the rules, Although >> practicality beats purity. >> >> What would others use? > > inventory_db > > The rest should be clear from the context. How long and descriptive a name is ought to depend on the wideness of its visibility. n might be acceptable in a short comprehension, while network_inventory_db_connection might be apposite for a module-level name. -- Neil Cerutti From robert.kern at gmail.com Tue Apr 9 03:45:42 2013 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 09 Apr 2013 13:15:42 +0530 Subject: classes and sub classes? In-Reply-To: References: Message-ID: On 2013-04-09 11:20, Morten Guldager wrote: > 'Aloha Friends! > > I'm about to write an API against a huge propitiatory Oracle based network > inventory database. The database have many different concepts stored in it's > tables, can one concept can span over multiple tables. > > I would like to write a class for accessing each concept, but only have a single > database connection throughout the whole program. > > I imagine some code along these lines, but cant figure out how to declare the > classes that will make it work: > > # create a connection to the database and perform come basic login and > initialization > nib = NwInvDb("scott/tiger at ora") > # find a device by ip > interesting_device = nib.Device.lookup_by_ip("192.168.1.1") > > In this example I access the concept Device. > > Should I make the Device class inherit from NwInvDb? Or should I keep them > separate? Later on I think I will even have to make some sort of sub-concepts, > but lets postpone that game until I really have really seen the need! You probably want to use an off-the-shelf ORM (Object Relational Mapper) instead of writing your own ad hoc ORM. http://www.sqlalchemy.org/ -- 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 info at egenix.com Tue Apr 9 04:25:21 2013 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Tue, 09 Apr 2013 10:25:21 +0200 Subject: ANN: eGenix mxODBC Connect - Python ODBC Database Interface 2.0.3 Message-ID: <5163D071.3090306@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mxODBC Connect Python ODBC Database Interface Version 2.0.3 mxODBC Connect is our commercially supported client-server product for connecting Python applications to relational databases in a truly platform independent way. This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mxODBC-Connect-2.0.3-GA.html ________________________________________________________________________ INTRODUCTION The mxODBC Connect Database Interface for Python allows users to easily connect Python applications to all major databases on the market today in a highly portable, convenient and secure way. Python Database Connectivity the Easy Way ----------------------------------------- Unlike our mxODBC Python extension, mxODBC Connect is designed as client-server application, so you no longer need to find production quality ODBC drivers for all the platforms you target with your Python application. Instead you use an easy to install royalty-free Python client library which connects directly to the mxODBC Connect database server over the network. This makes mxODBC Connect a great basis for writing cross-platform multi-tier database applications and utilities in Python, especially if you run applications that need to communicate with databases such as MS SQL Server and MS Access, Oracle Database, IBM DB2 and Informix, Sybase ASE and Sybase Anywhere, MySQL, PostgreSQL, SAP MaxDB and many more, that run on Windows or Linux machines. Ideal for Database Driven Client Applications --------------------------------------------- By removing the need to install and configure ODBC drivers on the client side and dealing with complicated network setups for each set of drivers, mxODBC Connect greatly simplifies deployment of database driven client applications, while at the same time making the network communication between client and database server more efficient and more secure. For more information, please have a look at the mxODBC Connect product page, in particular, the full list of available features. For more information, please see the product page: http://www.egenix.com/products/python/mxODBCConnect/ ________________________________________________________________________ NEWS The 2.0.3 release of mxODBC Connect includes the following enhancements and fixes: Security Enhancements --------------------- * Upgraded client and server to the most recent eGenix pyOpenSSL 0.13.1.1.0.1.5. Server Enhancements ------------------- * Updated the server to use mxODBC 3.2.2 for database connectivity. Client Enhancements ------------------- * Added support for the new .cursortype attribute in mxODBC 3.2.2 which is available on both connections and cursors to adjust the used ODBC cursor type. Performance Enhancements ------------------------ * MS SQL Server performance can now be much enhanced, and increased to levels beyond that of mxODBC Connect 2.0.2 and previous releases, by adjusting the default cursor type to forward-only cursors instead of static cursors: # Connect to the remote database from mx.ODBCConnect.Client import ServerSession session = ServerSession(...) ODBC = session.open() connection = ODBC.DriverConnect(...) # Use the faster forward-only cursors connection.cursortype = ODBC.SQL.CURSOR_FORWARD_ONLY # Cursors created on this connection will then default # to forward only cursors cursor = connection.cursor() * The performance increase compared to mxODBC Connect 2.0.2 is enormous: from 2-3x faster executes/fetches for average queries, up to 300x faster for simple cases. In mxODBC Connect 2.1, we will switch to using forward-only cursors per default for all database backends. * IBM DB2 can benefit from the same performance enhancements using forward-only cursors. The effect is a lot smaller compared to MS SQL Server, but still noticeable: up to 2x faster executes/fetches with forward-only cursors, compared to mxODBC Connect 2.0.2. * Added documentation to explain the different cursor types, compatibility with different database backends and effects on performance to the mxODBC documentation. New License Structure --------------------- Due to popular demand, we have added an unlimited connections server license, so now you can choose between: * the entry-level 20-connections server license, * an average use 50-connections server license. * and the unlimited connections server license for our high-end users. For the full set of changes, please check the mxODBC Connect change log. http://www.egenix.com/products/python/mxODBCConnect/changelog.html mxODBC Connect 2.0 Highlights ----------------------------- mxODBC Connect 2.0 was released on 2012-08-20. These are the most important highlights: * mxODBC Connect Server now uses mxODBC 3.2 internally and makes its API available in the mxODBC Connect Client. This is a major step forward from the mxODBC 3.0 version used in mxODBC Connect Server 1.0. * We've added native Windows x64 builds. * mxODBC Connect Client now integrates directly with gevent, allowing client applications to run asynchronous tasks while performing remote database queries. Please see the release announcement for full details: http://www.egenix.com/company/news/eGenix-mxODBC-Connect-2.0.0-GA.html ________________________________________________________________________ UPGRADING You are encouraged to upgrade to this latest mxODBC Connect release. When upgrading, please always upgrade both the server and the client installations to the same version - even for patch level releases. Customers who have purchased mxODBC Connect 2.0 licenses can continue to use their licenses with this patch level release. Customers who have purchased mxODBC Connect 1.x licenses can request 20% discount coupons for upgrade purchases. Please contact the eGenix.com Sales Team (sales at egenix.com) with your existing license serials for details. Users of our stand-alone mxODBC product will have to purchase new licenses from our online shop in order to use mxODBC Connect. You can request 30-day evaluation licenses by visiting our web-site or writing to sales at egenix.com, stating your name (or the name of the company) and the number of eval licenses that you need. http://www.egenix.com/products/python/mxODBCConnect/#Evaluation ________________________________________________________________________ DOWNLOADS The download archives as well as instructions for installation and configuration of the product can be found on the product page: http://www.egenix.com/products/python/mxODBCConnect/ If you want to try the package, jump straight to the download instructions: https://cms.egenix.com/products/python/mxODBCConnect/#Download Fully functional evaluation licenses for the mxODBC Connect Server are available free of charge: http://www.egenix.com/products/python/mxODBCConnect/#Evaluation mxODBC Connect Client is always free of charge. _______________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. _______________________________________________________________________ INFORMATION About Python (http://www.python.org/): Python is an object-oriented Open Source programming language which runs on all modern platforms. By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for today's IT challenges. About eGenix (http://www.egenix.com/): eGenix is a software project, consulting and product company focusing on expert project services and professional quality products for companies, Python users and developers. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Apr 09 2013) >>> Python Projects, Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2013-04-02: Released mxODBC Zope DA 2.1.1 ... http://egenix.com/go41 2013-04-10: Python Meeting Duesseldorf ... tomorrow ::::: Try our 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 k.lykourgos at gmail.com Tue Apr 9 05:58:09 2013 From: k.lykourgos at gmail.com (k.lykourgos at gmail.com) Date: Tue, 9 Apr 2013 02:58:09 -0700 (PDT) Subject: Python module vs library Message-ID: <03ee1902-ac8a-4d1f-9f2b-8e796fcccfe8@googlegroups.com> Hi, what is the difference between python module and library ? From tjreedy at udel.edu Tue Apr 9 10:02:03 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Tue, 09 Apr 2013 10:02:03 -0400 Subject: Python module vs library In-Reply-To: <03ee1902-ac8a-4d1f-9f2b-8e796fcccfe8@googlegroups.com> References: <03ee1902-ac8a-4d1f-9f2b-8e796fcccfe8@googlegroups.com> Message-ID: On 4/9/2013 5:58 AM, k.lykourgos at gmail.com wrote: > Hi, what is the difference between python module and library ? They are in different categories. A Python module is a namespace (a mapping of names to objects) created by running Python code as a main module or by import statements within Python code (or by executing import functions within a Python interpreter). A library in general is a collection of functions and classes used by multiple applications. A Python library is composed of Python modules, packages, and collections of such. From torriem at gmail.com Tue Apr 9 10:18:11 2013 From: torriem at gmail.com (Michael Torrie) Date: Tue, 09 Apr 2013 08:18:11 -0600 Subject: Python module vs library In-Reply-To: <03ee1902-ac8a-4d1f-9f2b-8e796fcccfe8@googlegroups.com> References: <03ee1902-ac8a-4d1f-9f2b-8e796fcccfe8@googlegroups.com> Message-ID: <51642323.4050705@gmail.com> On 04/09/2013 03:58 AM, k.lykourgos at gmail.com wrote: > Hi, what is the difference between python module and library ? "library" doesn't really mean anything specifically to Python's interpreter. It's not a valid keyword and is only used by humans to describe the abstract function and nature of a bunch of arbitrary Python code, usually in a module or library. Python does have a concept of modules and packages. Both serve the same purpose, which is to bring together a collection of attributes into a namespace that can be imported into the current namespace (IE a library!). From rustompmody at gmail.com Tue Apr 9 10:29:31 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 9 Apr 2013 07:29:31 -0700 (PDT) Subject: Python module vs library References: <03ee1902-ac8a-4d1f-9f2b-8e796fcccfe8@googlegroups.com> Message-ID: <4963dfe6-4fa1-444e-b703-5d6e05a942f7@ul7g2000pbc.googlegroups.com> On Apr 9, 7:18?pm, Michael Torrie wrote: > On 04/09/2013 03:58 AM, k.lykour... at gmail.com wrote: > > > Hi, what is the difference between python module and library ? > > "library" doesn't really mean anything specifically to Python's > interpreter. ?It's not a valid keyword and is only used by humans to > describe the abstract function and nature of a bunch of arbitrary Python > code, usually in a module or library. I guess Michael meant "...module or package." Else the next question is going to be "Can you explain recursion in python?" :-) > > Python does have a concept of modules and packages. ?Both serve the same > purpose, which is to bring together a collection of attributes into a > namespace that can be imported into the current namespace (IE a library!). From torriem at gmail.com Tue Apr 9 11:08:36 2013 From: torriem at gmail.com (Michael Torrie) Date: Tue, 09 Apr 2013 09:08:36 -0600 Subject: Python module vs library In-Reply-To: <4963dfe6-4fa1-444e-b703-5d6e05a942f7@ul7g2000pbc.googlegroups.com> References: <03ee1902-ac8a-4d1f-9f2b-8e796fcccfe8@googlegroups.com> <4963dfe6-4fa1-444e-b703-5d6e05a942f7@ul7g2000pbc.googlegroups.com> Message-ID: <51642EF4.3090801@gmail.com> On 04/09/2013 08:29 AM, rusi wrote: > I guess Michael meant "...module or package." > Else the next question is going to be "Can you explain recursion in > python?" :-) You're right. On both counts. :) From xxy-php at qq.com Tue Apr 9 06:20:04 2013 From: xxy-php at qq.com (=?gb18030?B?0KHRp9SwUEhQ?=) Date: Tue, 9 Apr 2013 18:20:04 +0800 Subject: Python httplib, request & putrequest Message-ID: I need to use the python httplib. And i code two sample, the first works, not the second. But what i need is the second. In the second sample, the data seems not be sent correctly. I want to know where is the problem in the second. TIA, Levi Here is my two code: first sample: conn=httplib.HTTPConnection(data_host) a_file=open("/home/levi/5","rb") data=a_file.read() a_file.close() conn.request("PUT", "/webhdfs/v1/levi/5?op=CREATE&user.name=levi", data) res=conn.getresponse() print res.status,res.reason print res.msg conn.close() And the second: conn=httplib.HTTPConnection(data_host) conn.connect() conn.putrequest("PUT","/webhdfs/v1/levi/5?op=CREATE&user.name=levi") conn.endheaders() a_file=open("/home/levi/5","rb") data=a_file.read() a_file.close() conn.send(data) res=conn.getresponse() print res.status,res.reason print res.read() print res.msg conn.close() -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Tue Apr 9 11:27:58 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 09 Apr 2013 15:27:58 GMT Subject: Python httplib, request & putrequest References: Message-ID: <5164337d$0$30003$c3e8da3$5496439d@news.astraweb.com> On Tue, 09 Apr 2013 18:20:04 +0800, ???PHP wrote: > I need to use the python httplib. > > And i code two sample, the first works, not the second. > > But what i need is the second. > > In the second sample, the data seems not be sent correctly. > > I want to know where is the problem in the second. It works for me. When I try it on my local webserver, I get the expected 405 "Method Not Allowed". What do you get? Of course, I have had to use a different website, since you don't give us enough information to test your code. Without knowing what data_host is, we have no way of running your code and seeing what it does. Please take the time to give us sample code that we can actually run. You might find it useful to read this page first: http://sscce.org/ Also, in your message, I see dozens of lines of HTML like this: >
 class="pln">conn= class="pln">httplib. class="typ">HTTPConnection( class="pln">data_host)
> a_file=

I need to use the python httplib.
 
And i code two sample, the first works, not the second.
 
But what i need is the second.
 
In the second sample, the data seems not be sent correctly.
 
I want to know where is the problem in the second.
 
TIA, Levi
 
Here is my two code:
 
first sample:
 conn=httplib.HTTPConnection(data_host) a_file=open("/home/levi/5","rb") data=a_file.read() a_file.close() conn.request("PUT", "/webhdfs/v1/levi/5?op=CREATE&user.name=levi", data) res=conn.getresponse() print res.status,res.reason print res.msg conn.close() 
And the second:
 conn=httplib.HTTPConnection(data_host) conn.connect() conn.putrequest("PUT","/webhdfs/v1/levi/5?op=CREATE&user.name=levi") conn.endheaders() a_file=open("/home/levi/5","rb") data=a_file.read() a_file.close() conn.send(data) res=conn.getresponse() print res.status,res.reason print res.read() print res.msg conn.close()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 

From emmanuel.richiardone at gmail.com  Tue Apr  9 06:56:37 2013
From: emmanuel.richiardone at gmail.com (emmanuel.richiardone at gmail.com)
Date: Tue, 9 Apr 2013 03:56:37 -0700 (PDT)
Subject: Concurrent multicast udp socket
Message-ID: <59e4e707-0c45-49df-a85a-3264855e91d1@googlegroups.com>

Dear all

I have a problem with multicast sockets of the same port but belonging to different groups.

For example, I have two udp sockets, listening on the same local address and same port; for each one I set the sockopt to listen on a specific multicast group (I can also see the igmp packets going out of the interface).

But when data is sent on the network to one multicast address, I receive the same data to both the socket; I understand why, because I set the SO_REUSEPORT option.

I'm looking for a way to identify to which multicast group the data was sent after have been received on each socket.

I'm working on debian, python version 2.7 or 3.3.1.
Here is a sample of code:
 http://pastebin.com/BF1gkvgg

Thanks for helps..

--
Emmanuel (http://richiardone.eu)


From jhunter.dunefsky at gmail.com  Tue Apr  9 07:07:55 2013
From: jhunter.dunefsky at gmail.com (Jake D)
Date: Tue, 9 Apr 2013 04:07:55 -0700 (PDT)
Subject: New version
Message-ID: <39d857a2-f739-4e47-82b2-fb3abf05aa8c@c7g2000vbe.googlegroups.com>

There's a new version of im.py out on GitHub:
https://github.com/jhunter-d/im.py/blob/master/im.py


From rodrick.brown at gmail.com  Tue Apr  9 07:20:00 2013
From: rodrick.brown at gmail.com (Rodrick Brown)
Date: Tue, 9 Apr 2013 07:20:00 -0400
Subject: New version
In-Reply-To: <39d857a2-f739-4e47-82b2-fb3abf05aa8c@c7g2000vbe.googlegroups.com>
References: <39d857a2-f739-4e47-82b2-fb3abf05aa8c@c7g2000vbe.googlegroups.com>
Message-ID: <-9134712786223064505@unknownmsgid>

Was it so hard to state in the email subject what the new version is
or describe in the body a small summary on what you've released? I
swear the users on this list post the most useless emails.

Sent from my iPhone

On Apr 9, 2013, at 7:12 AM, Jake D  wrote:

> There's a new version of im.py out on GitHub:
> https://github.com/jhunter-d/im.py/blob/master/im.py
> --
> http://mail.python.org/mailman/listinfo/python-list


From cabbar at gmail.com  Tue Apr  9 07:41:51 2013
From: cabbar at gmail.com (cabbar at gmail.com)
Date: Tue, 9 Apr 2013 04:41:51 -0700 (PDT)
Subject: newbie question about confusing exception handling in urllib
Message-ID: <1ae3261b-078d-4362-abff-ea4471addd6a@googlegroups.com>

Hi,

I have been using Java/Perl professionally for many years and have been trying to learn python3 recently. As my first program, I tried writing a class for a small project, and I am having really hard time understanding exception handling in urllib and in python in general...
Basically, what I want to do is very simple, try to fetch something "tryurllib.request.urlopen(request)", and:
  - If request times out or connection is reset, re-try n times
  - If it fails, return an error
  - If it works return the content.

But, this simple requirement became a nightmare for me. I am really confused about how I should be checking this because:
  - When connection times out, I sometimes get URLException with "reason" field set to socket.timeout, and checking (isinstance(exception.reason, socket.timeout)) works fine
  - But sometimes I get socket.timeout exception directly, and it has no "reason" field, so above statement fails, since there is no reason field there.
  - Connection reset is a totally different exception
  - Not to mention, some exceptions have msg / reason / errno fields but some don't, so there is no way of knowing exception details unless you check them one by one. The only common thing I could was to find call __str__()?
  - Since, there are too many possible exceptions, you need to catch BaseException (I received URLError, socket.timeout, ConnectionRefusedError, ConnectionResetError, BadStatusLine, and none share a common parent). And, catching the top level exception is not a good thing.

So, I ended up writing the following, but from everything I know, this looks really ugly and wrong???

        try: 
            response = urllib.request.urlopen(request)
            content = response.read()
        except BaseException as ue:
            if (isinstance(ue, socket.timeout) or (hasattr(ue, "reason") and isinstance(ue.reason, socket.timeout)) or isinstance(ue, ConnectionResetError)):
                print("REQUEST TIMED OUT")

or, something like:

        except:
            (a1,a2,a3) = sys.exc_info()
            errorString = a2.__str__()
            if ((errorString.find("Connection reset by peer") >= 0) or (errorString.find("error timed out") >= 0)):

Am I missing something here? I mean, is this really how I should be doing it?

Thanks.


From __peter__ at web.de  Tue Apr  9 08:19:06 2013
From: __peter__ at web.de (Peter Otten)
Date: Tue, 09 Apr 2013 14:19:06 +0200
Subject: newbie question about confusing exception handling in urllib
References: <1ae3261b-078d-4362-abff-ea4471addd6a@googlegroups.com>
Message-ID: 

cabbar at gmail.com wrote:

> Hi,
> 
> I have been using Java/Perl professionally for many years and have been
> trying to learn python3 recently. As my first program, I tried writing a
> class for a small project, and I am having really hard time understanding
> exception handling in urllib and in python in general... Basically, what I
> want to do is very simple, try to fetch something
> "tryurllib.request.urlopen(request)", and:
>   - If request times out or connection is reset, re-try n times
>   - If it fails, return an error
>   - If it works return the content.
> 
> But, this simple requirement became a nightmare for me. I am really
> confused about how I should be checking this because:
>   - When connection times out, I sometimes get URLException with "reason"
>   field set to socket.timeout, and checking (isinstance(exception.reason,
>   socket.timeout)) works fine - But sometimes I get socket.timeout
>   exception directly, and it has no "reason" field, so above statement
>   fails, since there is no reason field there. - Connection reset is a
>   totally different exception - Not to mention, some exceptions have msg /
>   reason / errno fields but some don't, so there is no way of knowing
>   exception details unless you check them one by one. The only common
>   thing I could was to find call __str__()? - Since, there are too many
>   possible exceptions, you need to catch BaseException (I received
>   URLError, socket.timeout, ConnectionRefusedError, ConnectionResetError,
>   BadStatusLine, and none share a common parent). And, catching the top
>   level exception is not a good thing.
> 
> So, I ended up writing the following, but from everything I know, this
> looks really ugly and wrong???
> 
>         try:
>             response = urllib.request.urlopen(request)
>             content = response.read()
>         except BaseException as ue:
>             if (isinstance(ue, socket.timeout) or (hasattr(ue, "reason")
>             and isinstance(ue.reason, socket.timeout)) or isinstance(ue,
>             ConnectionResetError)):
>                 print("REQUEST TIMED OUT")
> 
> or, something like:
> 
>         except:
>             (a1,a2,a3) = sys.exc_info()
>             errorString = a2.__str__()
>             if ((errorString.find("Connection reset by peer") >= 0) or
>             (errorString.find("error timed out") >= 0)):
> 
> Am I missing something here? I mean, is this really how I should be doing
> it?

Does it help if you reorganize your code a bit? For example:

def read_content(request)
    try:
        response = urllib.request.urlopen(request)
        content = response.read()
    except socket.timeout:
        return None
    except URLError as ue:
        if isinstance(ue.reason, socket.timeout):
            return None
        raise
    return content

for i in range(max_tries):
    content = read_content(request)
    if content is not None:
        break
else:
    print("Could not download", request)

Instead of returning an out-of-band response (None) you could also raise a 
custom exception (called MyTimeoutError below). The retry-loop would then 
become

for i in range(max_tries):
    try:
        content = read_content(request):
    except MyTimeoutError:
        pass
    else:
        break
else:
    print("Could not download", request)





From cabbar at gmail.com  Tue Apr  9 09:19:09 2013
From: cabbar at gmail.com (cabbar at gmail.com)
Date: Tue, 9 Apr 2013 06:19:09 -0700 (PDT)
Subject: newbie question about confusing exception handling in urllib
In-Reply-To: <1ae3261b-078d-4362-abff-ea4471addd6a@googlegroups.com>
References: <1ae3261b-078d-4362-abff-ea4471addd6a@googlegroups.com>
Message-ID: 

Ah, looks better. 

But, 2 questions:

1. I should also catch ConnectionResetError I am guessing.
2. How do I handle all other exceptions, just say Exception: and handle them? I want to silently ignore them.

Thanks...

On Tuesday, April 9, 2013 2:41:51 PM UTC+3, cab... at gmail.com wrote:
> Hi,
> 
> 
> 
> I have been using Java/Perl professionally for many years and have been trying to learn python3 recently. As my first program, I tried writing a class for a small project, and I am having really hard time understanding exception handling in urllib and in python in general...
> 
> Basically, what I want to do is very simple, try to fetch something "tryurllib.request.urlopen(request)", and:
> 
>   - If request times out or connection is reset, re-try n times
> 
>   - If it fails, return an error
> 
>   - If it works return the content.
> 
> 
> 
> But, this simple requirement became a nightmare for me. I am really confused about how I should be checking this because:
> 
>   - When connection times out, I sometimes get URLException with "reason" field set to socket.timeout, and checking (isinstance(exception.reason, socket.timeout)) works fine
> 
>   - But sometimes I get socket.timeout exception directly, and it has no "reason" field, so above statement fails, since there is no reason field there.
> 
>   - Connection reset is a totally different exception
> 
>   - Not to mention, some exceptions have msg / reason / errno fields but some don't, so there is no way of knowing exception details unless you check them one by one. The only common thing I could was to find call __str__()?
> 
>   - Since, there are too many possible exceptions, you need to catch BaseException (I received URLError, socket.timeout, ConnectionRefusedError, ConnectionResetError, BadStatusLine, and none share a common parent). And, catching the top level exception is not a good thing.
> 
> 
> 
> So, I ended up writing the following, but from everything I know, this looks really ugly and wrong???
> 
> 
> 
>         try: 
> 
>             response = urllib.request.urlopen(request)
> 
>             content = response.read()
> 
>         except BaseException as ue:
> 
>             if (isinstance(ue, socket.timeout) or (hasattr(ue, "reason") and isinstance(ue.reason, socket.timeout)) or isinstance(ue, ConnectionResetError)):
> 
>                 print("REQUEST TIMED OUT")
> 
> 
> 
> or, something like:
> 
> 
> 
>         except:
> 
>             (a1,a2,a3) = sys.exc_info()
> 
>             errorString = a2.__str__()
> 
>             if ((errorString.find("Connection reset by peer") >= 0) or (errorString.find("error timed out") >= 0)):
> 
> 
> 
> Am I missing something here? I mean, is this really how I should be doing it?
> 
> 
> 
> Thanks.



From __peter__ at web.de  Tue Apr  9 10:46:38 2013
From: __peter__ at web.de (Peter Otten)
Date: Tue, 09 Apr 2013 16:46:38 +0200
Subject: newbie question about confusing exception handling in urllib
References: <1ae3261b-078d-4362-abff-ea4471addd6a@googlegroups.com>
	
Message-ID: 

cabbar at gmail.com wrote:

> Ah, looks better.
> 
> But, 2 questions:
> 
> 1. I should also catch ConnectionResetError I am guessing.

Does it need a special reaction? If so give it its own except suite.

> 2. How do I handle all other exceptions, just say Exception: and handle
> them? I want to silently ignore them.

If at all I would do that in the client code. Also, catch Exception rather 
than BaseException.





From steve+comp.lang.python at pearwood.info  Tue Apr  9 11:05:22 2013
From: steve+comp.lang.python at pearwood.info (Steven D'Aprano)
Date: 09 Apr 2013 15:05:22 GMT
Subject: newbie question about confusing exception handling in urllib
References: <1ae3261b-078d-4362-abff-ea4471addd6a@googlegroups.com>
	
Message-ID: <51642e32$0$30003$c3e8da3$5496439d@news.astraweb.com>

On Tue, 09 Apr 2013 06:19:09 -0700, cabbar wrote:

> How do I
> handle all other exceptions, just say Exception: and handle them? I want
> to silently ignore them.

Please don't. That is normally poor practice, since it simply hides bugs 
in your code.

As a general rule, you should only catch exceptions that you know are 
harmless, and that you can recover from. If you don't know that it's 
harmless, then it's probably a bug, and you should let it raise, so you 
can see the traceback and fix it. In the words of Chris Smith:

    "I find it amusing when novice programmers believe their 
     main job is preventing programs from crashing. ... More 
     experienced programmers realize that correct code is 
     great, code that crashes could use improvement, but 
     incorrect code that doesn?t crash is a horrible nightmare."


One exception to this rule (no pun intended) is that sometimes you want 
to hide the details of unexpected tracebacks from your users. In that 
case, it may be acceptable to wrap your application's main function in a 
try block, catch any unexpected exceptions, log the exception, and then 
quietly exit with a short, non-threatening error message that won't scare 
the civilians:


try:
    main()
except Exception as err:
    log(err)
    print("Sorry, an unexpected error has occurred.")
    print("Please contact support for assistance.")
    sys.exit(-1)


Still want to catch all unexpected errors, and ignore them? If you're 
absolutely sure that this is the right thing to do, then:

try:
    code_goes_here()
except Exception:
    pass

But really, you shouldn't do this.

(For experts only: you *probably* shouldn't do this.)



-- 
Steven


From rosuav at gmail.com  Tue Apr  9 12:23:27 2013
From: rosuav at gmail.com (Chris Angelico)
Date: Wed, 10 Apr 2013 02:23:27 +1000
Subject: newbie question about confusing exception handling in urllib
In-Reply-To: <51642e32$0$30003$c3e8da3$5496439d@news.astraweb.com>
References: <1ae3261b-078d-4362-abff-ea4471addd6a@googlegroups.com>
	
	<51642e32$0$30003$c3e8da3$5496439d@news.astraweb.com>
Message-ID: 

On Wed, Apr 10, 2013 at 1:05 AM, Steven D'Aprano
 wrote:
> One exception to this rule (no pun intended) is that sometimes you want
> to hide the details of unexpected tracebacks from your users. In that
> case, it may be acceptable to wrap your application's main function in a
> try block, catch any unexpected exceptions, log the exception, and then
> quietly exit with a short, non-threatening error message that won't scare
> the civilians

This is important to some types of security concern, too; for
instance, if I'm running a web server, I probably don't want to leak
details of exceptions and tracebacks to a potential attacker. Same
again: catch the exception, log it, return simple error message;
additionally, you can return that message as an HTTP response rather
than simply bombing the web server. But again, a bare except should
almost always be logging its exceptions.

True story, though not in Python: After taking over the code of an
ex-coworker, I was trying to fix some crazy problems. Everything I did
seemed to kinda-work, but nothing properly worked. Trying to clean up
the code to comply with "use strict" mode (which will tell you what
language this is, and it isn't Perl) was a matter of blundering about
in the dark. Turned out there was an event handler somewhere that
buried the *entire file full of code* behind a callback that caught
and suppressed everything. Gee, thanks. Web browsers these days are
pretty good at reporting exceptions - we were mainly using Chrome's
inbuilt Firebug-equivalent - but our brilliant coworker saw fit to
hide them all.

Exceptions are a huge boon.

ChrisA


From ramit.prasad at jpmorgan.com  Fri Apr 12 17:29:21 2013
From: ramit.prasad at jpmorgan.com (Prasad, Ramit)
Date: Fri, 12 Apr 2013 21:29:21 +0000
Subject: newbie question about confusing exception handling in urllib
In-Reply-To: <51642e32$0$30003$c3e8da3$5496439d@news.astraweb.com>
References: <1ae3261b-078d-4362-abff-ea4471addd6a@googlegroups.com>
	
	<51642e32$0$30003$c3e8da3$5496439d@news.astraweb.com>
Message-ID: <5B80DD153D7D744689F57F4FB69AF474182F6F39@SCACMX008.exchad.jpmchase.net>

Steven D'Aprano wrote:
> try:
>     main()
> except Exception as err:
>     log(err)
>     print("Sorry, an unexpected error has occurred.")
>     print("Please contact support for assistance.")
>     sys.exit(-1)
> 
> 

I like the traceback[0] module for logging last exception thrown.
See traceback.format_exc() or traceback.print_exc().

trace = traceback.format_exc()
log.error('I was trying to do , but unexpected error.\n{0}'.format(trace))

[0] http://docs.python.org/2/library/traceback.html


~Ramit



This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  

From tjreedy at udel.edu  Tue Apr  9 10:19:08 2013
From: tjreedy at udel.edu (Terry Jan Reedy)
Date: Tue, 09 Apr 2013 10:19:08 -0400
Subject: newbie question about confusing exception handling in urllib
In-Reply-To: <1ae3261b-078d-4362-abff-ea4471addd6a@googlegroups.com>
References: <1ae3261b-078d-4362-abff-ea4471addd6a@googlegroups.com>
Message-ID: 

On 4/9/2013 7:41 AM, cabbar at gmail.com wrote:
> Hi,
>
> I have been using Java/Perl professionally for many years and have been trying to learn python3 recently. As my first program, I tried writing a class for a small project, and I am having really hard time understanding exception handling in urllib and in python in general...
> Basically, what I want to do is very simple,

Very funny ;-). What you are trying to do, as your first project, is 
interact with the large, multi-layered, non=deterministic monster known 
as Internet, with timeout handling, through multiple layers of library 
code. When it comes to exception handling, this is about the most 
complex thing you can do.

> try to fetch something "tryurllib.request.urlopen(request)", and:
>    - If request times out or connection is reset, re-try n times
>    - If it fails, return an error
>    - If it works return the content.
>
> But, this simple requirement became a nightmare for me. I am really confused about how I should be checking this because:
>    - When connection times out, I sometimes get URLException with "reason" field set to socket.timeout, and checking (isinstance(exception.reason, socket.timeout)) works fine
>    - But sometimes I get socket.timeout exception directly, and it has no "reason" field, so above statement fails, since there is no reason field there.

If you are curious why the different exceptions for seemingly the same 
problem, you can look at the printed traceback to see where the 
different exceptions come from. Either don't catch the exceptions, 
re-raise them, or explicitly grab the traceback (from exc_info, I believe)

>    - Connection reset is a totally different exception
>    - Not to mention, some exceptions have msg / reason / errno fields but some don't, so there is no way of knowing exception details unless you check them one by one. The only common thing I could was to find call __str__()?

The system is probably a bit more ragged then it might be if completely 
re-designed from scratch.

>    - Since, there are too many possible exceptions, you need to catch BaseException (I received URLError, socket.timeout, ConnectionRefusedError, ConnectionResetError, BadStatusLine, and none share a common parent). And, catching the top level exception is not a good thing.

You are right, catching BaseException is bad. In particular, it will 
catch KeyboardInterrupt from a user trying to stop the process. It is 
also unnecessary as all the exceptions you want to catch are derived 
from Exception, which itself is derived from BaseException.

> So, I ended up writing the following, but from everything I know, this looks really ugly and wrong???
>
>          try:
>              response = urllib.request.urlopen(request)
>              content = response.read()
>          except BaseException as ue:

except Exception as ue:

>              if (isinstance(ue, socket.timeout) or (hasattr(ue, "reason") and isinstance(ue.reason, socket.timeout)) or isinstance(ue, ConnectionResetError)):
>                  print("REQUEST TIMED OUT")
>
> or, something like:
>
>          except:

except Exception:

>              (a1,a2,a3) = sys.exc_info()
>              errorString = a2.__str__()
>              if ((errorString.find("Connection reset by peer") >= 0) or (errorString.find("error timed out") >= 0)):

--
Terry Jan Reedy




From ian.g.kelly at gmail.com  Tue Apr  9 15:11:18 2013
From: ian.g.kelly at gmail.com (Ian Kelly)
Date: Tue, 9 Apr 2013 13:11:18 -0600
Subject: newbie question about confusing exception handling in urllib
In-Reply-To: <1ae3261b-078d-4362-abff-ea4471addd6a@googlegroups.com>
References: <1ae3261b-078d-4362-abff-ea4471addd6a@googlegroups.com>
Message-ID: 

On Tue, Apr 9, 2013 at 5:41 AM,   wrote:
>         try:
>             response = urllib.request.urlopen(request)
>             content = response.read()
>         except BaseException as ue:
>             if (isinstance(ue, socket.timeout) or (hasattr(ue, "reason") and isinstance(ue.reason, socket.timeout)) or isinstance(ue, ConnectionResetError)):
>                 print("REQUEST TIMED OUT")

I'm surprised nobody has yet pointed out that you can catch multiple
specific exception types in the except clause rather than needing to
organize them under a catch-all base class.  These two code blocks are
basically equivalent:

try:
    do_stuff()
except BaseException as ue:
    if isinstance(ue, (socket.timeout, ConnectionResetError)):
        handle_it()
    else:
        raise

try:
    do_stuff()
except (socket.timeout, ConnectionResetError) as ue:
    handle_it()

Cheers,
Ian


From amiwinter at gmail.com  Tue Apr  9 09:31:06 2013
From: amiwinter at gmail.com (amiwinter at gmail.com)
Date: Tue, 9 Apr 2013 06:31:06 -0700 (PDT)
Subject: print to screen and file with one print statement
In-Reply-To: <7049ba55.0302130451.7b9e2f4e@posting.google.com>
References: 
	<7049ba55.0302130451.7b9e2f4e@posting.google.com>
Message-ID: <7a819c41-a8fc-4f06-97b5-f0f1129bc9c3@googlegroups.com>

On Thursday, February 13, 2003 2:51:02 PM UTC+2, Mike M?ller wrote:
> "Mark McEahern"  wrote in message news:...
> > Same basic idea:
> > 
> > #!/usr/bin/env python
> > 
> > import sys
> > 
> > class MyWriter:
> > 
> >     def __init__(self, stdout, filename):
> >         self.stdout = stdout
> >         self.logfile = file(filename, 'a')
> > 
> >     def write(self, text):
> >         self.stdout.write(text)
> >         self.logfile.write(text)
> > 
> >     def close(self):
> >         self.stdout.close()
> >         self.logfile.close()
> > 
> > writer = MyWriter(sys.stdout, 'log.txt')
> > sys.stdout = writer
> > 
> > print 'test'
> > 
> 
> Hi Mark, 
> 
> works perfect. Just had to change ?file? to ?open? for my Python 2.1.
> Adding the method ?flush(self)? to Writer helped to get my
> ?sys.stdout.flush()? to work.
> 
> Thanks also to two inches (previous post).
> 
> 
> Mike

Hay Mike,

Can you tell me how & where you added the 'flush(self)' & 'sys.stdout.flush()'?


Thanks!
Ami


From thomasancilleri at gmail.com  Tue Apr  9 09:32:18 2013
From: thomasancilleri at gmail.com (thomasancilleri at gmail.com)
Date: Tue, 9 Apr 2013 06:32:18 -0700 (PDT)
Subject: While loop help
Message-ID: 

I'm new to learning python and creating a basic program to convert units of measurement which I will eventually expand upon but im trying to figure out how to loop the entire program. When I insert a while loop it only loops the first 2 lines. Can someone provide a detailed beginner friendly explanation. Here is my program.

#!/usr/bin/env python
restart = "true"
while restart == "true":
#Program starts here
    print "To start the Unit Converter please type the number next to the conversion you would like to perform"
    choice = input("\n1:Inches to Meter\n2:Millileters to Pint\n3:Acres to Square-Miles\n")

#If user enters 1:Program converts inches to meters
    if choice == 1:
        number = int(raw_input("\n\nType the amount in Inches you would like to convert to Meters.\n"))
        operation = "Inches to Meters"
        calc = round(number * .0254, 2)
        print "\n",number,"Inches =",calc,"Meters"
        restart = raw_input("If you would like to perform another conversion type: true\n"

#If user enters 2:Program converts millimeters to pints  
    elif choice == 2:
        number = int(raw_input("\n\nType the amount in Milliliters you would like to convert to Pints.\n"))
        operation = "Milliliters to Pints"
        calc = round(number * 0.0021134,2)
        print "\n",number,"Milliliters =",calc,"Pints"
        restart = raw_input("If you would like to perform another conversion type: true\n")

#If user enter 3:Program converts kilometers to miles
    elif choice == 3:
        number = int(raw_input("\n\nType the amount in Kilometers you would like to convert to Miles.\n"))
        operation = "Kilometers to Miles"
        calc = round(number * 0.62137,2)
        print "\n",number,"Kilometers =",calc,"Miles"
        restart = raw_input("If you would like to perform another conversion type: true\n")


From thomasancilleri at gmail.com  Tue Apr  9 09:57:37 2013
From: thomasancilleri at gmail.com (thomasancilleri at gmail.com)
Date: Tue, 9 Apr 2013 06:57:37 -0700 (PDT)
Subject: While loop help
In-Reply-To: 
References: 
Message-ID: 

On Tuesday, April 9, 2013 9:32:18 AM UTC-4, thomasa... at gmail.com wrote:
> I'm new to learning python and creating a basic program to convert units of measurement which I will eventually expand upon but im trying to figure out how to loop the entire program. When I insert a while loop it only loops the first 2 lines. Can someone provide a detailed beginner friendly explanation. Here is my program. Also suddenly I'm getting an invalid syntax error next to my elif statements when I wasn't a minute ago. What is wrong here?
> 
> 
> 
> #!/usr/bin/env python
> 
> restart = "true"
> 
> while restart == "true":
> 
> #Program starts here
> 
>     print "To start the Unit Converter please type the number next to the conversion you would like to perform"
> 
>     choice = input("\n1:Inches to Meter\n2:Millileters to Pint\n3:Acres to Square-Miles\n")
> 
> 
> 
> #If user enters 1:Program converts inches to meters
> 
>     if choice == 1:
> 
>         number = int(raw_input("\n\nType the amount in Inches you would like to convert to Meters.\n"))
> 
>         operation = "Inches to Meters"
> 
>         calc = round(number * .0254, 2)
> 
>         print "\n",number,"Inches =",calc,"Meters"
> 
>         restart = raw_input("If you would like to perform another conversion type: true\n"
> 
> 
> 
> #If user enters 2:Program converts millimeters to pints  
> 
>     elif choice == 2:
> 
>         number = int(raw_input("\n\nType the amount in Milliliters you would like to convert to Pints.\n"))
> 
>         operation = "Milliliters to Pints"
> 
>         calc = round(number * 0.0021134,2)
> 
>         print "\n",number,"Milliliters =",calc,"Pints"
> 
>         restart = raw_input("If you would like to perform another conversion type: true\n")
> 
> 
> 
> #If user enter 3:Program converts kilometers to miles
> 
>     elif choice == 3:
> 
>         number = int(raw_input("\n\nType the amount in Kilometers you would like to convert to Miles.\n"))
> 
>         operation = "Kilometers to Miles"
> 
>         calc = round(number * 0.62137,2)
> 
>         print "\n",number,"Kilometers =",calc,"Miles"
> 
>         restart = raw_input("If you would like to perform another conversion type: true\n")



From davea at davea.name  Tue Apr  9 13:12:43 2013
From: davea at davea.name (Dave Angel)
Date: Tue, 09 Apr 2013 13:12:43 -0400
Subject: While loop help
In-Reply-To: 
References: 
	
Message-ID: <51644C0B.80101@davea.name>

On 04/09/2013 09:57 AM, thomasancilleri at gmail.com wrote:
> On Tuesday, April 9, 2013 9:32:18 AM UTC-4, thomasa... at gmail.com wrote:
>> I'm new to learning python and creating a basic program to convert units of measurement which I will eventually expand upon but im trying to figure out how to loop the entire program. When I insert a while loop it only loops the first 2 lines. Can someone provide a detailed beginner friendly explanation. Here is my program. Also suddenly I'm getting an invalid syntax error next to my elif statements when I wasn't a minute ago. What is wrong here?
>>
>>
>>
>> #!/usr/bin/env python
>>
>> restart = "true"
>>
>> while restart == "true":
>>
>> #Program starts here
>>
>>      print "To start the Unit Converter please type the number next to the conversion you would like to perform"
>>
>>      choice = input("\n1:Inches to Meter\n2:Millileters to Pint\n3:Acres to Square-Miles\n")
>>
Quoting that many lines, and double-spacing every one of them is very 
impolite.  Almost makes me want to skip the thread.

If you must use buggy googlegroups, then at least fix its most annoying 
bugs:

     read this http://wiki.python.org/moin/GoogleGroupsPython.

(rest deleted, as the point has been made)



-- 
DaveA


From thomasancilleri at gmail.com  Tue Apr  9 13:18:17 2013
From: thomasancilleri at gmail.com (thomasancilleri at gmail.com)
Date: Tue, 9 Apr 2013 10:18:17 -0700 (PDT)
Subject: While loop help
In-Reply-To: 
References: 
	
	
Message-ID: 

sorry i just started using google groups, not really all that sure how to use it properly.


From rosuav at gmail.com  Tue Apr  9 13:23:27 2013
From: rosuav at gmail.com (Chris Angelico)
Date: Wed, 10 Apr 2013 03:23:27 +1000
Subject: While loop help
In-Reply-To: 
References: 
	
	
	
Message-ID: 

On Wed, Apr 10, 2013 at 3:18 AM,   wrote:
> sorry i just started using google groups, not really all that sure how to use it properly.

The best way to use Google Groups is to not use it, frankly. Just
subscribe to the mailing list in gmail; it has its own issues (eg it
encourages top-posting by putting a couple of blank lines at the top
of the quoted text), but they're easier to work around than the GG
problems.

ChrisA


From davea at davea.name  Tue Apr  9 13:30:44 2013
From: davea at davea.name (Dave Angel)
Date: Tue, 09 Apr 2013 13:30:44 -0400
Subject: While loop help
In-Reply-To: 
References: 
	
	
	
Message-ID: <51645044.1040201@davea.name>

On 04/09/2013 01:18 PM, thomasancilleri at gmail.com wrote:
> sorry i just started using google groups, not really all that sure how to use it properly.
>

IMHO, best way is to switch to a good email program, and mail your 
messages to comp.lang.python.  That's after subscribing via
     http://mail.python.org/mailman/listinfo/python-list

You can set up filters in your email program so all forum messages to 
into a separate folder, one per forum.  And you tell your email program 
to use text mail, not html.

-- 
DaveA


From thomasancilleri at gmail.com  Tue Apr  9 09:58:44 2013
From: thomasancilleri at gmail.com (thomasancilleri at gmail.com)
Date: Tue, 9 Apr 2013 06:58:44 -0700 (PDT)
Subject: While loop help
In-Reply-To: 
References: 
Message-ID: <596ca4b8-b5aa-4112-b086-6320108075f7@googlegroups.com>

Also I'm getting a invalid syntax next to my elif statements that i wasnt getting before. why is this happening now?


From rosuav at gmail.com  Tue Apr  9 10:05:25 2013
From: rosuav at gmail.com (Chris Angelico)
Date: Wed, 10 Apr 2013 00:05:25 +1000
Subject: While loop help
In-Reply-To: <596ca4b8-b5aa-4112-b086-6320108075f7@googlegroups.com>
References: 
	<596ca4b8-b5aa-4112-b086-6320108075f7@googlegroups.com>
Message-ID: 

On Tue, Apr 9, 2013 at 11:58 PM,   wrote:
> Also I'm getting a invalid syntax next to my elif statements that i wasnt getting before. why is this happening now?

Ah! That's relating to the close parenthesis problem I mentioned.
That's the exact issue I saw.

When you get told about a problem, sometimes the location pointed out
isn't the actual cause. What you have is a (near) guarantee that the
problem is no later in the file than that point; often it'll be on
that line or the one previous line. In this case, the code is
"raw_input(........ elif", which can't be properly parsed - the open
parenthesis is forcing the code to be interpreted as an expression,
and elif isn't an expression.

If you're stuck figuring out a problem, one neat trick is to delete
the line of code that's blamed for the problem and try again. If the
problem disappears, it was on that line; if the problem moves down to
the next line, it's probably on the preceding line. This trick doesn't
always work, but it can occasionally be quite handy.

ChrisA


From thomasancilleri at gmail.com  Tue Apr  9 11:47:05 2013
From: thomasancilleri at gmail.com (thomasancilleri at gmail.com)
Date: Tue, 9 Apr 2013 08:47:05 -0700 (PDT)
Subject: While loop help
In-Reply-To: 
References: 
	<596ca4b8-b5aa-4112-b086-6320108075f7@googlegroups.com>
	
Message-ID: 

Sorry I'm just starting to learn python and I'm not sure what version I'm using to be quite honest. I just started typing it up in Komodo edit (Which I'm not personally a fan in particular) I fixed the missing parenthesis which fixed the invalid syntax problem. Also, I apologize for submitting code that did not run. This is the code I have now before I tried looping it again:

#!/usr/bin/env python

#Program starts here
print "To start the Unit Converter please type the number next to the conversion you would like to perform"
choice = raw_input("\n1:Inches to Meter\n2:Millileters to Pint\n3:Acres to Square-Miles\n")

#If user enters 1:Program converts inches to meters
if choice == 1:
    #operation = "Inches to Meters"
    number = int(raw_input("\n\nType the amount in Inches you would like to convert to Meters.\n"))
    calc = round(number * .0254, 2)
    print "\n",number,"Inches =",calc,"Meters"
    restart = raw_input("If you would like to perform another conversion type: true\n")
    
#If user enters 2:Program converts millimeters to pints
elif choice == 2:
    #operation = "Milliliters to Pints"    
    number = int(raw_input("\n\nType the amount in Milliliters you would like to convert to Pints.\n"))
    calc = round(number * 0.0021134,2)
    print "\n",number,"Milliliters =",calc,"Pints"
    restart = raw_input("If you would like to perform another conversion type: true\n")
    
#If user enter 3:Program converts kilometers to miles
elif choice == 3:
    #operation = "Kilometers to Miles"
    number = int(raw_input("\n\nType the amount in Kilometers you would like to convert to Miles.\n"))
    calc = round(number * 0.62137,2)
    print "\n",number,"Kilometers =",calc,"Miles"
    restart = raw_input("If you would like to perform another conversion type: true\n")

Not sure what you meant to exactly by this:
"There's a lot of duplicated code here, most notably your continuation 
condition. You can simply back-tab after the elif block and have some 
code that reunites all the branches; this would also make things 
clearer"

Thanks for your reply and if you have any ideas for me to improve my coding that will prevent me from learning python in a sloppy way. I'd like to learn it correctly the first time!


From joel.goldstick at gmail.com  Tue Apr  9 12:02:15 2013
From: joel.goldstick at gmail.com (Joel Goldstick)
Date: Tue, 9 Apr 2013 12:02:15 -0400
Subject: While loop help
In-Reply-To: 
References: 
	<596ca4b8-b5aa-4112-b086-6320108075f7@googlegroups.com>
	
	
Message-ID: 

On Tue, Apr 9, 2013 at 11:47 AM,  wrote:

> Sorry I'm just starting to learn python and I'm not sure what version I'm
> using to be quite honest. I just started typing it up in Komodo edit (Which
> I'm not personally a fan in particular) I fixed the missing parenthesis
> which fixed the invalid syntax problem. Also, I apologize for submitting
> code that did not run. This is the code I have now before I tried looping
> it again:
>
> #!/usr/bin/env python
>
> #Program starts here
> print "To start the Unit Converter please type the number next to the
> conversion you would like to perform"
>

choice is not converted to an integer.  raw_input returns a string.


> choice = raw_input("\n1:Inches to Meter\n2:Millileters to Pint\n3:Acres to
> Square-Miles\n")
>

 This will convert choice to an int.  Actually, it might not if what you
type is not a number.  Then it will cause and exception.
But for now, do this:

> choice = int(choice)
>

or leave choices as a string and make your if statements like if choice ==
'1'


> #If user enters 1:Program converts inches to meters
> if choice == 1:
>     #operation = "Inches to Meters"
>     number = int(raw_input("\n\nType the amount in Inches you would like
> to convert to Meters.\n"))
>     calc = round(number * .0254, 2)
>     print "\n",number,"Inches =",calc,"Meters"
>     restart = raw_input("If you would like to perform another conversion
> type: true\n")
>
> #If user enters 2:Program converts millimeters to pints
> elif choice == 2:
>     #operation = "Milliliters to Pints"
>     number = int(raw_input("\n\nType the amount in Milliliters you would
> like to convert to Pints.\n"))
>     calc = round(number * 0.0021134,2)
>     print "\n",number,"Milliliters =",calc,"Pints"
>     restart = raw_input("If you would like to perform another conversion
> type: true\n")
>
> #If user enter 3:Program converts kilometers to miles
> elif choice == 3:
>     #operation = "Kilometers to Miles"
>     number = int(raw_input("\n\nType the amount in Kilometers you would
> like to convert to Miles.\n"))
>     calc = round(number * 0.62137,2)
>     print "\n",number,"Kilometers =",calc,"Miles"
>     restart = raw_input("If you would like to perform another conversion
> type: true\n")
>
> Not sure what you meant to exactly by this:
> "There's a lot of duplicated code here, most notably your continuation
> condition. You can simply back-tab after the elif block and have some
> code that reunites all the branches; this would also make things
> clearer"
>
> Thanks for your reply and if you have any ideas for me to improve my
> coding that will prevent me from learning python in a sloppy way. I'd like
> to learn it correctly the first time!
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 

From rosuav at gmail.com  Tue Apr  9 12:10:29 2013
From: rosuav at gmail.com (Chris Angelico)
Date: Wed, 10 Apr 2013 02:10:29 +1000
Subject: While loop help
In-Reply-To: 
References: 
	<596ca4b8-b5aa-4112-b086-6320108075f7@googlegroups.com>
	
	
Message-ID: 

On Wed, Apr 10, 2013 at 1:47 AM,   wrote:
> ... I'm not sure what version I'm using ...

Try putting these lines into a Python script:

import sys
print(sys.version)

That, on any version of Python (back a fairly long way, Steven
D'Aprano can probably say how far), will give you a line or so of
output that summarizes your version. For instance, I can get the
following:

3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)]

2.7.4 (default, Apr  6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)]

3.1.1+ (r311:74480, Nov  2 2009, 14:49:22)
[GCC 4.4.1]

3.4.0a0 (default:5dcd7ee0716a, Mar 30 2013, 08:17:06)
[GCC 4.7.2]

It's a handy system summary.

> choice = raw_input("\n1:Inches to Meter\n2:Millileters to Pint\n3:Acres to Square-Miles\n")
> if choice == 1:

You probably want to use int(raw_input(...)) here; currently, you're
going to get back a string eg "1", which is not equal to the integer
1. But at least now you don't have the automatic evaluation happening
:)

>     restart = raw_input("If you would like to perform another conversion type: true\n")
>
> Not sure what you meant to exactly by this:
> "There's a lot of duplicated code here, most notably your continuation
> condition. You can simply back-tab after the elif block and have some
> code that reunites all the branches; this would also make things
> clearer"

Notice how you have the "restart = " line (which I quote above)
duplicated into each of your code branches? That's what I'm talking
about. Here's a pseudocode version of the looping you have:

while restart:
  choice = get_choice()
  if choice == 1:
    do_choice_1()
    restart = get_restart()
  elif choice == 2:
    do_choice_2()
    restart = get_restart()
  elif choice == 3:
    do_choice_3()
    restart = get_restart()

Here's how you could deduplicate that:

while restart:
  choice = get_choice()
  if choice == 1:
    do_choice_1()
  elif choice == 2:
    do_choice_2()
  elif choice == 3:
    do_choice_3()
  restart = get_restart()

The restart line is unindented one level, which brings it out of the
if/elif block, and then it'll get executed regardless of 'choice'. (To
strictly match your original code, you'd need to finish the elif block
with "else: continue", but the code makes at least as good sense
without it, so I'd consider that optional.)

> Thanks for your reply and if you have any ideas for me to improve my coding that will prevent me from learning python in a sloppy way. I'd like to learn it correctly the first time!

You're doing fine. The general pattern of programming is:

while True:
  write_code()
  try:
    figure_out_what_is_wrong_with_code()
  except LackOfSkillException:
    mail("python-list at python.org",smart_question())
  run_code()

So far, looks like you're following it just fine. :)

ChrisA


From thomasancilleri at gmail.com  Tue Apr  9 12:24:15 2013
From: thomasancilleri at gmail.com (thomasancilleri at gmail.com)
Date: Tue, 9 Apr 2013 09:24:15 -0700 (PDT)
Subject: While loop help
In-Reply-To: 
References: 
	<596ca4b8-b5aa-4112-b086-6320108075f7@googlegroups.com>
	
	
	
Message-ID: <1629a072-c512-439c-b751-c44f8e945c2e@googlegroups.com>

For system version I get this:
2.7.2 (default, Oct 11 2012, 20:14:37) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)]

Also, I understand what your saying about the continuation code. There's no need for me to include it in each if/else statement, I could just use it at the end of the program outside of the statements and it would run no matter what. But, what I don't understand exactly is the while statement. I've been looking around a lot lately and notice that people say to use for instance:

while restart: or while true: or while restart = true:

What makes a statement true? Is there a way to return a true or false message. My method was to ask the user to type "true" and if that print statement matched restart = "true" then the loop would continue but i imagine there is a better way then matching strings and integers like i have been.

Also what confuses me is that python doesn't use brackets. How do I contain all of my if/else statements into one while loop? Do I have to indent each line of code and extra indentation? I'm used to highschool doing c++ and java when I would just say:

while (x<3) 
{
     if ()
    else ()
}


From thomasancilleri at gmail.com  Tue Apr  9 12:24:15 2013
From: thomasancilleri at gmail.com (thomasancilleri at gmail.com)
Date: Tue, 9 Apr 2013 09:24:15 -0700 (PDT)
Subject: While loop help
In-Reply-To: 
References: 
	<596ca4b8-b5aa-4112-b086-6320108075f7@googlegroups.com>
	
	
	
Message-ID: <1629a072-c512-439c-b751-c44f8e945c2e@googlegroups.com>

For system version I get this:
2.7.2 (default, Oct 11 2012, 20:14:37) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)]

Also, I understand what your saying about the continuation code. There's no need for me to include it in each if/else statement, I could just use it at the end of the program outside of the statements and it would run no matter what. But, what I don't understand exactly is the while statement. I've been looking around a lot lately and notice that people say to use for instance:

while restart: or while true: or while restart = true:

What makes a statement true? Is there a way to return a true or false message. My method was to ask the user to type "true" and if that print statement matched restart = "true" then the loop would continue but i imagine there is a better way then matching strings and integers like i have been.

Also what confuses me is that python doesn't use brackets. How do I contain all of my if/else statements into one while loop? Do I have to indent each line of code and extra indentation? I'm used to highschool doing c++ and java when I would just say:

while (x<3) 
{
     if ()
    else ()
}


From joel.goldstick at gmail.com  Tue Apr  9 12:36:57 2013
From: joel.goldstick at gmail.com (Joel Goldstick)
Date: Tue, 9 Apr 2013 12:36:57 -0400
Subject: While loop help
In-Reply-To: <1629a072-c512-439c-b751-c44f8e945c2e@googlegroups.com>
References: 
	<596ca4b8-b5aa-4112-b086-6320108075f7@googlegroups.com>
	
	
	
	<1629a072-c512-439c-b751-c44f8e945c2e@googlegroups.com>
Message-ID: 

On Tue, Apr 9, 2013 at 12:24 PM,  wrote:

> For system version I get this:
> 2.7.2 (default, Oct 11 2012, 20:14:37)
> [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)]
>
> Also, I understand what your saying about the continuation code. There's
> no need for me to include it in each if/else statement, I could just use it
> at the end of the program outside of the statements and it would run no
> matter what. But, what I don't understand exactly is the while statement.
> I've been looking around a lot lately and notice that people say to use for
> instance:
>
> while restart: or while true: or while restart = true:
>
> What makes a statement true? Is there a way to return a true or false
> message. My method was to ask the user to type "true" and if that print
> statement matched restart = "true" then the loop would continue but i
> imagine there is a better way then matching strings and integers like i
> have been.
>
> Also what confuses me is that python doesn't use brackets. How do I
> contain all of my if/else statements into one while loop? Do I have to
> indent each line of code and extra indentation? I'm used to highschool
> doing c++ and java when I would just say:
>
> Python uses indentation.  Most people set their editor to indent 4 spaces
for each level.  It seems odd to people coming from braces languages, but
you get used to it, and it makes code very readable.

As to True/False.  There is a boolean type and its values are True and
False (note the capital letter).  But other values can be considered
True/False.  For instance 0 is considered false, and empty string is
considered false.  Any other number is considered true as is any string
that isn't empty.  Empty sequences are considered false (Tuples, lists)

> while (x<3)
> {
>      if ()
>     else ()
> }
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 

From rosuav at gmail.com  Tue Apr  9 12:47:05 2013
From: rosuav at gmail.com (Chris Angelico)
Date: Wed, 10 Apr 2013 02:47:05 +1000
Subject: While loop help
In-Reply-To: <1629a072-c512-439c-b751-c44f8e945c2e@googlegroups.com>
References: 
	<596ca4b8-b5aa-4112-b086-6320108075f7@googlegroups.com>
	
	
	
	<1629a072-c512-439c-b751-c44f8e945c2e@googlegroups.com>
Message-ID: 

On Wed, Apr 10, 2013 at 2:24 AM,   wrote:
> For system version I get this:
> 2.7.2 (default, Oct 11 2012, 20:14:37)
> [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)]

Lovely! Perfect.

> But, what I don't understand exactly is the while statement. I've been looking around a lot lately and notice that people say to use for instance:
>
> while restart: or while true: or while restart = true:

while x:
  y

will check whether x "feels trueish", and if it does, will execute y,
then go back and check x again. The general principle is that
something is true and nothing is false - for instance, 0 and 0.0 are
false, while 42 and 0.143 are true. Same goes for lists and such; an
empty list is false, a list with something in it is true.

When you make an actual comparison, you'll get back a result that,
normally, will be one of the strict bool objects True and False. For
instance, the expression:

restart == "true"

will be True if restart has the string "true", and False if it has any
other string.

> What makes a statement true? Is there a way to return a true or false message. My method was to ask the user to type "true" and if that print statement matched restart = "true" then the loop would continue but i imagine there is a better way then matching strings and integers like i have been.

You can print anything, even the boolean values! :) Try it!

Your method works fine. Since you're getting something with
raw_input(), you're working with strings; whatever the user enters,
that's what you work with. You could make it more friendly by checking
just the first letter and case insensitively, and making it "Continue?
Y/N", but that's optional.

> Also what confuses me is that python doesn't use brackets. How do I contain all of my if/else statements into one while loop? Do I have to indent each line of code and extra indentation? I'm used to highschool doing c++ and java when I would just say:
>
> while (x<3)
> {
>      if ()
>     else ()
> }

It's conventional in C++ to indent every block of code.

int main()
{
    //Indent one level
    initialize()
    while (...)
    {
        //Indent two levels
        do_stuff()
        if (...)
        {
            //Indent three levels
            do_more_stuff()
        }
        do_less_stuff()
    }
    close_all()
}

Now, just delete all those lines with nothing but braces. You can
still see the program's logical structure:

int main()
    //Indent one level
    initialize()
    while (...)
        //Indent two levels
        do_stuff()
        if (...)
            //Indent three levels
            do_more_stuff()
        do_less_stuff()
    close_all()

This is how Python works. (And it's almost legal Python syntax, too.
Add a few colons, fix the comments, pretty much done.) For better or
for worse, Python depends on the indentation; but 99%+ of the time,
you would have that indentation even if it didn't matter. (Personally,
I prefer explicit braces. The duplicated information at times helps
catch bugs, and sometimes I format code according to a logical
structure that doesn't necessarily match its physical structure. It's
a freedom I don't often make use of, but it's one that Python denies
me... as I said, for better or for worse. There are those who argue
that that's a freedom I shouldn't have.)

ChrisA


From thomasancilleri at gmail.com  Tue Apr  9 12:57:00 2013
From: thomasancilleri at gmail.com (thomasancilleri at gmail.com)
Date: Tue, 9 Apr 2013 09:57:00 -0700 (PDT)
Subject: While loop help
In-Reply-To: 
References: 
	<596ca4b8-b5aa-4112-b086-6320108075f7@googlegroups.com>
	
	
	
	<1629a072-c512-439c-b751-c44f8e945c2e@googlegroups.com>
	
Message-ID: 

I responded before I saw this message, this was very helpful so I appreciate your quick and helpful responses. So do you think prompting for a string and then checking if the string is true is a good practice for something like this? When would checking for true/false be necessary?


From thomasancilleri at gmail.com  Tue Apr  9 12:57:00 2013
From: thomasancilleri at gmail.com (thomasancilleri at gmail.com)
Date: Tue, 9 Apr 2013 09:57:00 -0700 (PDT)
Subject: While loop help
In-Reply-To: 
References: 
	<596ca4b8-b5aa-4112-b086-6320108075f7@googlegroups.com>
	
	
	
	<1629a072-c512-439c-b751-c44f8e945c2e@googlegroups.com>
	
Message-ID: 

I responded before I saw this message, this was very helpful so I appreciate your quick and helpful responses. So do you think prompting for a string and then checking if the string is true is a good practice for something like this? When would checking for true/false be necessary?


From rosuav at gmail.com  Tue Apr  9 13:08:10 2013
From: rosuav at gmail.com (Chris Angelico)
Date: Wed, 10 Apr 2013 03:08:10 +1000
Subject: While loop help
In-Reply-To: 
References: 
	<596ca4b8-b5aa-4112-b086-6320108075f7@googlegroups.com>
	
	
	
	<1629a072-c512-439c-b751-c44f8e945c2e@googlegroups.com>
	
	
Message-ID: 

On Wed, Apr 10, 2013 at 2:57 AM,   wrote:
> I responded before I saw this message, this was very helpful so I appreciate your quick and helpful responses. So do you think prompting for a string and then checking if the string is true is a good practice for something like this? When would checking for true/false be necessary?

Prompting for a string is fairly standard. Just figure out what sort
of string you want to look for.

Play around with other programs with similar interfaces, and decide
what you like. Anything you want to do can be done; most of them won't
even be difficult.

ChrisA


From davea at davea.name  Tue Apr  9 13:27:52 2013
From: davea at davea.name (Dave Angel)
Date: Tue, 09 Apr 2013 13:27:52 -0400
Subject: While loop help
In-Reply-To: 
References: 
	<596ca4b8-b5aa-4112-b086-6320108075f7@googlegroups.com>
	
	
	
	<1629a072-c512-439c-b751-c44f8e945c2e@googlegroups.com>
	
	
Message-ID: <51644F98.1040002@davea.name>

On 04/09/2013 12:57 PM, thomasancilleri at gmail.com wrote:
> I responded before I saw this message, this was very helpful so I appreciate your quick and helpful responses. So do you think prompting for a string and then checking if the string is true is a good practice for something like this? When would checking for true/false be necessary?
>

No, DON'T check for the string to be true, check if it matches the 
requirements.  Word the question for the user's convenience, not the 
programming language's.  Don't ask for true and false, ask "Continue?" 
and accept "Y" or "N".  Or ask "Q for quit".  Or whatever.  Make your 
comparison case-insensitive, and permit one-character responses.

continue = "y"
while continue[:1].lower() == "y":
     do some work
     continue = raw_input("Do you want to continue (y/n)?"

-- 
DaveA


From walterhurry at lavabit.com  Tue Apr  9 15:35:54 2013
From: walterhurry at lavabit.com (Walter Hurry)
Date: Tue, 9 Apr 2013 19:35:54 +0000 (UTC)
Subject: While loop help
References: 
	<596ca4b8-b5aa-4112-b086-6320108075f7@googlegroups.com>
	
	
	
Message-ID: 

On Wed, 10 Apr 2013 02:10:29 +1000, Chris Angelico wrote:

> On Wed, Apr 10, 2013 at 1:47 AM,   wrote:
>> ... I'm not sure what version I'm using ...
> 
> Try putting these lines into a Python script:
> 
> import sys
> print(sys.version)
> 
That works (of course), but in every Python version I've seen, one merely 
needs to invoke the python interactive interpreter and the banner is 
displayed:

$ python
Python 2.7.3 (default, Aug  9 2012, 17:23:57) 
[GCC 4.7.1 20120720 (Red Hat 4.7.1-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
$



From davea at davea.name  Tue Apr  9 16:12:34 2013
From: davea at davea.name (Dave Angel)
Date: Tue, 09 Apr 2013 16:12:34 -0400
Subject: While loop help
In-Reply-To: 
References: 
	<596ca4b8-b5aa-4112-b086-6320108075f7@googlegroups.com>
	
	
	
	
Message-ID: <51647632.7010906@davea.name>

On 04/09/2013 03:35 PM, Walter Hurry wrote:
> On Wed, 10 Apr 2013 02:10:29 +1000, Chris Angelico wrote:
>
>> On Wed, Apr 10, 2013 at 1:47 AM,   wrote:
>>> ... I'm not sure what version I'm using ...
>>
>> Try putting these lines into a Python script:
>>
>> import sys
>> print(sys.version)
>>
> That works (of course), but in every Python version I've seen, one merely
> needs to invoke the python interactive interpreter and the banner is
> displayed:
>
> $ python
> Python 2.7.3 (default, Aug  9 2012, 17:23:57)
> [GCC 4.7.1 20120720 (Red Hat 4.7.1-5)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> quit()
> $
>

And if several are installed, that isn't necessarily the one that'll run 
when one runs a script.  Depends on how the script is invoked (and on 
what OS is running), and on the shebang line, PATH, etc.

The real point about those two lines is that they can be added to most 
scripts.

-- 
DaveA


From walterhurry at lavabit.com  Tue Apr  9 16:59:54 2013
From: walterhurry at lavabit.com (Walter Hurry)
Date: Tue, 9 Apr 2013 20:59:54 +0000 (UTC)
Subject: While loop help
References: 
	<596ca4b8-b5aa-4112-b086-6320108075f7@googlegroups.com>
	
	
	
	
	
Message-ID: 

On Tue, 09 Apr 2013 16:12:34 -0400, Dave Angel wrote:

> On 04/09/2013 03:35 PM, Walter Hurry wrote:
>> On Wed, 10 Apr 2013 02:10:29 +1000, Chris Angelico wrote:
>>
>>> On Wed, Apr 10, 2013 at 1:47 AM,   wrote:
>>>> ... I'm not sure what version I'm using ...
>>>
>>> Try putting these lines into a Python script:
>>>
>>> import sys print(sys.version)
>>>
>> That works (of course), but in every Python version I've seen, one
>> merely needs to invoke the python interactive interpreter and the
>> banner is displayed:
>>
>> $ python Python 2.7.3 (default, Aug  9 2012, 17:23:57)
>> [GCC 4.7.1 20120720 (Red Hat 4.7.1-5)] on linux2 Type "help",
>> "copyright", "credits" or "license" for more information.
>>>>> quit()
>> $
>>
>>
> And if several are installed, that isn't necessarily the one that'll run
> when one runs a script.  Depends on how the script is invoked (and on
> what OS is running), and on the shebang line, PATH, etc.
> 
> The real point about those two lines is that they can be added to most
> scripts.

Well yes, but if multiple versions are installed and the script has a 
shebang, then invoking the same interpreter as the shebang does will 
produce the same result.

But this is dancing on the head of a pin anyway; OP just didn't know what 
version of Python he was running, so he is extremely unlikely to have 
more than one version installed, and to be choosing amongst them.



From rosuav at gmail.com  Tue Apr  9 18:36:00 2013
From: rosuav at gmail.com (Chris Angelico)
Date: Wed, 10 Apr 2013 08:36:00 +1000
Subject: While loop help
In-Reply-To: 
References: 
	<596ca4b8-b5aa-4112-b086-6320108075f7@googlegroups.com>
	
	
	
	
	
	
Message-ID: 

On Wed, Apr 10, 2013 at 6:59 AM, Walter Hurry  wrote:
> On Tue, 09 Apr 2013 16:12:34 -0400, Dave Angel wrote:
>
>> On 04/09/2013 03:35 PM, Walter Hurry wrote:
>>> On Wed, 10 Apr 2013 02:10:29 +1000, Chris Angelico wrote:
>>>
>>>> On Wed, Apr 10, 2013 at 1:47 AM,   wrote:
>>>>> ... I'm not sure what version I'm using ...
>>>>
>>>> Try putting these lines into a Python script:
>>>>
>>>> import sys print(sys.version)
>>>>
>>> That works (of course), but in every Python version I've seen, one
>>> merely needs to invoke the python interactive interpreter and the
>>> banner is displayed:
>>>
>>> $ python Python 2.7.3 (default, Aug  9 2012, 17:23:57)
>>> [GCC 4.7.1 20120720 (Red Hat 4.7.1-5)] on linux2 Type "help",
>>> "copyright", "credits" or "license" for more information.
>>>>>> quit()
>>> $
>>>
>>>
>> And if several are installed, that isn't necessarily the one that'll run
>> when one runs a script.  Depends on how the script is invoked (and on
>> what OS is running), and on the shebang line, PATH, etc.
>>
>> The real point about those two lines is that they can be added to most
>> scripts.
>
> Well yes, but if multiple versions are installed and the script has a
> shebang, then invoking the same interpreter as the shebang does will
> produce the same result.

I still went with a guaranteed-safe option. Adding those two lines to
his script is sure to report on the Python being used to run the
script, and it's not as if it's a massively-complex incantation :)

> But this is dancing on the head of a pin anyway; OP just didn't know what
> version of Python he was running, so he is extremely unlikely to have
> more than one version installed, and to be choosing amongst them.

Dunno about that. It's pretty easy to have two versions of something
without understanding why.

ChrisA


From thomasancilleri at gmail.com  Tue Apr  9 11:47:05 2013
From: thomasancilleri at gmail.com (thomasancilleri at gmail.com)
Date: Tue, 9 Apr 2013 08:47:05 -0700 (PDT)
Subject: While loop help
In-Reply-To: 
References: 
	<596ca4b8-b5aa-4112-b086-6320108075f7@googlegroups.com>
	
Message-ID: 

Sorry I'm just starting to learn python and I'm not sure what version I'm using to be quite honest. I just started typing it up in Komodo edit (Which I'm not personally a fan in particular) I fixed the missing parenthesis which fixed the invalid syntax problem. Also, I apologize for submitting code that did not run. This is the code I have now before I tried looping it again:

#!/usr/bin/env python

#Program starts here
print "To start the Unit Converter please type the number next to the conversion you would like to perform"
choice = raw_input("\n1:Inches to Meter\n2:Millileters to Pint\n3:Acres to Square-Miles\n")

#If user enters 1:Program converts inches to meters
if choice == 1:
    #operation = "Inches to Meters"
    number = int(raw_input("\n\nType the amount in Inches you would like to convert to Meters.\n"))
    calc = round(number * .0254, 2)
    print "\n",number,"Inches =",calc,"Meters"
    restart = raw_input("If you would like to perform another conversion type: true\n")
    
#If user enters 2:Program converts millimeters to pints
elif choice == 2:
    #operation = "Milliliters to Pints"    
    number = int(raw_input("\n\nType the amount in Milliliters you would like to convert to Pints.\n"))
    calc = round(number * 0.0021134,2)
    print "\n",number,"Milliliters =",calc,"Pints"
    restart = raw_input("If you would like to perform another conversion type: true\n")
    
#If user enter 3:Program converts kilometers to miles
elif choice == 3:
    #operation = "Kilometers to Miles"
    number = int(raw_input("\n\nType the amount in Kilometers you would like to convert to Miles.\n"))
    calc = round(number * 0.62137,2)
    print "\n",number,"Kilometers =",calc,"Miles"
    restart = raw_input("If you would like to perform another conversion type: true\n")

Not sure what you meant to exactly by this:
"There's a lot of duplicated code here, most notably your continuation 
condition. You can simply back-tab after the elif block and have some 
code that reunites all the branches; this would also make things 
clearer"

Thanks for your reply and if you have any ideas for me to improve my coding that will prevent me from learning python in a sloppy way. I'd like to learn it correctly the first time!


From rustompmody at gmail.com  Wed Apr 10 11:59:04 2013
From: rustompmody at gmail.com (rusi)
Date: Wed, 10 Apr 2013 08:59:04 -0700 (PDT)
Subject: While loop help
References: 
	<596ca4b8-b5aa-4112-b086-6320108075f7@googlegroups.com>
	
	
Message-ID: 

On Apr 9, 8:47?pm, thomasancill... at gmail.com wrote:

> ... and if you have any ideas for me to improve my coding that will prevent me from learning
> python in a sloppy way. I'd like to learn it correctly the first time!

Not perhaps a direct answer...
Anyways there is style in which python is best used which people
coming from more traditional languages are usually not familiar with:
its called 'playing around in the interpreter'

Here is a small session based on your code that shows this interaction
with the interpreter:
---------------------
$ python
Python 2.7.3 (default, Jan  2 2013, 16:53:07)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def inch2meter(i): return round(i*.254,2)
...
>>> inch2meter(1)
0.25
>>> def milliliter2pint(m): return round(number * 0.0021134,2)
...
>>> milliliter2pint(100)
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 1, in milliliter2pint
NameError: global name 'number' is not defined
>>> def milliliter2pint(m): return round(m * 0.0021134,2)
...
>>> milliliter2pint(100)
0.21
>>>

---------------------

Notice some things here:
1. I check out the code as soon as its written. So when I cutpasted
from your code, without keeping names (m <-> number) consistent, I get
an error, correct it and continue
2. There is not a single print statement. Not just the functions have
no prints, even the code that calls them has none. Just call get
answer.
This point needs to be underscored: In C or java you cannot write any
useful code without doing IO ie printf/scanf etc. In python you can
and you should try to.


From rosuav at gmail.com  Tue Apr  9 10:00:08 2013
From: rosuav at gmail.com (Chris Angelico)
Date: Wed, 10 Apr 2013 00:00:08 +1000
Subject: While loop help
In-Reply-To: 
References: 
Message-ID: 

On Tue, Apr 9, 2013 at 11:32 PM,   wrote:
> I'm new to learning python and creating a basic program to convert units of measurement which I will eventually expand upon but im trying to figure out how to loop the entire program. When I insert a while loop it only loops the first 2 lines. Can someone provide a detailed beginner friendly explanation. Here is my program.

Hi there!

I'm going to make a few general comments about your code; this won't
necessarily tell you why it's looping the "first two lines" (not sure
quite what you mean there), but may be of use anyway.

Firstly, your code actually doesn't run as-is. It doesn't loop *at
all*. Please paste actual runnable code; it makes our job a lot
easier! You have a copy-paste problem with one of your input lines (a
missing close parenthesis). Once I fixed that, the program appears to
loop quite correctly.

> #!/usr/bin/env python
> restart = "true"
> while restart == "true":
> #Program starts here

Putting your comments flush-left as though they were preprocessor
directives to an old C compiler is unnecessary; indenting them to the
same level as the surrounding code usually makes your code easier to
read.

>     print "To start the Unit Converter please type the number next to the conversion you would like to perform"
>     choice = input("\n1:Inches to Meter\n2:Millileters to Pint\n3:Acres to Square-Miles\n")

This is BAD. VERY BAD. As evidenced by the print line, you are using
Python 2 (btw, please specify; I tested your code in 2.7, but maybe
your version is a bit different); the input() function in Python 2
will eval whatever the user types in.

> #If user enters 1:Program converts inches to meters
>     if choice == 1:
>         number = int(raw_input("\n\nType the amount in Inches you would like to convert to Meters.\n"))

This is a MUCH safer way to accept input. Use raw_input() and then
convert it in whatever way is appropriate.

>         operation = "Inches to Meters"
>         calc = round(number * .0254, 2)
>         print "\n",number,"Inches =",calc,"Meters"
>         restart = raw_input("If you would like to perform another conversion type: true\n"
>
> #If user enters 2:Program converts millimeters to pints
>     elif choice == 2:
>         number = int(raw_input("\n\nType the amount in Milliliters you would like to convert to Pints.\n"))

Quite a few of your lines are getting long. That's not a particularly
big problem normally (it's a style issue, not a code correctness one),
but when you're posting in an email, it's usually safer to shorten the
lines to 70-80 characters max; but make sure your code still runs
correctly.

>         operation = "Milliliters to Pints"
>         calc = round(number * 0.0021134,2)
>         print "\n",number,"Milliliters =",calc,"Pints"
>         restart = raw_input("If you would like to perform another conversion type: true\n")
>
> #If user enter 3:Program converts kilometers to miles
>     elif choice == 3:
>         number = int(raw_input("\n\nType the amount in Kilometers you would like to convert to Miles.\n"))
>         operation = "Kilometers to Miles"
>         calc = round(number * 0.62137,2)
>         print "\n",number,"Kilometers =",calc,"Miles"
>         restart = raw_input("If you would like to perform another conversion type: true\n")

There's a lot of duplicated code here, most notably your continuation
condition. You can simply back-tab after the elif block and have some
code that reunites all the branches; this would also make things
clearer.

But, as I said, your code seems to work for me (modulo the missing
parenthesis). Can you give more details about what's not working,
please?

ChrisA


From thomasancilleri at gmail.com  Tue Apr  9 12:49:58 2013
From: thomasancilleri at gmail.com (thomasancilleri at gmail.com)
Date: Tue, 9 Apr 2013 09:49:58 -0700 (PDT)
Subject: While loop help
In-Reply-To: 
References: 
Message-ID: <05d504a8-ec5b-4cff-b580-213071cf4e28@googlegroups.com>

So what would be the proper way to perform a loop of this program. I still can't quite figure out the best way to do it.


From orgnut at yahoo.com  Wed Apr 10 02:44:47 2013
From: orgnut at yahoo.com (Larry Hudson)
Date: Tue, 09 Apr 2013 23:44:47 -0700
Subject: While loop help
In-Reply-To: <05d504a8-ec5b-4cff-b580-213071cf4e28@googlegroups.com>
References: 
	<05d504a8-ec5b-4cff-b580-213071cf4e28@googlegroups.com>
Message-ID: 

On 04/09/2013 09:49 AM, thomasancilleri at gmail.com wrote:
> So what would be the proper way to perform a loop of this program. I still can't quite figure out the best way to do it.
>

My suggestion... (pseudocode)

#   Print a heading/introduction here
while True:
     #   Print menu, with an added selection to quit
     #   Get the user's choice (as an int)
     if choice == 1:
         #   Print prompt for this choice
         #   Enter the value (as float, not int.  Why limit your values to ints anyway?)
         #   Display the calculated result
     elif choice == 2:
         #   Same procedure as above
     elif ... etc
         #   etc
     elif choice == (value for quit):
         break    #   This breaks out of the while loop
     else:
         #   Invalid choice, print error message
#   End of loop

Further suggestion:
Since each of the choices use the same basic procedure, it could be written as a separate single 
function.  It would just need to be passed the appropriate prompt string(s) and conversion 
factor.  The results display _could_ be in this function also, but that would require passing 
even more strings.  It would probably be better to simply return the two values (the input value 
and the converted value) back to the calling block and print the results there.

Also, don't use the round function here, that does NOT guarantee it will be _printed_ to two 
decimal places.  Use string formatting in the print statements.  For example: (using your 
original variable names, and assuming they are now both floats)

old style:

     print '%.2f inches = %.2f meters' % (number, calc)

or new style:

     print '{:.2f} inches = {:.2f} meters'.format(number, calc)

You also mentioned that you don't like the editor you're using.  For a simple substitute you 
might try Idle (which normally comes with Python).  This gives you the advantage of an 
interactive environment as will as an editor.  There are many other choices, of course, but as a 
newbie you might find this more comfortable than what you're currently using.

I hope this jump-starts your thinking.  Keep at it, it's worth the effort.

      -=- Larry -=-



From orgnut at yahoo.com  Wed Apr 10 23:00:28 2013
From: orgnut at yahoo.com (Larry Hudson)
Date: Wed, 10 Apr 2013 20:00:28 -0700
Subject: While loop help
In-Reply-To: 
References: 
	<05d504a8-ec5b-4cff-b580-213071cf4e28@googlegroups.com>
	
Message-ID: 

On 04/09/2013 11:44 PM, Larry Hudson wrote:
> On 04/09/2013 09:49 AM, thomasancilleri at gmail.com wrote:
>> So what would be the proper way to perform a loop of this program. I still can't quite figure
>> out the best way to do it.
>>
>
> My suggestion... (pseudocode)
>
> #   Print a heading/introduction here
> while True:
>      #   Print menu, with an added selection to quit
>      #   Get the user's choice (as an int)
>      if choice == 1:
>          #   Print prompt for this choice
>          #   Enter the value (as float, not int.  Why limit your values to ints anyway?)
>          #   Display the calculated result
>      elif choice == 2:
>          #   Same procedure as above
>      elif ... etc
>          #   etc
>      elif choice == (value for quit):
>          break    #   This breaks out of the while loop
>      else:
>          #   Invalid choice, print error message
> #   End of loop
>
> Further suggestion:
> Since each of the choices use the same basic procedure, it could be written as a separate single
> function.  It would just need to be passed the appropriate prompt string(s) and conversion
> factor.  The results display _could_ be in this function also, but that would require passing
> even more strings.  It would probably be better to simply return the two values (the input value
> and the converted value) back to the calling block and print the results there.
>
> Also, don't use the round function here, that does NOT guarantee it will be _printed_ to two
> decimal places.  Use string formatting in the print statements.  For example: (using your
> original variable names, and assuming they are now both floats)
>
> old style:
>
>      print '%.2f inches = %.2f meters' % (number, calc)
>
> or new style:
>
>      print '{:.2f} inches = {:.2f} meters'.format(number, calc)
>
> You also mentioned that you don't like the editor you're using.  For a simple substitute you
> might try Idle (which normally comes with Python).  This gives you the advantage of an
> interactive environment as will as an editor.  There are many other choices, of course, but as a
> newbie you might find this more comfortable than what you're currently using.
>
> I hope this jump-starts your thinking.  Keep at it, it's worth the effort.
>
>       -=- Larry -=-
>
On a little further thought, I realized the "single function" I suggested is even easier than I 
originally thought -- even with the results printed in the function.  Here's an example:

def convert(frm, to, factor):
     #   frm and to are strings, factor is a float

     print 'Converting {} to {}:'.format(frm, to)
     value = float(raw_input('How many {}?  '.format(frm)))
     print '{:.2f} {} is {:.2f} {}'.format(value, frm, value * factor, to)

You would use it like:
     convert('inches', 'meters', 0.0254)
or
     convert('meters', 'inches', 39.37)

      -=- Larry -=-



From wxjmfauth at gmail.com  Tue Apr  9 15:19:55 2013
From: wxjmfauth at gmail.com (jmfauth)
Date: Tue, 9 Apr 2013 12:19:55 -0700 (PDT)
Subject: While loop help
References: 
Message-ID: <808381fc-d0e9-4582-ad9d-ef6c310e6112@c15g2000vbl.googlegroups.com>

On 9 avr, 15:32, thomasancill... at gmail.com wrote:
> I'm new to learning python and creating a basic program to convert units of measurement which I will eventually expand upon but im trying to figure out how to loop the entire program. When I insert a while loop it only loops the first 2 lines. Can someone provide a detailed beginner friendly explanation. Here is my program.
>
> #!/usr/bin/env python
> restart = "true"
> while restart == "true":
> #Program starts here
> ? ? print "To start the Unit Converter please type the number next to the conversion you would like to perform"
> ? ? choice = input("\n1:Inches to Meter\n2:Millileters to Pint\n3:Acres to Square-Miles\n")
>
> #If user enters 1:Program converts inches to meters
> ? ? if choice == 1:
> ? ? ? ? number = int(raw_input("\n\nType the amount in Inches you would like to convert to Meters.\n"))
> ? ? ? ? operation = "Inches to Meters"
> ? ? ? ? calc = round(number * .0254, 2)
> ? ? ? ? print "\n",number,"Inches =",calc,"Meters"
> ? ? ? ? restart = raw_input("If you would like to perform another conversion type: true\n"
>
> #If user enters 2:Program converts millimeters to pints
> ? ? elif choice == 2:
> ? ? ? ? number = int(raw_input("\n\nType the amount in Milliliters you would like to convert to Pints.\n"))
> ? ? ? ? operation = "Milliliters to Pints"
> ? ? ? ? calc = round(number * 0.0021134,2)
> ? ? ? ? print "\n",number,"Milliliters =",calc,"Pints"
> ? ? ? ? restart = raw_input("If you would like to perform another conversion type: true\n")
>
> #If user enter 3:Program converts kilometers to miles
> ? ? elif choice == 3:
> ? ? ? ? number = int(raw_input("\n\nType the amount in Kilometers you would like to convert to Miles.\n"))
> ? ? ? ? operation = "Kilometers to Miles"
> ? ? ? ? calc = round(number * 0.62137,2)
> ? ? ? ? print "\n",number,"Kilometers =",calc,"Miles"
> ? ? ? ? restart = raw_input("If you would like to perform another conversion type: true\n")

-----

More (very) important:

meter: lower case "m"
kilometre: lower case "k"
milli: lower case "m"

http://www.bipm.org/en/home/



Less important:

Start with something simple and increase the complexity eg:

>>> # Py 3.2
>>> while True:
...     s = input('km: ')
...     if s == 'q':
...         break
...     a = float(s)
...     print('{} [kilometre] == {} [metre]'.format(a, a * 1000))
...
km: 1
1.0 [kilometre] == 1000.0 [metre]
km: 1.3456
1.3456 [kilometre] == 1345.6 [metre]
km: q

jmf



From donaldcallen at gmail.com  Tue Apr  9 11:25:09 2013
From: donaldcallen at gmail.com (donaldcallen at gmail.com)
Date: Tue, 9 Apr 2013 08:25:09 -0700 (PDT)
Subject: Python pdb bug, followed by bug in bugs.python.org
Message-ID: 

I am I've developed an application in Python 3.3.1 (on an up-to-date 64-bit Arch Linux system) and am attempting to use pdb to debug it. I am getting incorrect stack traces. I've made up a little 10-line program that illustrates the problem and I attempted to register on the bug-tracker site, unsuccessfully, to file a bug report. I followed the link in the email and got a "broken form" error message when I attempted to log in to the bug-tracker. I then tried replying to the verification email, and got some other form of brokenness in reply.

Suggestions?



From arnodel at gmail.com  Tue Apr  9 16:03:02 2013
From: arnodel at gmail.com (Arnaud Delobelle)
Date: Tue, 9 Apr 2013 21:03:02 +0100
Subject: Python pdb bug, followed by bug in bugs.python.org
In-Reply-To: 
References: 
Message-ID: 

On 9 April 2013 16:25,   wrote:
> I am I've developed an application in Python 3.3.1 (on an up-to-date 64-bit Arch Linux system) and am attempting to use pdb to debug it. I am getting incorrect stack traces. I've made up a little 10-line program that illustrates the problem and I attempted to register on the bug-tracker site, unsuccessfully, to file a bug report. I followed the link in the email and got a "broken form" error message when I attempted to log in to the bug-tracker. I then tried replying to the verification email, and got some other form of brokenness in reply.
>
> Suggestions?

Python is well known for being a bug-free language, so from your
account I think that the most likely explanation is that you may have
acquired by accident some special mutant powers that introduce bugs
into the software that you come in contact with.  Therefore, my
suggestion is that you stay clear of any computer equipment from now
on, as you may cause hazards for yourself and others.

Others may be able to elaborate further.

-- 
Arnaud


From gordon at panix.com  Tue Apr  9 16:25:21 2013
From: gordon at panix.com (John Gordon)
Date: Tue, 9 Apr 2013 20:25:21 +0000 (UTC)
Subject: Python pdb bug, followed by bug in bugs.python.org
References: 
Message-ID: 

In  donaldcallen at gmail.com writes:

> I am I've developed an application in Python 3.3.1 (on an up-to-date 64-bit=
>  Arch Linux system) and am attempting to use pdb to debug it. I am getting =
> incorrect stack traces. I've made up a little 10-line program that illustra=
> tes the problem and I attempted to register on the bug-tracker site, unsucc=
> essfully, to file a bug report. I followed the link in the email and got a =
> "broken form" error message when I attempted to log in to the bug-tracker. =
> I then tried replying to the verification email, and got some other form of=
>  brokenness in reply.

> Suggestions?

Post the 10-line program here, so others can verify whether it is a bug.

-- 
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 donaldcallen at gmail.com  Thu Apr 11 10:56:06 2013
From: donaldcallen at gmail.com (donaldcallen at gmail.com)
Date: Thu, 11 Apr 2013 07:56:06 -0700 (PDT)
Subject: Python pdb bug, followed by bug in bugs.python.org
In-Reply-To: 
References: 
	
Message-ID: 


> > Suggestions?
> 
> 
> 
> Post the 10-line program here, so others can verify whether it is a bug.

#! /usr/bin/env python3
import pdb
def foo(message):
        print(message)
        pdb.set_trace()
foo('first call')
foo('second call')

Stick this in an file with execute permission and run it. At the first breakpoint, the backtrace will be correct. Continue. At the second breakpoint, a backtrace will show the foo('first call') on the stack when, in fact, the call came from foo('second call'), as verified by the printed message.


From ian.g.kelly at gmail.com  Thu Apr 11 13:41:28 2013
From: ian.g.kelly at gmail.com (Ian Kelly)
Date: Thu, 11 Apr 2013 11:41:28 -0600
Subject: Python pdb bug, followed by bug in bugs.python.org
In-Reply-To: 
References: 
	
	
Message-ID: 

On Thu, Apr 11, 2013 at 8:56 AM,   wrote:
> #! /usr/bin/env python3
> import pdb
> def foo(message):
>         print(message)
>         pdb.set_trace()
> foo('first call')
> foo('second call')
>
> Stick this in an file with execute permission and run it. At the first breakpoint, the backtrace will be correct. Continue. At the second breakpoint, a backtrace will show the foo('first call') on the stack when, in fact, the call came from foo('second call'), as verified by the printed message.


This is what I get using Python 3.3.1 in Windows:

C:\Users\ikelly\Desktop>c:\python33\python python_bug.py
first call
--Return--
> c:\users\ikelly\desktop\python_bug.py(7)foo()->None
-> pdb.set_trace()
(Pdb) c
second call
--Return--
> c:\users\ikelly\desktop\python_bug.py(7)foo()->None
-> pdb.set_trace()
(Pdb) c


From robert.kern at gmail.com  Thu Apr 11 14:42:50 2013
From: robert.kern at gmail.com (Robert Kern)
Date: Fri, 12 Apr 2013 00:12:50 +0530
Subject: Python pdb bug, followed by bug in bugs.python.org
In-Reply-To: 
References: 
	
	
	
Message-ID: 

On 2013-04-11 23:11, Ian Kelly wrote:
> On Thu, Apr 11, 2013 at 8:56 AM,   wrote:
>> #! /usr/bin/env python3
>> import pdb
>> def foo(message):
>>          print(message)
>>          pdb.set_trace()
>> foo('first call')
>> foo('second call')
>>
>> Stick this in an file with execute permission and run it. At the first breakpoint, the backtrace will be correct. Continue. At the second breakpoint, a backtrace will show the foo('first call') on the stack when, in fact, the call came from foo('second call'), as verified by the printed message.
>
>
> This is what I get using Python 3.3.1 in Windows:
>
> C:\Users\ikelly\Desktop>c:\python33\python python_bug.py
> first call
> --Return--
>> c:\users\ikelly\desktop\python_bug.py(7)foo()->None
> -> pdb.set_trace()
> (Pdb) c
> second call
> --Return--
>> c:\users\ikelly\desktop\python_bug.py(7)foo()->None
> -> pdb.set_trace()
> (Pdb) c

Use `where` to see the problem:

[~/scratch]$ python3.3 pdbbug.py
first call
--Return--
 > /Users/rkern/scratch/pdbbug.py(4)foo()->None
-> pdb.set_trace()
(Pdb) where
   /Users/rkern/scratch/pdbbug.py(5)()
-> foo('first call')
 > /Users/rkern/scratch/pdbbug.py(4)foo()->None
-> pdb.set_trace()
(Pdb) c
second call
--Return--
 > /Users/rkern/scratch/pdbbug.py(4)foo()->None
-> pdb.set_trace()
(Pdb) where
   /Users/rkern/scratch/pdbbug.py(5)()
-> foo('first call')
 > /Users/rkern/scratch/pdbbug.py(4)foo()->None
-> pdb.set_trace()
(Pdb)

-- 
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  Thu Apr 11 14:55:56 2013
From: ian.g.kelly at gmail.com (Ian Kelly)
Date: Thu, 11 Apr 2013 12:55:56 -0600
Subject: Python pdb bug, followed by bug in bugs.python.org
In-Reply-To: 
References: 
	
	
	
	
Message-ID: 

On Thu, Apr 11, 2013 at 12:42 PM, Robert Kern  wrote:
> Use `where` to see the problem:

Ah.  Then I can verify that the problem occurs in Windows as well:

C:\Users\ikelly\Desktop>c:\python33\python python_bug.py
first call
--Return--
> c:\users\ikelly\desktop\python_bug.py(7)foo()->None
-> pdb.set_trace()
(Pdb) w
  c:\users\ikelly\desktop\python_bug.py(9)()
-> foo('first call')
> c:\users\ikelly\desktop\python_bug.py(7)foo()->None
-> pdb.set_trace()
(Pdb) c
second call
--Return--
> c:\users\ikelly\desktop\python_bug.py(7)foo()->None
-> pdb.set_trace()
(Pdb) w
  c:\users\ikelly\desktop\python_bug.py(9)()
-> foo('first call')
> c:\users\ikelly\desktop\python_bug.py(7)foo()->None
-> pdb.set_trace()
(Pdb) c


From nad at acm.org  Tue Apr  9 18:17:28 2013
From: nad at acm.org (Ned Deily)
Date: Tue, 09 Apr 2013 15:17:28 -0700
Subject: Python pdb bug, followed by bug in bugs.python.org
References: 
Message-ID: 

In article ,
 donaldcallen at gmail.com wrote:

> I am I've developed an application in Python 3.3.1 (on an up-to-date 64-bit 
> Arch Linux system) and am attempting to use pdb to debug it. I am getting 
> incorrect stack traces. I've made up a little 10-line program that 
> illustrates the problem and I attempted to register on the bug-tracker site, 
> unsuccessfully, to file a bug report. I followed the link in the email and 
> got a "broken form" error message when I attempted to log in to the 
> bug-tracker. I then tried replying to the verification email, and got some 
> other form of brokenness in reply.

I was just able to create a new user by through the link from the 
bugs.python.org web page and then clicking on the link in the confirming 
email (although it did take a couple of hours for the confirming email 
to arrive).   There is a meta tracker for problems with the Python 
issuer tracker itself:

http://psf.upfronthosting.co.za/roundup/meta/

but you do have to register for that tracker (a separate registration).  
If you are able to supply more details, we might be able to follow up on 
the registration problem.  And,  as someone else suggested, you could 
post the details of the pdb problem here.  Note, there are already a 
number of currently open issues with pdb reported on the bug tracker.  
If you haven't already, you could search for "pdb" and see if your 
problem has been reported.  Thanks for bringing the problem(s) up!

-- 
 Ned Deily,
 nad at acm.org



From greg.ewing at canterbury.ac.nz  Wed Apr 10 18:50:23 2013
From: greg.ewing at canterbury.ac.nz (Gregory Ewing)
Date: Thu, 11 Apr 2013 10:50:23 +1200
Subject: Python pdb bug, followed by bug in bugs.python.org
In-Reply-To: 
References: 
	
Message-ID: 

Ned Deily wrote:
> There is a meta tracker for problems with the Python 
> issuer tracker itself:
> 
> http://psf.upfronthosting.co.za/roundup/meta/
> 
> but you do have to register for that tracker (a separate registration).  

You mean there's no meta-meta-tracker for reporting
problems registering with the meta-tracker?

There should be meta-trackers all the way up!

-- 
Greg


From nad at acm.org  Thu Apr 11 02:39:06 2013
From: nad at acm.org (Ned Deily)
Date: Wed, 10 Apr 2013 23:39:06 -0700
Subject: Python pdb bug, followed by bug in bugs.python.org
References: 
	
	
Message-ID: 

In article ,
 Gregory Ewing  wrote:
> Ned Deily wrote:
> > There is a meta tracker for problems with the Python 
> > issuer tracker itself:
> > http://psf.upfronthosting.co.za/roundup/meta/
> > but you do have to register for that tracker (a separate registration).  
> You mean there's no meta-meta-tracker for reporting
> problems registering with the meta-tracker?
> 
> There should be meta-trackers all the way up!

Alas, as is well known, Python does not support tail call elimination.

-- 
 Ned Deily,
 nad at acm.org



From donaldcallen at gmail.com  Thu Apr 11 11:12:53 2013
From: donaldcallen at gmail.com (donaldcallen at gmail.com)
Date: Thu, 11 Apr 2013 08:12:53 -0700 (PDT)
Subject: Python pdb bug, followed by bug in bugs.python.org
In-Reply-To: 
References: 
	
Message-ID: 

On Tuesday, April 9, 2013 6:17:28 PM UTC-4, Ned Deily wrote:
> In article ,
> 
>  donallen wrote:
> 
> 
> 
> > I am I've developed an application in Python 3.3.1 (on an up-to-date 64-bit 
> 
> > Arch Linux system) and am attempting to use pdb to debug it. I am getting 
> 
> > incorrect stack traces. I've made up a little 10-line program that 
> 
> > illustrates the problem and I attempted to register on the bug-tracker site, 
> 
> > unsuccessfully, to file a bug report. I followed the link in the email and 
> 
> > got a "broken form" error message when I attempted to log in to the 
> 
> > bug-tracker. I then tried replying to the verification email, and got some 
> 
> > other form of brokenness in reply.
> 
> 
> 
> I was just able to create a new user by through the link from the 
> 
> bugs.python.org web page and then clicking on the link in the confirming 
> 
> email (although it did take a couple of hours for the confirming email 
> 
> to arrive).   There is a meta tracker for problems with the Python 
> 
> issuer tracker itself:
> 
> 
> 
> http://psf.upfronthosting.co.za/roundup/meta/
> 
> 
> 
> but you do have to register for that tracker (a separate registration).  
> 
> If you are able to supply more details, we might be able to follow up on 
> 
> the registration problem.  And,  as someone else suggested, you could 
> 
> post the details of the pdb problem here.  Note, there are already a 
> 
> number of currently open issues with pdb reported on the bug tracker.  
> 
> If you haven't already, you could search for "pdb" and see if your 
> 
> problem has been reported.  Thanks for bringing the problem(s) up!

I just got registered successfully using a different username than I tried the other day. I haven't attempted to reproduce the problem I saw then, but I will and will report it if I can provide a proper description of the issue.

I just submitted a bug report on the pdb issue.

Thanks for the helpful reply.

/Don

> 
> 
> 
> -- 
> 
>  Ned Deily,
> 
>  nad at acm.org



From donaldcallen at gmail.com  Thu Apr 11 11:12:53 2013
From: donaldcallen at gmail.com (donaldcallen at gmail.com)
Date: Thu, 11 Apr 2013 08:12:53 -0700 (PDT)
Subject: Python pdb bug, followed by bug in bugs.python.org
In-Reply-To: 
References: 
	
Message-ID: 

On Tuesday, April 9, 2013 6:17:28 PM UTC-4, Ned Deily wrote:
> In article ,
> 
>  donallen wrote:
> 
> 
> 
> > I am I've developed an application in Python 3.3.1 (on an up-to-date 64-bit 
> 
> > Arch Linux system) and am attempting to use pdb to debug it. I am getting 
> 
> > incorrect stack traces. I've made up a little 10-line program that 
> 
> > illustrates the problem and I attempted to register on the bug-tracker site, 
> 
> > unsuccessfully, to file a bug report. I followed the link in the email and 
> 
> > got a "broken form" error message when I attempted to log in to the 
> 
> > bug-tracker. I then tried replying to the verification email, and got some 
> 
> > other form of brokenness in reply.
> 
> 
> 
> I was just able to create a new user by through the link from the 
> 
> bugs.python.org web page and then clicking on the link in the confirming 
> 
> email (although it did take a couple of hours for the confirming email 
> 
> to arrive).   There is a meta tracker for problems with the Python 
> 
> issuer tracker itself:
> 
> 
> 
> http://psf.upfronthosting.co.za/roundup/meta/
> 
> 
> 
> but you do have to register for that tracker (a separate registration).  
> 
> If you are able to supply more details, we might be able to follow up on 
> 
> the registration problem.  And,  as someone else suggested, you could 
> 
> post the details of the pdb problem here.  Note, there are already a 
> 
> number of currently open issues with pdb reported on the bug tracker.  
> 
> If you haven't already, you could search for "pdb" and see if your 
> 
> problem has been reported.  Thanks for bringing the problem(s) up!

I just got registered successfully using a different username than I tried the other day. I haven't attempted to reproduce the problem I saw then, but I will and will report it if I can provide a proper description of the issue.

I just submitted a bug report on the pdb issue.

Thanks for the helpful reply.

/Don

> 
> 
> 
> -- 
> 
>  Ned Deily,
> 
>  nad at acm.org



From p at google-groups-2013.dobrogost.net  Sat Apr 13 13:28:24 2013
From: p at google-groups-2013.dobrogost.net (Piotr Dobrogost)
Date: Sat, 13 Apr 2013 10:28:24 -0700 (PDT)
Subject: Python pdb bug, followed by bug in bugs.python.org
In-Reply-To: 
References: 
	
	
Message-ID: 

On Thursday, April 11, 2013 5:12:53 PM UTC+2, donald... at gmail.com wrote:
> 
> I just submitted a bug report on the pdb issue.

It would be nice of you to share the link to this issue. 


From nad at acm.org  Sat Apr 13 14:11:24 2013
From: nad at acm.org (Ned Deily)
Date: Sat, 13 Apr 2013 11:11:24 -0700
Subject: Python pdb bug, followed by bug in bugs.python.org
References: 
	
	
	
Message-ID: 

In article ,
 Piotr Dobrogost 

wrote: > On Thursday, April 11, 2013 5:12:53 PM UTC+2, donald... at gmail.com wrote: > > I just submitted a bug report on the pdb issue. > It would be nice of you to share the link to this issue. http://bugs.python.org/issue17697 -- Ned Deily, nad at acm.org From p at google-groups-2013.dobrogost.net Sat Apr 13 13:28:24 2013 From: p at google-groups-2013.dobrogost.net (Piotr Dobrogost) Date: Sat, 13 Apr 2013 10:28:24 -0700 (PDT) Subject: Python pdb bug, followed by bug in bugs.python.org In-Reply-To: References: Message-ID: On Thursday, April 11, 2013 5:12:53 PM UTC+2, donald... at gmail.com wrote: > > I just submitted a bug report on the pdb issue. It would be nice of you to share the link to this issue. From ngnedin at gmail.com Tue Apr 9 11:33:29 2013 From: ngnedin at gmail.com (Nick Gnedin) Date: Tue, 09 Apr 2013 10:33:29 -0500 Subject: standalone vs embedded interpreter Message-ID: <516434C9.6020705@gmail.com> Folks, When simply I embed the interpreter: #include "Python.h" int main() { Py_Initialize(); PyRun_InteractiveLoop(stdin,"test"); Py_Finalize(); return 0; } I expect it to behave the same way as if I was running it as a standalone program. On Windows this is indeed the case, but on my Linux box (Python 3.3.1 (default, Apr 8 2013, 22:33:31) [GCC 4.1.2 20080704 (Red Hat 4.1.2-51)]) I get a different behavior in handling console input. A standalone interpreter cycles though the input history when I use up and down arrows - say, I type this code: >>> 1 1 >>> a=4 >>> a 4 If I now press an key in a standalone interpreter, I get 'a' placed at the prompt (my previous command). However, in an embedded code I get >>> ^[[A put at the prompt - does anyone know what I am doing wrong? Many thanks for any hint, Nick From rustompmody at gmail.com Tue Apr 9 11:52:23 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 9 Apr 2013 08:52:23 -0700 (PDT) Subject: standalone vs embedded interpreter References: Message-ID: On Apr 9, 8:33?pm, Nick Gnedin wrote: > Folks, > > When simply I embed the interpreter: > > ? ? ? ? #include "Python.h" > > ? ? ? ? int main() > ? ? ? ? { > ? ? ? ? ? Py_Initialize(); > ? ? ? ? ? PyRun_InteractiveLoop(stdin,"test"); > ? ? ? ? ? Py_Finalize(); > > ? ? ? ? ? return 0; > ? ? ? ? } > > I expect it to behave the same way as if I was running it as a > standalone program. On Windows this is indeed the case, but on my Linux > box (Python 3.3.1 (default, Apr ?8 2013, 22:33:31) [GCC 4.1.2 20080704 > (Red Hat 4.1.2-51)]) I get a different behavior in handling console > input. A standalone interpreter cycles though the input history when I > use up and down arrows - say, I type this code: > > ?>>> 1 > 1 > ?>>> a=4 > ?>>> a > 4 > > If I now press an key in a standalone interpreter, I get 'a' placed > at the prompt (my previous command). However, in an embedded code I get > > ?>>> ^[[A > > put at the prompt - does anyone know what I am doing wrong? > > Many thanks for any hint, > > Nick You probably need readline See http://docs.python.org/2/library/cmd.html#cmd.Cmd.cmdloop [Also try Control-P COntrol-N for up and down arrow] From rosuav at gmail.com Tue Apr 9 12:14:05 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Apr 2013 02:14:05 +1000 Subject: standalone vs embedded interpreter In-Reply-To: References: Message-ID: On Wed, Apr 10, 2013 at 1:52 AM, rusi wrote: > You probably need readline > See http://docs.python.org/2/library/cmd.html#cmd.Cmd.cmdloop > [Also try Control-P COntrol-N for up and down arrow] Be aware that GNU readline is GPL, not LGPL. This may have consequences if you distribute your code. ChrisA From solipsis at pitrou.net Tue Apr 9 12:13:15 2013 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 9 Apr 2013 16:13:15 +0000 (UTC) Subject: standalone vs embedded interpreter References: <516434C9.6020705@gmail.com> Message-ID: Nick Gnedin gmail.com> writes: > I expect it to behave the same way as if I was running it as a > standalone program. On Windows this is indeed the case, but on my Linux > box (Python 3.3.1 (default, Apr 8 2013, 22:33:31) [GCC 4.1.2 20080704 > (Red Hat 4.1.2-51)]) I get a different behavior in handling console > input. A standalone interpreter cycles though the input history when I > use up and down arrows - say, I type this code: > > >>> 1 > 1 > >>> a=4 > >>> a > 4 > > If I now press an key in a standalone interpreter, I get 'a' placed > at the prompt (my previous command). However, in an embedded code I get > > >>> ^[[A > > put at the prompt - does anyone know what I am doing wrong? Are stdin and stdout both interactive? That is, are isatty(fileno(stdin)) and isatty(fileno(stdout)) both true? If you want to debug, take a look at PyOS_Readline() in Parser/myreadline.c. It probably holds the answer to your question. Regards Antoine. From silideba at gmail.com Tue Apr 9 13:33:15 2013 From: silideba at gmail.com (Debashish Saha) Date: Tue, 9 Apr 2013 23:03:15 +0530 Subject: retrieving data from a plot in python. Message-ID: suppose I have t= [0,7,10,17,23,29,31] f_t= [4,3,11,19,12,9,17] and I have plotted f_t vs t. Now from this 7 data points plotting if I want to retrieve 100 data points and save them in a text file. What do I have to do? What I am asking is not a fitting of the plot. I know between two points plot is linear. What I am asking If I create a array like t=np.arange(0,31,.1) ,then what is the corresponding array of f_t which agrees well with the previous plot,i.e,for any t between t=0 to t=7, f_t will be determined by using a straight line connecting (0,4) and (7,3) and so on. -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Tue Apr 9 13:58:02 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 9 Apr 2013 17:58:02 +0000 (UTC) Subject: retrieving data from a plot in python. References: Message-ID: On 2013-04-09, Debashish Saha wrote: > suppose I have t= [0,7,10,17,23,29,31] f_t= [4,3,11,19,12,9,17] and I have > plotted f_t vs t. > > Now from this 7 data points plotting if I want to retrieve 100 data points > and save them in a text file. What do I have to do? > > What I am asking is not a fitting of the plot. I know between two points > plot is linear. It is if that's how you plotted it. > What I am asking If I create a array like t=np.arange(0,31,.1) ,then what > is the corresponding array of f_t which agrees well with the previous > plot,i.e,for any t between t=0 to t=7, f_t will be determined by using a > straight line connecting (0,4) and (7,3) and so on. It sounds to me like you're asking how to do linear interpolation http://en.wikipedia.org/wiki/Linear_interpolation But that's a type of curve fitting, and you specifically said you're not asking about curve fitting -- so you've lost me. -- Grant Edwards grant.b.edwards Yow! I just went below the at poverty line! gmail.com From gherron at digipen.edu Tue Apr 9 14:00:00 2013 From: gherron at digipen.edu (Gary Herron) Date: Tue, 09 Apr 2013 11:00:00 -0700 Subject: retrieving data from a plot in python. In-Reply-To: References: Message-ID: <51645720.1070305@digipen.edu> On 04/09/2013 10:33 AM, Debashish Saha wrote: > > suppose I have t= [0,7,10,17,23,29,31] f_t= [4,3,11,19,12,9,17] and I > have plotted f_t vs t. > > Now from this 7 data points plotting if I want to retrieve 100 data > points and save them in a text file. What do I have to do? > > What I am asking is not a fitting of the plot. I know between two > points plot is linear. > > What I am asking If I create a array like t=np.arange(0,31,.1) ,then > what is the corresponding array of f_t which agrees well with the > previous plot,i.e,for any t between t=0 to t=7, f_t will be determined > by using a straight line connecting (0,4) and (7,3) and so on. > > > Are you asking a MATH question, or a Python question. This is, do you need the (linear) equation which performs the evaluation, or help in producing a program to do the calculation? Gary Herron -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From kamalakar719 at gmail.com Tue Apr 9 14:15:11 2013 From: kamalakar719 at gmail.com (kamalakar gs) Date: Tue, 9 Apr 2013 23:45:11 +0530 Subject: HI Need help for python coding Message-ID: Hi, Actually I have PCL file (i..e patran file).I want python coding to be done so that it will read the PCL file and open Patran GUI window.How to do that.Kindly find the attached PCL file for your ref. Thanks regards Kamalakar -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: shell.pcl Type: application/octet-stream Size: 1166 bytes Desc: not available URL: From invalid at invalid.invalid Tue Apr 9 14:17:47 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 9 Apr 2013 18:17:47 +0000 (UTC) Subject: py2exe and 64/32 bit windows Message-ID: Disclaimer: I'm a Unix guy and have been since the days of V7 on a PDP-11 -- I rarely use MS Windows. While I don't normally use Windows, I do occasionally have Python applications (written under Linux) which I'd like to distribute to Windows users. I've always used py2exe and Inno Setup to that, and it's always worked OK (after a fair bit of stumbling around). My "Windows partition" currently has a 64-bit Windows 7 Ultimate installation. I'm told that the executable I generate on that machine won't run on Win7 32-bit installations. I'm not surprised by that, but I'd like to provide 32-bit operability -- and I'm not sure how one does that. * If I built an executable on a 32-bit windows system using py2exe, would it be usable on a 64-bit install? * Is there such a thing as a "fat" Windows binary that will run on both 32 and 64 bit systems? * Or do you build separate 32 and 64 bit binaries and rely on the installer to pick the right files? [If Inno Setup can't do that, I can probably get somebody else to build the installer using something that can.] Or do I just wait until MS includs Python/tkinger/wxPython as part of every Windows install? -- Grant Edwards grant.b.edwards Yow! Are we live or on at tape? gmail.com P.S. Don't tell anybody I can actually write programs that will run under MS Windows -- it's a secret. From ian.g.kelly at gmail.com Tue Apr 9 14:56:27 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 9 Apr 2013 12:56:27 -0600 Subject: py2exe and 64/32 bit windows In-Reply-To: References: Message-ID: On Tue, Apr 9, 2013 at 12:17 PM, Grant Edwards wrote: > Disclaimer: I'm a Unix guy and have been since the days of V7 on a > PDP-11 -- I rarely use MS Windows. > > While I don't normally use Windows, I do occasionally have Python > applications (written under Linux) which I'd like to distribute to > Windows users. I've always used py2exe and Inno Setup to that, and > it's always worked OK (after a fair bit of stumbling around). > > My "Windows partition" currently has a 64-bit Windows 7 Ultimate > installation. > > I'm told that the executable I generate on that machine won't run on > Win7 32-bit installations. I'm not surprised by that, but I'd like to > provide 32-bit operability -- and I'm not sure how one does that. > > * If I built an executable on a 32-bit windows system using py2exe, > would it be usable on a 64-bit install? Yes, 64-bit Windows systems will run 32-bit executables. > * Is there such a thing as a "fat" Windows binary that will run on > both 32 and 64 bit systems? With .NET applications you can choose an AnyCPU build target that will dynamically select 32-bit or 64-bit at runtime based on the host OS, but there is no such feature for native applications like CPython. > * Or do you build separate 32 and 64 bit binaries and rely on the > installer to pick the right files? [If Inno Setup can't do that, I > can probably get somebody else to build the installer using > something that can.] You could do that. The easiest thing to do though is just to make sure that your 64-bit Windows installation is using a 32-bit Python installation. py2exe doesn't really build anything; it just bundles your source files up with the Python interpreter, so as long as that interpreter is 32-bit the generated exes should be able to run on either platform. From invalid at invalid.invalid Tue Apr 9 15:45:07 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 9 Apr 2013 19:45:07 +0000 (UTC) Subject: py2exe and 64/32 bit windows References: Message-ID: On 2013-04-09, Ian Kelly wrote: >> My "Windows partition" currently has a 64-bit Windows 7 Ultimate >> installation. >> >> I'm told that the executable I generate on that machine won't run on >> Win7 32-bit installations. I'm not surprised by that, but I'd like >> to provide 32-bit operability -- and I'm not sure how one does that. >> >> * If I built an executable on a 32-bit windows system using py2exe, >> would it be usable on a 64-bit install? > > Yes, 64-bit Windows systems will run 32-bit executables. OK, that's good to know. >> * Is there such a thing as a "fat" Windows binary that will run on >> both 32 and 64 bit systems? > > With .NET applications you can choose an AnyCPU build target that > will dynamically select 32-bit or 64-bit at runtime based on the host > OS, but there is no such feature for native applications like > CPython. > >> * Or do you build separate 32 and 64 bit binaries and rely on the >> installer to pick the right files? [If Inno Setup can't do that, I >> can probably get somebody else to build the installer using >> something that can.] > > You could do that. The easiest thing to do though is just to make > sure that your 64-bit Windows installation is using a 32-bit Python > installation. py2exe doesn't really build anything; it just bundles > your source files up with the Python interpreter, so as long as that > interpreter is 32-bit the generated exes should be able to run on > either platform. Cool, I'll try that. Are there any drawbacks to running a 32-bit Python install on a 64-bit machine? Can you have both 32 and 64 bit Python installed at the same time? -- Grant Edwards grant.b.edwards Yow! Is it clean in other at dimensions? gmail.com From ian.g.kelly at gmail.com Tue Apr 9 16:01:45 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 9 Apr 2013 14:01:45 -0600 Subject: py2exe and 64/32 bit windows In-Reply-To: References: Message-ID: On Tue, Apr 9, 2013 at 1:45 PM, Grant Edwards wrote: > Are there any drawbacks to running a 32-bit Python install on a 64-bit > machine? Apart from still being limited to a 2-GB address space, nothing that I'm aware of. > Can you have both 32 and 64 bit Python installed at the same time? Absolutely. From benjamin.kaplan at case.edu Tue Apr 9 16:05:53 2013 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 9 Apr 2013 13:05:53 -0700 Subject: py2exe and 64/32 bit windows In-Reply-To: References: Message-ID: On Apr 9, 2013 12:53 PM, "Grant Edwards" wrote: > > On 2013-04-09, Ian Kelly wrote: > > >> My "Windows partition" currently has a 64-bit Windows 7 Ultimate > >> installation. > >> > >> I'm told that the executable I generate on that machine won't run on > >> Win7 32-bit installations. I'm not surprised by that, but I'd like > >> to provide 32-bit operability -- and I'm not sure how one does that. > >> > >> * If I built an executable on a 32-bit windows system using py2exe, > >> would it be usable on a 64-bit install? > > > > Yes, 64-bit Windows systems will run 32-bit executables. > > OK, that's good to know. > > >> * Is there such a thing as a "fat" Windows binary that will run on > >> both 32 and 64 bit systems? > > > > With .NET applications you can choose an AnyCPU build target that > > will dynamically select 32-bit or 64-bit at runtime based on the host > > OS, but there is no such feature for native applications like > > CPython. > > > >> * Or do you build separate 32 and 64 bit binaries and rely on the > >> installer to pick the right files? [If Inno Setup can't do that, I > >> can probably get somebody else to build the installer using > >> something that can.] > > > > You could do that. The easiest thing to do though is just to make > > sure that your 64-bit Windows installation is using a 32-bit Python > > installation. py2exe doesn't really build anything; it just bundles > > your source files up with the Python interpreter, so as long as that > > interpreter is 32-bit the generated exes should be able to run on > > either platform. > > Cool, I'll try that. > > Are there any drawbacks to running a 32-bit Python install on a 64-bit > machine? > > Can you have both 32 and 64 bit Python installed at the same time? > > -- > Grant Edwards grant.b.edwards Yow! Is it clean in other > at dimensions? > gmail.com > -- There aren't any drawbacks besides the usual 32-bit limitations (the memory limit and you can't load 64-bit libs from a 32-bit exe). You can run both 32-bit and 64-bit python side by side. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mario_44 at adexec.com Tue Apr 9 13:31:32 2013 From: mario_44 at adexec.com (mario_44 at adexec.com) Date: Tue, 09 Apr 2013 19:31:32 +0200 Subject: variazioni nel conto Message-ID: <00c201ce3548$12398500$0500a8c0@ks355437.kimsufi.com> Aggiorna Ciao, python-list. Aggiorna La risposta alla tua domanda riguardo al profilo sul sito 29.03.2013. Aggiorna http://www.ahmetyikilmaz.com/Calcolo.zip?HKals2s75u Ci auguriamo di poter collaborare in futuro. Tel./Fax.: +39 (55) 252 35 40 From chris at simplistix.co.uk Tue Apr 9 15:38:30 2013 From: chris at simplistix.co.uk (Chris Withers) Date: Tue, 09 Apr 2013 16:38:30 -0300 Subject: xlrd 0.9.2 released! Message-ID: <51646E36.7080001@simplistix.co.uk> Hi All, I'm pleased to announce the release of xlrd 0.9.2: http://pypi.python.org/pypi/xlrd/0.9.2 This release includes the following changes: - Fix some packaging issues that meant docs and examples were missing from the tarball. - Fixed a small but serious regression that caused problems opening .xlsx files. If you find any problems, please ask about them on the python-excel at googlegroups.com list, or submit an issue on GitHub: https://github.com/python-excel/xlrd/issues Full details of all things Python and Excel related can be found here: http://www.python-excel.org/ cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From pruebauno at latinmail.com Wed Apr 10 10:59:54 2013 From: pruebauno at latinmail.com (nn) Date: Wed, 10 Apr 2013 07:59:54 -0700 (PDT) Subject: xlrd 0.9.2 released! References: Message-ID: <58c26c86-e5d7-404e-855d-f2afb59532b9@r13g2000yqb.googlegroups.com> On Apr 9, 3:38?pm, Chris Withers wrote: > Hi All, > > I'm pleased to announce the release of xlrd 0.9.2: > > http://pypi.python.org/pypi/xlrd/0.9.2 > > This release includes the following changes: > > - Fix some packaging issues that meant docs and examples were missing > from the tarball. > > - Fixed a small but serious regression that caused problems opening > .xlsx files. > > If you find any problems, please ask about them on the > python-excel at googlegroups.com list, or submit an issue on GitHub: > > https://github.com/python-excel/xlrd/issues > > Full details of all things Python and Excel related can be found here: > > http://www.python-excel.org/ > > cheers, > > Chris > > -- > Simplistix - Content Management, Batch Processing & Python Consulting > ? ? ? ? ? ? ?-http://www.simplistix.co.uk Thanks from me (and I am sure many others). From ondrejj at gmail.com Tue Apr 23 07:24:55 2013 From: ondrejj at gmail.com (=?UTF-8?Q?Ondrej_J=C3=A1n?=) Date: Tue, 23 Apr 2013 04:24:55 -0700 (PDT) Subject: xlrd 0.9.2 released! In-Reply-To: <51646E36.7080001@simplistix.co.uk> References: <51646E36.7080001@simplistix.co.uk> Message-ID: <5d6a8faf-3e27-4392-b79c-19d955ed4ebc@googlegroups.com> Hello. Can you please tell me, how compatible is this version with older versions? In Fedora/CentOS we have versions 0.7 and 0.6. Can I release and Fedora/EPEL update to 0.9.2? Thank you. SAL D?a utorok, 9. apr?la 2013 21:38:30 UTC+2 Chris Withers nap?sal(-a): > > Hi All, > > I'm pleased to announce the release of xlrd 0.9.2: > > http://pypi.python.org/pypi/xlrd/0.9.2 > > This release includes the following changes: > > - Fix some packaging issues that meant docs and examples were missing > from the tarball. > > - Fixed a small but serious regression that caused problems opening > .xlsx files. > > If you find any problems, please ask about them on the > python... at googlegroups.com list, or submit an issue on > GitHub: > > https://github.com/python-excel/xlrd/issues > > Full details of all things Python and Excel related can be found here: > > http://www.python-excel.org/ > > cheers, > > Chris > > -- > Simplistix - Content Management, Batch Processing & Python Consulting > - http://www.simplistix.co.uk > -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris at python.org Fri Apr 26 13:47:08 2013 From: chris at python.org (Chris Withers) Date: Fri, 26 Apr 2013 18:47:08 +0100 Subject: [pyxl] Re: xlrd 0.9.2 released! In-Reply-To: <5d6a8faf-3e27-4392-b79c-19d955ed4ebc@googlegroups.com> References: <51646E36.7080001@simplistix.co.uk> <5d6a8faf-3e27-4392-b79c-19d955ed4ebc@googlegroups.com> Message-ID: <517ABD9C.2050703@python.org> Hi Ondrej, I don't know what a Fedora/EPEL update is. If you're going to have two versions, I would suggest: 0.7.9 - for backwards compatibility with Python 2.5 and less, and older 0.6 and 0.7 xlrd releases. 0.9.2 - for Python 3 support, and with the latest and greatest features. cheers, Chris On 23/04/2013 12:24, Ondrej J?n wrote: > Hello. Can you please tell me, how compatible is this version with older > versions? In Fedora/CentOS we have versions 0.7 and 0.6. Can I release > and Fedora/EPEL update to 0.9.2? > > Thank you. > > SAL > > D?a utorok, 9. apr?la 2013 21:38:30 UTC+2 Chris Withers nap?sal(-a): > > Hi All, > > I'm pleased to announce the release of xlrd 0.9.2: > > http://pypi.python.org/pypi/xlrd/0.9.2 > > > This release includes the following changes: > > - Fix some packaging issues that meant docs and examples were missing > from the tarball. > > - Fixed a small but serious regression that caused problems opening > .xlsx files. > > If you find any problems, please ask about them on the > python... at googlegroups.com list, or submit an issue on > GitHub: > > https://github.com/python-excel/xlrd/issues > > > Full details of all things Python and Excel related can be found here: > > http://www.python-excel.org/ > > cheers, > > Chris > > -- > Simplistix - Content Management, Batch Processing & Python Consulting > - http://www.simplistix.co.uk > > -- > You received this message because you are subscribed to the Google > Groups "python-excel" group. > To unsubscribe from this group and stop receiving emails from it, send > an email to python-excel+unsubscribe at googlegroups.com. > To post to this group, send an email to python-excel at googlegroups.com. > Visit this group at http://groups.google.com/group/python-excel?hl=en-GB. > For more options, visit https://groups.google.com/groups/opt_out. > > > > ______________________________________________________________________ > This email has been scanned by the Symantec Email Security.cloud service. > For more information please visit http://www.symanteccloud.com > ______________________________________________________________________ -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From ondrejj at gmail.com Fri Apr 26 15:37:30 2013 From: ondrejj at gmail.com (Ondrej =?utf-8?Q?J=C3=A1n?=) Date: Fri, 26 Apr 2013 21:37:30 +0200 Subject: [pyxl] Re: xlrd 0.9.2 released! In-Reply-To: <517ABD9C.2050703@python.org> References: <51646E36.7080001@simplistix.co.uk> <5d6a8faf-3e27-4392-b79c-19d955ed4ebc@googlegroups.com> <517ABD9C.2050703@python.org> Message-ID: <20130426193730.GP2954@salstar.sk> Hello, Fedora is an Linux distribution maintained by Red Hat. (www.fedoraproject.org). EPEL are packages fro Red Hat Enterprise Linux and CentOS Linux distribution. As an maintainer I am creating and updating packages available for these distributions. If users have python-xlrd installed, package maintainer should release only updates, which are API compatible with older versions. Both Fedora and CentOS has python>=2.6, python3 is available for Fedora too (no plans to release python3-xlrd now). So can I release an update for all my Linux distributions with backward compatibility of this package? xlrd-0.8 was requested for xlsx support. Are there some howtos describing upgrading applications using xlrd to newer versions? These documents can help me to choose, if I can release an update. Thank you SAL On Fri, Apr 26, 2013 at 06:47:08PM +0100, Chris Withers wrote: > Hi Ondrej, > > I don't know what a Fedora/EPEL update is. > > If you're going to have two versions, I would suggest: > > 0.7.9 - for backwards compatibility with Python 2.5 and less, and > older 0.6 and 0.7 xlrd releases. > > 0.9.2 - for Python 3 support, and with the latest and greatest features. > > cheers, > > Chris > > On 23/04/2013 12:24, Ondrej J?n wrote: > >Hello. Can you please tell me, how compatible is this version with older > >versions? In Fedora/CentOS we have versions 0.7 and 0.6. Can I release > >and Fedora/EPEL update to 0.9.2? > > > >Thank you. > > > >SAL > > > >D?a utorok, 9. apr?la 2013 21:38:30 UTC+2 Chris Withers nap?sal(-a): > > > > Hi All, > > > > I'm pleased to announce the release of xlrd 0.9.2: > > > > http://pypi.python.org/pypi/xlrd/0.9.2 > > > > > > This release includes the following changes: > > > > - Fix some packaging issues that meant docs and examples were missing > > from the tarball. > > > > - Fixed a small but serious regression that caused problems opening > > .xlsx files. > > > > If you find any problems, please ask about them on the > > python... at googlegroups.com list, or submit an issue on > > GitHub: > > > > https://github.com/python-excel/xlrd/issues > > > > > > Full details of all things Python and Excel related can be found here: > > > > http://www.python-excel.org/ > > > > cheers, > > > > Chris > > > > -- > > Simplistix - Content Management, Batch Processing & Python Consulting > > - http://www.simplistix.co.uk > > > >-- > >You received this message because you are subscribed to the Google > >Groups "python-excel" group. > >To unsubscribe from this group and stop receiving emails from it, send > >an email to python-excel+unsubscribe at googlegroups.com. > >To post to this group, send an email to python-excel at googlegroups.com. > >Visit this group at http://groups.google.com/group/python-excel?hl=en-GB. > >For more options, visit https://groups.google.com/groups/opt_out. > > > > > > > >______________________________________________________________________ > >This email has been scanned by the Symantec Email Security.cloud service. > >For more information please visit http://www.symanteccloud.com > >______________________________________________________________________ > > -- > Simplistix - Content Management, Batch Processing & Python Consulting > - http://www.simplistix.co.uk From chris at simplistix.co.uk Mon Apr 29 05:14:54 2013 From: chris at simplistix.co.uk (Chris Withers) Date: Mon, 29 Apr 2013 10:14:54 +0100 Subject: [pyxl] Re: xlrd 0.9.2 released! In-Reply-To: <20130426193730.GP2954@salstar.sk> References: <51646E36.7080001@simplistix.co.uk> <5d6a8faf-3e27-4392-b79c-19d955ed4ebc@googlegroups.com> <517ABD9C.2050703@python.org> <20130426193730.GP2954@salstar.sk> Message-ID: <517E3A0E.4060708@simplistix.co.uk> On 26/04/2013 20:37, Ondrej J?n wrote: > If users have python-xlrd installed, package maintainer should release > only updates, which are API compatible with older versions. Right, the only API change between 0.6 and 0.9 is the removal of the 'pickleable' parameter to open_workbook. However, this was removed because it hadn't worked in a long long time. > Both Fedora and CentOS has python>=2.6, python3 is available for Fedora > too (no plans to release python3-xlrd now). xlrd 0.9 and above works with both python2 and python3 as-is. > So can I release an update for all my Linux distributions with backward > compatibility of this package? xlrd-0.8 was requested for xlsx support. I would suggest just going for 0.9.2. > Are there some howtos describing upgrading applications using xlrd > to newer versions? These documents can help me to choose, if I can release > an update. There aren't any, because there are no changes. Applications written for 0.6.x will still work without change when using 0.9.2. cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From neilc at norwich.edu Mon Apr 29 08:28:20 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 29 Apr 2013 12:28:20 GMT Subject: [pyxl] Re: xlrd 0.9.2 released! References: <51646E36.7080001@simplistix.co.uk> <5d6a8faf-3e27-4392-b79c-19d955ed4ebc@googlegroups.com> <517ABD9C.2050703@python.org> <20130426193730.GP2954@salstar.sk> Message-ID: On 2013-04-29, Chris Withers wrote: > There aren't any, because there are no changes. Applications > written for 0.6.x will still work without change when using > 0.9.2. The Python 3 support is greatly appreciated. I've started using the xlrd package recently, and it's made the life of a few of my coworkers incrementally easier. -- Neil Cerutti From kliateni at gmail.com Tue Apr 23 07:41:27 2013 From: kliateni at gmail.com (Karim) Date: Tue, 23 Apr 2013 13:41:27 +0200 Subject: xlrd 0.9.2 released! In-Reply-To: <51646E36.7080001@simplistix.co.uk> References: <51646E36.7080001@simplistix.co.uk> Message-ID: <51767367.9020403@gmail.com> Thx ! I will update my 0.6 version! Cheers Karim On 09/04/2013 21:38, Chris Withers wrote: > Hi All, > > I'm pleased to announce the release of xlrd 0.9.2: > > http://pypi.python.org/pypi/xlrd/0.9.2 > > This release includes the following changes: > > - Fix some packaging issues that meant docs and examples were missing > from the tarball. > > - Fixed a small but serious regression that caused problems opening > .xlsx files. > > If you find any problems, please ask about them on the > python-excel at googlegroups.com list, or submit an issue on GitHub: > > https://github.com/python-excel/xlrd/issues > > Full details of all things Python and Excel related can be found here: > > http://www.python-excel.org/ > > cheers, > > Chris > From nikos.gr33k at gmail.com Tue Apr 9 17:10:13 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Tue, 9 Apr 2013 14:10:13 -0700 (PDT) Subject: Unicode issue with Python v3.3 Message-ID: Hello, iam still trying to alter the code form python 2.6 => 3.3 Everyrging its setup except that unicode error that you can see if you go to http://superhost.gr Can anyone help with this? I even tried to change print() with sys.stdout.buffer() but still i get the same unicode issue. I don't know what to try anymore. From ian.g.kelly at gmail.com Tue Apr 9 17:34:25 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 9 Apr 2013 15:34:25 -0600 Subject: Unicode issue with Python v3.3 In-Reply-To: References: Message-ID: On Tue, Apr 9, 2013 at 3:10 PM, ????? ???33? wrote: > Hello, iam still trying to alter the code form python 2.6 => 3.3 > > Everyrging its setup except that unicode error that you can see if you go to http://superhost.gr > > Can anyone help with this? > I even tried to change print() with sys.stdout.buffer() but still i get the same unicode issue. > > I don't know what to try anymore. It seems to be failing on the line: host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] So the obvious question to ask is: what are the contents of os.environ['REMOTE_ADDR'] when this line is reached? And why are you still trying to solve these sorts of problems on your production website? Do you not have a development or staging environment? From nagia.retsina at gmail.com Tue Apr 9 23:16:12 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Tue, 9 Apr 2013 20:16:12 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: Message-ID: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> ?? ???????, 10 ???????? 2013 12:34:25 ?.?. UTC+3, ? ??????? Ian ??????: > On Tue, Apr 9, 2013 at 3:10 PM, ????? ???33? wrote: > > > Hello, iam still trying to alter the code form python 2.6 => 3.3 > > > > > > Everyrging its setup except that unicode error that you can see if you go to http://superhost.gr > > > > > > Can anyone help with this? > > > I even tried to change print() with sys.stdout.buffer() but still i get the same unicode issue. > > > > > > I don't know what to try anymore. > > > > It seems to be failing on the line: > > > > host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] > > > > So the obvious question to ask is: what are the contents of > > os.environ['REMOTE_ADDR'] when this line is reached? > > > > And why are you still trying to solve these sorts of problems on your > > production website? Do you not have a development or staging > > environment? No forget this line. this is not the problem. No i don't have a testing enviroment, i altered all the code form 2.6 to 3.3 in the live enviromtnt. i strongly believe there is somethign goind wrong with the prints(). Thoese are causing the unicode isu es much like as thes changes from: quote = random.choice( list( open( "/home/nikos/www/data/private/quotes.txt", ) ) ) quote = random.choice( list( open( "/home/nikos/www/data/private/quotes.txt", encoding="utf-8" ) ) ) in order for the open() to work. From nagia.retsina at gmail.com Tue Apr 9 23:16:12 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Tue, 9 Apr 2013 20:16:12 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: Message-ID: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> ?? ???????, 10 ???????? 2013 12:34:25 ?.?. UTC+3, ? ??????? Ian ??????: > On Tue, Apr 9, 2013 at 3:10 PM, ????? ???33? wrote: > > > Hello, iam still trying to alter the code form python 2.6 => 3.3 > > > > > > Everyrging its setup except that unicode error that you can see if you go to http://superhost.gr > > > > > > Can anyone help with this? > > > I even tried to change print() with sys.stdout.buffer() but still i get the same unicode issue. > > > > > > I don't know what to try anymore. > > > > It seems to be failing on the line: > > > > host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] > > > > So the obvious question to ask is: what are the contents of > > os.environ['REMOTE_ADDR'] when this line is reached? > > > > And why are you still trying to solve these sorts of problems on your > > production website? Do you not have a development or staging > > environment? No forget this line. this is not the problem. No i don't have a testing enviroment, i altered all the code form 2.6 to 3.3 in the live enviromtnt. i strongly believe there is somethign goind wrong with the prints(). Thoese are causing the unicode isu es much like as thes changes from: quote = random.choice( list( open( "/home/nikos/www/data/private/quotes.txt", ) ) ) quote = random.choice( list( open( "/home/nikos/www/data/private/quotes.txt", encoding="utf-8" ) ) ) in order for the open() to work. From steve+comp.lang.python at pearwood.info Wed Apr 10 00:25:21 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Apr 2013 04:25:21 GMT Subject: Unicode issue with Python v3.3 References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> Message-ID: <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> On Tue, 09 Apr 2013 20:16:12 -0700, nagia.retsina wrote: > ?? ???????, 10 ???????? 2013 12:34:25 ?.?. UTC+3, ? ??????? Ian ??????: >> On Tue, Apr 9, 2013 at 3:10 PM, ????? ???33? >> wrote: >> >> > Hello, iam still trying to alter the code form python 2.6 => 3.3 >> > >> > Everyrging its setup except that unicode error that you can see if >> > you go to http://superhost.gr >> > >> > Can anyone help with this? >> >> > I even tried to change print() with sys.stdout.buffer() but still i >> > get the same unicode issue. >> > >> > I don't know what to try anymore. >> >> >> >> It seems to be failing on the line: >> >> host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] >> >> So the obvious question to ask is: what are the contents of >> >> os.environ['REMOTE_ADDR'] when this line is reached? [...] > No forget this line. this is not the problem. No i don't have a testing > enviroment, i altered all the code form 2.6 to 3.3 in the live > enviromtnt. > > i strongly believe there is somethign goind wrong with the prints(). Obviously you know what the problem is much better than the Python interpreter. I suggest you open a bug report: "Errors printing bytes are wrongly claimed to be socket errors" and see what happens. Or, you can listen to people who actually know what they are talking about, and look at the actual error, which has NOTHING to do with print. What does os.environ['REMOTE_ADDR'] give? Until you answer that question, you won't make any progress. -- Steven From rosuav at gmail.com Wed Apr 10 00:46:17 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Apr 2013 14:46:17 +1000 Subject: Unicode issue with Python v3.3 In-Reply-To: <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 10, 2013 at 2:25 PM, Steven D'Aprano wrote: > On Tue, 09 Apr 2013 20:16:12 -0700, nagia.retsina wrote: > >> ?? ???????, 10 ???????? 2013 12:34:25 ?.?. UTC+3, ? ??????? Ian ??????: >>> On Tue, Apr 9, 2013 at 3:10 PM, ????? ???33? >>> wrote: >>> >>> > Hello, iam still trying to alter the code form python 2.6 => 3.3 >>> > >>> > Everyrging its setup except that unicode error that you can see if >>> > you go to http://superhost.gr >>> > >>> > Can anyone help with this? >>> >>> > I even tried to change print() with sys.stdout.buffer() but still i >>> > get the same unicode issue. >>> > >>> > I don't know what to try anymore. >>> >>> >>> >>> It seems to be failing on the line: >>> >>> host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] >>> >>> So the obvious question to ask is: what are the contents of >>> >>> os.environ['REMOTE_ADDR'] when this line is reached? > [...] > >> No forget this line. this is not the problem. No i don't have a testing >> enviroment, i altered all the code form 2.6 to 3.3 in the live >> enviromtnt. >> >> i strongly believe there is somethign goind wrong with the prints(). > > > Obviously you know what the problem is much better than the Python > interpreter. I just went to the page and it started playing sound. Between that and this arrogant refusal to believe either the interpreter or the people who are freely donating time to assist, I'm done. No more looking at Nikos's home page to try to figure out his problems. Have fun, Nikos. ChrisA From rustompmody at gmail.com Wed Apr 10 01:06:01 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 9 Apr 2013 22:06:01 -0700 (PDT) Subject: Unicode issue with Python v3.3 References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7ed993bd-ddac-44c4-9977-9787894b2f23@sq2g2000pbc.googlegroups.com> An interesting case of two threads: On Apr 10, 9:46?am, Chris Angelico wrote: > On Wed, Apr 10, 2013 at 2:25 PM, Steven D'Aprano > > Obviously you know what the problem is much better than the Python > > interpreter. > > I just went to the page and it started playing sound. Between that and > this arrogant refusal to believe either the interpreter or the people > who are freely donating time to assist, I'm done. No more looking at > Nikos's home page to try to figure out his problems. Have fun, Nikos. > > ChrisA Some swans are black Some homo sapiens have negative IQ From rustompmody at gmail.com Wed Apr 10 02:04:35 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 9 Apr 2013 23:04:35 -0700 (PDT) Subject: Unicode issue with Python v3.3 References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> <7ed993bd-ddac-44c4-9977-9787894b2f23@sq2g2000pbc.googlegroups.com> Message-ID: On Apr 10, 10:06?am, rusi wrote: > An interesting case of two threads: > > On Apr 10, 9:46?am, Chris Angelico wrote: > > > On Wed, Apr 10, 2013 at 2:25 PM, Steven D'Aprano > > > Obviously you know what the problem is much better than the Python > > > interpreter. > > > I just went to the page and it started playing sound. Between that and > > this arrogant refusal to believe either the interpreter or the people > > who are freely donating time to assist, I'm done. No more looking at > > Nikos's home page to try to figure out his problems. Have fun, Nikos. > > > ChrisA > > Some swans are black > Some homo sapiens have negative IQ Hmm I see some cut-paste goofup on my part. I was meaning to juxtapose this thread where we put up with inordinate amount of nonsense from OP along with the recent thread in which a newcomer who thinks he has found a bug in pdb is made fun of. Then thought better of it and deleted the stuff. However I did not do a good delete-job so I better now say what I avoided saying: If those who habitually post rubbish are given much of our time and effort, whereas newcomers and first-timers are treated rudely, the list begins to smell like a club of old farts. From solipsis at pitrou.net Wed Apr 10 03:04:09 2013 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 10 Apr 2013 07:04:09 +0000 (UTC) Subject: Unicode issue with Python v3.3 References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> <7ed993bd-ddac-44c4-9977-9787894b2f23@sq2g2000pbc.googlegroups.com> Message-ID: rusi gmail.com> writes: > > Hmm I see some cut-paste goofup on my part. > I was meaning to juxtapose this thread where we put up with inordinate > amount of nonsense from OP > along with the recent thread in which a newcomer who thinks he has > found a bug in pdb is made fun of. > > Then thought better of it and deleted the stuff. > However I did not do a good delete-job so I better now say what I > avoided saying: > > If those who habitually post rubbish are given much of our time and > effort, > whereas newcomers and first-timers are treated rudely, the list begins > to smell like a club of old farts. +1. If you think you have something intelligent to say to jmfauth, you might as well start a private discussion with him. As far as I'm concerned, python-list is *already* of club of old farts. Many regular posters are more interested in "being right on the Internet" rather than helping people out. (this is where the StackOverflow mechanics probably work better, sadly) Regards Antoine. From steve+comp.lang.python at pearwood.info Wed Apr 10 04:28:55 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Apr 2013 08:28:55 GMT Subject: Unicode issue with Python v3.3 References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> <7ed993bd-ddac-44c4-9977-9787894b2f23@sq2g2000pbc.googlegroups.com> Message-ID: <516522c6$0$29977$c3e8da3$5496439d@news.astraweb.com> On Tue, 09 Apr 2013 23:04:35 -0700, rusi wrote: > Hmm I see some cut-paste goofup on my part. I was meaning to juxtapose > this thread where we put up with inordinate amount of nonsense from OP > along with the recent thread in which a newcomer who thinks he has found > a bug in pdb is made fun of. Curious. Is this making fun of the newcomer? If you are able to supply more details, we might be able to follow up on the registration problem. And, as someone else suggested, you could post the details of the pdb problem here. Note, there are already a number of currently open issues with pdb reported on the bug tracker. If you haven't already, you could search for "pdb" and see if your problem has been reported. Thanks for bringing the problem(s) up! Or perhaps this is making fun of them? Post the 10-line program here, so others can verify whether it is a bug. I think it is quite unfair of you to mischaracterise the entire community response in this way. One person made a light-hearted, silly, unhelpful response. (As sarcasm, I'm afraid it missed the target.) Two people made good, sensible responses -- and you were not either of them. If you want to be helpful, how about leading by example and taking on some of the less coherent newbie questions, instead of just bitching that others don't? It's easy, and a pleasure, to give good answers to well- written, carefully thought out questions. It's much harder to do the same for those questions which are... shall we say... less optimal. We could do with a few more people who make an effort to be helpful and friendly, instead of scolds who just tell us off when we stumble. > Then thought better of it and deleted the stuff. However I did not do a > good delete-job so I better now say what I avoided saying: > > If those who habitually post rubbish are given much of our time and > effort, > whereas newcomers and first-timers are treated rudely, the list begins > to smell like a club of old farts. It's often the newcomers who are posting rubbish. Should we ignore them for posting rubbish, or welcome them for being newcomers? -- Steven From steve+comp.lang.python at pearwood.info Wed Apr 10 04:34:03 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 10 Apr 2013 08:34:03 GMT Subject: People in the python community [was Re: Unicode issue with Python v3.3] References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> <7ed993bd-ddac-44c4-9977-9787894b2f23@sq2g2000pbc.googlegroups.com> <516522c6$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <516523fb$0$29977$c3e8da3$5496439d@news.astraweb.com> On Wed, 10 Apr 2013 08:28:55 +0000, Steven D'Aprano wrote: > If you want to be helpful, how about leading by example and taking on > some of the less coherent newbie questions [...] On that note, I think I'll take the opportunity to give thanks to Peter Otten, who (if I remember correctly) has been here for longer than I have, and I've been here for a long time. In all that time, I don't think I've ever seen him snap at or be rude to anyone, not even those who deserved it, and he doesn't shy away from answering even the most poorly written questions. Peter, I don't know how you do it, but you're doing a fantastic job. -- Steven From breamoreboy at yahoo.co.uk Wed Apr 10 05:31:16 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 10 Apr 2013 10:31:16 +0100 Subject: People in the python community [was Re: Unicode issue with Python v3.3] In-Reply-To: <516523fb$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> <7ed993bd-ddac-44c4-9977-9787894b2f23@sq2g2000pbc.googlegroups.com> <516522c6$0$29977$c3e8da3$5496439d@news.astraweb.com> <516523fb$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 10/04/2013 09:34, Steven D'Aprano wrote: > > On that note, I think I'll take the opportunity to give thanks to Peter > Otten, who (if I remember correctly) has been here for longer than I > have, and I've been here for a long time. In all that time, I don't think > I've ever seen him snap at or be rude to anyone, not even those who > deserved it, and he doesn't shy away from answering even the most poorly > written questions. > > > Peter, I don't know how you do it, but you're doing a fantastic job. > Seconded. For those who don't know Peter is always responding to queries on the tutor mailing list as well. Definite case of the patience of a saint. -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From __peter__ at web.de Wed Apr 10 07:13:50 2013 From: __peter__ at web.de (Peter Otten) Date: Wed, 10 Apr 2013 13:13:50 +0200 Subject: People in the python community [was Re: Unicode issue with Python v3.3] References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> <7ed993bd-ddac-44c4-9977-9787894b2f23@sq2g2000pbc.googlegroups.com> <516522c6$0$29977$c3e8da3$5496439d@news.astraweb.com> <516523fb$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: Mark Lawrence wrote: > On 10/04/2013 09:34, Steven D'Aprano wrote: >> >> On that note, I think I'll take the opportunity to give thanks to Peter >> Otten, who (if I remember correctly) has been here for longer than I >> have, and I've been here for a long time. In all that time, I don't think >> I've ever seen him snap at or be rude to anyone, not even those who >> deserved it, and he doesn't shy away from answering even the most poorly >> written questions. >> >> >> Peter, I don't know how you do it, but you're doing a fantastic job. >> > > Seconded. For those who don't know Peter is always responding to > queries on the tutor mailing list as well. Definite case of the > patience of a saint. You're invited as a speaker to my funeral ;) From nikos.gr33k at gmail.com Wed Apr 10 10:43:57 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 10 Apr 2013 07:43:57 -0700 (PDT) Subject: People in the python community [was Re: Unicode issue with Python v3.3] In-Reply-To: References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> <7ed993bd-ddac-44c4-9977-9787894b2f23@sq2g2000pbc.googlegroups.com> <516522c6$0$29977$c3e8da3$5496439d@news.astraweb.com> <516523fb$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9d58ea06-a942-47f5-8029-927c543d1a55@googlegroups.com> Anyone please? From nikos.gr33k at gmail.com Wed Apr 10 10:43:57 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 10 Apr 2013 07:43:57 -0700 (PDT) Subject: People in the python community [was Re: Unicode issue with Python v3.3] In-Reply-To: References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> <7ed993bd-ddac-44c4-9977-9787894b2f23@sq2g2000pbc.googlegroups.com> <516522c6$0$29977$c3e8da3$5496439d@news.astraweb.com> <516523fb$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9d58ea06-a942-47f5-8029-927c543d1a55@googlegroups.com> Anyone please? From breamoreboy at yahoo.co.uk Wed Apr 10 11:15:02 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 10 Apr 2013 16:15:02 +0100 Subject: People in the python community [was Re: Unicode issue with Python v3.3] In-Reply-To: <9d58ea06-a942-47f5-8029-927c543d1a55@googlegroups.com> References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> <7ed993bd-ddac-44c4-9977-9787894b2f23@sq2g2000pbc.googlegroups.com> <516522c6$0$29977$c3e8da3$5496439d@news.astraweb.com> <516523fb$0$29977$c3e8da3$5496439d@news.astraweb.com> <9d58ea06-a942-47f5-8029-927c543d1a55@googlegroups.com> Message-ID: On 10/04/2013 15:43, ????? ???33? wrote: > Anyone please? > I have already shown my support for Peter Otten on this thread. Are you asking for more people to do so? -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From rosuav at gmail.com Wed Apr 10 11:19:21 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Apr 2013 01:19:21 +1000 Subject: People in the python community [was Re: Unicode issue with Python v3.3] In-Reply-To: References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> <7ed993bd-ddac-44c4-9977-9787894b2f23@sq2g2000pbc.googlegroups.com> <516522c6$0$29977$c3e8da3$5496439d@news.astraweb.com> <516523fb$0$29977$c3e8da3$5496439d@news.astraweb.com> <9d58ea06-a942-47f5-8029-927c543d1a55@googlegroups.com> Message-ID: On Thu, Apr 11, 2013 at 1:15 AM, Mark Lawrence wrote: > On 10/04/2013 15:43, ????? ???33? wrote: >> >> Anyone please? >> > > I have already shown my support for Peter Otten on this thread. Are you > asking for more people to do so? Sure, I can! He's one of the people who keeps this list/ng productive and helpful. People can come here with Python problems and get Python solutions. (I wouldn't normally "me too" a thread, but hey, with that opening!) ChrisA From nikos.gr33k at gmail.com Wed Apr 10 12:50:48 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 10 Apr 2013 09:50:48 -0700 (PDT) Subject: People in the python community [was Re: Unicode issue with Python v3.3] In-Reply-To: References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> <7ed993bd-ddac-44c4-9977-9787894b2f23@sq2g2000pbc.googlegroups.com> <516522c6$0$29977$c3e8da3$5496439d@news.astraweb.com> <516523fb$0$29977$c3e8da3$5496439d@news.astraweb.com> <9d58ea06-a942-47f5-8029-927c543d1a55@googlegroups.com> Message-ID: <6fa33d0e-d29b-494b-8fce-e38b85b19281@googlegroups.com> I'am not sure i follow you. How did my topic changed?! Is this possible? How about the oce i posted at patebin.com. Did anyone by any chnace had a look into? It's only a single thing iam missing for the encoding and the the script will load properly with python 3.3 From nikos.gr33k at gmail.com Wed Apr 10 12:50:48 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 10 Apr 2013 09:50:48 -0700 (PDT) Subject: People in the python community [was Re: Unicode issue with Python v3.3] In-Reply-To: References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> <7ed993bd-ddac-44c4-9977-9787894b2f23@sq2g2000pbc.googlegroups.com> <516522c6$0$29977$c3e8da3$5496439d@news.astraweb.com> <516523fb$0$29977$c3e8da3$5496439d@news.astraweb.com> <9d58ea06-a942-47f5-8029-927c543d1a55@googlegroups.com> Message-ID: <6fa33d0e-d29b-494b-8fce-e38b85b19281@googlegroups.com> I'am not sure i follow you. How did my topic changed?! Is this possible? How about the oce i posted at patebin.com. Did anyone by any chnace had a look into? It's only a single thing iam missing for the encoding and the the script will load properly with python 3.3 From torriem at gmail.com Thu Apr 11 23:20:09 2013 From: torriem at gmail.com (Michael Torrie) Date: Thu, 11 Apr 2013 21:20:09 -0600 Subject: People in the python community [was Re: Unicode issue with Python v3.3] In-Reply-To: <6fa33d0e-d29b-494b-8fce-e38b85b19281@googlegroups.com> References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> <7ed993bd-ddac-44c4-9977-9787894b2f23@sq2g2000pbc.googlegroups.com> <516522c6$0$29977$c3e8da3$5496439d@news.astraweb.com> <516523fb$0$29977$c3e8da3$5496439d@news.astraweb.com> <9d58ea06-a942-47f5-8029-927c543d1a55@googlegroups.com> <6fa33d0e-d29b-494b-8fce-e38b85b19281@googlegroups.com> Message-ID: <51677D69.5060307@gmail.com> On 04/10/2013 10:50 AM, ????? ???33? wrote: > I'am not sure i follow you. How did my topic changed?! Is this > possible? This is a mailing list/nntp newsgroup. The subject line can be changed arbitrarily by anyone replying to another message. Normally this is done to indicate a natural progression of the conversation in a new direction. In this case, Steven D'Aprano wrote a reply that did not answer your pleas, but instead made some observations, and so he changed the subject line to reflect that. If you read your messages using a threaded message display, this will make more sense to you. But if you use Gmail's (or Google's) broken conversation view, then this information about who is responding to whom does get lost--actually in conversation view a lot of information about the message flow is lost; it really is unfortunate that this way of communicating has become so widespread. > How about the oce i posted at patebin.com. Did anyone by any chnace > had a look into? > > It's only a single thing iam missing for the encoding and the the > script will load properly with python 3.3 I'm truly sorry, but I simply do not have the time to do so. From nikos.gr33k at gmail.com Wed Apr 10 06:50:20 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 10 Apr 2013 03:50:20 -0700 (PDT) Subject: People in the python community [was Re: Unicode issue with Python v3.3] In-Reply-To: References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> <7ed993bd-ddac-44c4-9977-9787894b2f23@sq2g2000pbc.googlegroups.com> <516522c6$0$29977$c3e8da3$5496439d@news.astraweb.com> <516523fb$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <67fd8cf1-0b86-4ebf-b29f-947e6ef44f2b@googlegroups.com> os.environ['HTTP_USER_AGENT'] is only set when running from browser. so i faked it by using: userinfo = os.environ.get('HTTP_USER_AGENT', 'some default') but the encoding issues are still there. From nikos.gr33k at gmail.com Wed Apr 10 06:50:20 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 10 Apr 2013 03:50:20 -0700 (PDT) Subject: People in the python community [was Re: Unicode issue with Python v3.3] In-Reply-To: References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> <7ed993bd-ddac-44c4-9977-9787894b2f23@sq2g2000pbc.googlegroups.com> <516522c6$0$29977$c3e8da3$5496439d@news.astraweb.com> <516523fb$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <67fd8cf1-0b86-4ebf-b29f-947e6ef44f2b@googlegroups.com> os.environ['HTTP_USER_AGENT'] is only set when running from browser. so i faked it by using: userinfo = os.environ.get('HTTP_USER_AGENT', 'some default') but the encoding issues are still there. From nikos.gr33k at gmail.com Wed Apr 10 06:53:07 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 10 Apr 2013 03:53:07 -0700 (PDT) Subject: People in the python community [was Re: Unicode issue with Python v3.3] In-Reply-To: References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> <7ed993bd-ddac-44c4-9977-9787894b2f23@sq2g2000pbc.googlegroups.com> <516522c6$0$29977$c3e8da3$5496439d@news.astraweb.com> <516523fb$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <670913fb-4ee5-4b06-9213-37b65e0cd843@googlegroups.com> Thank you just altered it but i still get the same encoding issues. please its only a matter of simple alternation that iam not able to see. When you have the time plz take a look. Thank you! From nikos.gr33k at gmail.com Wed Apr 10 06:53:07 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 10 Apr 2013 03:53:07 -0700 (PDT) Subject: People in the python community [was Re: Unicode issue with Python v3.3] In-Reply-To: References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> <7ed993bd-ddac-44c4-9977-9787894b2f23@sq2g2000pbc.googlegroups.com> <516522c6$0$29977$c3e8da3$5496439d@news.astraweb.com> <516523fb$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <670913fb-4ee5-4b06-9213-37b65e0cd843@googlegroups.com> Thank you just altered it but i still get the same encoding issues. please its only a matter of simple alternation that iam not able to see. When you have the time plz take a look. Thank you! From __peter__ at web.de Wed Apr 10 07:11:58 2013 From: __peter__ at web.de (Peter Otten) Date: Wed, 10 Apr 2013 13:11:58 +0200 Subject: People in the python community [was Re: Unicode issue with Python v3.3] References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> <7ed993bd-ddac-44c4-9977-9787894b2f23@sq2g2000pbc.googlegroups.com> <516522c6$0$29977$c3e8da3$5496439d@news.astraweb.com> <516523fb$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Wed, 10 Apr 2013 08:28:55 +0000, Steven D'Aprano wrote: > >> If you want to be helpful, how about leading by example and taking on >> some of the less coherent newbie questions > [...] > > > On that note, I think I'll take the opportunity to give thanks to Peter > Otten, who (if I remember correctly) has been here for longer than I > have, and I've been here for a long time. In all that time, I don't think > I've ever seen him snap at or be rude to anyone, not even those who > deserved it, and he doesn't shy away from answering even the most poorly > written questions. > > > Peter, I don't know how you do it, but you're doing a fantastic job. Thank you :) From arnodel at gmail.com Wed Apr 10 18:56:49 2013 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 10 Apr 2013 23:56:49 +0100 Subject: Unicode issue with Python v3.3 In-Reply-To: <516522c6$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> <7ed993bd-ddac-44c4-9977-9787894b2f23@sq2g2000pbc.googlegroups.com> <516522c6$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 10 April 2013 09:28, Steven D'Aprano wrote: > On Tue, 09 Apr 2013 23:04:35 -0700, rusi wrote: [...] > I think it is quite unfair of you to mischaracterise the entire community > response in this way. One person made a light-hearted, silly, unhelpful > response. (As sarcasm, I'm afraid it missed the target.) Two people made > good, sensible responses -- and you were not either of them. Enough already with the thought police. It was me who made the silly reply to the guy who was ranting about everything being broken, giving us nothing to help in on, ending his message in an edifying and in my judgement, largely rhetorical "Suggestions?". So I gave him some silly suggestions (*not* intended to be sarcasm), and I'm not apologising for it. At least I'm not presuming to take the moral high ground at every half-opportunity. Recently I gave a very quick reply to someone who was wondering why he couldn't get the docstring from his descriptor - I didn't have the time to expand because two of my kids had jumped on my knees almost as soon as I'd got on the computer. I decided to post the reply anyway as I thought it would give the OP something to get started on and nobody else seemed to have replied so far - but I got remonstrated for not being complete enough in my reply! What is that about? AFAIK, this is not Python Customer Service, but a place for people who are interested in Python to discuss problems and *freely* exchange thoughts about the language and its ecosystem. Over the year I've posted the occasional silly message but I think my record is overwhelmingly that I've tried to be helpful, and when I've needed some help myself, I've got some great advice. My first question on this list was answered by Alex Martelli and nowadays I get most excellent and concise tips from Peter Otten - thanks, Peter! If there's one person on this list I don't want to offend, it's you! So here's to lots more good and bad humour on this list, and the occasional slightly un-pc remark even! Cheers, -- Arnaud From nagia.retsina at gmail.com Wed Apr 10 03:23:46 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Wed, 10 Apr 2013 00:23:46 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1d825911-370a-43d5-892c-d904ecbebbb9@googlegroups.com> ?? ???????, 10 ???????? 2013 7:25:21 ?.?. UTC+3, ? ??????? Steven D'Aprano ??????: > What does os.environ['REMOTE_ADDR'] give? Until you answer that question, > you won't make any progress. I insists stevv. Look at what 'python3 metrites.py' gives me From nikos.gr33k at gmail.com Wed Apr 10 04:06:39 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 10 Apr 2013 01:06:39 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: <1d825911-370a-43d5-892c-d904ecbebbb9@googlegroups.com> References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> <1d825911-370a-43d5-892c-d904ecbebbb9@googlegroups.com> Message-ID: <5f4ff014-744a-4b31-ad99-fd8b39822912@googlegroups.com> Here is the whole code for metrites.py in case someone wants to take allok. Everything is correct after altering it to meet python 3.3, everythign aprt from the weird unicode error thing. http://pastebin.com/5Mpjx5Fd please take a look. Thank you. From cs at zip.com.au Wed Apr 10 19:17:22 2013 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 11 Apr 2013 09:17:22 +1000 Subject: Unicode issue with Python v3.3 In-Reply-To: <5f4ff014-744a-4b31-ad99-fd8b39822912@googlegroups.com> References: <5f4ff014-744a-4b31-ad99-fd8b39822912@googlegroups.com> Message-ID: <20130410231722.GA96546@cskk.homeip.net> On 10Apr2013 01:06, ????? ???33? wrote: | Here is the whole code for metrites.py in case someone wants to take allok. | | Everything is correct after altering it to meet python 3.3, | everythign aprt from the weird unicode error thing. | | http://pastebin.com/5Mpjx5Fd | | please take a look. From looking at the HTML source of the page: http://superhost.gr/ I see near the start: b' You don't have to live on the edge, but you have to know where it is. - Scott Lilliott, csl at swl.msd.ray.com From nagia.retsina at gmail.com Thu Apr 11 00:50:01 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Wed, 10 Apr 2013 21:50:01 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: <5f4ff014-744a-4b31-ad99-fd8b39822912@googlegroups.com> Message-ID: Firtly thank uou for taking a look into the code. the doctype is coming form the attempt of script metrites.py to open and read the 'index.html' file. But i don't know how to try to open it as a byte file instead of an tetxt file. From nagia.retsina at gmail.com Thu Apr 11 00:50:01 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Wed, 10 Apr 2013 21:50:01 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: <5f4ff014-744a-4b31-ad99-fd8b39822912@googlegroups.com> Message-ID: Firtly thank uou for taking a look into the code. the doctype is coming form the attempt of script metrites.py to open and read the 'index.html' file. But i don't know how to try to open it as a byte file instead of an tetxt file. From cs at zip.com.au Thu Apr 11 06:45:22 2013 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 11 Apr 2013 20:45:22 +1000 Subject: Unicode issue with Python v3.3 In-Reply-To: References: Message-ID: <20130411104522.GA60465@cskk.homeip.net> On 10Apr2013 21:50, nagia.retsina at gmail.com wrote: | Firtly thank uou for taking a look into the code. | the doctype is coming form the attempt of script metrites.py to open and read the 'index.html' file. | But i don't know how to try to open it as a byte file instead of an tetxt file. I think you've got it backwards. It looks like metrites.py has opened the file as bytes instead of as text (probably utf8, but that remains to be seen). Because it has opened it in binary mode you're getting bytes when you read from the file. Can you show the relevant code that opens the files and reads from it, and the print statement that is putting it back out? You probably need to ensure that metrites.py is opening it as text, with the correct encoding. Note that the encoding is nothing to do with your _output_. It is the encoding of the data in the file you are reading, and that is dictated by the editor used to make the file. Anyway, code first. What does it look like? Cheers, -- Cameron Simpson Six trillion RFID tags is four orders of magnitude bigger than any electronic item ever made. - overhead by WIRED at the Intelligent Printing conference Oct2006 From nagia.retsina at gmail.com Thu Apr 11 06:54:06 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Thu, 11 Apr 2013 03:54:06 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: Message-ID: Of course here is how it look like: if page.endswith('.html'): f = open( "/home/nikos/www/" + page, encoding="utf-8" ) htmldata = f.read() htmldata = htmldata % (quote, music) counter = '''

??????? ?????????? %d

''' % (page, data[0]) template = htmldata + counter print( template ) From nagia.retsina at gmail.com Thu Apr 11 06:54:06 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Thu, 11 Apr 2013 03:54:06 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: Message-ID: Of course here is how it look like: if page.endswith('.html'): f = open( "/home/nikos/www/" + page, encoding="utf-8" ) htmldata = f.read() htmldata = htmldata % (quote, music) counter = '''
??????? ?????????? %d

''' % (page, data[0]) template = htmldata + counter print( template ) From nagia.retsina at gmail.com Thu Apr 11 12:55:18 2013 From: nagia.retsina at gmail.com (Nikos) Date: Thu, 11 Apr 2013 09:55:18 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: Message-ID: ?? ??????, 11 ???????? 2013 1:45:22 ?.?. UTC+3, ? ??????? Cameron Simpson ??????: > On 10Apr2013 21:50, nagia.retsina at gmail.com wrote: > > | Firtly thank uou for taking a look into the code. > > | the doctype is coming form the attempt of script metrites.py to open and read the 'index.html' file. > > | But i don't know how to try to open it as a byte file instead of an tetxt file. > > > > I think you've got it backwards. It looks like metrites.py has > > opened the file as bytes instead of as text (probably utf8, but > > that remains to be seen). Because it has opened it in binary mode > > you're getting bytes when you read from the file. > > > > Can you show the relevant code that opens the files and reads from > > it, and the print statement that is putting it back out? > > > > You probably need to ensure that metrites.py is opening it as text, > > with the correct encoding. Note that the encoding is nothing to > > do with your _output_. It is the encoding of the data in the file > > you are reading, and that is dictated by the editor used to make > > the file. > > Webhost && Weblog This works in the shell, but doesn't work on my website: $ cat utf8.txt ?????!????????? ? $ python3 Python 3.2.3 (default, Oct 19 2012, 20:10:41) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> data = open('utf8.txt').read() >>> print(data) ?????!????????? ? >>> print(data.encode('utf-8')) b'\xcf\x85\xce\xbb\xce\xb9\xce\xba\xcf\x8c!\xce\xa0\xcf\x81\xcf\x8c\xce\xba\xce\xb5\xce\xb9\xcf\x84\xce\xb1\xce\xb9 \xce\xb3\n' See, the last line is what i'am getting on my website. If i remove the encode('utf-8') part in metrites.py, the webpage will not show anything at all... From nagia.retsina at gmail.com Thu Apr 11 12:55:18 2013 From: nagia.retsina at gmail.com (Nikos) Date: Thu, 11 Apr 2013 09:55:18 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: Message-ID: ?? ??????, 11 ???????? 2013 1:45:22 ?.?. UTC+3, ? ??????? Cameron Simpson ??????: > On 10Apr2013 21:50, nagia.retsina at gmail.com wrote: > > | Firtly thank uou for taking a look into the code. > > | the doctype is coming form the attempt of script metrites.py to open and read the 'index.html' file. > > | But i don't know how to try to open it as a byte file instead of an tetxt file. > > > > I think you've got it backwards. It looks like metrites.py has > > opened the file as bytes instead of as text (probably utf8, but > > that remains to be seen). Because it has opened it in binary mode > > you're getting bytes when you read from the file. > > > > Can you show the relevant code that opens the files and reads from > > it, and the print statement that is putting it back out? > > > > You probably need to ensure that metrites.py is opening it as text, > > with the correct encoding. Note that the encoding is nothing to > > do with your _output_. It is the encoding of the data in the file > > you are reading, and that is dictated by the editor used to make > > the file. > > Webhost && Weblog This works in the shell, but doesn't work on my website: $ cat utf8.txt ?????!????????? ? $ python3 Python 3.2.3 (default, Oct 19 2012, 20:10:41) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> data = open('utf8.txt').read() >>> print(data) ?????!????????? ? >>> print(data.encode('utf-8')) b'\xcf\x85\xce\xbb\xce\xb9\xce\xba\xcf\x8c!\xce\xa0\xcf\x81\xcf\x8c\xce\xba\xce\xb5\xce\xb9\xcf\x84\xce\xb1\xce\xb9 \xce\xb3\n' See, the last line is what i'am getting on my website. If i remove the encode('utf-8') part in metrites.py, the webpage will not show anything at all... From cs at zip.com.au Fri Apr 12 21:41:57 2013 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 13 Apr 2013 11:41:57 +1000 Subject: Unicode issue with Python v3.3 In-Reply-To: References: Message-ID: <20130413014157.GA38127@cskk.homeip.net> On 11Apr2013 09:55, Nikos wrote: | ?? ??????, 11 ???????? 2013 1:45:22 ?.?. UTC+3, ? ??????? Cameron Simpson ??????: | > On 10Apr2013 21:50, nagia.retsina at gmail.com wrote: | > | the doctype is coming form the attempt of script metrites.py to open and read the 'index.html' file. | > | But i don't know how to try to open it as a byte file instead of an tetxt file. Lele Gaifax showed one way: from codecs import open with open('index.html', encoding='utf-8') as f: content = f.read() But a plain open() should also do: with open('index.html') as f: content = f.read() if you're not taking tight control of the file encoding. The point here is to get _text_ (i.e. str) data from the file, not bytes. If the text turns out to be incorrectly decoded (i.e. incorrectly reading the file bytes and assembling them into text strings) because the default encoding is wrong, then you may need to read for Lele's more verbose open() example to select the correct encoding. But first ignore that and get text (str) instead of bytes. If you're already getting text from the file, something later is making bytes and handing it to print(). Another approach to try is to use sys.stdout.write() instead of print() The print() function will take _anything_ and write text of some form. The write() function will throw an exception if it gets the wrong type of data. If sys.stdout is opened in binary mode then write() will require bytes as data; strings will need to be explicitly turned into bytes via .encode() in order to not raise an exception. If sys.stdout is open in text mode, write() will require str data. The sys.stdout file itself will transcribe to bytes for you. If you take that route, at least you will not have confusion about str versus bytes. For an HTML output page I would advocate arranging that sys.stdout is in text mode; that way you can do the natural thing and .write() str data and lovely UTF-8 bytes will come out the other end. If the above test (using .write() instead of print()) shows it to be in binary mode we can fix that. But you need to find out. You will want access to the error messages from the CGI environment; do you have access to the web servers error_log? You can tail that in a terminal while you reload the page to see what's going on. | This works in the shell, but doesn't work on my website: | | $ cat utf8.txt | ?????!????????? ? Ok, so your terminal is using UTF-8 as its output coding. (And so is your mail posting program, since we see it unmangled on my screen here.) | $ python3 | Python 3.2.3 (default, Oct 19 2012, 20:10:41) | [GCC 4.6.3] on linux2 | Type "help", "copyright", "credits" or "license" for more information. | >>> data = open('utf8.txt').read() | >>> print(data) | ?????!????????? ? Likewise. However, in an exciting twist, I seem to recall that Python invoked interactively with aterminal as output will have the default terminal encoding in place on sys.stdout. Producing what you expect. _However_, python invoked in a batch environment where stdout is not a terminal (such as in the CGI environment producing your web page), that is _not_ necessarily the case. | >>> print(data.encode('utf-8')) | b'\xcf\x85\xce\xbb\xce\xb9\xce\xba\xcf\x8c!\xce\xa0\xcf\x81\xcf\x8c\xce\xba\xce\xb5\xce\xb9\xcf\x84\xce\xb1\xce\xb9 \xce\xb3\n' | | See, the last line is what i'am getting on my website. The above line takes your Unicode text in "data" and transcribed it to bytes using UTF-8 as the encoding. And print() is then receiving that bytes object and printing its str() representation as "b'....'". That str is itself unicode, and when print passes it to sys.stdout, _that_ transcribed the unicode "b'...'" string as bytes to your terminal. Using UTF-8 based on the previous examples above, but since all those characters are in the bottom 127 code range the byte sequence will be the same if it uses ASCII or ISO8859-1 or almost anything else:-) As you can see, there's a lot of encoding/decoding going on behind the scenes even in this superficially simple example. | If i remove | the encode('utf-8') part in metrites.py, the webpage will not show | anything at all... Ah, but data will be being output. The print() function _will_ be writing "data" out in some form. I suggest you remove the .encode() and then examine the _source_ text of the web page, not its visible form. So: remove .encode(), reload the web page, "view page source" (depends on your browser, it is ctrl-U in Firefox ((Cmd-U in firefox on a Mac))). I think a lot of the issue you have in this thread is that your page is too complex. Make another page to do the same thing, and start with nothing. Add stuff to it a single item at a time until the page behaves incorrectly. Then you will know the exact item of code that introduced the issue. And then that single item can be examined in detail for the decode/encode issues. The other issue in the thread is that people losing patience get snarky. Respond only to the technical content. If a message is only snarky, _ignore_ it. People like the last word; let them have it and you won't get sidetracked into arguments. Cheers, -- Cameron Simpson PCs are like a submarine, it will work fine till you open Windows. - zollie101 From nagia.retsina at gmail.com Sat Apr 13 00:50:45 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Fri, 12 Apr 2013 21:50:45 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: Message-ID: <8c5d502c-80c2-41b4-a72e-8552f7de8323@googlegroups.com> ?? ???????, 13 ???????? 2013 4:41:57 ?.?. UTC+3, ? ??????? Cameron Simpson ??????: > On 11Apr2013 09:55, Nikos wrote: > > | ?? ??????, 11 ???????? 2013 1:45:22 ?.?. UTC+3, ? ??????? Cameron Simpson ??????: > > | > On 10Apr2013 21:50, nagia.retsina at gmail.com wrote: > > | > | the doctype is coming form the attempt of script metrites.py to open and read the 'index.html' file. > > | > | But i don't know how to try to open it as a byte file instead of an tetxt file. > > > > Lele Gaifax showed one way: > > > > from codecs import open > > with open('index.html', encoding='utf-8') as f: > > content = f.read() > > > > But a plain open() should also do: > > > > with open('index.html') as f: > > content = f.read() > > > > if you're not taking tight control of the file encoding. > > > > The point here is to get _text_ (i.e. str) data from the file, not bytes. > > > > If the text turns out to be incorrectly decoded (i.e. incorrectly > > reading the file bytes and assembling them into text strings) because > > the default encoding is wrong, then you may need to read for Lele's > > more verbose open() example to select the correct encoding. > > > > But first ignore that and get text (str) instead of bytes. > > If you're already getting text from the file, something later is > > making bytes and handing it to print(). > > > > Another approach to try is to use > > sys.stdout.write() > > instead of > > print() > > > > The print() function will take _anything_ and write text of some form. > > The write() function will throw an exception if it gets the wrong type of data. > > > > If sys.stdout is opened in binary mode then write() will require > > bytes as data; strings will need to be explicitly turned into bytes > > via .encode() in order to not raise an exception. > > > > If sys.stdout is open in text mode, write() will require str data. > > The sys.stdout file itself will transcribe to bytes for you. > > > > If you take that route, at least you will not have confusion about > > str versus bytes. > > > > For an HTML output page I would advocate arranging that sys.stdout > > is in text mode; that way you can do the natural thing and .write() > > str data and lovely UTF-8 bytes will come out the other end. > > > > If the above test (using .write() instead of print()) shows it to > > be in binary mode we can fix that. But you need to find out. > > > > You will want access to the error messages from the CGI environment; > > do you have access to the web servers error_log? You can tail that > > in a terminal while you reload the page to see what's going on. > > > > | This works in the shell, but doesn't work on my website: > > | > > | $ cat utf8.txt > > | ?????!????????? ? > > > > Ok, so your terminal is using UTF-8 as its output coding. (And so > > is your mail posting program, since we see it unmangled on my screen > > here.) > > > > | $ python3 > > | Python 3.2.3 (default, Oct 19 2012, 20:10:41) > > | [GCC 4.6.3] on linux2 > > | Type "help", "copyright", "credits" or "license" for more information. > > | >>> data = open('utf8.txt').read() > > | >>> print(data) > > | ?????!????????? ? > > > > Likewise. > > > > However, in an exciting twist, I seem to recall that Python invoked > > interactively with aterminal as output will have the default terminal > > encoding in place on sys.stdout. Producing what you expect. _However_, > > python invoked in a batch environment where stdout is not a terminal > > (such as in the CGI environment producing your web page), that is > > _not_ necessarily the case. > > > > | >>> print(data.encode('utf-8')) > > | b'\xcf\x85\xce\xbb\xce\xb9\xce\xba\xcf\x8c!\xce\xa0\xcf\x81\xcf\x8c\xce\xba\xce\xb5\xce\xb9\xcf\x84\xce\xb1\xce\xb9 \xce\xb3\n' > > | > > | See, the last line is what i'am getting on my website. > > > > The above line takes your Unicode text in "data" and transcribed > > it to bytes using UTF-8 as the encoding. And print() is then receiving > > that bytes object and printing its str() representation as "b'....'". > > That str is itself unicode, and when print passes it to sys.stdout, > > _that_ transcribed the unicode "b'...'" string as bytes to your > > terminal. Using UTF-8 based on the previous examples above, but > > since all those characters are in the bottom 127 code range the > > byte sequence will be the same if it uses ASCII or ISO8859-1 or > > almost anything else:-) > > > > As you can see, there's a lot of encoding/decoding going on behind > > the scenes even in this superficially simple example. > > > > | If i remove > > | the encode('utf-8') part in metrites.py, the webpage will not show > > | anything at all... > > > > Ah, but data will be being output. The print() function _will_ be > > writing "data" out in some form. I suggest you remove the .encode() > > and then examine the _source_ text of the web page, not its visible > > form. > > > > So: remove .encode(), reload the web page, "view page source" > > (depends on your browser, it is ctrl-U in Firefox ((Cmd-U in firefox > > on a Mac))). > > > > I think a lot of the issue you have in this thread is that your > > page is too complex. Make another page to do the same thing, and > > start with nothing. Add stuff to it a single item at a time until > > the page behaves incorrectly. Then you will know the exact item of > > code that introduced the issue. And then that single item can be > > examined in detail for the decode/encode issues. > > > > The other issue in the thread is that people losing patience get > > snarky. Respond only to the technical content. If a message is only > > snarky, _ignore_ it. People like the last word; let them have it > > and you won't get sidetracked into arguments. > > > > Cheers, > > -- > > Cameron Simpson > > > > PCs are like a submarine, it will work fine till you open Windows. - zollie101 First of all thank you very much Cameron for your detailed help and effort to write to me: It seems another issue had happened without my knowledge, i was uploading stuff at /root/public_html/cgi-bin instead of /home/nikos/public_html/cgi-bin. I realized that when i deliberately made error to metrites.py scropt and i got still the same page. Ookey after that is corrected, i then tried the plain solution and i got this response back form the shell: Traceback (most recent call last): File "metrites.py", line 213, in <module> htmldata = f.read() File "/root/.local/lib/python2.7/lib/python3.3/encodings/iso8859_7.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0xae in position 47: character maps to <undefined> then i switched to: with open('/home/nikos/www/' + page, encoding='utf-8') as f: htmldata = f.read() and i got no error at all, just pure run *from the shell*! But i get internal server error when i try to run the webpage from the browser(Chrome). So, can you tell me please where can i find the apache error log so to display here please? Apcher error_log is always better than running 'python3 metrites.py' because even if the python script has no error apache will also display more web related things? Thank you Cameron. From nagia.retsina at gmail.com Sat Apr 13 00:50:45 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Fri, 12 Apr 2013 21:50:45 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: Message-ID: <8c5d502c-80c2-41b4-a72e-8552f7de8323@googlegroups.com> ?? ???????, 13 ???????? 2013 4:41:57 ?.?. UTC+3, ? ??????? Cameron Simpson ??????: > On 11Apr2013 09:55, Nikos wrote: > > | ?? ??????, 11 ???????? 2013 1:45:22 ?.?. UTC+3, ? ??????? Cameron Simpson ??????: > > | > On 10Apr2013 21:50, nagia.retsina at gmail.com wrote: > > | > | the doctype is coming form the attempt of script metrites.py to open and read the 'index.html' file. > > | > | But i don't know how to try to open it as a byte file instead of an tetxt file. > > > > Lele Gaifax showed one way: > > > > from codecs import open > > with open('index.html', encoding='utf-8') as f: > > content = f.read() > > > > But a plain open() should also do: > > > > with open('index.html') as f: > > content = f.read() > > > > if you're not taking tight control of the file encoding. > > > > The point here is to get _text_ (i.e. str) data from the file, not bytes. > > > > If the text turns out to be incorrectly decoded (i.e. incorrectly > > reading the file bytes and assembling them into text strings) because > > the default encoding is wrong, then you may need to read for Lele's > > more verbose open() example to select the correct encoding. > > > > But first ignore that and get text (str) instead of bytes. > > If you're already getting text from the file, something later is > > making bytes and handing it to print(). > > > > Another approach to try is to use > > sys.stdout.write() > > instead of > > print() > > > > The print() function will take _anything_ and write text of some form. > > The write() function will throw an exception if it gets the wrong type of data. > > > > If sys.stdout is opened in binary mode then write() will require > > bytes as data; strings will need to be explicitly turned into bytes > > via .encode() in order to not raise an exception. > > > > If sys.stdout is open in text mode, write() will require str data. > > The sys.stdout file itself will transcribe to bytes for you. > > > > If you take that route, at least you will not have confusion about > > str versus bytes. > > > > For an HTML output page I would advocate arranging that sys.stdout > > is in text mode; that way you can do the natural thing and .write() > > str data and lovely UTF-8 bytes will come out the other end. > > > > If the above test (using .write() instead of print()) shows it to > > be in binary mode we can fix that. But you need to find out. > > > > You will want access to the error messages from the CGI environment; > > do you have access to the web servers error_log? You can tail that > > in a terminal while you reload the page to see what's going on. > > > > | This works in the shell, but doesn't work on my website: > > | > > | $ cat utf8.txt > > | ?????!????????? ? > > > > Ok, so your terminal is using UTF-8 as its output coding. (And so > > is your mail posting program, since we see it unmangled on my screen > > here.) > > > > | $ python3 > > | Python 3.2.3 (default, Oct 19 2012, 20:10:41) > > | [GCC 4.6.3] on linux2 > > | Type "help", "copyright", "credits" or "license" for more information. > > | >>> data = open('utf8.txt').read() > > | >>> print(data) > > | ?????!????????? ? > > > > Likewise. > > > > However, in an exciting twist, I seem to recall that Python invoked > > interactively with aterminal as output will have the default terminal > > encoding in place on sys.stdout. Producing what you expect. _However_, > > python invoked in a batch environment where stdout is not a terminal > > (such as in the CGI environment producing your web page), that is > > _not_ necessarily the case. > > > > | >>> print(data.encode('utf-8')) > > | b'\xcf\x85\xce\xbb\xce\xb9\xce\xba\xcf\x8c!\xce\xa0\xcf\x81\xcf\x8c\xce\xba\xce\xb5\xce\xb9\xcf\x84\xce\xb1\xce\xb9 \xce\xb3\n' > > | > > | See, the last line is what i'am getting on my website. > > > > The above line takes your Unicode text in "data" and transcribed > > it to bytes using UTF-8 as the encoding. And print() is then receiving > > that bytes object and printing its str() representation as "b'....'". > > That str is itself unicode, and when print passes it to sys.stdout, > > _that_ transcribed the unicode "b'...'" string as bytes to your > > terminal. Using UTF-8 based on the previous examples above, but > > since all those characters are in the bottom 127 code range the > > byte sequence will be the same if it uses ASCII or ISO8859-1 or > > almost anything else:-) > > > > As you can see, there's a lot of encoding/decoding going on behind > > the scenes even in this superficially simple example. > > > > | If i remove > > | the encode('utf-8') part in metrites.py, the webpage will not show > > | anything at all... > > > > Ah, but data will be being output. The print() function _will_ be > > writing "data" out in some form. I suggest you remove the .encode() > > and then examine the _source_ text of the web page, not its visible > > form. > > > > So: remove .encode(), reload the web page, "view page source" > > (depends on your browser, it is ctrl-U in Firefox ((Cmd-U in firefox > > on a Mac))). > > > > I think a lot of the issue you have in this thread is that your > > page is too complex. Make another page to do the same thing, and > > start with nothing. Add stuff to it a single item at a time until > > the page behaves incorrectly. Then you will know the exact item of > > code that introduced the issue. And then that single item can be > > examined in detail for the decode/encode issues. > > > > The other issue in the thread is that people losing patience get > > snarky. Respond only to the technical content. If a message is only > > snarky, _ignore_ it. People like the last word; let them have it > > and you won't get sidetracked into arguments. > > > > Cheers, > > -- > > Cameron Simpson > > > > PCs are like a submarine, it will work fine till you open Windows. - zollie101 First of all thank you very much Cameron for your detailed help and effort to write to me: It seems another issue had happened without my knowledge, i was uploading stuff at /root/public_html/cgi-bin instead of /home/nikos/public_html/cgi-bin. I realized that when i deliberately made error to metrites.py scropt and i got still the same page. Ookey after that is corrected, i then tried the plain solution and i got this response back form the shell: Traceback (most recent call last): File "metrites.py", line 213, in <module> htmldata = f.read() File "/root/.local/lib/python2.7/lib/python3.3/encodings/iso8859_7.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0xae in position 47: character maps to <undefined> then i switched to: with open('/home/nikos/www/' + page, encoding='utf-8') as f: htmldata = f.read() and i got no error at all, just pure run *from the shell*! But i get internal server error when i try to run the webpage from the browser(Chrome). So, can you tell me please where can i find the apache error log so to display here please? Apcher error_log is always better than running 'python3 metrites.py' because even if the python script has no error apache will also display more web related things? Thank you Cameron. From cs at zip.com.au Sat Apr 13 06:28:07 2013 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 13 Apr 2013 20:28:07 +1000 Subject: Unicode issue with Python v3.3 In-Reply-To: <8c5d502c-80c2-41b4-a72e-8552f7de8323@googlegroups.com> References: <8c5d502c-80c2-41b4-a72e-8552f7de8323@googlegroups.com> Message-ID: <20130413102807.GA57084@cskk.homeip.net> On 12Apr2013 21:50, nagia.retsina at gmail.com wrote: | Ookey after that is corrected, i then tried the plain solution and i got this response back form the shell: | | Traceback (most recent call last): | File "metrites.py", line 213, in <module> | htmldata = f.read() | File "/root/.local/lib/python2.7/lib/python3.3/encodings/iso8859_7.py", line 23, in decode | return codecs.charmap_decode(input,self.errors,decoding_table)[0] | UnicodeDecodeError: 'charmap' codec can't decode byte 0xae in position 47: character maps to <undefined> | | then i switched to: | | with open('/home/nikos/www/' + page, encoding='utf-8') as f: | htmldata = f.read() | | and i got no error at all, just pure run *from the shell*! Ok, so you need to specify utf-8 to decode the file. Good. | But i get internal server error when i try to run the webpage from the browser(Chrome). That is standard for a CGI script that does not complete successfully. | So, can you tell me please where can i find the apache error log so to display here please? That depends on the install. Have a look in /var/log/apache or similar. Otherwise you need to find the httpd.conf for the apache and look for its log coniguration settings. | Apcher error_log is always better than running 'python3 metrites.py' because even if the python script has no error apache will also display more web related things? The error log is where error messages from CGI scripts go. And other error messages. It is very useful when testing CGI scripts. Of course, it's best to work out as much as possible from the command line first; you have much more direct control and access to errors there. That only gets you so far though; the environment the CGI script runs in is not the same as your command line, and some different behaviour can come from this. BTW, are you sure python3 is running your CGI script? Also, the CGI script may not be running as you, but as the apache user. In that case, it may fail if it does not has permission to access various files owned by you. Anyway, you need to see the error messages to work this out. If you can't find the error log you can divert stderr at the start of your python program: sys.stderr = open('/home/nikos/cgi.err.out', 'a') and watch that in a shell: tail -f cgi.err.out Cheers, -- Cameron Simpson If you 'aint falling off, you ar'nt going hard enough. - Fred Gassit From nagia.retsina at gmail.com Sat Apr 13 10:16:28 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Sat, 13 Apr 2013 07:16:28 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: <8c5d502c-80c2-41b4-a72e-8552f7de8323@googlegroups.com> Message-ID: ?? ???????, 13 ???????? 2013 1:28:07 ?.?. UTC+3, ? ??????? Cameron Simpson ??????: > On 12Apr2013 21:50, nagia.retsina at gmail.com wrote: > > | Ookey after that is corrected, i then tried the plain solution and i got this response back form the shell: > > | > > | Traceback (most recent call last): > > | File "metrites.py", line 213, in <module> > > | htmldata = f.read() > > | File "/root/.local/lib/python2.7/lib/python3.3/encodings/iso8859_7.py", line 23, in decode > > | return codecs.charmap_decode(input,self.errors,decoding_table)[0] > > | UnicodeDecodeError: 'charmap' codec can't decode byte 0xae in position 47: character maps to <undefined> > > | > > | then i switched to: > > | > > | with open('/home/nikos/www/' + page, encoding='utf-8') as f: > > | htmldata = f.read() > > | > > | and i got no error at all, just pure run *from the shell*! > > > > Ok, so you need to specify utf-8 to decode the file. Good. > > > > | But i get internal server error when i try to run the webpage from the browser(Chrome). > > > > That is standard for a CGI script that does not complete successfully. > > > > | So, can you tell me please where can i find the apache error log so to display here please? > > > > That depends on the install. Have a look in /var/log/apache or similar. > > Otherwise you need to find the httpd.conf for the apache and look > > for its log coniguration settings. > > > > | Apcher error_log is always better than running 'python3 metrites.py' because even if the python script has no error apache will also display more web related things? > > > > The error log is where error messages from CGI scripts go. And other error messages. > > It is very useful when testing CGI scripts. > > > > Of course, it's best to work out as much as possible from the command > > line first; you have much more direct control and access to errors > > there. That only gets you so far though; the environment the CGI > > script runs in is not the same as your command line, and some > > different behaviour can come from this. > > > > BTW, are you sure python3 is running your CGI script? > > Also, the CGI script may not be running as you, but as the apache user. > > In that case, it may fail if it does not has permission to access various > > files owned by you. > > > > Anyway, you need to see the error messages to work this out. > > > > If you can't find the error log you can divert stderr at the > > start of your python program: > > > > sys.stderr = open('/home/nikos/cgi.err.out', 'a') > > > > and watch that in a shell: > > > > tail -f cgi.err.out > > > > Cheers, > > -- > > Cameron Simpson > > > > If you 'aint falling off, you ar'nt going hard enough. - Fred Gassit root at macgyver [/home/nikos/public_html/cgi-bin]# ls ../cgi.err.out ../cgi.err.out root at macgyver [/home/nikos/public_html/cgi-bin]# cat ../cgi.err.out root at macgyver [/home/nikos/public_html/cgi-bin]# Also i have foudn the error log and i tried to view it but it was empty and then i removed it and then run the script both from shell and broswer but it didnt reappeared. root at macgyver [/home/nikos/public_html/cgi-bin]# cat /var/log/httpd/error_log cat: /var/log/httpd/error_log: No such file or directory root at macgyver [/home/nikos/public_html/cgi-bin]# Maybe its somehtign wron with my enviroment? Should we check the Apache and CGI enviroment somehow and also make sure as you say that *I* run the CGI scripts and not user 'Apache' ? Tell me what commands i should issues please and i will display the output to you. Thank you Cameron, for helpimg me. Somehow the script doesnt seem to be the issue in my VPS. From nagia.retsina at gmail.com Sat Apr 13 10:16:28 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Sat, 13 Apr 2013 07:16:28 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: <8c5d502c-80c2-41b4-a72e-8552f7de8323@googlegroups.com> Message-ID: ?? ???????, 13 ???????? 2013 1:28:07 ?.?. UTC+3, ? ??????? Cameron Simpson ??????: > On 12Apr2013 21:50, nagia.retsina at gmail.com wrote: > > | Ookey after that is corrected, i then tried the plain solution and i got this response back form the shell: > > | > > | Traceback (most recent call last): > > | File "metrites.py", line 213, in <module> > > | htmldata = f.read() > > | File "/root/.local/lib/python2.7/lib/python3.3/encodings/iso8859_7.py", line 23, in decode > > | return codecs.charmap_decode(input,self.errors,decoding_table)[0] > > | UnicodeDecodeError: 'charmap' codec can't decode byte 0xae in position 47: character maps to <undefined> > > | > > | then i switched to: > > | > > | with open('/home/nikos/www/' + page, encoding='utf-8') as f: > > | htmldata = f.read() > > | > > | and i got no error at all, just pure run *from the shell*! > > > > Ok, so you need to specify utf-8 to decode the file. Good. > > > > | But i get internal server error when i try to run the webpage from the browser(Chrome). > > > > That is standard for a CGI script that does not complete successfully. > > > > | So, can you tell me please where can i find the apache error log so to display here please? > > > > That depends on the install. Have a look in /var/log/apache or similar. > > Otherwise you need to find the httpd.conf for the apache and look > > for its log coniguration settings. > > > > | Apcher error_log is always better than running 'python3 metrites.py' because even if the python script has no error apache will also display more web related things? > > > > The error log is where error messages from CGI scripts go. And other error messages. > > It is very useful when testing CGI scripts. > > > > Of course, it's best to work out as much as possible from the command > > line first; you have much more direct control and access to errors > > there. That only gets you so far though; the environment the CGI > > script runs in is not the same as your command line, and some > > different behaviour can come from this. > > > > BTW, are you sure python3 is running your CGI script? > > Also, the CGI script may not be running as you, but as the apache user. > > In that case, it may fail if it does not has permission to access various > > files owned by you. > > > > Anyway, you need to see the error messages to work this out. > > > > If you can't find the error log you can divert stderr at the > > start of your python program: > > > > sys.stderr = open('/home/nikos/cgi.err.out', 'a') > > > > and watch that in a shell: > > > > tail -f cgi.err.out > > > > Cheers, > > -- > > Cameron Simpson > > > > If you 'aint falling off, you ar'nt going hard enough. - Fred Gassit root at macgyver [/home/nikos/public_html/cgi-bin]# ls ../cgi.err.out ../cgi.err.out root at macgyver [/home/nikos/public_html/cgi-bin]# cat ../cgi.err.out root at macgyver [/home/nikos/public_html/cgi-bin]# Also i have foudn the error log and i tried to view it but it was empty and then i removed it and then run the script both from shell and broswer but it didnt reappeared. root at macgyver [/home/nikos/public_html/cgi-bin]# cat /var/log/httpd/error_log cat: /var/log/httpd/error_log: No such file or directory root at macgyver [/home/nikos/public_html/cgi-bin]# Maybe its somehtign wron with my enviroment? Should we check the Apache and CGI enviroment somehow and also make sure as you say that *I* run the CGI scripts and not user 'Apache' ? Tell me what commands i should issues please and i will display the output to you. Thank you Cameron, for helpimg me. Somehow the script doesnt seem to be the issue in my VPS. From rosuav at gmail.com Sat Apr 13 11:45:30 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Apr 2013 01:45:30 +1000 Subject: Unicode issue with Python v3.3 In-Reply-To: References: <8c5d502c-80c2-41b4-a72e-8552f7de8323@googlegroups.com> Message-ID: On Sun, Apr 14, 2013 at 12:16 AM, wrote: > Also i have foudn the error log and i tried to view it but it was empty and then i removed it and then run the script both from shell and broswer but it didnt reappeared. > > root at macgyver [/home/nikos/public_html/cgi-bin]# cat /var/log/httpd/error_log > cat: /var/log/httpd/error_log: No such file or directory > root at macgyver [/home/nikos/public_html/cgi-bin]# https://www.google.com/search?q=log+file+rotation ChrisA From cs at zip.com.au Sat Apr 13 20:01:07 2013 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 14 Apr 2013 10:01:07 +1000 Subject: Unicode issue with Python v3.3 In-Reply-To: References: Message-ID: <20130414000107.GA63240@cskk.homeip.net> On 13Apr2013 07:16, nagia.retsina at gmail.com wrote: | root at macgyver [/home/nikos/public_html/cgi-bin]# ls ../cgi.err.out | ../cgi.err.out I prefer "ls -ld" myself. | root at macgyver [/home/nikos/public_html/cgi-bin]# cat ../cgi.err.out | | Also i have foudn the error log and i tried to view it but it was | empty and then i removed it and then run the script both from shell | and broswer but it didnt reappeared. Never remove it. It is only created by the web server at startup or log rotation time. So now you need to restart the apache to get it back. Just open a spare terminal and run: tail -f /var/log/httpd/error_log | Should we check the Apache and CGI enviroment somehow and also | make sure as you say that *I* run the CGI scripts and not user | 'Apache' ? Well, it is helpful to know. if the CGI script tries to write any data to files, if it runs as a different user it will need different permissions on the files. | Tell me what commands i should issues please and i will display the output to you. I would be tempter to wrap the CGI script in a shell script. Suppose your script is named foo.py. You can move the script to foo-py and make a shell script called "foo.py" looking like this: #!/bin/sh exec 2>>/home/nikos/cgi.err.out echo "$0 $*" >&2 id >&2 env | sort >&2 set -x exec /full/path/to/foo-py ${1+"$@"} and make sure it, like the original, is readable and executable: chmod a+rx foo.py foo-py Make sure cgi.err.out is publicly writable (in case the apache is not running the CGIs are you): chmod a+w cgi.err.out Then: tail -f cgi.err.out in a spare window. Then try the script. It should transcribe information about the script's user and environment and also catch errors. This should help in debugging. Cheers, -- I die. I have a terrible fever in my head and it gets hotter and hotter until my head is a fire, a forge, a star. I set the world on fire and all die. O the embarrassment. - Joe Haldeman, _A !Tangled Web_ From nagia.retsina at gmail.com Thu Apr 11 03:13:46 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Thu, 11 Apr 2013 00:13:46 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: <5f4ff014-744a-4b31-ad99-fd8b39822912@googlegroups.com> Message-ID: Since now we k ow the problem maybe we can tell metrites.py to open index.html using utf-8 encoding rather as binary, dont you think? From nagia.retsina at gmail.com Thu Apr 11 03:13:46 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Thu, 11 Apr 2013 00:13:46 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: <5f4ff014-744a-4b31-ad99-fd8b39822912@googlegroups.com> Message-ID: Since now we k ow the problem maybe we can tell metrites.py to open index.html using utf-8 encoding rather as binary, dont you think? From steve+comp.lang.python at pearwood.info Thu Apr 11 03:50:19 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Apr 2013 07:50:19 GMT Subject: Unicode issue with Python v3.3 References: <5f4ff014-744a-4b31-ad99-fd8b39822912@googlegroups.com> Message-ID: <51666b3b$0$29977$c3e8da3$5496439d@news.astraweb.com> On Thu, 11 Apr 2013 00:13:46 -0700, nagia.retsina wrote: > Since now we k ow the problem maybe we can tell metrites.py to open > index.html using utf-8 encoding rather as binary, dont you think? What makes you think it is UTF-8? Last time you tried decoding content as UTF-8, you got an error that it wasn't a legal UTF-8 file. Where does index.html come from? Whatever program generates that, you need to find out what encoding it is using. -- Steven From steve+comp.lang.python at pearwood.info Thu Apr 11 04:20:47 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Apr 2013 08:20:47 GMT Subject: Unicode issue with Python v3.3 References: <5f4ff014-744a-4b31-ad99-fd8b39822912@googlegroups.com> <51666b3b$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5166725f$0$29977$c3e8da3$5496439d@news.astraweb.com> On Thu, 11 Apr 2013 07:50:19 +0000, Steven D'Aprano wrote: > On Thu, 11 Apr 2013 00:13:46 -0700, nagia.retsina wrote: > >> Since now we k ow the problem maybe we can tell metrites.py to open >> index.html using utf-8 encoding rather as binary, dont you think? > > What makes you think it is UTF-8? > > Last time you tried decoding content as UTF-8, you got an error that it > wasn't a legal UTF-8 file. Oops, sorry, correction. It wasn't a legal UTF-8 string. It was an environment variable that was causing the decoding error, since it contained illegal bytes for a UTF-8 string. > Where does index.html come from? Whatever program generates that, you > need to find out what encoding it is using. -- Steven From nagia.retsina at gmail.com Thu Apr 11 06:07:51 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Thu, 11 Apr 2013 03:07:51 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: <5166725f$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <5f4ff014-744a-4b31-ad99-fd8b39822912@googlegroups.com> <51666b3b$0$29977$c3e8da3$5496439d@news.astraweb.com> <5166725f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57205362-8da8-40ed-a79e-9e896b8c696f@googlegroups.com> ?? ??????, 11 ???????? 2013 11:20:47 ?.?. UTC+3, ? ??????? Steven D'Aprano ??????: > On Thu, 11 Apr 2013 07:50:19 +0000, Steven D'Aprano wrote: > > > > > On Thu, 11 Apr 2013 00:13:46 -0700, nagia.retsina wrote: > > > > > >> Since now we k ow the problem maybe we can tell metrites.py to open > > >> index.html using utf-8 encoding rather as binary, dont you think? > > > > > > What makes you think it is UTF-8? > > > > > > Last time you tried decoding content as UTF-8, you got an error that it > > > wasn't a legal UTF-8 file. > > > > Oops, sorry, correction. It wasn't a legal UTF-8 string. It was an > > environment variable that was causing the decoding error, since it > > contained illegal bytes for a UTF-8 string. > > > > > > > Where does index.html come from? Whatever program generates that, you > > > need to find out what encoding it is using. Hello steven, index.html was writenn by handcode from me utilizing html + css metrites.py tries to open that script so we must tell it to open as utf-8 text and not as a binary file. How can we do that? From lele at metapensiero.it Thu Apr 11 06:45:03 2013 From: lele at metapensiero.it (Lele Gaifax) Date: Thu, 11 Apr 2013 12:45:03 +0200 Subject: Unicode issue with Python v3.3 References: <5f4ff014-744a-4b31-ad99-fd8b39822912@googlegroups.com> <51666b3b$0$29977$c3e8da3$5496439d@news.astraweb.com> <5166725f$0$29977$c3e8da3$5496439d@news.astraweb.com> <57205362-8da8-40ed-a79e-9e896b8c696f@googlegroups.com> Message-ID: <87li8p8hxs.fsf@nautilus.nautilus> nagia.retsina at gmail.com writes: > metrites.py tries to open that script so we must tell it to open as > utf-8 text and not as a binary file. One way is the following: from codecs import open with open('index.html', encoding='utf-8') as f: content = f.read() 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 nobody at nowhere.com Wed Apr 10 14:08:38 2013 From: nobody at nowhere.com (Nobody) Date: Wed, 10 Apr 2013 19:08:38 +0100 Subject: Unicode issue with Python v3.3 References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> <1d825911-370a-43d5-892c-d904ecbebbb9@googlegroups.com> Message-ID: On Wed, 10 Apr 2013 00:23:46 -0700, nagia.retsina wrote: > Look at what 'python3 metrites.py' gives me > File "/root/.local/lib/python2.7/lib/python3.3/os.py", line 669, ... ^^^ ^^^ From nikos.gr33k at gmail.com Wed Apr 10 14:25:34 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 10 Apr 2013 11:25:34 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> <1d825911-370a-43d5-892c-d904ecbebbb9@googlegroups.com> Message-ID: <551beeb5-1a45-493a-914c-2d7f495871b3@googlegroups.com> ?? ???????, 10 ???????? 2013 9:08:38 ?.?. UTC+3, ? ??????? Nobody ??????: > On Wed, 10 Apr 2013 00:23:46 -0700, nagia.retsina wrote: > > > > > Look at what 'python3 metrites.py' gives me > > > > > File "/root/.local/lib/python2.7/lib/python3.3/os.py", line 669, ... > > ^^^ ^^^ Yes i see it in the traceback but i dont know what it means. Please explain to me. Tahnk you. From ian.g.kelly at gmail.com Wed Apr 10 15:50:01 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 10 Apr 2013 13:50:01 -0600 Subject: Unicode issue with Python v3.3 In-Reply-To: <551beeb5-1a45-493a-914c-2d7f495871b3@googlegroups.com> References: <6ff0e019-28b9-4aa6-ae8a-d73d7e748350@googlegroups.com> <5164e9b0$0$29977$c3e8da3$5496439d@news.astraweb.com> <1d825911-370a-43d5-892c-d904ecbebbb9@googlegroups.com> <551beeb5-1a45-493a-914c-2d7f495871b3@googlegroups.com> Message-ID: On Wed, Apr 10, 2013 at 12:25 PM, ????? ???33? wrote: > ?? ???????, 10 ???????? 2013 9:08:38 ?.?. UTC+3, ? ??????? Nobody ??????: >> On Wed, 10 Apr 2013 00:23:46 -0700, nagia.retsina wrote: >> >> >> >> > Look at what 'python3 metrites.py' gives me >> >> >> >> > File "/root/.local/lib/python2.7/lib/python3.3/os.py", line 669, ... >> >> ^^^ ^^^ > > Yes i see it in the traceback but i dont know what it means. > Please explain to me. > Tahnk you. It means that there is something very strange about the way that your Python 3.3 is installed, as the libraries appear to be installed under your Python 2.7 library directory. From nagia.retsina at gmail.com Fri Apr 12 00:36:18 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Thu, 11 Apr 2013 21:36:18 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: Message-ID: Well, can somebody else propose somehting plz? i have paste the whole script and even the necessary snippet that perhaps causing this encoding confusion in 3.3 From wuwei23 at gmail.com Fri Apr 12 01:06:14 2013 From: wuwei23 at gmail.com (alex23) Date: Thu, 11 Apr 2013 22:06:14 -0700 (PDT) Subject: Unicode issue with Python v3.3 References: Message-ID: On Apr 12, 2:36?pm, nagia.rets... at gmail.com wrote: > Well, can somebody else propose somehting plz? Pay for a professional. From nagia.retsina at gmail.com Fri Apr 12 08:50:19 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Fri, 12 Apr 2013 05:50:19 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: <1521dbf5-ffa7-4e15-9995-d9e7a733ba62@googlegroups.com> References: <1521dbf5-ffa7-4e15-9995-d9e7a733ba62@googlegroups.com> Message-ID: <9602aba1-d870-4b03-ba81-44d8af0072ee@googlegroups.com> Someone HEEEEEEEEEELP MEEEEEEEEE!! From rosuav at gmail.com Fri Apr 12 09:14:39 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Apr 2013 23:14:39 +1000 Subject: Unicode issue with Python v3.3 In-Reply-To: <9602aba1-d870-4b03-ba81-44d8af0072ee@googlegroups.com> References: <1521dbf5-ffa7-4e15-9995-d9e7a733ba62@googlegroups.com> <9602aba1-d870-4b03-ba81-44d8af0072ee@googlegroups.com> Message-ID: On Fri, Apr 12, 2013 at 10:50 PM, wrote: > Someone HEEEEEEEEEELP MEEEEEEEEE!! http://youtu.be/VxMYwjp8t0o ChrisA From nagia.retsina at gmail.com Fri Apr 12 09:18:45 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Fri, 12 Apr 2013 06:18:45 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: <1521dbf5-ffa7-4e15-9995-d9e7a733ba62@googlegroups.com> <9602aba1-d870-4b03-ba81-44d8af0072ee@googlegroups.com> Message-ID: ?? ?????????, 12 ???????? 2013 4:14:39 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > On Fri, Apr 12, 2013 at 10:50 PM, wrote: > > > Someone HEEEEEEEEEELP MEEEEEEEEE!! > > > > http://youtu.be/VxMYwjp8t0o > > > > ChrisA Well, instead of being a smartass it would be nice if you could actually help for once. From nagia.retsina at gmail.com Fri Apr 12 09:18:45 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Fri, 12 Apr 2013 06:18:45 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: <1521dbf5-ffa7-4e15-9995-d9e7a733ba62@googlegroups.com> <9602aba1-d870-4b03-ba81-44d8af0072ee@googlegroups.com> Message-ID: ?? ?????????, 12 ???????? 2013 4:14:39 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > On Fri, Apr 12, 2013 at 10:50 PM, wrote: > > > Someone HEEEEEEEEEELP MEEEEEEEEE!! > > > > http://youtu.be/VxMYwjp8t0o > > > > ChrisA Well, instead of being a smartass it would be nice if you could actually help for once. From rosuav at gmail.com Fri Apr 12 09:21:47 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Apr 2013 23:21:47 +1000 Subject: Unicode issue with Python v3.3 In-Reply-To: References: <1521dbf5-ffa7-4e15-9995-d9e7a733ba62@googlegroups.com> <9602aba1-d870-4b03-ba81-44d8af0072ee@googlegroups.com> Message-ID: On Fri, Apr 12, 2013 at 11:18 PM, wrote: > ?? ?????????, 12 ???????? 2013 4:14:39 ?.?. UTC+3, ? ??????? Chris Angelico ??????: >> On Fri, Apr 12, 2013 at 10:50 PM, wrote: >> >> > Someone HEEEEEEEEEELP MEEEEEEEEE!! >> >> http://youtu.be/VxMYwjp8t0o >> >> ChrisA > > > Well, instead of being a smartass it would be nice if you could actually help for once. Yeah, I'm done with that. Your whining ran through my patience a few posts ago. But you should feel special; I clipped that just for you. ChrisA From rustompmody at gmail.com Fri Apr 12 09:29:51 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 12 Apr 2013 06:29:51 -0700 (PDT) Subject: Unicode issue with Python v3.3 References: <1521dbf5-ffa7-4e15-9995-d9e7a733ba62@googlegroups.com> <9602aba1-d870-4b03-ba81-44d8af0072ee@googlegroups.com> Message-ID: <218d468e-5e8e-4e63-bba0-c20e1882caa1@ul7g2000pbc.googlegroups.com> On Apr 12, 6:18?pm, nagia.rets... at gmail.com wrote: > ?? ?????????, 12 ???????? 2013 4:14:39 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > > > On Fri, Apr 12, 2013 at 10:50 PM, ? wrote: > > > > Someone HEEEEEEEEEELP MEEEEEEEEE!! > > >http://youtu.be/VxMYwjp8t0o > > > ChrisA > > Well, instead of being a smartass it would be nice if you could actually help for once. Interesting! Among the things which you dont seem to know is the meaning of the word 'once'. From nagia.retsina at gmail.com Fri Apr 12 10:36:56 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Fri, 12 Apr 2013 07:36:56 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: <218d468e-5e8e-4e63-bba0-c20e1882caa1@ul7g2000pbc.googlegroups.com> References: <1521dbf5-ffa7-4e15-9995-d9e7a733ba62@googlegroups.com> <9602aba1-d870-4b03-ba81-44d8af0072ee@googlegroups.com> <218d468e-5e8e-4e63-bba0-c20e1882caa1@ul7g2000pbc.googlegroups.com> Message-ID: <2b23fe0a-722d-4e5e-9b97-b8099f36a668@googlegroups.com> ?? ?????????, 12 ???????? 2013 4:29:51 ?.?. UTC+3, ? ??????? rusi ??????: > On Apr 12, 6:18?pm, nagia.rets... at gmail.com wrote: > > > ?? ?????????, 12 ???????? 2013 4:14:39 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > > > > > > > On Fri, Apr 12, 2013 at 10:50 PM, ? wrote: > > > > > > > > Someone HEEEEEEEEEELP MEEEEEEEEE!! > > > > > > >http://youtu.be/VxMYwjp8t0o > > > > > > > ChrisA > > > > > > Well, instead of being a smartass it would be nice if you could actually help for once. > > > > Interesting! > > Among the things which you dont seem to know is the meaning of the > > word 'once'. Same applies for you too. Stop being smartasses. From ian.g.kelly at gmail.com Fri Apr 12 14:37:29 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 12 Apr 2013 12:37:29 -0600 Subject: Unicode issue with Python v3.3 In-Reply-To: <2b23fe0a-722d-4e5e-9b97-b8099f36a668@googlegroups.com> References: <1521dbf5-ffa7-4e15-9995-d9e7a733ba62@googlegroups.com> <9602aba1-d870-4b03-ba81-44d8af0072ee@googlegroups.com> <218d468e-5e8e-4e63-bba0-c20e1882caa1@ul7g2000pbc.googlegroups.com> <2b23fe0a-722d-4e5e-9b97-b8099f36a668@googlegroups.com> Message-ID: On Fri, Apr 12, 2013 at 8:36 AM, wrote: > ?? ?????????, 12 ???????? 2013 4:29:51 ?.?. UTC+3, ? ??????? rusi ??????: >> On Apr 12, 6:18 pm, nagia.rets... at gmail.com wrote: >> > Well, instead of being a smartass it would be nice if you could actually help for once. >> >> Interesting! >> >> Among the things which you dont seem to know is the meaning of the >> word 'once'. > > Same applies for you too. Stop being smartasses. Please keep in mind that this is a community of volunteers. Nobody here is being paid for their time to help you fix your website, and if you manage to irritate us in the process, we're likely to just walk away from it. I looked over the code that you have provided us with, and based on that I could not see any reason why the html would be in the form of a bytes instead of a str. Since nobody else here seems to have any further insight into the problem either, you're just going to have to find a a way to debug the code. If you cannot do that on your own, then I suggest that you find a contractor who can, hire them, and grant them the access they need to do a real debugging session. I would also recommend that in the future you should stop deploying untested code to your production website. Set up a development environment for yourself, make the changes there, and only deploy when you know that everything is working. From roy at panix.com Fri Apr 12 14:49:17 2013 From: roy at panix.com (Roy Smith) Date: Fri, 12 Apr 2013 14:49:17 -0400 Subject: Unicode issue with Python v3.3 References: <1521dbf5-ffa7-4e15-9995-d9e7a733ba62@googlegroups.com> <9602aba1-d870-4b03-ba81-44d8af0072ee@googlegroups.com> <218d468e-5e8e-4e63-bba0-c20e1882caa1@ul7g2000pbc.googlegroups.com> <2b23fe0a-722d-4e5e-9b97-b8099f36a668@googlegroups.com> Message-ID: In article , Ian Kelly wrote: > I would also recommend that in the future you should stop deploying > untested code to your production website. Set up a development > environment for yourself, make the changes there, and only deploy when > you know that everything is working. But that takes all the fun out of it :-) From nagia.retsina at gmail.com Fri Apr 12 16:48:38 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Fri, 12 Apr 2013 13:48:38 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: <1521dbf5-ffa7-4e15-9995-d9e7a733ba62@googlegroups.com> <9602aba1-d870-4b03-ba81-44d8af0072ee@googlegroups.com> <218d468e-5e8e-4e63-bba0-c20e1882caa1@ul7g2000pbc.googlegroups.com> <2b23fe0a-722d-4e5e-9b97-b8099f36a668@googlegroups.com> Message-ID: ?? ?????????, 12 ???????? 2013 9:37:29 ?.?. UTC+3, ? ??????? Ian ??????: > On Fri, Apr 12, 2013 at 8:36 AM, wrote: > > > ?? ?????????, 12 ???????? 2013 4:29:51 ?.?. UTC+3, ? ??????? rusi ??????: > > >> On Apr 12, 6:18 pm, nagia.rets... at gmail.com wrote: > > >> > Well, instead of being a smartass it would be nice if you could actually help for once. > > >> > > >> Interesting! > > >> > > >> Among the things which you dont seem to know is the meaning of the > > >> word 'once'. > > > > > > Same applies for you too. Stop being smartasses. > > > > Please keep in mind that this is a community of volunteers. Nobody > > here is being paid for their time to help you fix your website, and if > > you manage to irritate us in the process, we're likely to just walk > > away from it. > > > > I looked over the code that you have provided us with, and based on > > that I could not see any reason why the html would be in the form of a > > bytes instead of a str. Since nobody else here seems to have any > > further insight into the problem either, you're just going to have to > > find a a way to debug the code. If you cannot do that on your own, > > then I suggest that you find a contractor who can, hire them, and > > grant them the access they need to do a real debugging session. > > > > I would also recommend that in the future you should stop deploying > > untested code to your production website. Set up a development > > environment for yourself, make the changes there, and only deploy when > > you know that everything is working. I agree with what you say except form the fact that i try to irritate people. Look at the thread and you will see who's irritating whom first. From nagia.retsina at gmail.com Fri Apr 12 16:48:38 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Fri, 12 Apr 2013 13:48:38 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: <1521dbf5-ffa7-4e15-9995-d9e7a733ba62@googlegroups.com> <9602aba1-d870-4b03-ba81-44d8af0072ee@googlegroups.com> <218d468e-5e8e-4e63-bba0-c20e1882caa1@ul7g2000pbc.googlegroups.com> <2b23fe0a-722d-4e5e-9b97-b8099f36a668@googlegroups.com> Message-ID: ?? ?????????, 12 ???????? 2013 9:37:29 ?.?. UTC+3, ? ??????? Ian ??????: > On Fri, Apr 12, 2013 at 8:36 AM, wrote: > > > ?? ?????????, 12 ???????? 2013 4:29:51 ?.?. UTC+3, ? ??????? rusi ??????: > > >> On Apr 12, 6:18 pm, nagia.rets... at gmail.com wrote: > > >> > Well, instead of being a smartass it would be nice if you could actually help for once. > > >> > > >> Interesting! > > >> > > >> Among the things which you dont seem to know is the meaning of the > > >> word 'once'. > > > > > > Same applies for you too. Stop being smartasses. > > > > Please keep in mind that this is a community of volunteers. Nobody > > here is being paid for their time to help you fix your website, and if > > you manage to irritate us in the process, we're likely to just walk > > away from it. > > > > I looked over the code that you have provided us with, and based on > > that I could not see any reason why the html would be in the form of a > > bytes instead of a str. Since nobody else here seems to have any > > further insight into the problem either, you're just going to have to > > find a a way to debug the code. If you cannot do that on your own, > > then I suggest that you find a contractor who can, hire them, and > > grant them the access they need to do a real debugging session. > > > > I would also recommend that in the future you should stop deploying > > untested code to your production website. Set up a development > > environment for yourself, make the changes there, and only deploy when > > you know that everything is working. I agree with what you say except form the fact that i try to irritate people. Look at the thread and you will see who's irritating whom first. From nagia.retsina at gmail.com Sun Apr 14 02:00:39 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Sat, 13 Apr 2013 23:00:39 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: Message-ID: ?? ???????, 10 ???????? 2013 12:10:13 ?.?. UTC+3, ? ??????? ????? ???33? ??????: > Hello, iam still trying to alter the code form python 2.6 => 3.3 > > > > Everyrging its setup except that unicode error that you can see if you go to http://superhost.gr > > > > Can anyone help with this? > > I even tried to change print() with sys.stdout.buffer() but still i get the same unicode issue. > > > > I don't know what to try anymore. root at nikos [/home/nikos/public_html/foo-py]# pwd /home/nikos/public_html/foo-py root at nikos [/home/nikos/public_html/foo-py]# cat foo.py #!/bin/sh exec 2>>/home/nikos/cgi.err.out echo "$0 $*" >&2 id >&2 env | sort >&2 set -x exec /full/path/to/foo-py ${1+"$@"} root at nikos [/home/nikos/public_html/foo-py]# python3 foo.py File "foo.py", line 2 exec 2>>/home/nikos/cgi.err.out ^ SyntaxError: invalid syntax root at nikos [/home/nikos/public_html/foo-py]# As far as thr tail -f of the error_log: root at nikos [/home/nikos/public_html]# touch /var/log/httpd/error_log root at nikos [/home/nikos/public_html]# tail -f /var/log/httpd/error_log and its empty even when at the exact same time i run 'python3 metrites.py' from another interactive prompt when it supposed to give live feed of the error messages. Cameron would it be too much to ask to provide you with root access to my VPS server so you can have a look there too? i can pay you if you like if you wait a few days to gather some money. From cs at zip.com.au Sun Apr 14 05:28:32 2013 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 14 Apr 2013 19:28:32 +1000 Subject: Unicode issue with Python v3.3 In-Reply-To: References: Message-ID: <20130414092832.GA30136@cskk.homeip.net> On 13Apr2013 23:00, nagia.retsina at gmail.com wrote: | root at nikos [/home/nikos/public_html/foo-py]# pwd | /home/nikos/public_html/foo-py | root at nikos [/home/nikos/public_html/foo-py]# cat foo.py | #!/bin/sh | exec 2>>/home/nikos/cgi.err.out | echo "$0 $*" >&2 | id >&2 | env | sort >&2 | set -x | exec /full/path/to/foo-py ${1+"$@"} | | root at nikos [/home/nikos/public_html/foo-py]# python3 foo.py | File "foo.py", line 2 | exec 2>>/home/nikos/cgi.err.out | ^ | SyntaxError: invalid syntax That is because foo.py isn't a python script anymore, it is a shell script. Its purpose is to divert stderr to a file and to recite various things about the environment to that file in addition to any error messages. Just run it directly: ./foo.py The #! line should cause it to be run by the shell. I also recommend you try to do all this as your normal user account. Root is for administration, such as stopping/starting apache and so on. Not test running scripts from the command line; consider: if the script has bugs, as root it can do an awful lot of damage. | root at nikos [/home/nikos/public_html/foo-py]# | As far as thr tail -f of the error_log: | root at nikos [/home/nikos/public_html]# touch /var/log/httpd/error_log That won't do you much good; apache has not opened it, and so it will not be writing to it. It was writing to a file of that name, but you removed that file. Apache probably still has its hooks in the old file (which now has no name). Restarting apache should open (or create if missing) this file for you. | root at nikos [/home/nikos/public_html]# tail -f /var/log/httpd/error_log | and its empty even when at the exact same time i run 'python3 | metrites.py' from another interactive prompt when it supposed to | give live feed of the error messages. No, _apache_ writes to that file. So only when you visit the web page will stuff appear there. If you just run things from the command line, error messages will appear on your terminal. Or, after this line of the wrapper script: exec 2>>/home/nikos/cgi.err.out the error messages will appear in cgi.err.out. | Cameron would it be too much to ask to provide you with root | access to my VPS server so you can have a look there too? | i can pay you if you like if you wait a few days to gather some money. I really do not recommend that: - it is nuts to blithely allow a stranger root access to your system - you won't learn anything about CGI scripts What you need for further debugging of your python issues is access to the error messages from the CGI script. That is the purpose of the wrapper script. Get the wrapper running on the command line and then test it via the browser. Cheers, -- Cameron Simpson Lord grant me the serenity to accept the things I can not change, the courage to change the things that I can, and the wisdom to hide the bodies of those people I had to kill because they pissed me off. - Jeffrey Papen From nagia.retsina at gmail.com Sun Apr 14 07:22:49 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Sun, 14 Apr 2013 04:22:49 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: Message-ID: <5108f522-3117-41e6-9ad0-88ceed14398c@googlegroups.com> ?? ???????, 14 ???????? 2013 12:28:32 ?.?. UTC+3, ? ??????? Cameron Simpson ??????: > On 13Apr2013 23:00, nagia.retsina at gmail.com wrote: > > | root at nikos [/home/nikos/public_html/foo-py]# pwd > > | /home/nikos/public_html/foo-py > > | root at nikos [/home/nikos/public_html/foo-py]# cat foo.py > > | #!/bin/sh > > | exec 2>>/home/nikos/cgi.err.out > > | echo "$0 $*" >&2 > > | id >&2 > > | env | sort >&2 > > | set -x > > | exec /full/path/to/foo-py ${1+"$@"} > > | > > | root at nikos [/home/nikos/public_html/foo-py]# python3 foo.py > > | File "foo.py", line 2 > > | exec 2>>/home/nikos/cgi.err.out > > | ^ > > | SyntaxError: invalid syntax > > > > That is because foo.py isn't a python script anymore, it is a shell script. > > Its purpose is to divert stderr to a file and to recite various > > things about the environment to that file in addition to any error > > messages. > > > > Just run it directly: > > > > ./foo.py > > > > The #! line should cause it to be run by the shell. > > > > I also recommend you try to do all this as your normal user account. > > Root is for administration, such as stopping/starting apache and > > so on. Not test running scripts from the command line; consider: > > if the script has bugs, as root it can do an awful lot of damage. > > > > | root at nikos [/home/nikos/public_html/foo-py]# > > | As far as thr tail -f of the error_log: > > | root at nikos [/home/nikos/public_html]# touch /var/log/httpd/error_log > > > > That won't do you much good; apache has not opened it, and so it > > will not be writing to it. It was writing to a file of that name, > > but you removed that file. Apache probably still has its hooks in the old > > file (which now has no name). > > > > Restarting apache should open (or create if missing) this file for you. > > > > | root at nikos [/home/nikos/public_html]# tail -f /var/log/httpd/error_log > > | and its empty even when at the exact same time i run 'python3 > > | metrites.py' from another interactive prompt when it supposed to > > | give live feed of the error messages. > > > > No, _apache_ writes to that file. So only when you visit the web > > page will stuff appear there. > > > > If you just run things from the command line, error messages will appear on your terminal. Or, after this line of the wrapper script: > > > > exec 2>>/home/nikos/cgi.err.out > > > > the error messages will appear in cgi.err.out. > > > > | Cameron would it be too much to ask to provide you with root > > | access to my VPS server so you can have a look there too? > > | i can pay you if you like if you wait a few days to gather some money. > > > > I really do not recommend that: > > > > - it is nuts to blithely allow a stranger root access to your system > > - you won't learn anything about CGI scripts > > > > What you need for further debugging of your python issues is access > > to the error messages from the CGI script. That is the purpose of > > the wrapper script. > > > > Get the wrapper running on the command line and then test it via the browser. > > > > Cheers, > > -- > > Cameron Simpson > > > > Lord grant me the serenity to accept the things I can not change, > > the courage to change the things that I can, > > and the wisdom to hide the bodies of those people I had to kill > > because they pissed me off. > > - Jeffrey Papen Well i trust you because you are the only one along with Lele that are helpimg me here: i tried what you said: root at nikos [/home/nikos/public_html/cgi-bin]# service httpd restart root at nikos [/home/nikos/public_html/cgi-bin]# python3 metrites.py root at nikos [/home/nikos/public_html]# cd foo-py/ root at nikos [/home/nikos/public_html/foo-py]# ls ./ ../ foo.py* root at nikos [/home/nikos/public_html/foo-py]# ./foo.py root at nikos [/home/nikos/public_html/foo-py]# cd .. root at nikos [/home/nikos/public_html]# cat cgi.err.out root at nikos [/home/nikos/public_html/cgi-bin]# cat /var/log/httpd/error_log root at nikos [/home/nikos/public_html/cgi-bin]# and i have run the script form browser but i still see nothing. I insist that you will make the most of this if you access the VPS yourself. it runs CentOS 6.4 Please accept, i trust you. From nagia.retsina at gmail.com Sun Apr 14 07:22:49 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Sun, 14 Apr 2013 04:22:49 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: Message-ID: <5108f522-3117-41e6-9ad0-88ceed14398c@googlegroups.com> ?? ???????, 14 ???????? 2013 12:28:32 ?.?. UTC+3, ? ??????? Cameron Simpson ??????: > On 13Apr2013 23:00, nagia.retsina at gmail.com wrote: > > | root at nikos [/home/nikos/public_html/foo-py]# pwd > > | /home/nikos/public_html/foo-py > > | root at nikos [/home/nikos/public_html/foo-py]# cat foo.py > > | #!/bin/sh > > | exec 2>>/home/nikos/cgi.err.out > > | echo "$0 $*" >&2 > > | id >&2 > > | env | sort >&2 > > | set -x > > | exec /full/path/to/foo-py ${1+"$@"} > > | > > | root at nikos [/home/nikos/public_html/foo-py]# python3 foo.py > > | File "foo.py", line 2 > > | exec 2>>/home/nikos/cgi.err.out > > | ^ > > | SyntaxError: invalid syntax > > > > That is because foo.py isn't a python script anymore, it is a shell script. > > Its purpose is to divert stderr to a file and to recite various > > things about the environment to that file in addition to any error > > messages. > > > > Just run it directly: > > > > ./foo.py > > > > The #! line should cause it to be run by the shell. > > > > I also recommend you try to do all this as your normal user account. > > Root is for administration, such as stopping/starting apache and > > so on. Not test running scripts from the command line; consider: > > if the script has bugs, as root it can do an awful lot of damage. > > > > | root at nikos [/home/nikos/public_html/foo-py]# > > | As far as thr tail -f of the error_log: > > | root at nikos [/home/nikos/public_html]# touch /var/log/httpd/error_log > > > > That won't do you much good; apache has not opened it, and so it > > will not be writing to it. It was writing to a file of that name, > > but you removed that file. Apache probably still has its hooks in the old > > file (which now has no name). > > > > Restarting apache should open (or create if missing) this file for you. > > > > | root at nikos [/home/nikos/public_html]# tail -f /var/log/httpd/error_log > > | and its empty even when at the exact same time i run 'python3 > > | metrites.py' from another interactive prompt when it supposed to > > | give live feed of the error messages. > > > > No, _apache_ writes to that file. So only when you visit the web > > page will stuff appear there. > > > > If you just run things from the command line, error messages will appear on your terminal. Or, after this line of the wrapper script: > > > > exec 2>>/home/nikos/cgi.err.out > > > > the error messages will appear in cgi.err.out. > > > > | Cameron would it be too much to ask to provide you with root > > | access to my VPS server so you can have a look there too? > > | i can pay you if you like if you wait a few days to gather some money. > > > > I really do not recommend that: > > > > - it is nuts to blithely allow a stranger root access to your system > > - you won't learn anything about CGI scripts > > > > What you need for further debugging of your python issues is access > > to the error messages from the CGI script. That is the purpose of > > the wrapper script. > > > > Get the wrapper running on the command line and then test it via the browser. > > > > Cheers, > > -- > > Cameron Simpson > > > > Lord grant me the serenity to accept the things I can not change, > > the courage to change the things that I can, > > and the wisdom to hide the bodies of those people I had to kill > > because they pissed me off. > > - Jeffrey Papen Well i trust you because you are the only one along with Lele that are helpimg me here: i tried what you said: root at nikos [/home/nikos/public_html/cgi-bin]# service httpd restart root at nikos [/home/nikos/public_html/cgi-bin]# python3 metrites.py root at nikos [/home/nikos/public_html]# cd foo-py/ root at nikos [/home/nikos/public_html/foo-py]# ls ./ ../ foo.py* root at nikos [/home/nikos/public_html/foo-py]# ./foo.py root at nikos [/home/nikos/public_html/foo-py]# cd .. root at nikos [/home/nikos/public_html]# cat cgi.err.out root at nikos [/home/nikos/public_html/cgi-bin]# cat /var/log/httpd/error_log root at nikos [/home/nikos/public_html/cgi-bin]# and i have run the script form browser but i still see nothing. I insist that you will make the most of this if you access the VPS yourself. it runs CentOS 6.4 Please accept, i trust you. From cs at zip.com.au Wed Apr 17 19:00:48 2013 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 18 Apr 2013 09:00:48 +1000 Subject: Unicode issue with Python v3.3 In-Reply-To: <5108f522-3117-41e6-9ad0-88ceed14398c@googlegroups.com> References: <5108f522-3117-41e6-9ad0-88ceed14398c@googlegroups.com> Message-ID: <20130417230048.GA46676@cskk.homeip.net> On 14Apr2013 04:22, nagia.retsina at gmail.com wrote: | > | Cameron would it be too much to ask to provide you with root | > | access to my VPS server so you can have a look there too? | > | i can pay you if you like if you wait a few days to gather some money. | > | > I really do not recommend that: | > - it is nuts to blithely allow a stranger root access to your system | > - you won't learn anything about CGI scripts [...] | I insist that you will make the most of this if you access the VPS yourself. | it runs CentOS 6.4 | Please accept, i trust you. Very well. Let's take this off list to personal email (note that the reply-to on this message is just myself, not the list/group). We can return here after sorting CGI issues, should there be any further python specific issues. Reply to this message. I will email you my ssh public key. Please make me an _ordinary_ user account called "cameron" and send me the ssh details of your VPS. -- Cameron Simpson TeX: When you pronounce it correctly to your computer, the terminal may become slightly moist. - D. E. Knuth. From nikos.gr33k at gmail.com Wed Apr 17 23:37:21 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 17 Apr 2013 20:37:21 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: <5108f522-3117-41e6-9ad0-88ceed14398c@googlegroups.com> Message-ID: <5b84d1d7-f769-4e4a-b033-9e2e4cc12f94@googlegroups.com> ?? ??????, 18 ???????? 2013 2:00:48 ?.?. UTC+3, ? ??????? Cameron Simpson ??????: > Reply to this message. I will email you my ssh public key. Please make me an > _ordinary_ user account called "cameron" and send me the ssh details of your > VPS. Thank you very much Cameron, i appreciate all your help and i'am willing to open you a free lifetime premium account at my webhosting as a token of appreciation. I have just mail you the login credentials. From nikos.gr33k at gmail.com Wed Apr 17 23:37:21 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Wed, 17 Apr 2013 20:37:21 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: <5108f522-3117-41e6-9ad0-88ceed14398c@googlegroups.com> Message-ID: <5b84d1d7-f769-4e4a-b033-9e2e4cc12f94@googlegroups.com> ?? ??????, 18 ???????? 2013 2:00:48 ?.?. UTC+3, ? ??????? Cameron Simpson ??????: > Reply to this message. I will email you my ssh public key. Please make me an > _ordinary_ user account called "cameron" and send me the ssh details of your > VPS. Thank you very much Cameron, i appreciate all your help and i'am willing to open you a free lifetime premium account at my webhosting as a token of appreciation. I have just mail you the login credentials. From nikos.gr33k at gmail.com Fri Apr 19 15:16:11 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Fri, 19 Apr 2013 12:16:11 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: <5108f522-3117-41e6-9ad0-88ceed14398c@googlegroups.com> Message-ID: <79a45556-6702-43f0-855a-e73db6012dc2@googlegroups.com> Hello Cameron, Did you received my yesterday's mail? From nikos.gr33k at gmail.com Mon Apr 15 14:42:11 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Mon, 15 Apr 2013 11:42:11 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: Message-ID: <751502a7-e2d4-4bb5-9712-100a7d6564f2@googlegroups.com> Hello, can you still help me please? From nikos.gr33k at gmail.com Mon Apr 15 14:42:11 2013 From: nikos.gr33k at gmail.com (=?ISO-8859-7?B?zd/q7/Igw+rxMzPq?=) Date: Mon, 15 Apr 2013 11:42:11 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: Message-ID: <751502a7-e2d4-4bb5-9712-100a7d6564f2@googlegroups.com> Hello, can you still help me please? From nagia.retsina at gmail.com Wed Apr 17 02:56:40 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Tue, 16 Apr 2013 23:56:40 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: Message-ID: ?? ???????, 14 ???????? 2013 12:28:32 ?.?. UTC+3, ? ??????? Cameron Simpson ??????: > On 13Apr2013 23:00, nagia.retsina at gmail.com wrote: > > | root at nikos [/home/nikos/public_html/foo-py]# pwd > > | /home/nikos/public_html/foo-py > > | root at nikos [/home/nikos/public_html/foo-py]# cat foo.py > > | #!/bin/sh > > | exec 2>>/home/nikos/cgi.err.out > > | echo "$0 $*" >&2 > > | id >&2 > > | env | sort >&2 > > | set -x > > | exec /full/path/to/foo-py ${1+"$@"} > > | > > | root at nikos [/home/nikos/public_html/foo-py]# python3 foo.py > > | File "foo.py", line 2 > > | exec 2>>/home/nikos/cgi.err.out > > | ^ > > | SyntaxError: invalid syntax > > > > That is because foo.py isn't a python script anymore, it is a shell script. > > Its purpose is to divert stderr to a file and to recite various > > things about the environment to that file in addition to any error > > messages. > > > > Just run it directly: > > > > ./foo.py > > > > The #! line should cause it to be run by the shell. > > > > I also recommend you try to do all this as your normal user account. > > Root is for administration, such as stopping/starting apache and > > so on. Not test running scripts from the command line; consider: > > if the script has bugs, as root it can do an awful lot of damage. > > > > | root at nikos [/home/nikos/public_html/foo-py]# > > | As far as thr tail -f of the error_log: > > | root at nikos [/home/nikos/public_html]# touch /var/log/httpd/error_log > > > > That won't do you much good; apache has not opened it, and so it > > will not be writing to it. It was writing to a file of that name, > > but you removed that file. Apache probably still has its hooks in the old > > file (which now has no name). > > > > Restarting apache should open (or create if missing) this file for you. > > > > | root at nikos [/home/nikos/public_html]# tail -f /var/log/httpd/error_log > > | and its empty even when at the exact same time i run 'python3 > > | metrites.py' from another interactive prompt when it supposed to > > | give live feed of the error messages. > > > > No, _apache_ writes to that file. So only when you visit the web > > page will stuff appear there. > > > > If you just run things from the command line, error messages will appear on your terminal. Or, after this line of the wrapper script: > > > > exec 2>>/home/nikos/cgi.err.out > > > > the error messages will appear in cgi.err.out. > > > > | Cameron would it be too much to ask to provide you with root > > | access to my VPS server so you can have a look there too? > > | i can pay you if you like if you wait a few days to gather some money. > > > > I really do not recommend that: > > > > - it is nuts to blithely allow a stranger root access to your system > > - you won't learn anything about CGI scripts > > > > What you need for further debugging of your python issues is access > > to the error messages from the CGI script. That is the purpose of > > the wrapper script. > > > > Get the wrapper running on the command line and then test it via the browser. > > > > Cheers, > > -- > > Cameron Simpson > > > > Lord grant me the serenity to accept the things I can not change, > > the courage to change the things that I can, > > and the wisdom to hide the bodies of those people I had to kill > > because they pissed me off. > > - Jeffrey Papen cameron, can you help please or tell me what else i need to try? Hello From nagia.retsina at gmail.com Wed Apr 17 02:56:40 2013 From: nagia.retsina at gmail.com (nagia.retsina at gmail.com) Date: Tue, 16 Apr 2013 23:56:40 -0700 (PDT) Subject: Unicode issue with Python v3.3 In-Reply-To: References: Message-ID: ?? ???????, 14 ???????? 2013 12:28:32 ?.?. UTC+3, ? ??????? Cameron Simpson ??????: > On 13Apr2013 23:00, nagia.retsina at gmail.com wrote: > > | root at nikos [/home/nikos/public_html/foo-py]# pwd > > | /home/nikos/public_html/foo-py > > | root at nikos [/home/nikos/public_html/foo-py]# cat foo.py > > | #!/bin/sh > > | exec 2>>/home/nikos/cgi.err.out > > | echo "$0 $*" >&2 > > | id >&2 > > | env | sort >&2 > > | set -x > > | exec /full/path/to/foo-py ${1+"$@"} > > | > > | root at nikos [/home/nikos/public_html/foo-py]# python3 foo.py > > | File "foo.py", line 2 > > | exec 2>>/home/nikos/cgi.err.out > > | ^ > > | SyntaxError: invalid syntax > > > > That is because foo.py isn't a python script anymore, it is a shell script. > > Its purpose is to divert stderr to a file and to recite various > > things about the environment to that file in addition to any error > > messages. > > > > Just run it directly: > > > > ./foo.py > > > > The #! line should cause it to be run by the shell. > > > > I also recommend you try to do all this as your normal user account. > > Root is for administration, such as stopping/starting apache and > > so on. Not test running scripts from the command line; consider: > > if the script has bugs, as root it can do an awful lot of damage. > > > > | root at nikos [/home/nikos/public_html/foo-py]# > > | As far as thr tail -f of the error_log: > > | root at nikos [/home/nikos/public_html]# touch /var/log/httpd/error_log > > > > That won't do you much good; apache has not opened it, and so it > > will not be writing to it. It was writing to a file of that name, > > but you removed that file. Apache probably still has its hooks in the old > > file (which now has no name). > > > > Restarting apache should open (or create if missing) this file for you. > > > > | root at nikos [/home/nikos/public_html]# tail -f /var/log/httpd/error_log > > | and its empty even when at the exact same time i run 'python3 > > | metrites.py' from another interactive prompt when it supposed to > > | give live feed of the error messages. > > > > No, _apache_ writes to that file. So only when you visit the web > > page will stuff appear there. > > > > If you just run things from the command line, error messages will appear on your terminal. Or, after this line of the wrapper script: > > > > exec 2>>/home/nikos/cgi.err.out > > > > the error messages will appear in cgi.err.out. > > > > | Cameron would it be too much to ask to provide you with root > > | access to my VPS server so you can have a look there too? > > | i can pay you if you like if you wait a few days to gather some money. > > > > I really do not recommend that: > > > > - it is nuts to blithely allow a stranger root access to your system > > - you won't learn anything about CGI scripts > > > > What you need for further debugging of your python issues is access > > to the error messages from the CGI script. That is the purpose of > > the wrapper script. > > > > Get the wrapper running on the command line and then test it via the browser. > > > > Cheers, > > -- > > Cameron Simpson > > > > Lord grant me the serenity to accept the things I can not change, > > the courage to change the things that I can, > > and the wisdom to hide the bodies of those people I had to kill > > because they pissed me off. > > - Jeffrey Papen cameron, can you help please or tell me what else i need to try? Hello From rosuav at gmail.com Wed Apr 17 03:01:43 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Apr 2013 17:01:43 +1000 Subject: Unicode issue with Python v3.3 In-Reply-To: References: Message-ID: On Wed, Apr 17, 2013 at 4:56 PM, wrote: > can you help please or tell me what else i need to try? You need to try trimming quoted text in replies, not double-spacing, and paying for help. ChrisA From rosuav at gmail.com Wed Apr 17 03:32:18 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Apr 2013 17:32:18 +1000 Subject: Unicode issue with Python v3.3 In-Reply-To: References: Message-ID: On Wed, Apr 17, 2013 at 4:56 PM, wrote: > can you help please or tell me what else i need to try? You need to try trimming quoted text in replies, not double-spacing, and paying for help. ChrisA From jabba.laci at gmail.com Wed Apr 10 04:44:08 2013 From: jabba.laci at gmail.com (Jabba Laci) Date: Wed, 10 Apr 2013 10:44:08 +0200 Subject: extract HTML table in a structured format Message-ID: Hi, I wonder if there is a nice way to extract a whole HTML table and have the result in a nice structured format. What I want is to have the lifetime table at the bottom of this page: http://en.wikipedia.org/wiki/List_of_Ubuntu_releases (then figure out with a script until when my Ubuntu release is supported). I could do it with BeautifulSoup or lxml but is there a better way? There should be :) Thanks, Laszlo -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at gmail.com Wed Apr 10 14:11:33 2013 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 10 Apr 2013 19:11:33 +0100 Subject: extract HTML table in a structured format In-Reply-To: References: Message-ID: On 10 April 2013 09:44, Jabba Laci wrote: > Hi, > > I wonder if there is a nice way to extract a whole HTML table and have the > result in a nice structured format. What I want is to have the lifetime > table at the bottom of this page: > http://en.wikipedia.org/wiki/List_of_Ubuntu_releases (then figure out with a > script until when my Ubuntu release is supported). > > I could do it with BeautifulSoup or lxml but is there a better way? There > should be :) Instead of parsing HTML, you could just parse the source of the page (available via action=raw): ------------------------------ import urllib2 url = ( 'http://en.wikipedia.org/w/index.php' '?title=List_of_Ubuntu_releases&action=raw' ) source = urllib2.urlopen(url).read() # Table rows are separated with the line "|-" # Then there is a line starting with "|" potential_rows = source.split("\n|-\n|") rows = [] for row in potential_rows: # Rows in the table start with a link (' [[ ... ]]') if row.startswith(" [["): row = [item.strip() for item in row.split("\n|")] rows.append(row) ------------------------------ >>> import pprint >>> pprint.pprint(rows) [['[[Warty Warthog|4.10]]', 'Warty Warthog', '20 October 2004', 'colspan="2" {{Version |o |30 April 2006}}', '2.6.8'], ['[[Hoary Hedgehog|5.04]]', 'Hoary Hedgehog', '8 April 2005', 'colspan="2" {{Version |o |31 October 2006}}', '2.6.10'], ['[[Breezy Badger|5.10]]', 'Breezy Badger', '13 October 2005', 'colspan="2" {{Version |o |13 April 2007}}', '2.6.12'], ['[[Ubuntu 6.06|6.06 LTS]]', 'Dapper Drake', '1 June 2006', '{{Version |o | 14 July 2009}}', '{{Version |o | 1 June 2011}}', '2.6.15'], ['[[Ubuntu 6.10|6.10]]', 'Edgy Eft', '26 October 2006', 'colspan="2" {{Version |o | 25 April 2008}}', '2.6.17'], [...] ] >>> That should give you the info you need (until the wiki page changes too much!) -- Arnaud From jabba.laci at gmail.com Wed Apr 10 14:15:17 2013 From: jabba.laci at gmail.com (Jabba Laci) Date: Wed, 10 Apr 2013 20:15:17 +0200 Subject: extract HTML table in a structured format In-Reply-To: References: Message-ID: Hi, Thanks, it's a great idea to parse the wiki source. Since then I have found a command for this particular task called "ubuntu-support-status" that shows what I need. But the idea to extract an HTML table from a webpage in a structured format could be an interesting (and useful) project idea. Best, Laszlo On Wed, Apr 10, 2013 at 8:11 PM, Arnaud Delobelle wrote: > On 10 April 2013 09:44, Jabba Laci wrote: > > Hi, > > > > I wonder if there is a nice way to extract a whole HTML table and have > the > > result in a nice structured format. What I want is to have the lifetime > > table at the bottom of this page: > > http://en.wikipedia.org/wiki/List_of_Ubuntu_releases (then figure out > with a > > script until when my Ubuntu release is supported). > > > > I could do it with BeautifulSoup or lxml but is there a better way? There > > should be :) > > Instead of parsing HTML, you could just parse the source of the page > (available via action=raw): > > ------------------------------ > import urllib2 > > url = ( > 'http://en.wikipedia.org/w/index.php' > '?title=List_of_Ubuntu_releases&action=raw' > ) > > source = urllib2.urlopen(url).read() > > # Table rows are separated with the line "|-" > # Then there is a line starting with "|" > potential_rows = source.split("\n|-\n|") > > rows = [] > > for row in potential_rows: > # Rows in the table start with a link (' [[ ... ]]') > if row.startswith(" [["): > row = [item.strip() for item in row.split("\n|")] > rows.append(row) > ------------------------------ > > >>> import pprint > >>> pprint.pprint(rows) > [['[[Warty Warthog|4.10]]', > 'Warty Warthog', > '20 October 2004', > 'colspan="2" {{Version |o |30 April 2006}}', > '2.6.8'], > ['[[Hoary Hedgehog|5.04]]', > 'Hoary Hedgehog', > '8 April 2005', > 'colspan="2" {{Version |o |31 October 2006}}', > '2.6.10'], > ['[[Breezy Badger|5.10]]', > 'Breezy Badger', > '13 October 2005', > 'colspan="2" {{Version |o |13 April 2007}}', > '2.6.12'], > ['[[Ubuntu 6.06|6.06 LTS]]', > 'Dapper Drake', > '1 June 2006', > '{{Version |o | 14 July 2009}}', > '{{Version |o | 1 June 2011}}', > '2.6.15'], > ['[[Ubuntu 6.10|6.10]]', > 'Edgy Eft', > '26 October 2006', > 'colspan="2" {{Version |o | 25 April 2008}}', > '2.6.17'], > [...] > ] > >>> > > That should give you the info you need (until the wiki page changes too > much!) > > -- > Arnaud > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Apr 10 21:04:45 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Apr 2013 11:04:45 +1000 Subject: extract HTML table in a structured format In-Reply-To: References: Message-ID: On Thu, Apr 11, 2013 at 4:15 AM, Jabba Laci wrote: > Hi, > > Thanks, it's a great idea to parse the wiki source. Since then I have found > a command for this particular task called "ubuntu-support-status" that shows > what I need. That sounds like an even better option. Anything that depends on parsing a wiki is vulnerable to format changes at a moment's notice, even worse than other web page parsing. > But the idea to extract an HTML table from a webpage in a structured format > could be an interesting (and useful) project idea. There are, unfortunately, too many different ways this can be done. Too many differences in HTML that a human eye would read as the same thing. I'd recommend either BeautifulSoup or specifically looking at the HTML to be parsed and finding a shortcut from that. ChrisA From ramit.prasad at jpmorgan.com Fri Apr 12 18:00:25 2013 From: ramit.prasad at jpmorgan.com (Prasad, Ramit) Date: Fri, 12 Apr 2013 22:00:25 +0000 Subject: extract HTML table in a structured format In-Reply-To: References: Message-ID: <5B80DD153D7D744689F57F4FB69AF474182F7067@SCACMX008.exchad.jpmchase.net> Jabba Laci > Hi, > > I wonder if there is a nice way to extract a whole HTML table and have the result in a nice structured > format. What I want is to have the lifetime table at the bottom of this page: > http://en.wikipedia.org/wiki/List_of_Ubuntu_releases (then figure out with a script until when my > Ubuntu release is supported). > > I could do it with BeautifulSoup or lxml but is there a better way? There should be :) > I know you already answered your question, but thought this might be helpful in the future. Wikipedia has an API for programmatic access. http://www.mediawiki.org/wiki/API ~Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. From martaamunar at gmail.com Wed Apr 10 04:40:55 2013 From: martaamunar at gmail.com (martaamunar at gmail.com) Date: Wed, 10 Apr 2013 01:40:55 -0700 (PDT) Subject: use a loop to create lists Message-ID: <4c47da9e-c632-4855-98a7-0506d8013046@googlegroups.com> Hi! I would like to create a list containing lists. I need each list to have a differente name and i would like to use a loop to name the list. But as the name, is a string, i cannot asign it to a value... how can I do that?? global_list=[] for i in range (20): ("list_"+i)=[] #These would be the name of the list... global_list.append("list_"+i) Thank you!!!!! From rosuav at gmail.com Wed Apr 10 04:52:39 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Apr 2013 18:52:39 +1000 Subject: use a loop to create lists In-Reply-To: <4c47da9e-c632-4855-98a7-0506d8013046@googlegroups.com> References: <4c47da9e-c632-4855-98a7-0506d8013046@googlegroups.com> Message-ID: On Wed, Apr 10, 2013 at 6:40 PM, wrote: > Hi! > > I would like to create a list containing lists. I need each list to have a differente name and i would like to use a loop to name the list. But as the name, is a string, i cannot asign it to a value... how can I do that?? > > > global_list=[] > for i in range (20): > ("list_"+i)=[] #These would be the name of the list... > global_list.append("list_"+i) They don't need unique names. Just use the same name inside the loop: global_list=[] for i in range(20): current_list=[] # Presumably you do something with it here global_list.append(current_list) That'll work fine, and you can reference the lists by their positions in global_list. ChrisA From davea at davea.name Wed Apr 10 08:36:12 2013 From: davea at davea.name (Dave Angel) Date: Wed, 10 Apr 2013 08:36:12 -0400 Subject: use a loop to create lists In-Reply-To: <4c47da9e-c632-4855-98a7-0506d8013046@googlegroups.com> References: <4c47da9e-c632-4855-98a7-0506d8013046@googlegroups.com> Message-ID: <51655CBC.3040004@davea.name> On 04/10/2013 04:40 AM, martaamunar at gmail.com wrote: > Hi! > > I would like to create a list containing lists. I need each list to have a differente name and i would like to use a loop to name the list. But as the name, is a string, i cannot asign it to a value... how can I do that?? > > > global_list=[] > for i in range (20): > ("list_"+i)=[] #These would be the name of the list... > global_list.append("list_"+i) > > Thank you!!!!! > The fact that the content of the outer list also happens to be lists is irrelevant to your question. I believe the real question here is how to create an arbitrary bunch of new names, and bind them to elements of he list. In general, you can't. But more importantly, in general you don't want to. If you come up with a convoluted way to fake it, you'll have to use the same convoluted way to access those names, so there's no point. As Chris says, just reference them by index. On the other hand, if the outer list happens to have exactly 7 elements, and you know that ahead of time, then it may well make sense to assign names to them. Not list_0 through list_6, but name, addr1, ec. global_list = [] for i in range(7): global_list.append[] first_name, mid_name, last_name, addr1, addr2, city, town = global_list Incidentally, that's approximately what a collections.namedtuple is all about, giving names to items that are otherwise considered elements of a tuple. -- DaveA From rustompmody at gmail.com Wed Apr 10 11:31:50 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 10 Apr 2013 08:31:50 -0700 (PDT) Subject: use a loop to create lists References: <4c47da9e-c632-4855-98a7-0506d8013046@googlegroups.com> Message-ID: On Apr 10, 1:40?pm, martaamu... at gmail.com wrote: > Hi! > > I would like to create a list containing lists. I need each list to have a differente name and i would like to use a loop to name the list. But as the name, is a string, i cannot asign it to a value... how can I do that?? > > global_list=[] > for i in range (20): > ? ("list_"+i)=[] ? #These would be the name of the list... > ? global_list.append("list_"+i) > > Thank you!!!!! If as Chris points out you dont actually need names, a list should suffice (with indexing serving as 'naming') If however there are a fixed (at program-writing time) small set of names, you can do as Dave suggests and use unpacking assignment. [Some people like to use objects for this] If however you need an arbitrary set of names, unknown at programming time, a dictionary is typically what is appropriate: For dictionary d - get the value of name n with d[n] - set (bind) name n to value v in dict d with d[n] = v Which of these options you should follow is not clear from your question; you need to tell us a bit more about what you are trying to do. From Thomas.Goebel at ohm-hochschule.de Wed Apr 10 09:55:54 2013 From: Thomas.Goebel at ohm-hochschule.de (Thomas Goebel) Date: Wed, 10 Apr 2013 15:55:54 +0200 Subject: use a loop to create lists In-Reply-To: <4c47da9e-c632-4855-98a7-0506d8013046@googlegroups.com> References: <4c47da9e-c632-4855-98a7-0506d8013046@googlegroups.com> Message-ID: <51656F6A.5040103@th-nuernberg.de> * On 10/04/2013 10:40, martaamunar at gmail.com wrote: > Hi! > > I would like to create a list containing lists. I need each list to > have a differente name and i would like to use a loop to name the > list. > [...] > global_list=[] > for i in range (20): > ("list_"+i)=[] #These would be the name of the list... > global_list.append("list_"+i) You can use a dictionary instead of a list of lists: global_list = {'_'.join(['list', str(i)]):[] for i in range(20)} global_list_1 = global_list['list_0'] From kelnreiter at gmail.com Thu Apr 11 08:11:52 2013 From: kelnreiter at gmail.com (Franz Kelnreiter) Date: Thu, 11 Apr 2013 14:11:52 +0200 Subject: Fwd: use a loop to create lists In-Reply-To: References: <4c47da9e-c632-4855-98a7-0506d8013046@googlegroups.com> <51656F6A.5040103@th-nuernberg.de> <5166A297.70104@th-nuernberg.de> Message-ID: ---------- Forwarded message ---------- From: Franz Kelnreiter Date: Thu, Apr 11, 2013 at 2:09 PM Subject: Re: use a loop to create lists To: Thomas.Goebel at ohm-hochschule.de On Thu, Apr 11, 2013 at 1:46 PM, Thomas Goebel < Thomas.Goebel at ohm-hochschule.de> wrote: > * On 11/04/2013 13:25, Franz Kelnreiter wrote: > > On Wed, Apr 10, 2013 at 3:55 PM, Thomas Goebel wrote: > >> > >> global_list = {'_'.join(['list', str(i)]):[] for i in range(20)} > >> global_list_1 = global_list['list_0'] -- > > > > Sorry Thomas, but you had a typo or in any case a wrong syntax > > concept in your last posting. If you'd like to use list > > comprehension it should be written as: > > > > mydict = {'_'.join(['list', str(i)]):[x for x in range(20)]} > > Hi Franz, > > the difference between your and my code is that > > global_list = {'_'.join(['list', str(i)]):[] for i in range(20)} > > creates a dict 'global_list' which has 20 keys named from 'list_0' to > 'list_19'. The value for all keys is an empty list. If you want to > create i.e. 20 keys which value is a list with 20 ints you have to use > > global_list = ({'_'.join(['list', str(i)]):[a for a in range(20)] for > i in range(20)}) > > Your code creates a dict with one key 'list_19' which value is a list > with 20 ints if you replace str(i) with str(a). > > Regards, Tom > Tom, Thanks for your explanation, I think I know what you want to do and I would very much like to understand your code in detail - maybe I am too stupid - but when I execute the value part of your code construct: [a for a in range(20)] for i in range(20) I get a syntax error, as I exepected (Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19)). So how can you get me on the right direction to make your code running on my machine? Thank you, Franz -------------- next part -------------- An HTML attachment was scrubbed... URL: From Thomas.Goebel at ohm-hochschule.de Thu Apr 11 08:57:41 2013 From: Thomas.Goebel at ohm-hochschule.de (Thomas Goebel) Date: Thu, 11 Apr 2013 14:57:41 +0200 Subject: use a loop to create lists In-Reply-To: References: <4c47da9e-c632-4855-98a7-0506d8013046@googlegroups.com> <51656F6A.5040103@th-nuernberg.de> <5166A297.70104@th-nuernberg.de> Message-ID: <5166B345.8080200@th-nuernberg.de> * On 11/04/2013 14:11, Franz Kelnreiter wrote: > On Thu, Apr 11, 2013 at 1:46 PM, Thomas Goebel wrote: >> >> the difference between your and my code is that >> >> global_list = {'_'.join(['list', str(i)]):[] for i in range(20)} >> >> creates a dict 'global_list' which has 20 keys named from 'list_0' to >> 'list_19'. The value for all keys is an empty list. If you want to >> create i.e. 20 keys which value is a list with 20 ints you have to use >> >> global_list = ({'_'.join(['list', str(i)]):[a for a in range(20)] for >> i in range(20)}) > > Thanks for your explanation, I think I know what you want to do and I would > very much like to understand your code in detail - maybe I am too stupid - > but when I execute the value part of your code construct: This code > [a for a in range(20)] for i in range(20) won't run because you you didn't define 'i'! [a for a in range(3)] will return a list [0, 1, 2] To get a dict with n keys we can use a for-loop, too: d = {} for n in range(3): # Create keys 'list_0' to 'list_n' d['list_' + str(n)] = [] So we finally get: d.keys() ['list_2', 'list_1', 'list_0'] d.values() [[], [], []] Now we create a dict with n keys and for every key n we set the value to a list of m ints: e = {} for n in range(3): # Create keys 'list_0' to 'list_n' e['list_' + str(n)] = [] for m in range(3): # Create a list [0, 1, 2] for every key of e e['list_' + str(n)].append(m) The results is as follows: e.keys() ['list_2', 'list_1', 'list_0'] e.values() [[0, 1, 2], [0, 1, 2], [0, 1, 2]] Which is the same as: f = {'list_' + str(n):[m for m in range(3)] for n in range(3)} I double checked the code and everything is working fine for me. Maybe you forgot some braces? P.S: I'm running on python 2.7.4: '2.7.4 (default, Apr 6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)]' From rosuav at gmail.com Thu Apr 11 09:22:41 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Apr 2013 23:22:41 +1000 Subject: use a loop to create lists In-Reply-To: <5166B345.8080200@th-nuernberg.de> References: <4c47da9e-c632-4855-98a7-0506d8013046@googlegroups.com> <51656F6A.5040103@th-nuernberg.de> <5166A297.70104@th-nuernberg.de> <5166B345.8080200@th-nuernberg.de> Message-ID: On Thu, Apr 11, 2013 at 10:57 PM, Thomas Goebel wrote: > [a for a in range(3)] > > will return a list > [0, 1, 2] Simplification possible: That's the same as: list(range(3)) > f = {'list_' + str(n):[m for m in range(3)] for n in range(3)} Meaning that this can be simplified too: f = {'list_' + str(n):list(range(3)) for n in range(3)} ChrisA From kelnreiter at gmail.com Thu Apr 11 10:11:13 2013 From: kelnreiter at gmail.com (Franz Kelnreiter) Date: Thu, 11 Apr 2013 16:11:13 +0200 Subject: use a loop to create lists In-Reply-To: <5166B345.8080200@th-nuernberg.de> References: <4c47da9e-c632-4855-98a7-0506d8013046@googlegroups.com> <51656F6A.5040103@th-nuernberg.de> <5166A297.70104@th-nuernberg.de> <5166B345.8080200@th-nuernberg.de> Message-ID: On Thu, Apr 11, 2013 at 2:57 PM, Thomas Goebel < Thomas.Goebel at ohm-hochschule.de> wrote: > ... > Which is the same as: > f = {'list_' + str(n):[m for m in range(3)] for n in range(3)} > Thomas, thank you for your patience and your long explanation! Now I understand better this shorthand expression of one single 'pythonic' ;) line. But didnt you miss square brackets: f = {'list_' + str(n):[[m for m in range(3)] for n in range(3)]} ?? Otherwise the code wont work for me... -------------- next part -------------- An HTML attachment was scrubbed... URL: From Thomas.Goebel at ohm-hochschule.de Thu Apr 11 10:33:21 2013 From: Thomas.Goebel at ohm-hochschule.de (Thomas Goebel) Date: Thu, 11 Apr 2013 16:33:21 +0200 Subject: use a loop to create lists In-Reply-To: References: <4c47da9e-c632-4855-98a7-0506d8013046@googlegroups.com> <51656F6A.5040103@th-nuernberg.de> <5166A297.70104@th-nuernberg.de> <5166B345.8080200@th-nuernberg.de> Message-ID: <5166C9B1.2070407@th-nuernberg.de> * On 11/04/2013 16:11, Franz Kelnreiter wrote: > On Thu, Apr 11, 2013 at 2:57 PM, Thomas Goebel < > Thomas.Goebel at ohm-hochschule.de> wrote: > >> ... >> Which is the same as: >> f = {'list_' + str(n):[m for m in range(3)] for n in range(3)} >> > [...] > But didnt you miss square brackets: > > f = {'list_' + str(n):[[m for m in range(3)] for n in range(3)]} If i try your code i get a dict with key 'list_2' which value is a list of three lists. Maybe this occurs because we're using different python versions?! I never used python<2.7! Have you tried this one d2 = dict(('list_' + str(i), list(range(3))) for i in range(3)) with Chris' simplification: * On 11/04/2013 15:22, Chris Angelico wrote: > On Thu, Apr 11, 2013 at 10:57 PM, Thomas Goebel wrote: >> [a for a in range(3)] >> >> will return a list >> [0, 1, 2] > > Simplification possible: That's the same as: > > list(range(3)) > >> f = {'list_' + str(n):[m for m in range(3)] for n in range(3)} > > Meaning that this can be simplified too: > > f = {'list_' + str(n):list(range(3)) for n in range(3)} From Thomas.Goebel at ohm-hochschule.de Thu Apr 11 09:43:09 2013 From: Thomas.Goebel at ohm-hochschule.de (Thomas Goebel) Date: Thu, 11 Apr 2013 15:43:09 +0200 Subject: Fwd: use a loop to create lists In-Reply-To: References: <4c47da9e-c632-4855-98a7-0506d8013046@googlegroups.com> <51656F6A.5040103@th-nuernberg.de> <5166A297.70104@th-nuernberg.de> Message-ID: <5166BDED.7090002@th-nuernberg.de> * On 11/04/2013 14:11, Franz Kelnreiter wrote: > On Thu, Apr 11, 2013 at 1:46 PM, Thomas Goebel wrote: > >> global_list = {'_'.join(['list', str(i)]):[] for i in range(20)} > > Thanks for your explanation, I think I know what you want to do and I would > very much like to understand your code in detail - maybe I am too stupid - > but when I execute the value part of your code construct: > > [a for a in range(20)] for i in range(20) > > I get a syntax error, as I exepected (Python 2.6.4 (r264:75708, Oct 26 > 2009, 08:23:19)). Sorry Franz, as you are using python 2.6 you have to use d1 = dict(('list_' + str(i), []) for i in range(3)) d2 = dict(('list_' + str(i), [m for m in range(3)]) for i in range(3)) like stated here: http://stackoverflow.com/questions/1747817/python-create-a-dictionary-with-list-comprehension From kelnreiter at gmail.com Thu Apr 11 10:33:41 2013 From: kelnreiter at gmail.com (Franz Kelnreiter) Date: Thu, 11 Apr 2013 16:33:41 +0200 Subject: Fwd: use a loop to create lists In-Reply-To: <5166BDED.7090002@th-nuernberg.de> References: <4c47da9e-c632-4855-98a7-0506d8013046@googlegroups.com> <51656F6A.5040103@th-nuernberg.de> <5166A297.70104@th-nuernberg.de> <5166BDED.7090002@th-nuernberg.de> Message-ID: On Thu, Apr 11, 2013 at 3:43 PM, Thomas Goebel < Thomas.Goebel at ohm-hochschule.de> wrote: > ... > > I get a syntax error, as I exepected (Python 2.6.4 (r264:75708, Oct 26 > > 2009, 08:23:19)). > > Sorry Franz, > > as you are using python 2.6 you have to use > > d1 = dict(('list_' + str(i), []) for i in range(3)) > d2 = dict(('list_' + str(i), [m for m in range(3)]) for i in range(3)) > > like stated here: > > http://stackoverflow.com/questions/1747817/python-create-a-dictionary-with-list-comprehension > -- > Thank you, Thomas, for your last posting and your help, that makes everything clear for me now! All best, Franz -------------- next part -------------- An HTML attachment was scrubbed... URL: From ulrich.eckhardt at dominolaser.com Wed Apr 10 04:18:04 2013 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Wed, 10 Apr 2013 10:18:04 +0200 Subject: name lookup failure using metaclasses with unittests Message-ID: Hi! I'm having problems using a metaclass to generate test functions. This works when I try to run all tests from the module or test case, but it fails when I'm trying to specify a single test function. My environment is Python 2.7.3 on MS Windows 7 at the moment. It should be upgraded to at least 2.7.4 or better to 3, but see the notes on Python 3 below. # my_module.py import unittest class X(unittest.TestCase): def __metaclass__(name, bases, dict): # attach function def test(self): pass dict['test_1'] = test dict['test_2'] = test # create class return type(name, bases, dict) The error when I'm trying to run "python -m unittest my_module.X.test_1" is: "Value error: no such test method in : test". The astonishing part is that it claims that "test" is not found while I asked it to run "test_1". The name it complains about is the name of the function inside the metaclass function. In all other cases, like e.g. giving "-v" it reports the correct function name. My question here is whether I'm doing something wrong or whether I discovered a bug. Now, concerning Python 3, it fails to detect any test case at all! My guess is that the unittest library was changed to use metaclasses itself in order to detect classes derived from unittest.TestCase. Therefore, overriding the metaclass breaks test case discovery. My question in that context is how do I extend metaclasses instead of overriding it? In other words, what is the equivalent to super() for class creation? Thank you for your help! Uli From __peter__ at web.de Wed Apr 10 05:52:56 2013 From: __peter__ at web.de (Peter Otten) Date: Wed, 10 Apr 2013 11:52:56 +0200 Subject: name lookup failure using metaclasses with unittests References: Message-ID: Ulrich Eckhardt wrote: > Hi! > > I'm having problems using a metaclass to generate test functions. This > works when I try to run all tests from the module or test case, but it > fails when I'm trying to specify a single test function. My environment > is Python 2.7.3 on MS Windows 7 at the moment. It should be upgraded to > at least 2.7.4 or better to 3, but see the notes on Python 3 below. > > # my_module.py > import unittest > class X(unittest.TestCase): > def __metaclass__(name, bases, dict): > # attach function > def test(self): > pass > dict['test_1'] = test > dict['test_2'] = test > # create class > return type(name, bases, dict) > > The error when I'm trying to run "python -m unittest my_module.X.test_1" > is: "Value error: no such test method in : test". > The astonishing part is that it claims that "test" is not found while I > asked it to run "test_1". The name it complains about is the name of the > function inside the metaclass function. In all other cases, like e.g. > giving "-v" it reports the correct function name. My question here is > whether I'm doing something wrong or whether I discovered a bug. Here's a simpler demo of the problem: $ cat tmp.py import unittest class X(unittest.TestCase): def test_1(self): pass test_1.__name__ = "test_2" $ python -m unittest -v tmp test_1 (tmp.X) ... ok ---------------------------------------------------------------------- Ran 1 test in 0.001s OK $ python -m unittest -v tmp.X.test_1 Traceback (most recent call last): File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main "__main__", fname, loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/usr/lib/python2.7/unittest/__main__.py", line 12, in main(module=None) File "/usr/lib/python2.7/unittest/main.py", line 94, in __init__ self.parseArgs(argv) File "/usr/lib/python2.7/unittest/main.py", line 149, in parseArgs self.createTests() File "/usr/lib/python2.7/unittest/main.py", line 158, in createTests self.module) File "/usr/lib/python2.7/unittest/loader.py", line 128, in loadTestsFromNames suites = [self.loadTestsFromName(name, module) for name in names] File "/usr/lib/python2.7/unittest/loader.py", line 109, in loadTestsFromName return self.suiteClass([parent(obj.__name__)]) File "/usr/lib/python2.7/unittest/case.py", line 191, in __init__ (self.__class__, methodName)) ValueError: no such test method in : test_2 It looks like this particular invocation relies on class attribute and function __name__ being identical. Please file a bug report. > Now, concerning Python 3, it fails to detect any test case at all! My > guess is that the unittest library was changed to use metaclasses itself > in order to detect classes derived from unittest.TestCase. Therefore, > overriding the metaclass breaks test case discovery. My question in that > context is how do I extend metaclasses instead of overriding it? In > other words, what is the equivalent to super() for class creation? Python 3 does not recognize the __metaclass__ attribute as the metaclass. You need to provide it like so: def __metaclass__(name, bases, dict): ... class X(unittest.TestCase, metaclass=__metaclass__): pass From ulrich.eckhardt at dominolaser.com Thu Apr 11 03:09:03 2013 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 11 Apr 2013 09:09:03 +0200 Subject: name lookup failure using metaclasses with unittests In-Reply-To: References: Message-ID: Am 10.04.2013 11:52, schrieb Peter Otten: > It looks like this particular invocation relies on class attribute and > function __name__ being identical. > > Please file a bug report. http://bugs.python.org/issue17696 Uli From ulrich.eckhardt at dominolaser.com Thu Apr 11 02:43:58 2013 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Thu, 11 Apr 2013 08:43:58 +0200 Subject: name lookup failure using metaclasses with unittests In-Reply-To: References: Message-ID: Am 10.04.2013 11:52, schrieb Peter Otten: > Ulrich Eckhardt wrote: [...] > It looks like this particular invocation relies on class attribute and > function __name__ being identical. > > Please file a bug report. Thanks for confirming this and reducing the test case even more. >> Now, concerning Python 3, it fails to detect any test case at all! My >> guess is that the unittest library was changed to use metaclasses itself >> in order to detect classes derived from unittest.TestCase. Therefore, >> overriding the metaclass breaks test case discovery. My question in that >> context is how do I extend metaclasses instead of overriding it? In >> other words, what is the equivalent to super() for class creation? > > Python 3 does not recognize the __metaclass__ attribute as the metaclass. > You need to provide it like so: > > def __metaclass__(name, bases, dict): > ... > > class X(unittest.TestCase, metaclass=__metaclass__): > pass :| Doing some research[0, 1] on metaclasses in 2 and 3, I have a few more questions... The first thing I was wondering was why Python doesn't complain about a class property that is marked as special (leading and trailing double underscores) but that it knows nothing about. Worse, Python 3 should be aware of its legacy and recognize the Python 2 metaclass syntax, even if only to reject it loudly. I'm pretty sure there is a reason for that, The second question that came up was if there is a way to keep a metaclass defined inside the class or if the only way is to provide it externally. The reason I like this in-class definition is that for my case of autogenerated test functions, everything is in one place which used to be in a loop that modified the class after its creation. Maybe I'm just too brainwashed by static languages though. To get the Python2 feeling back, I have a hack in mind that involves creating a baseclass which in turn provides a metaclass that invokes a specific function to post-initialize the class, similar to the way Python 2 does it automatically, but I'm wondering if there isn't anything better. Also PEP 3115 "Metaclasses in Python 3000"[2] seems to consider postprocessing of a class definition as better handled by a class decorator, which is something I haven't looked at yet. Greetings from Hamburg! Uli [0] http://mikewatkins.ca/2008/11/29/python-2-and-3-metaclasses/ [1] http://www.artima.com/weblogs/viewpost.jsp?thread=236234 [2] http://www.python.org/dev/peps/pep-3115/ From steve+comp.lang.python at pearwood.info Thu Apr 11 04:19:27 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Apr 2013 08:19:27 GMT Subject: name lookup failure using metaclasses with unittests References: Message-ID: <5166720e$0$29977$c3e8da3$5496439d@news.astraweb.com> On Thu, 11 Apr 2013 08:43:58 +0200, Ulrich Eckhardt wrote: > The first thing I was wondering was why Python doesn't complain about a > class property that is marked as special (leading and trailing double > underscores) but that it knows nothing about. Because that breaks backward compatibility. You write a class in Python 2.6 or 2.7, and make it backward compatible with 2.5: class MyIterator(object): def __next__(self): ... next = __next__ Now you import it into Python 2.5, which has no idea about __next__ so it blows up. (For no good reason, since __next__ is harmless in 2.5.) > Worse, Python 3 should be > aware of its legacy and recognize the Python 2 metaclass syntax, even if > only to reject it loudly. I'm pretty sure there is a reason for that, That will break any future re-use of __metaclass__. It will also make version agnostic code much harder: class Meta(type): ... if sys.version >= '3': kwargs = {'metaclass': Meta} else: kwargs = {} class MyClass(object, **kwargs): __metaclass__ = Meta > The second question that came up was if there is a way to keep a > metaclass defined inside the class or if the only way is to provide it > externally. The reason I like this in-class definition is that for my > case of autogenerated test functions, everything is in one place which > used to be in a loop that modified the class after its creation. Maybe > I'm just too brainwashed by static languages though. Not in general, since the metaclass has to exist independently of the class. The class is an instance of your metaclass. That means that the metaclass must exist first, so it can be instantiated when you define the class. However, there is a loophole: Python's metaclass machinery is actually more general than just class-of-classes. The metaclass doesn't have to be a class, it can be any callable with the same function signature as the three-argument version of type. So despite what I said above, you *can* embed the metaclass in the class, if the metaclass is a function created with lambda (or equivalent): # Python 2 version class MyClass(object): __metaclass__ = (lambda name, bases, dict: sys.stdout.write("Spam!\n") or type(name, bases, dict) ) # Python 3 version class MyClass(object, metaclass=lambda name, bases, dict: sys.stdout.write("Spam!\n") and type(name, bases, dict) ): pass But really, except as a trick, why would you do that? > To get the Python2 feeling back, I have a hack in mind that involves > creating a baseclass which in turn provides a metaclass that invokes a > specific function to post-initialize the class, similar to the way > Python 2 does it automatically, but I'm wondering if there isn't > anything better. Seems awfully convoluted and complicated. Python 3 metaclasses work exactly the same as Python 2 metaclasses, except the syntax for declaring them is slightly different. So if you had this: class Meta(type): ... class MyClass: __metaclass__ = Meta ... just change it to this, and it should work exactly the same: class Meta(type): ... class MyClass(metaclass=Meta): ... > Also PEP 3115 "Metaclasses in Python 3000"[2] seems to > consider postprocessing of a class definition as better handled by a > class decorator, which is something I haven't looked at yet. Generally, class decorators are less brain-melting than metaclasses. -- Steven From ulrich.eckhardt at dominolaser.com Fri Apr 12 03:17:39 2013 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Fri, 12 Apr 2013 09:17:39 +0200 Subject: name lookup failure using metaclasses with unittests In-Reply-To: <5166720e$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <5166720e$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 11.04.2013 10:19, schrieb Steven D'Aprano: > if sys.version >= '3': Use sys.version_info >= (3,), otherwise your code breaks when upgrading to Python 10 and greater. ;^) >> The second question that came up was if there is a way to keep a >> metaclass defined inside the class or if the only way is to provide it >> externally. [...] > > Not in general, since the metaclass has to exist independently of the > class. Thanks for your explanations, they are appreciated. > The class is an instance of your metaclass. That means that the > metaclass must exist first, so it can be instantiated when you > define the class. I don't like the approach to define the code to post-process a class before defining the class. It's a bit like top-posting, it messes up the reading order. Since I really intend to post-process the class, it seems that metaclasses are simply not the right tool. At the moment, this leaves me with two options: 1. post-process the class class X: pass # attach constants to clas X for i in (1, 2, 3): setattr(X, 'f{}' % i, i) 2. generate code inline class Y: pass # generate constants in local (class-)namespace for i in (1, 2, 3): locals()['f{}' % i] = i In both cases, variables (loop variable 'i') are leaked into the surrounding namespace, which is kind-of ugly. The second approach also seems a bit hackish and I can't use the class-in-definition there, which is limiting when you want to attach e.g. constants of type X to X. >> Also PEP 3115 "Metaclasses in Python 3000"[2] seems to >> consider postprocessing of a class definition as better handled by a >> class decorator, which is something I haven't looked at yet. > > Generally, class decorators are less brain-melting than metaclasses. Alas, they also need to be defined before the class, messing with the mentioned order of declaration. They can be used to call a class function though which then does the necessary postprocessing... 3. post-process the class triggered with decorator def postprocess_class(cls): """invoke postprocess() on the decorated object""" cls.postprocess() del cls.postprocess return cls @postprocess_class class Z: @classfunction def postprocess(cls): # attach constants to class for i in (1, 2, 3): setattr(cls, 'f{}' % i, i) I guess I'll stay with variant 1 for now, since it requires the least amount of code and the least amount of questions from other developers here. Thanks everybody! Uli From tjreedy at udel.edu Fri Apr 12 10:58:01 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Fri, 12 Apr 2013 10:58:01 -0400 Subject: name lookup failure using metaclasses with unittests In-Reply-To: References: <5166720e$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/12/2013 3:17 AM, Ulrich Eckhardt wrote: > Am 11.04.2013 10:19, schrieb Steven D'Aprano: >> if sys.version >= '3': > > Use sys.version_info >= (3,), otherwise your code breaks when upgrading > to Python 10 and greater. ;^) > > >>> The second question that came up was if there is a way to keep a >>> metaclass defined inside the class or if the only way is to provide it >>> externally. [...] >> >> Not in general, since the metaclass has to exist independently of the >> class. > > Thanks for your explanations, they are appreciated. > > > > The class is an instance of your metaclass. That means that the > > metaclass must exist first, so it can be instantiated when you > > define the class. > > I don't like the approach to define the code to post-process a class > before defining the class. It's a bit like top-posting, it messes up the > reading order. Since I really intend to post-process the class, it seems > that metaclasses are simply not the right tool. Using a post-processing object as a metaclass or decorator necessarily requires predefinition. Such objects are usually used more than once. For one-off postprocessing, I probably would not bother. > At the moment, this leaves me with two options: > > 1. post-process the class > > class X: > pass > # attach constants to clas X > for i in (1, 2, 3): > setattr(X, 'f{}' % i, i) > > 2. generate code inline > > class Y: pass > # generate constants in local (class-)namespace > for i in (1, 2, 3): > locals()['f{}' % i] = i Mutating class locals() currently works in CPython, but is explicitly not guaranteed to work by the language definition. > In both cases, variables (loop variable 'i') are leaked into the > surrounding namespace, which is kind-of ugly. The second approach also > seems a bit hackish and I can't use the class-in-definition there, which > is limiting when you want to attach e.g. constants of type X to X. > > >>> Also PEP 3115 "Metaclasses in Python 3000"[2] seems to >>> consider postprocessing of a class definition as better handled by a >>> class decorator, which is something I haven't looked at yet. >> >> Generally, class decorators are less brain-melting than metaclasses. > > Alas, they also need to be defined before the class, messing with the > mentioned order of declaration. They can be used to call a class > function though which then does the necessary postprocessing... > > 3. post-process the class triggered with decorator > > def postprocess_class(cls): > """invoke postprocess() on the decorated object""" > cls.postprocess() > del cls.postprocess > return cls > > @postprocess_class > class Z: > @classfunction > def postprocess(cls): > # attach constants to class > for i in (1, 2, 3): > setattr(cls, 'f{}' % i, i) > > > I guess I'll stay with variant 1 for now, since it requires the least > amount of code and the least amount of questions from other developers > here. From arnodel at gmail.com Thu Apr 11 04:19:59 2013 From: arnodel at gmail.com (Arnaud Delobelle) Date: Thu, 11 Apr 2013 09:19:59 +0100 Subject: name lookup failure using metaclasses with unittests In-Reply-To: References: Message-ID: On 11 April 2013 07:43, Ulrich Eckhardt wrote: > The second question that came up was if there is a way to keep a metaclass > defined inside the class or if the only way is to provide it externally. Yes, using metaclasses! I wouldn't recommend it though. Here's a proof of concept: class MyType(type): def __new__(meta, name, bases, attrs): try: metaclass = attrs.pop('__metaclass__') except KeyError: return type.__new__(meta, name, bases, attrs) else: return metaclass(name, bases, attrs) class MyObject(metaclass=MyType): pass >>> class Test(MyObject): ... def __metaclass__(name, bases, attrs): ... print("Test metaclass") ... return MyType(name, bases, attrs) ... Test metaclass -- Arnaud From eschneider92 at comcast.net Wed Apr 10 05:39:23 2013 From: eschneider92 at comcast.net (eschneider92 at comcast.net) Date: Wed, 10 Apr 2013 02:39:23 -0700 (PDT) Subject: guessthenumber print games left Message-ID: <0e8b4a09-3d1d-4b92-a0ef-2274a2a651c9@googlegroups.com> Could anyone tell me how to make the program tell me how many games are left before the first game and second game? For example, after one game of guess the number, I want it to tell me that i get one more game. P.S. I'm totally new to python (obviously), and I just added numberofgames variable in hopes of solving this problem. am I on the right track? Thanks for any assistance! numberofgames=1 while numberofgames<4: numberofgames=numberofgames+2 import random print ('type name') name=input() print ('guess a number between 1 and 20, ' + name) number=random.randint(1,20) guessestaken=0 while guessestaken<5: guessestaken=guessestaken+1 guess=input() guess=int(guess) if guessnumber: print ('your guess is too high0') if guess==number: break if guess==number: print ('you win!') if guess!=number: number=str(number) print ('you lose. the number was ' + number) From rosuav at gmail.com Wed Apr 10 05:44:20 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 10 Apr 2013 19:44:20 +1000 Subject: guessthenumber print games left In-Reply-To: <0e8b4a09-3d1d-4b92-a0ef-2274a2a651c9@googlegroups.com> References: <0e8b4a09-3d1d-4b92-a0ef-2274a2a651c9@googlegroups.com> Message-ID: On Wed, Apr 10, 2013 at 7:39 PM, wrote: > Could anyone tell me how to make the program tell me how many games are left before the first game and second game? For example, after one game of guess the number, I want it to tell me that i get one more game. P.S. I'm totally new to python (obviously), and I just added numberofgames variable in hopes of solving this problem. am I on the right track? Thanks for any assistance! > numberofgames=1 > while numberofgames<4: > numberofgames=numberofgames+2 First off, why are you adding two? Is this a typo? You have here a counter, but it's counting up. To figure out how many games are left, just subtract the numberofgames from the total number of games that you'll be allowing - that's how many there are left. Do you know how to do that? ChrisA From eschneider92 at comcast.net Wed Apr 10 17:01:53 2013 From: eschneider92 at comcast.net (eschneider92 at comcast.net) Date: Wed, 10 Apr 2013 14:01:53 -0700 (PDT) Subject: guessthenumber print games left In-Reply-To: References: <0e8b4a09-3d1d-4b92-a0ef-2274a2a651c9@googlegroups.com> Message-ID: On Wednesday, April 10, 2013 5:44:20 AM UTC-4, Chris Angelico wrote: > On Wed, Apr 10, 2013 at 7:39 PM, wrote: > > > Could anyone tell me how to make the program tell me how many games are left before the first game and second game? For example, after one game of guess the number, I want it to tell me that i get one more game. P.S. I'm totally new to python (obviously), and I just added numberofgames variable in hopes of solving this problem. am I on the right track? Thanks for any assistance! > > > > > numberofgames=1 > > > while numberofgames<4: > > > numberofgames=numberofgames+2 > > > > First off, why are you adding two? Is this a typo? > > > > You have here a counter, but it's counting up. To figure out how many > > games are left, just subtract the numberofgames from the total number > > of games that you'll be allowing - that's how many there are left. Do > > you know how to do that? > > > > ChrisA Thanks for the quick reply. I've been trying your advice but I can't figure it out. If anyone could show me how to do it in program form, it would be much obliged. From eschneider92 at comcast.net Wed Apr 10 17:01:53 2013 From: eschneider92 at comcast.net (eschneider92 at comcast.net) Date: Wed, 10 Apr 2013 14:01:53 -0700 (PDT) Subject: guessthenumber print games left In-Reply-To: References: <0e8b4a09-3d1d-4b92-a0ef-2274a2a651c9@googlegroups.com> Message-ID: On Wednesday, April 10, 2013 5:44:20 AM UTC-4, Chris Angelico wrote: > On Wed, Apr 10, 2013 at 7:39 PM, wrote: > > > Could anyone tell me how to make the program tell me how many games are left before the first game and second game? For example, after one game of guess the number, I want it to tell me that i get one more game. P.S. I'm totally new to python (obviously), and I just added numberofgames variable in hopes of solving this problem. am I on the right track? Thanks for any assistance! > > > > > numberofgames=1 > > > while numberofgames<4: > > > numberofgames=numberofgames+2 > > > > First off, why are you adding two? Is this a typo? > > > > You have here a counter, but it's counting up. To figure out how many > > games are left, just subtract the numberofgames from the total number > > of games that you'll be allowing - that's how many there are left. Do > > you know how to do that? > > > > ChrisA Thanks for the quick reply. I've been trying your advice but I can't figure it out. If anyone could show me how to do it in program form, it would be much obliged. From rosuav at gmail.com Wed Apr 10 18:31:19 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Apr 2013 08:31:19 +1000 Subject: guessthenumber print games left In-Reply-To: References: <0e8b4a09-3d1d-4b92-a0ef-2274a2a651c9@googlegroups.com> Message-ID: On Thu, Apr 11, 2013 at 7:01 AM, wrote: > On Wednesday, April 10, 2013 5:44:20 AM UTC-4, Chris Angelico wrote: >> On Wed, Apr 10, 2013 at 7:39 PM, wrote: >> >> You have here a counter, but it's counting up. To figure out how many >> games are left, just subtract the numberofgames from the total number >> of games that you'll be allowing - that's how many there are left. Do >> you know how to do that? >> > > Thanks for the quick reply. I've been trying your advice but I can't figure it out. If anyone could show me how to do it in program form, it would be much obliged. Set your current code aside, and just make a program that counts games without actually playing them. Start with this part of your existing code: numberofgames=1 while numberofgames<4: numberofgames=numberofgames+2 That will run, but do nothing. Now add a print call to the loop, and see if you can work out how to make it count how many games are left. If you get stuck, post the code for just this program and we'll see where it takes us! ChrisA From eschneider92 at comcast.net Thu Apr 11 01:34:41 2013 From: eschneider92 at comcast.net (eschneider92 at comcast.net) Date: Wed, 10 Apr 2013 22:34:41 -0700 (PDT) Subject: guessthenumber print games left In-Reply-To: <0e8b4a09-3d1d-4b92-a0ef-2274a2a651c9@googlegroups.com> References: <0e8b4a09-3d1d-4b92-a0ef-2274a2a651c9@googlegroups.com> Message-ID: On Wednesday, April 10, 2013 5:39:23 AM UTC-4, eschne... at comcast.net wrote: > Could anyone tell me how to make the program tell me how many games are left before the first game and second game? For example, after one game of guess the number, I want it to tell me that i get one more game. P.S. I'm totally new to python (obviously), and I just added numberofgames variable in hopes of solving this problem. am I on the right track? Thanks for any assistance! > > numberofgames=1 > > while numberofgames<4: > > numberofgames=numberofgames+2 > > import random > > print ('type name') > > name=input() > > print ('guess a number between 1 and 20, ' + name) > > number=random.randint(1,20) > > guessestaken=0 > > while guessestaken<5: > > guessestaken=guessestaken+1 > > guess=input() > > guess=int(guess) > > if guess > print ('your guess is too low') > > if guess>number: > > print ('your guess is too high0') > > if guess==number: > > break > > if guess==number: > > print ('you win!') > > if guess!=number: > > number=str(number) > > print ('you lose. the number was ' + number) I can't figure out how to make it count down by itself and state how many are left. From eschneider92 at comcast.net Thu Apr 11 01:41:13 2013 From: eschneider92 at comcast.net (eschneider92 at comcast.net) Date: Wed, 10 Apr 2013 22:41:13 -0700 (PDT) Subject: guessthenumber print games left In-Reply-To: <0e8b4a09-3d1d-4b92-a0ef-2274a2a651c9@googlegroups.com> References: <0e8b4a09-3d1d-4b92-a0ef-2274a2a651c9@googlegroups.com> Message-ID: <2177e45e-2f1d-45f0-8970-5dda0220922a@googlegroups.com> (Didn't mean to post the last bit.) Is this possibly what you meant? If it is I still can't figure out how to apply it to the guessthenumber program. numberofgames=1 while numberofgames<4: numberofgames=numberofgames+2 print (4-numberofgames) if numberofguesses>3: print(numberofgames) From rosuav at gmail.com Thu Apr 11 01:48:12 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Apr 2013 15:48:12 +1000 Subject: guessthenumber print games left In-Reply-To: <2177e45e-2f1d-45f0-8970-5dda0220922a@googlegroups.com> References: <0e8b4a09-3d1d-4b92-a0ef-2274a2a651c9@googlegroups.com> <2177e45e-2f1d-45f0-8970-5dda0220922a@googlegroups.com> Message-ID: On Thu, Apr 11, 2013 at 3:41 PM, wrote: > (Didn't mean to post the last bit.) Is this possibly what you meant? If it is I still can't figure out how to apply it to the guessthenumber program. > numberofgames=1 > while numberofgames<4: > numberofgames=numberofgames+2 > print (4-numberofgames) > if numberofguesses>3: > print(numberofgames) That's close to it. I still don't understand why you're adding two, and the last print seems to be unnecessary. But if you just add one, then yes, that would be exactly what you want. ChrisA From eschneider92 at comcast.net Thu Apr 11 01:56:59 2013 From: eschneider92 at comcast.net (eschneider92 at comcast.net) Date: Wed, 10 Apr 2013 22:56:59 -0700 (PDT) Subject: guessthenumber print games left In-Reply-To: <0e8b4a09-3d1d-4b92-a0ef-2274a2a651c9@googlegroups.com> References: <0e8b4a09-3d1d-4b92-a0ef-2274a2a651c9@googlegroups.com> Message-ID: <7326d558-0aad-4059-ba85-d5bf078201e6@googlegroups.com> How do I make it say that I have one game left? I'm having trouble fitting it into my main code. Thanks a lot for the help btw. From rosuav at gmail.com Thu Apr 11 02:02:17 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Apr 2013 16:02:17 +1000 Subject: guessthenumber print games left In-Reply-To: <7326d558-0aad-4059-ba85-d5bf078201e6@googlegroups.com> References: <0e8b4a09-3d1d-4b92-a0ef-2274a2a651c9@googlegroups.com> <7326d558-0aad-4059-ba85-d5bf078201e6@googlegroups.com> Message-ID: On Thu, Apr 11, 2013 at 3:56 PM, wrote: > How do I make it say that I have one game left? I'm having trouble fitting it into my main code. Thanks a lot for the help btw. The main confusion seems to be over whether to add one or two. If you add one, it'll tell you you have just one game left (at some point). Try that! ChrisA From eschneider92 at comcast.net Thu Apr 11 02:15:43 2013 From: eschneider92 at comcast.net (eschneider92 at comcast.net) Date: Wed, 10 Apr 2013 23:15:43 -0700 (PDT) Subject: guessthenumber print games left In-Reply-To: <0e8b4a09-3d1d-4b92-a0ef-2274a2a651c9@googlegroups.com> References: <0e8b4a09-3d1d-4b92-a0ef-2274a2a651c9@googlegroups.com> Message-ID: <3ede3be7-f008-407f-8d48-d2cff2bd1c81@googlegroups.com> The 2 makes the game play twice instead of 3 times, right? I've tried it with the 1, but but I'm still having trouble. Again, to be exact, I want to somehow make it count down from 2 (the number of games)and print. If that's what this does, is it possible to insert it into my original main program? From rosuav at gmail.com Thu Apr 11 02:27:16 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Apr 2013 16:27:16 +1000 Subject: guessthenumber print games left In-Reply-To: <3ede3be7-f008-407f-8d48-d2cff2bd1c81@googlegroups.com> References: <0e8b4a09-3d1d-4b92-a0ef-2274a2a651c9@googlegroups.com> <3ede3be7-f008-407f-8d48-d2cff2bd1c81@googlegroups.com> Message-ID: On Thu, Apr 11, 2013 at 4:15 PM, wrote: > The 2 makes the game play twice instead of 3 times, right? I've tried it with the 1, but but I'm still having trouble. Again, to be exact, I want to somehow make it count down from 2 (the number of games)and print. If that's what this does, is it possible to insert it into my original main program? Let's leave Python aside for a moment and go back to grade-school arithmetic. How do you count up to three? 1, 2, 3 How much do you add to a number to get to the next number? Once you figure out where you're starting, how much you're increasing at each step, and where you're stopping, you can put those numbers into your program. ChrisA From eschneider92 at comcast.net Thu Apr 11 03:15:07 2013 From: eschneider92 at comcast.net (eschneider92 at comcast.net) Date: Thu, 11 Apr 2013 00:15:07 -0700 (PDT) Subject: guessthenumber print games left In-Reply-To: <0e8b4a09-3d1d-4b92-a0ef-2274a2a651c9@googlegroups.com> References: <0e8b4a09-3d1d-4b92-a0ef-2274a2a651c9@googlegroups.com> Message-ID: If you get the time, please post an example, because I don't understand. From rosuav at gmail.com Thu Apr 11 03:27:39 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Apr 2013 17:27:39 +1000 Subject: guessthenumber print games left In-Reply-To: References: <0e8b4a09-3d1d-4b92-a0ef-2274a2a651c9@googlegroups.com> Message-ID: On Thu, Apr 11, 2013 at 5:15 PM, wrote: > If you get the time, please post an example, because I don't understand. (It helps to include some quoted text to provide context to your post.) Imagine you had a program that just showed the number of games left, nothing else. Write me out what you would expect that program to output. Just do it manually so I can see what you're trying to do. That'll also help you sort out, in your own mind, what you're doing. ChrisA From neilc at norwich.edu Thu Apr 11 08:31:56 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 11 Apr 2013 12:31:56 GMT Subject: guessthenumber print games left References: <0e8b4a09-3d1d-4b92-a0ef-2274a2a651c9@googlegroups.com> Message-ID: On 2013-04-11, eschneider92 at comcast.net wrote: > If you get the time, please post an example, because I don't > understand. Maybe it would help to think about contraints. Write them next to your variable names, and then check, at every point in your program, if the contraint is still true. Here's and example. maximum_games = 4 # You must stop playing after 4 games. games_played = 0 # Always equals the number of games played while games_played < maximum_games: play_game() # This is where you update games_played to reflect the number # of games played. -- Neil Cerutti From chrisgreen at hotmail.com Wed Apr 10 06:53:29 2013 From: chrisgreen at hotmail.com (Chris Green) Date: Wed, 10 Apr 2013 18:53:29 +0800 Subject: pymysql KeyError Message-ID: Hello everyone, greetings from Hong Kong. I'm a relative noob with Python and have managed to break it. I'm hoping someone would be kind enough to help out, or perhaps just point me in the right direction. I've written a program which pulls in an XML document from an API on a server and populates the data into a MySQL table which I will then use to create reports. Everything is fine up until the point it tries to write the record to MySQL with this statement: dbcur.execute("INSERT INTO BackupJobs (bj_bsname, bj_bsid, bj_startdate, bj_starttime, bj_enddate, bj_endtime, bj_status, bj_uploadsize) values (%s,%s,%s,%s,%s,%s,%s,%s)", newrecord) which borks with this: Traceback (most recent call last): ? File "./blahblahblah.py", line 99, in ??? dbcur.execute("INSERT INTO BackupJobs (bj_bsname, bj_bsid, bj_startdate, bj_starttime, bj_enddate, bj_endtime, bj_status, bj_uploadsize) values (%s,%s,%s,%s,%s,%s,%s,%s)", newrecord) ? File "/usr/local/lib/python3.2/dist-packages/pymysql/cursors.py", line 100, in execute ??? escaped_args = tuple(conn.escape(arg) for arg in args) ? File "/usr/local/lib/python3.2/dist-packages/pymysql/cursors.py", line 100, in ??? escaped_args = tuple(conn.escape(arg) for arg in args) ? File "/usr/local/lib/python3.2/dist-packages/pymysql/connections.py", line 650, in escape ??? return escape_item(obj, self.charset) ? File "/usr/local/lib/python3.2/dist-packages/pymysql/converters.py", line 31, in escape_item ??? encoder = encoders[type(val)] KeyError: I can dump out the (dummy) contents of the table using: for r in dbcur: ??? print(r) ...so it seems the connection itself is working. User ID has full permissions, I'm pretty sure the data types are correct for each field. I can provide more code snippets if necessary. I'd be very grateful for any help. And if you're in Hong Kong and have helped me through this I'll buy you a beer too :-) From __peter__ at web.de Wed Apr 10 07:20:53 2013 From: __peter__ at web.de (Peter Otten) Date: Wed, 10 Apr 2013 13:20:53 +0200 Subject: pymysql KeyError References: Message-ID: Chris Green wrote: > Hello everyone, greetings from Hong Kong. > > I'm a relative noob with Python and have managed to break it. I'm hoping > someone would be kind enough to help out, or perhaps just point me in the > right direction. > > I've written a program which pulls in an XML document from an API on a > server and populates the data into a MySQL table which I will then use to > create reports. Everything is fine up until the point it tries to write > the record to MySQL with this statement: > > dbcur.execute("INSERT INTO BackupJobs (bj_bsname, bj_bsid, bj_startdate, > bj_starttime, bj_enddate, bj_endtime, bj_status, bj_uploadsize) values > (%s,%s,%s,%s,%s,%s,%s,%s)", newrecord) > > which borks with this: > > Traceback (most recent call last): > File "./blahblahblah.py", line 99, in > dbcur.execute("INSERT INTO BackupJobs (bj_bsname, bj_bsid, bj_startdate, > bj_starttime, bj_enddate, bj_endtime, bj_status, bj_uploadsize) values > (%s,%s,%s,%s,%s,%s,%s,%s)", newrecord) File > "/usr/local/lib/python3.2/dist-packages/pymysql/cursors.py", line 100, in > execute escaped_args = tuple(conn.escape(arg) for arg in args) File > "/usr/local/lib/python3.2/dist-packages/pymysql/cursors.py", line 100, in > escaped_args = tuple(conn.escape(arg) for arg in args) File > "/usr/local/lib/python3.2/dist-packages/pymysql/connections.py", line 650, > in escape return escape_item(obj, self.charset) File > "/usr/local/lib/python3.2/dist-packages/pymysql/converters.py", line 31, > in escape_item encoder = encoders[type(val)] KeyError: 'builtin_function_or_method'> > > I can dump out the (dummy) contents of the table using: > > for r in dbcur: > print(r) > > ...so it seems the connection itself is working. User ID has full > permissions, I'm pretty sure the data types are correct for each field. > > I can provide more code snippets if necessary. > > I'd be very grateful for any help. And if you're in Hong Kong and have > helped me through this I'll buy you a beer too :-) Add a print(newrecord) before the dbcur.execute(...) line and tell us what it shows. I'm guessing that for one of the values in it you forgot to call a method written in C, e. g. >>> [42].pop >>> type(_) instead of >>> [42].pop() 42 From chrisgreen at hotmail.com Wed Apr 10 12:13:42 2013 From: chrisgreen at hotmail.com (Chris Green) Date: Thu, 11 Apr 2013 00:13:42 +0800 Subject: pymysql KeyError In-Reply-To: References: , Message-ID: > Add a > > print(newrecord) > > before the > > dbcur.execute(...) > > line and tell us what it shows. I'm guessing that for one of the values in > it you forgot to call a method written in C, e. g. > > >>> [42].pop > > >>> type(_) > > > instead of > > >>> [42].pop() > 42 > Thank you Peter - that got me back on track. Indeed, my date and time values were coded incorrectly. I read up properly on datetime to fix that, then ran straight into a pymysql bug. After swapping that out for MySQL Connector/Python everything instantly sprang to life. So a bit convoluted but I got there in the end! From steven.miale at gmail.com Wed Apr 10 11:03:15 2013 From: steven.miale at gmail.com (steven.miale at gmail.com) Date: Wed, 10 Apr 2013 08:03:15 -0700 (PDT) Subject: Really throwing this out there - does anyone have a copy of my old Dancer web browser? Message-ID: <05812bab-eab6-428f-a805-4abbea0953ad@googlegroups.com> About... er, a few years ago (1994!) I wrote a very basic web browser called Dancer. My FTP site at Indiana is long gone. Grail is based on at least some of the ideas of Dancer (but not the code itself.) I'm wondering if anyone perchance has a copy of the code. I know it will not run in any recent version of Python; it's just for my records. Thanks, Steve From rosuav at gmail.com Wed Apr 10 11:32:12 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Apr 2013 01:32:12 +1000 Subject: Really throwing this out there - does anyone have a copy of my old Dancer web browser? In-Reply-To: <05812bab-eab6-428f-a805-4abbea0953ad@googlegroups.com> References: <05812bab-eab6-428f-a805-4abbea0953ad@googlegroups.com> Message-ID: On Thu, Apr 11, 2013 at 1:03 AM, wrote: > About... er, a few years ago (1994!) I wrote a very basic web browser called Dancer. My FTP site at Indiana is long gone. Grail is based on at least some of the ideas of Dancer (but not the code itself.) > > I'm wondering if anyone perchance has a copy of the code. I know it will not run in any recent version of Python; it's just for my records. Have you tried the Wayback Machine at http://www.archive.org/ ? They mainly crawl HTTP, not FTP, so it's a bit of a long shot, but if you remember the address you had it hosted at, it's worth a try! Alas, back in 1994 I wasn't doing much on the internet. We'd put together our own LAN by that time, but our uplink was over a modem and not shared to all computers. Wasn't for a few more years after that that I actually really got a usable connection, much less got involved in things like this. So I can't help any more than that, sorry. ChrisA From rkd at rkd.me.uk Wed Apr 10 17:33:37 2013 From: rkd at rkd.me.uk (Rob Day) Date: Wed, 10 Apr 2013 22:33:37 +0100 Subject: Strange files?? In-Reply-To: References: Message-ID: <2998068.bAa2sCrAEb@pantalaimon> On Wednesday 10 Apr 2013 14:16:23 Joe Hill wrote: > Recently I installed Python 3.3 successfully. > > Yesterday - I have a bunch of PY files such as thesaurus.py, some *.p7s > files, some signature files and an index.fpickle. A total of 23 files. > > Where do they come from and how do they end up as incoming mail??? > Are any of these needed for anything? > As a rule I sort out or delete all incoming attachments every day. > j What do you mean, you have them? Did someone email them to you? If so, surely they're nothing to do with installing Python. From davea at davea.name Wed Apr 10 17:34:27 2013 From: davea at davea.name (Dave Angel) Date: Wed, 10 Apr 2013 17:34:27 -0400 Subject: Strange files?? In-Reply-To: References: Message-ID: <5165DAE3.8050008@davea.name> On 04/10/2013 05:16 PM, Joe Hill wrote: > Recently I installed Python 3.3 successfully. > > Yesterday - I have a bunch of PY files such as thesaurus.py, some *.p7s > files, some signature files and an index.fpickle. A total of 23 files. > > Where do they come from and how do they end up as incoming mail??? > Are any of these needed for anything? > As a rule I sort out or delete all incoming attachments every day. > j > What operating system is this, and what are you doing to protect yourself from hackers, virus, etc? So, which is it, files, or mail attachments? If the latter, could you please tell us your mail environment? And if it's files rather than mail, please tell us where these are appearing. -- DaveA From awilliam at whitemice.org Wed Apr 10 17:34:45 2013 From: awilliam at whitemice.org (Adam Tauno Williams) Date: Wed, 10 Apr 2013 17:34:45 -0400 Subject: Print to an IPP printer (pkipplib?) In-Reply-To: References: Message-ID: <1365629685.10501.2.camel@linux-22wg.site> On Wed, 2010-10-20 at 14:45 +0000, Martin Gregorie wrote: > On Fri, 15 Oct 2010 15:28:10 -0400, Adam Tauno Williams wrote: > > I've found the module pkipplib which seems to work well for things like > > interrogating an IPP (CUPS) server. But is there a way to send a print > > job to an IPP print queue? [and no, the local system knows nothing about > > the print architecture so popen....lp is not an option]. I just want to > > send the data from a file handle to a remote IPP queue as a print job. > See RFC 2910. Queuing a file directly to an IPP server is possible using pycups. Example: From newsboost at gmail.com Wed Apr 10 18:06:35 2013 From: newsboost at gmail.com (someone) Date: Thu, 11 Apr 2013 00:06:35 +0200 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? Message-ID: Hi, Here's my data: ----------------------- 20130315T071500 39000. 10 26 48000. 1 40 20130315T071501 39000. 10 26 48000. 2 42 20130315T071501 39000. 10 26 47520. 15 69 20130315T071501 39000. 10 26 47160. 1 70 20130315T071501 39000. 10 26 47000. 1 72 20130315T071501 39000. 10 26 47000. 2 81 20130315T071501 39000. 10 26 47000. 6 85 20130315T071501 39000. 10 26 46520. 10 95 20130315T071501 43000. 10 36 46520. 10 95 20130315T071501 43200. 4 43 46520. 10 104 20130315T071501 44040. 1 45 46520. 10 108 20130315T071501 44080. 3 48 46520. 10 109 20130315T071501 44080. 3 48 46520. 11 113 20130315T071501 44080. 3 48 46400. 2 131 20130315T071501 45080. 1 51 46400. 2 145 20130315T071501 45080. 1 51 46200. 1 147 20130315T071501 45080. 1 60 46120. 1 182 20130315T071501 45520. 1 65 46120. 1 225 20130315T071501 45520. 1 73 46120. 2 247 20130315T080000 45760. 1 133 46120. 2 378 20130315T080241 45760. 2 199 46120. 2 453 20130315T080945 45760. 3 217 46120. 2 456 20130315T081103 45760. 3 217 46080. 1 457 20130315T081105 45760. 3 218 46080. 2 458 20130315T081106 45760. 4 222 46080. 2 458 20130315T081107 45800. 1 229 46080. 2 458 20130315T082754 45800. 8 266 46080. 2 514 ..... .... ... etc. ----------------------- The first column is date + time. I know how to use simple tuples, list's and dict's. But I don't think it's a good idea to make each line an element in a list/dict ? I want to put this table into an appropriate container such that afterwards I want to: 1) Put the data into a mySql-table 2) Be able to easily plot column 1 vs. either of the other columns using matplotlib etc... I consider myself a python-newbie so I'm not that good with containers... I found something here: http://docs.python.org/dev/library/collections.html but I'm not really sure what is a good pythonic way of storing this data? I also think that maybe I ought to convert the first data+time column into a single number, because right now it's a string (because there's a "T" in the middle of column 1)... Letting the date+time-column (=column 1) become entirely numbers, makes it easier to plot in matplotlib afterwards... I'm not sure how to store this in an efficient manner... What (=how?) would you do it? Thanks... From cousinstanley at gmail.com Wed Apr 10 21:39:07 2013 From: cousinstanley at gmail.com (Cousin Stanley) Date: Thu, 11 Apr 2013 01:39:07 +0000 (UTC) Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? References: Message-ID: someone wrote: > .... > I want to put this table into an appropriate container > such that afterwards I want to: > > 1) Put the data into a mySql-table > 2) Be able to easily plot column 1 vs. either of the other columns > using matplotlib etc... > .... Consider editing your data file into a csv file named someone.csv .... 20130315T071500,39000.,10,26,48000.,1,40 20130315T071501,39000.,10,26,48000.,2,42 20130315T071501,39000.,10,26,47520.,15,69 20130315T071501,39000.,10,26,47160.,1,70 20130315T071501,39000.,10,26,47000.,1,72 20130315T071501,39000.,10,26,47000.,2,81 20130315T071501,39000.,10,26,47000.,6,85 20130315T071501,39000.,10,26,46520.,10,95 20130315T071501,43000.,10,36,46520.,10,95 20130315T071501,43200.,4,43,46520.,10,104 20130315T071501,44040.,1,45,46520.,10,108 20130315T071501,44080.,3,48,46520.,10,109 20130315T071501,44080.,3,48,46520.,11,113 20130315T071501,44080.,3,48,46400.,2,131 20130315T071501,45080.,1,51,46400.,2,145 20130315T071501,45080.,1,51,46200.,1,147 20130315T071501,45080.,1,60,46120.,1,182 20130315T071501,45520.,1,65,46120.,1,225 20130315T071501,45520.,1,73,46120.,2,247 20130315T080000,45760.,1,133,46120.,2,378 20130315T080241,45760.,2,199,46120.,2,453 20130315T080945,45760.,3,217,46120.,2,456 20130315T081103,45760.,3,217,46080.,1,457 20130315T081105,45760.,3,218,46080.,2,458 20130315T081106,45760.,4,222,46080.,2,458 20130315T081107,45800.,1,229,46080.,2,458 20130315T082754,45800.,8,266,46080.,2,514 # ----------------------------------------------- # # The csv data can be loaded using the csv module # # named tuples might be used # for convenience to access # individual columns #!/usr/bin/env python import csv from collections import namedtuple as NT file_source = open( 'someone.ssv' ) # -------------------> individual column names --------------- nt = NT( 'csv_data' , 'date time col1 col2 col3 col4 col5 col6' ) list_tuples = [ ] for this_row in csv.reader( file_source ) : # unpack the current row zed , one , two , tre , fur , fiv , six = this_row # split the date and time d , t = zed.split( 'T' ) # convert individual columns in row to a named tuple this_tuple = nt( d , t , float( one ) , int( two ) , int( tre ) , float( fur ) , int( fiv ) , int( six ) ) # save the current named tuple into a list list_tuples.append( this_tuple ) # update_data_base( this_tuple ) # .... or .... # update_data_base( choose individual columns ) # individual elements of the named tuples # can be accessed by name # # this might be convenient for settup up # data for plots of diffeent columns print for row in list_tuples : print ' ' , row.date , row.time , row.col1 , row.col3 , row.col4 file_source.close() -- Stanley C. Kitching Human Being Phoenix, Arizona From newsboost at gmail.com Thu Apr 11 04:49:59 2013 From: newsboost at gmail.com (someone) Date: Thu, 11 Apr 2013 10:49:59 +0200 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: References: Message-ID: On 2013-04-11 03:39, Cousin Stanley wrote: > for row in list_tuples : > > print ' ' , row.date , row.time , row.col1 , row.col3 , row.col4 > > file_source.close() Oh, that's great - thank you - I didn't know this named-tuple container before... I'm still wondering whether or not it's the optimal container type for me, because I just added a bit of matplotlib-code: ----------------- #!/usr/bin/env python import csv from collections import namedtuple as NT file_source = open( 'someone.csv' ) # -------------------> individual column names --------------- nt = NT( 'csv_data' , 'date time col1 col2 col3 col4 col5 col6' ) list_tuples = [ ] for this_row in csv.reader( file_source ) : # unpack the current row zed , one , two , tre , fur , fiv , six = this_row # split the date and time d , t = zed.split( 'T' ) # convert individual columns in row to a named tuple this_tuple = nt( d , t , float( one ) , int( two ) , int( tre ) , float( fur ) , int( fiv ) , int( six ) ) # save the current named tuple into a list list_tuples.append( this_tuple ) # update_data_base( this_tuple ) # .... or .... # update_data_base( choose individual columns ) file_source.close() # individual elements of the named tuples # can be accessed by name # # this might be convenient for settup up # data for plots of diffeent columns x=[] y=[] print for row in list_tuples : print ' ' , row.date , row.time , row.col1 , row.col3 , row.col4 x.append(row.col3) y.append(row.col4) import matplotlib.pyplot as plt plt.plot(x,y) plt.ylabel('some numbers') plt.show() ----------------- As you can see, in order for me to make the x- and y-vectors, I need to make a for-loop to access the individual rows in list_tuples and then I append to the x- and y- lists... Is there any clever way of avoiding this for loop, for either this container or another clever container type? If there isn't, then this is absolutely also an acceptable/good solution for me... I also use Matlab and for matrices you can type e.g. plot( matrix(:,3), matrix(:,4) ) to plot columns 3 against column 4. But Matlab also has this problem, that it cannot store strings and numbers in the same matrix - matrices must entirely be numeric, which my data isn't (due to 1st column)... Thanks for any input, if someone has any good ideas... From newsboost at gmail.com Thu Apr 11 09:38:50 2013 From: newsboost at gmail.com (someone) Date: Thu, 11 Apr 2013 15:38:50 +0200 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: References: Message-ID: On 2013-04-11 10:49, someone wrote: > On 2013-04-11 03:39, Cousin Stanley wrote: > Is there any clever way of avoiding this for loop, for either this > container or another clever container type? Ah, I see - I can also just add a numpy array, i.e: ------------------------------ import matplotlib.pyplot as plt test=numpy.random.rand(8,2) new_tuple = nt(d,t, float(one), int(two), int(tre), float(fur), int(fiv), test) #new_tuple is now: #csv_data(date='20130315', time='071500', col1=39000.0, col2=10, #col3=26, col4=48000.0, col5=1, col6=array([[ 0.77714064, 0.06729907], # [ 0.20418563, 0.97882722], # [ 0.39130897, 0.06611205], # [ 0.94938335, 0.50254674], # [ 0.82047434, 0.71624034], # [ 0.66618477, 0.92025612], # [ 0.2789423 , 0.19212809], # [ 0.7048946 , 0.79112071]])) x=new_tuple.col6[:,0] y=new_tuple.col6[:,1] plt.plot(x,y) plt.show() ------------------------ I get it - THANKS! From cousinstanley at gmail.com Thu Apr 11 13:58:26 2013 From: cousinstanley at gmail.com (Cousin Stanley) Date: Thu, 11 Apr 2013 17:58:26 +0000 (UTC) Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? References: Message-ID: someone wrote: > .... > I want to put this table into an appropriate container > such that afterwards I want to: > > 1) Put the data into a mySql-table > .... You might consider using sqlite3 as a database manager since it is "batteries included" with python .... The stand-alone sqlite interpreter can first be used to create an empty database named some.sql3 and create a table named xdata in that data base .... sqlite3 some.sql3 '.read xdata_create.sql' where the file xdata_create.sql contains .... create table xdata ( xdate integer , xtime integer , col1 real , col2 integer , col3 integer , col4 real , col5 integer , col6 integer ) ; # ----------------------------------------------------------- The csv data file can then be inserted into the xdata table in the some.sql3 database via python .... import sqlite3 as DBM fs = open( 'some.csv' ) ls = [ ] dbc = DBN.connect( 'some.sql3' ) cur = dbc.cursor() sql = 'insert into xdata values( ? , ? , ? , ? , ? , ? , ? , ? )' for row in fs : dt, col1, col2, col3, col4,col5, col6 = row.strip().split(',' ) xdate , xtime = dt.split( 'T' ) xtuple = ( xdate, xtime, col1, col2, col3, col4, col5, col6 ) cur.execute( sql , xtuple ) fs.close() dbc.commit() dbc.close() # ---------------------------------------------------------------- # python data selection example # for column 4 between 8 and 9 import sqlite3 as DBM fs = open( 'some.csv' ) ls = [ ] dbc = DBM.connect( 'some.sql3' ) dbc.row_factory = DBM.Row cur = dbc.cursor() list_sql = [ 'select xtime , col4' , 'from xdata' , 'where xtime >= 80000 and xtime <= 90000 ; ' ] str_sql = '\n'.join( list_sql ) cur.execute( str_sql ) for row in cur : print row[ 'xtime' ] , row[ 'col4' ] fs.close() dbc.close() # ---------------------------------------------------- You can be creative with the data selections and pass them off to be plotted as needed .... If mysql is used instead of sqlite3 you should only have to monkey with the data type declarations in xdata_create.sql and the dbc.connect strings in the python code .... -- Stanley C. Kitching Human Being Phoenix, Arizona From cousinstanley at gmail.com Thu Apr 11 14:44:12 2013 From: cousinstanley at gmail.com (Cousin Stanley) Date: Thu, 11 Apr 2013 18:44:12 +0000 (UTC) Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? References: Message-ID: Cousin Stanley wrote: > The stand-alone sqlite interpreter can first be used > to create an empty database named some.sql3 > and create a table named xdata in that data base .... > > sqlite3 some.sql3 '.read xdata_create.sql' This step can also be done in python without using the stand-alone sqlite interpreter .... # ----------------------------------------- import sqlite3 as DBM dbc = DBM.connect( 'some.sql3' ) cur = dbc.cursor() list_sql = [ 'create table if not exists xdata ' , '( ' , ' xdate integer , ' , ' xtime integer , ' , ' col1 real , ' , ' col2 integer , ' , ' col3 integer , ' , ' col4 real , ' , ' col5 integer , ' , ' col6 integer ' , ') ; ' ] str_sql = '\n'.join( list_sql ) cur.execute( str_sql ) dbc.commit() dbc.close() -- Stanley C. Kitching Human Being Phoenix, Arizona From newsboost at gmail.com Fri Apr 12 10:19:06 2013 From: newsboost at gmail.com (someone) Date: Fri, 12 Apr 2013 16:19:06 +0200 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: References: Message-ID: On 2013-04-11 20:44, Cousin Stanley wrote: > Cousin Stanley wrote: > >> The stand-alone sqlite interpreter can first be used >> to create an empty database named some.sql3 >> and create a table named xdata in that data base .... >> >> sqlite3 some.sql3 '.read xdata_create.sql' > > This step can also be done in python > without using the stand-alone sqlite interpreter .... Ah, that's great (and even better so I don't have to create the xdata_create.sql file) - thank you! I collected what you wrote and put together this script: ===================== #!/usr/bin/python import sqlite3 as DBM import ipdb # ls = [ ] # this seems to be un-used ? dbc = DBM.connect( 'some.sql3' ) cur = dbc.cursor() fs = open( 'some.csv' ) if 0: # select whether to create new database file or query from it? if 0: # switch between "create table xdata" and "... if not exists" list_sql = [ 'create table xdata ', '( ', ' xdate integer , ', ' xtime integer , ', ' col1 real , ', ' col2 integer , ', ' col3 integer , ', ' col4 real , ', ' col5 integer , ', ' col6 integer ', ') ;' ] else: list_sql = [ 'create table if not exists xdata ' , '( ' , ' xdate integer , ' , ' xtime integer , ' , ' col1 real , ' , ' col2 integer , ' , ' col3 integer , ' , ' col4 real , ' , ' col5 integer , ' , ' col6 integer ' , ') ; ' ] # --------------------------------------------- str_sql = '\n'.join( list_sql ) cur.execute( str_sql ) # --------------------------------------------- # Insert data from input file fs ("some.csv") sql = 'insert into xdata values( ? , ? , ? , ? , ? , ? , ? , ? )' for row in fs : dt, col1, col2, col3, col4,col5, col6 = row.strip().split(',' ) xdate , xtime = dt.split( 'T' ) xtuple = ( xdate, xtime, col1, col2, col3, col4, col5, col6 ) cur.execute( sql , xtuple ) dbc.commit() else: list_sql = [ 'select xtime , col4' , 'from xdata' , 'where xtime >= 80000 and xtime <= 81104 ; ' ] str_sql = '\n'.join( list_sql ) cur.execute( str_sql ) for row in cur : #ipdb.set_trace() # I get: TypeError: "tuple indices must be integers, not str" # "ipdb> row" says: "(80000, 46120.0)" #print row[ 'xtime' ] , row[ 'col4' ] print row[0] , row[1] fs.close() dbc.close() ===================== I think I can learn a lot from google, based on this code - I'm very grateful for your help! Now I just need to make a nice interface and couple it to matplotlib, so it's easy to plot - I think there's a good chance that I can come up with a good solution from here, based on the help I got from you people... Thanks again! From newsboost at gmail.com Thu Apr 11 15:42:49 2013 From: newsboost at gmail.com (someone) Date: Thu, 11 Apr 2013 21:42:49 +0200 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: References: Message-ID: On 04/11/2013 07:58 PM, Cousin Stanley wrote: > someone wrote: > You can be creative with the data selections > and pass them off to be plotted as needed .... > > If mysql is used instead of sqlite3 > you should only have to monkey with > the data type declarations in xdata_create.sql > and the dbc.connect strings in the python code .... Uh, thank you very much for providing me with this (+ also the example in the other post)! Unfortunately, I'm struggling a bit with my code (I'm making some python-class'es), so it'll take a few days before I begin on the SQL-stuff... I'll get back, if the SQL-code you suggested causes any problems - thank you VERY much for both examples (in both posts)... I'll try it out ASAP, when I've made my code object-oriented and well-organized :-) Thanks! From newsboost at gmail.com Fri Apr 12 10:03:49 2013 From: newsboost at gmail.com (someone) Date: Fri, 12 Apr 2013 16:03:49 +0200 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: References: Message-ID: On 2013-04-11 19:58, Cousin Stanley wrote: > someone wrote: > >> .... >> I want to put this table into an appropriate container >> such that afterwards I want to: >> >> 1) Put the data into a mySql-table >> .... > > You might consider using sqlite3 as a database manager > since it is "batteries included" with python .... > > The stand-alone sqlite interpreter can first be used > to create an empty database named some.sql3 > and create a table named xdata in that data base .... > > sqlite3 some.sql3 '.read xdata_create.sql' > > where the file xdata_create.sql contains .... > > create table xdata > ( > xdate integer , > xtime integer , > col1 real , > col2 integer , > col3 integer , > col4 real , > col5 integer , > col6 integer > ) ; Oh, thank you very much! Now I understand this (I haven't really worked much with sql before, so this was/is new to me, thanks!). > The csv data file can then be inserted into the xdata table > in the some.sql3 database via python .... ........ and ....... > # python data selection example > # for column 4 between 8 and 9 I combined both code snippets into: ============================== #!/usr/bin/python import sqlite3 as DBM import ipdb fs = open( 'some.csv' ) ls = [ ] dbc = DBM.connect( 'some.sql3' ) cur = dbc.cursor() if 0: sql = 'insert into xdata values( ? , ? , ? , ? , ? , ? , ? , ? )' for row in fs : dt, col1, col2, col3, col4,col5, col6 = row.strip().split(',' ) xdate , xtime = dt.split( 'T' ) xtuple = ( xdate, xtime, col1, col2, col3, col4, col5, col6 ) cur.execute( sql , xtuple ) dbc.commit() else: list_sql = [ 'select xtime , col4' , 'from xdata' , 'where xtime >= 80000 and xtime <= 90000 ; ' ] str_sql = '\n'.join( list_sql ) cur.execute( str_sql ) for row in cur : #ipdb.set_trace() # I get: TypeError: "tuple indices must be integers, not str" # "ipdb> row" says: "(80000, 46120.0)" #print row[ 'xtime' ] , row[ 'col4' ] print row[0] , row[1] fs.close() dbc.close() ============================== I don't fully understand it yet, but it's nice to see that it works! Thank you very much for that! Now I'll have to concentrate on figuring out how/why it works :-) > You can be creative with the data selections > and pass them off to be plotted as needed .... Yes, I understand. Thank you very much. As you can see, on my system I had to use: print row[0] , row[1] instead of: print row[ 'xtime' ] , row[ 'col4' ] I'm not sure exactly why - is it because you have another version of sqlite3 ? This is a bit strange, but anyway I can live with that - at least for now... > If mysql is used instead of sqlite3 > you should only have to monkey with > the data type declarations in xdata_create.sql > and the dbc.connect strings in the python code .... Actually I didn't knew anything about this sqlite3 before now. This is the first time I try it out, so I don't really know what's the difference between sqlite3 and mysql... But thank you very much for providing some code I can now study and learn from !!! Much appreciated.... From cousinstanley at gmail.com Fri Apr 12 12:58:15 2013 From: cousinstanley at gmail.com (Cousin Stanley) Date: Fri, 12 Apr 2013 16:58:15 +0000 (UTC) Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? References: Message-ID: someone wrote: > As you can see, on my system I > had to use: > > print row[0] , row[1] > > instead of: > > print row[ 'xtime' ] , row[ 'col4' ] > > I'm not sure exactly why The magic there is setting up the row_factory after the database connection .... dbc = DBM.connect( 'some.sql3' ) dbc.row_factory = DBM.Row > I don't really know what's the difference > between sqlite3 and mysql... MySQL is used through a client/server system where the db server is always running and client processes submit requests to it in the form of sql statements .... SQLite is used as a stand-alone single process with no external server involved .... Both speak sql but there are some differences mostly in data base connection strings and data type declarations .... Basic sql selection is .... select these fields from these files where these conditions are met And that part of sql doesn't vary much among different data base managers .... -- Stanley C. Kitching Human Being Phoenix, Arizona From newsboost at gmail.com Fri Apr 12 16:52:40 2013 From: newsboost at gmail.com (someone) Date: Fri, 12 Apr 2013 22:52:40 +0200 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: References: Message-ID: On 04/12/2013 06:58 PM, Cousin Stanley wrote: > someone wrote: > >> As you can see, on my system I >> had to use: >> >> print row[0] , row[1] >> >> instead of: >> >> print row[ 'xtime' ] , row[ 'col4' ] >> >> I'm not sure exactly why > > The magic there is setting up the row_factory > after the database connection .... > > dbc = DBM.connect( 'some.sql3' ) > > dbc.row_factory = DBM.Row Ah, thanks a lot - now it works! This is much more "user-friendly"... >> I don't really know what's the difference >> between sqlite3 and mysql... > > MySQL is used through a client/server system > where the db server is always running > and client processes submit requests to it > in the form of sql statements .... > > SQLite is used as a stand-alone single process > with no external server involved .... Ok, I see... So SQLite is very good for "practicing"... I'll remember that, thank you. > Both speak sql but there are some differences > mostly in data base connection strings > and data type declarations .... > > Basic sql selection is .... > > select these fields > from these files > where these conditions are met > > And that part of sql doesn't vary much > among different data base managers .... Great, thank you very much... Looks like everything is on track now... I just have to sit and play with it and make a good interface with matplotlib, but I think I should be able to come up with something nice, based on the help I god in this thread... Thanks again... I just love this python language - makes it possible to do so much, in so little time and without being an expert at all... From cousinstanley at gmail.com Fri Apr 12 19:26:05 2013 From: cousinstanley at gmail.com (Cousin Stanley) Date: Fri, 12 Apr 2013 23:26:05 +0000 (UTC) Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? References: Message-ID: someone wrote: > .... > So SQLite is very good for "practicing" > .... Yes it is but it is also very good for much more than just practice .... Check the wikipedia info .... http://en.wikipedia.org/wiki/Sqlite "It is arguably the most widely deployed database engine, as it is used today by several widespread browsers, operating systems, and embedded systems, among others" The firefox browser keeps different sqlite database files for various uses .... If you use firefox check its default directory and you will see several files with .sqlite file type extensions .... Under debian debian linux .... ~/.mozilla/firefox/*.default Many programmers, including pythonistas, use sqlite for a convenient and persistent data store where data can be stashed now and used later in many different ways through the diversity of sql selections .... > Thanks again .... You're welcome .... > I just love this python language Me too .... :-) -- Stanley C. Kitching Human Being Phoenix, Arizona From newsboost at gmail.com Fri Apr 12 20:00:40 2013 From: newsboost at gmail.com (someone) Date: Sat, 13 Apr 2013 02:00:40 +0200 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: References: Message-ID: On 04/13/2013 01:26 AM, Cousin Stanley wrote: > someone wrote: > >> .... >> So SQLite is very good for "practicing" >> .... > > Yes it is but it is also very good > for much more than just practice .... > > Check the wikipedia info .... > > http://en.wikipedia.org/wiki/Sqlite Very interesting... > "It is arguably the most widely deployed database engine, > as it is used today by several widespread browsers, > operating systems, and embedded systems, among others" > > The firefox browser keeps different sqlite database files > for various uses .... I should remember to use this in the future for my small apps... > If you use firefox check its default directory > and you will see several files with .sqlite > file type extensions .... > > Under debian debian linux .... > > ~/.mozilla/firefox/*.default You're right: /home/myUser/.mozilla/firefox/pv079lxv.default/addons.sqlite /home/myUser/.mozilla/firefox/pv079lxv.default/chromeappsstore.sqlite /home/myUser/.mozilla/firefox/pv079lxv.default/content-prefs.sqlite /home/myUser/.mozilla/firefox/pv079lxv.default/cookies.sqlite /home/myUser/.mozilla/firefox/pv079lxv.default/downloads.sqlite /home/myUser/.mozilla/firefox/pv079lxv.default/extensions.sqlite /home/myUser/.mozilla/firefox/pv079lxv.default/formhistory.sqlite /home/myUser/.mozilla/firefox/pv079lxv.default/permissions.sqlite /home/myUser/.mozilla/firefox/pv079lxv.default/places.sqlite /home/myUser/.mozilla/firefox/pv079lxv.default/search.sqlite /home/myUser/.mozilla/firefox/pv079lxv.default/signons.sqlite /home/myUser/.mozilla/firefox/pv079lxv.default/urlclassifier3.sqlite /home/myUser/.mozilla/firefox/pv079lxv.default/webappsstore.sqlite Very interesting, I didn't knew that :-) > Many programmers, including pythonistas, > use sqlite for a convenient and persistent > data store where data can be stashed now > and used later in many different ways > through the diversity of sql selections .... I'll try to do this in the future also... I just have to practice a bit more with the SQL commands, but now I can create, update, delete, query and I guess that's the most important things to know :-) Thanks for your help and for providing interesting background info :-) From steve+comp.lang.python at pearwood.info Fri Apr 12 21:44:31 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Apr 2013 01:44:31 GMT Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? References: Message-ID: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> On Fri, 12 Apr 2013 23:26:05 +0000, Cousin Stanley wrote: > The firefox browser keeps different sqlite database files for various > uses .... Yes, and I *really* wish they wouldn't. It's my number 1 cause of major problems with Firefox. E.g. http://kb.mozillazine.org/Bookmarks_history_and_toolbar_buttons_not_working_-_Firefox Using a database for such lightweight data as bookmarks is, in my opinion, gross overkill and adds to the complexity of Firefox. More complexity leads to more bugs, e.g.: https://bugzilla.mozilla.org/show_bug.cgi?id=465684#c11 https://bugzilla.mozilla.org/show_bug.cgi?id=431558 Please don't use a full-featured database if you don't need the overhead of ACID compliance. And if you do, well, Sqlite is not fully ACID compliant. -- Steven From newsboost at gmail.com Sat Apr 13 07:08:14 2013 From: newsboost at gmail.com (someone) Date: Sat, 13 Apr 2013 13:08:14 +0200 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04/13/2013 03:44 AM, Steven D'Aprano wrote: > On Fri, 12 Apr 2013 23:26:05 +0000, Cousin Stanley wrote: > >> The firefox browser keeps different sqlite database files for various >> uses .... > > Yes, and I *really* wish they wouldn't. It's my number 1 cause of major > problems with Firefox. E.g. > > http://kb.mozillazine.org/Bookmarks_history_and_toolbar_buttons_not_working_-_Firefox Oh, sorry to hear that... Actually I mostly use chromium (but I also have firefox installed). I just opened a few of my sqlite files from within sqlite3 - that was very interesting to see the contents of these files without being anything like a "hacker"... :-) > Using a database for such lightweight data as bookmarks is, in my > opinion, gross overkill and adds to the complexity of Firefox. More > complexity leads to more bugs, e.g.: > > https://bugzilla.mozilla.org/show_bug.cgi?id=465684#c11 > > https://bugzilla.mozilla.org/show_bug.cgi?id=431558 On the other hand, I guess it's in the spirit of "open source" that it's easy for everyone to go in an see what's in the configuration files and (if one wants) modify and/or make own improvements/programs that tamper with these sql-files ? > Please don't use a full-featured database if you don't need the overhead Ok, you're saying there's overhead I should think of... Most of my programs are rather small in comparison with commercial programs so I think I don't have to worry about overhead (I don't have any real speed-critical applications). > of ACID compliance. And if you do, well, Sqlite is not fully ACID compliant. I just had to google what ACID compliance means and accordingly to this: http://en.wikipedia.org/wiki/SQLite "SQLite is ACID-compliant and implements most of the SQL standard, using a dynamically and weakly typed SQL syntax that does not guarantee the domain integrity." So you seem to disagree with wikipedia? I however don't understand what it means "to not guarantee domain integrity"... As I read this, I get the feeling that sqlite *IS* ACID compliant (wikipedia however doesn't use the wording: "fully ACID compliant", maybe this is the culprit) ? From rosuav at gmail.com Sat Apr 13 07:39:02 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 13 Apr 2013 21:39:02 +1000 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Apr 13, 2013 at 9:08 PM, someone wrote: > I just had to google what ACID compliance means and accordingly to this: > > http://en.wikipedia.org/wiki/SQLite > > "SQLite is ACID-compliant and implements most of the SQL standard, using a > dynamically and weakly typed SQL syntax that does not guarantee the domain > integrity." > > So you seem to disagree with wikipedia? Disagreeing with Wikipedia doesn't mean much, but try this: http://www.sqlite.org/atomiccommit.html Note that there's a caveat: You have to tell SQLite to be ACID compliant, effectively. ChrisA From newsboost at gmail.com Sat Apr 13 09:30:06 2013 From: newsboost at gmail.com (someone) Date: Sat, 13 Apr 2013 15:30:06 +0200 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04/13/2013 01:39 PM, Chris Angelico wrote: > On Sat, Apr 13, 2013 at 9:08 PM, someone wrote: >> I just had to google what ACID compliance means and accordingly to this: >> >> http://en.wikipedia.org/wiki/SQLite >> >> "SQLite is ACID-compliant and implements most of the SQL standard, using a >> dynamically and weakly typed SQL syntax that does not guarantee the domain >> integrity." >> >> So you seem to disagree with wikipedia? > > Disagreeing with Wikipedia doesn't mean much, but try this: > > http://www.sqlite.org/atomiccommit.html Ok, thanks - I didn't read it all, but interesting. > Note that there's a caveat: You have to tell SQLite to be ACID > compliant, effectively. So, you're saying to me that by default SQLite isn't ACID compliant, if I begin to use it in my own small programs? I don't know so much about it - maybe it's a matter of definition... If I just google for the 3 words: "sqlite acid compliance" I get: Hit no. 1 is wikipedia. Hit no. 3 says: "SQLite is an ACID-compliant embedded relational database management system" Hit no. 4 says: "SQLite implements ACID-compliance by way of a transaction journal" Hit no. 5 says: "SQLite transactions are fully ACID-compliant, allowing safe access from.." Hit no. 6 says: "Techopedia explains SQLite. SQLite is atomicity, consistency, isolation, durability (ACID) compliant." Hit no. 7: "Tell me what you know about SQLite, the ACID-compliant embedded relational" Hit no. 9: "SQLite is superior to Jet for the major reason that SQLite is ACID-compliant whereas Jet, unfortunately, isn't..." Hit no. 10: "SQLite for Linux 3.6.17. An ACID-compliant relational database management system" I think maybe being it's a question of definitions, i.e. "well, Sqlite is not fully ACID compliant" vs. all the google hits that just tells that sqlite is "ACID compliant"... Do I understand you correct, that by "You have to tell SQLite to be ACID compliant, effectively", you're saying that by default SQLite isn't ACID compliant ? Next question: Is it something I should worry about in my own programs (I'm not sure, I'm an SQL noob)... ? Thanks. From rosuav at gmail.com Sat Apr 13 10:03:25 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Apr 2013 00:03:25 +1000 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Apr 13, 2013 at 11:30 PM, someone wrote: > On 04/13/2013 01:39 PM, Chris Angelico wrote: >> Note that there's a caveat: You have to tell SQLite to be ACID >> compliant, effectively. > > > So, you're saying to me that by default SQLite isn't ACID compliant, if I > begin to use it in my own small programs? > ... > Do I understand you correct, that by "You have to tell SQLite to be ACID > compliant, effectively", you're saying that by default SQLite isn't ACID > compliant ? > First off: I am NOT inherently familiar with sqlite. I'm more familiar with PostgreSQL, DB2, and MySQL. I'm also not an expert at database engine design, so this discussion is from the point of view of an applications developer who has used databases from his apps. True ACID compliance demands support at every level: 1) The application has to operate in logical units of work, which - apart from with DB2 - requires an explicit "BEGIN" query, or single-statement transactions. 2) The database engine must employ some form of write-ahead log. Different databases do this somewhat differently (according to the page I linked to, SQLite does this in reverse, maintaining a log that's sufficient to *undo* the transaction, while PostgreSQL does this forwards, maintaining a log that's sufficient to *redo* it as well - more effort, but it can be used for database replication), but one way or another, there must be a way to detect half-done transactions. 3) The operating system and filesystem must support a forced file synchronization (fsync/fdatasync), so the database engine can wait for the data to be written to disk. 4) The underlying media (hard disk, SSD, USB stick, etc) must respond to the fsync call by actually writing the content to persistent storage before returning. Failure at any level means the overall system is not ACID compliant. PostgreSQL has a huge amount of code in it to try to deal with (or at least recognize) a level-3 failure, but nothing in the database engine can deal with level 1 or 4 issues. You'd have to actually test it. The easiest way is to get two computers, side by side, and run the database engine on one and a monitor on the other. To test some SSDs at work, I knocked together a little program that worked somewhat thus: * Connect to the database over TCP/IP (easy, as we were doing this with PostgreSQL) * Create a table with a number of rows with an ID and a counter, initialized to 0 * Repeatedly, in parallel, perform a transaction: - Increment the counter on one of the rows (at random) - Increment a "possible" in-memory counter for that row - Commit the database transaction - Increment a "confirmed" in-memory counter for that row * When an error of "database seems to be down" is detected, wait for it to come up again, then query the table. The counters must all be at least their corresponding "possible" value and at most the "confirmed". With that running, I simply pulled the plug on the database computer. With a properly-configured hard disk, every one of the counters was within its correct range. With a lying SSD, though, they could be anywhere from "pretty close" (with a low workload - simulated by having only a single thread doing transactions and having it sleep for a few ms each iteration) to "pretty appalling" (with a bunch of threads spinning tightly, keeping the workload high). Once the SSD starts doing major write reordering, its throughput soars, but at the cost of trustworthiness. > Next question: Is it something I should worry about in my own programs (I'm > not sure, I'm an SQL noob)... ? Yes, it most certainly is. If you have any data that you care about, put together some kind of test that will allow you to literally pull the plug on the database, while still knowing whether or not your transaction was completed (so you'll most likely need some kind of "possible" / "confirmed" counter pair as I used above). ChrisA From newsboost at gmail.com Sat Apr 13 17:36:07 2013 From: newsboost at gmail.com (someone) Date: Sat, 13 Apr 2013 23:36:07 +0200 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04/13/2013 10:01 PM, Dennis Lee Bieber wrote: > On Sun, 14 Apr 2013 00:03:25 +1000, Chris Angelico > declaimed the following in gmane.comp.python.general: [ ....] >> * Create a table with a number of rows with an ID and a counter, >> initialized to 0 >> * Repeatedly, in parallel, perform a transaction: >> - Increment the counter on one of the rows (at random) >> - Increment a "possible" in-memory counter for that row >> - Commit the database transaction >> - Increment a "confirmed" in-memory counter for that row >> * When an error of "database seems to be down" is detected, wait for >> it to come up again, then query the table. The counters must all be at >> least their corresponding "possible" value and at most the >> "confirmed". >> > SQLite is a "file server" database (like M$ JET engine [aka: > "Access"]). It's locking system is multi-stage. It allows multiple > concurrent readers on a "shared" lock state. Only one connection can > perform write operations ("reserved" lock) alongside the readers. A > second connection attempting to perform a write will be rejected with a > database locked condition. Then it really gets nasty -- the writer > attempts to commit the update: The first step is to block other > connections from even entering the read state (the "pending" lock). > However, the writer itself is blocked until all remaining readers have > exited; only then does it have exclusive access to and SQLite makes > changes to the database file itself (prior to that, the writer > connection is changing page images in memory) Ok, this makes sense... It's not something I'll bother about to begin with, but maybe later (for critical apps) I can see that this is important. [ ....] > In the commit phase, SQLite first tries to ensure the rollback > journal is flushed to disk -- but that apparently is out of its control; > it can submit a sync command to the OS, but has to rely on what the OS > tells it about the state of the writes to disk (the book indicates that > some IDE drives would lie when queried about sync status, while still > having unwritten data in the on-board buffers). After the rollback > journal it submits the data to the database. I I agree, this must be a problem, when the OS is lying... > Crash during journal write: restart finds no journal, that transaction > is lost but the database itself is clean > > Crash after journal during database update, restart finds journal, > assumes database is suspect, and rolls back the pages, database is > restored to pre-transaction state > > Crash after database sync during removal of journal, restart either > finds journal still there and rolls back the pages restoring to > pretransaction state, or the file was removed from the directory and > SQLite determines database file is good with the last transaction in > place. Ok, this is a bit more advanced - I'll try to make my own experiments now and then after some time I guess I can dig more into these details, thanks. From rosuav at gmail.com Sat Apr 13 18:44:28 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Apr 2013 08:44:28 +1000 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Apr 14, 2013 at 6:01 AM, Dennis Lee Bieber wrote: > On Sun, 14 Apr 2013 00:03:25 +1000, Chris Angelico > declaimed the following in gmane.comp.python.general: > >> True ACID compliance demands support at every level: >> >> 1) The application has to operate in logical units of work, which - >> apart from with DB2 - requires an explicit "BEGIN" query, or >> single-statement transactions. >> > While SQLite3 normally runs in an auto-commit mode, the Python > DB-API spec, in general, requires that auto-commit be turned off. "The > Definitive Guide to SQLite" states that the Python adapter scans > queries, and will start a transaction if the query is one that will > change data (insert/replace/update). Read-only queries stay auto-commit > until one of the data change queries is submitted and not committed. Okay, that's good. Point still stands, though, that the application has to use BEGIN/COMMIT correctly; the size of the logical unit of work should be defined by what's one logical action, not by what gives the best performance. >> * Connect to the database over TCP/IP (easy, as we were doing this >> with PostgreSQL) > > You don't with SQLite -- or, properly, it is not to an SQLite > port... It would be something like an NFS mounted file share -- and we > all know how uncertain file locking is over NFS. Sure, but you could easily make a tiny "SQLite server" that accepts socket connections, reads integers, and writes back "OK" when the transaction's committed. The only difference is that you have to write two halves instead of letting the DB itself be the other half. >> * Create a table with a number of rows with an ID and a counter, >> initialized to 0 >> * Repeatedly, in parallel, perform a transaction: >> - Increment the counter on one of the rows (at random) > So in your example above, the first process to submit an update > command is going to lock all the others from submitting updates AND will > itself be held from committing the update until all the other processes > have closed (commit or rollback their "read sessions"). Ah, that'd be a problem. What if each row is in its own file, though? Would that work? That is, instead of: UPDATE durability_test_table SET counter=counter+1 WHERE id=:random_value you use: UPDATE durability_test_:random_value SET counter=counter+1 (except, of course, that SQL parameterization wouldn't work there, so it'd be Python string manipulation) - this way, transactions will lock only against other transactions manipulating the same entry, which is effectively the same as row-level locking. With 2-3 times as many "rows" as threads, there should be very little lock contention. ChrisA From roy at panix.com Sat Apr 13 10:36:19 2013 From: roy at panix.com (Roy Smith) Date: Sat, 13 Apr 2013 10:36:19 -0400 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Chris Angelico wrote: > 2) The database engine must employ some form of write-ahead log. > [...] > one way or another, there must be a way to detect half-done > transactions. > > 3) The operating system and filesystem must support a forced file > synchronization (fsync/fdatasync), so the database engine can wait for > the data to be written to disk. > > 4) The underlying media (hard disk, SSD, USB stick, etc) must respond > to the fsync call by actually writing the content to persistent > storage before returning. Some of the early Unix file systems were very fragile. One of the (often under-appreciated) major advances in BSD (it was certainly in 4.2, not sure how much earlier) was a new filesystem which was much more robust in the face of hardware failures and system crashes. Prior to BSD, the on-disk data could be left in an inconsistent state if the system crashed at the wrong time. In BSD, data was written to disk in such a way that every operation could either be backed out cleanly or had enough information to complete the transaction. From newsboost at gmail.com Sat Apr 13 15:25:08 2013 From: newsboost at gmail.com (someone) Date: Sat, 13 Apr 2013 21:25:08 +0200 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04/13/2013 04:36 PM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> 2) The database engine must employ some form of write-ahead log. >> [...] >> one way or another, there must be a way to detect half-done >> transactions. >> >> 3) The operating system and filesystem must support a forced file >> synchronization (fsync/fdatasync), so the database engine can wait for >> the data to be written to disk. >> >> 4) The underlying media (hard disk, SSD, USB stick, etc) must respond >> to the fsync call by actually writing the content to persistent >> storage before returning. > > Some of the early Unix file systems were very fragile. One of the > (often under-appreciated) major advances in BSD (it was certainly in > 4.2, not sure how much earlier) was a new filesystem which was much more > robust in the face of hardware failures and system crashes. Prior to Are you talking about (journaling?) filesystems such as ext3, ext4, JFS, ReiserFS and XFS ? http://en.wikipedia.org/wiki/Journaling_file_system > BSD, the on-disk data could be left in an inconsistent state if the > system crashed at the wrong time. In BSD, data was written to disk in > such a way that every operation could either be backed out cleanly or > had enough information to complete the transaction. Journaling filesystems? I myself use ext4... There's a comparison here: http://en.wikipedia.org/wiki/Comparison_of_file_systems ? From roy at panix.com Sat Apr 13 17:38:07 2013 From: roy at panix.com (Roy Smith) Date: Sat, 13 Apr 2013 17:38:07 -0400 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , someone wrote: > > Some of the early Unix file systems were very fragile. One of the > > (often under-appreciated) major advances in BSD (it was certainly in > > 4.2, not sure how much earlier) was a new filesystem which was much more > > robust in the face of hardware failures and system crashes. Prior to > > Are you talking about (journaling?) filesystems such as ext3, ext4, JFS, > ReiserFS and XFS ? > > http://en.wikipedia.org/wiki/Journaling_file_system No, I'm talking about http://en.wikipedia.org/wiki/Berkeley_Fast_File_System Journaling came along later. From newsboost at gmail.com Sat Apr 13 10:39:12 2013 From: newsboost at gmail.com (someone) Date: Sat, 13 Apr 2013 16:39:12 +0200 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04/13/2013 04:03 PM, Chris Angelico wrote: > On Sat, Apr 13, 2013 at 11:30 PM, someone wrote: >> On 04/13/2013 01:39 PM, Chris Angelico wrote: >>> Note that there's a caveat: You have to tell SQLite to be ACID >>> compliant, effectively. >> >> >> So, you're saying to me that by default SQLite isn't ACID compliant, if I >> begin to use it in my own small programs? >> ... >> Do I understand you correct, that by "You have to tell SQLite to be ACID >> compliant, effectively", you're saying that by default SQLite isn't ACID >> compliant ? >> > > First off: I am NOT inherently familiar with sqlite. I'm more familiar > with PostgreSQL, DB2, and MySQL. I'm also not an expert at database > engine design, so this discussion is from the point of view of an > applications developer who has used databases from his apps. Ok, would be nice to hear the opinion from an sqlite expert then... > True ACID compliance demands support at every level: > > 1) The application has to operate in logical units of work, which - > apart from with DB2 - requires an explicit "BEGIN" query, or > single-statement transactions. > > 2) The database engine must employ some form of write-ahead log. > Different databases do this somewhat differently (according to the > page I linked to, SQLite does this in reverse, maintaining a log > that's sufficient to *undo* the transaction, while PostgreSQL does > this forwards, maintaining a log that's sufficient to *redo* it as > well - more effort, but it can be used for database replication), but > one way or another, there must be a way to detect half-done > transactions. > > 3) The operating system and filesystem must support a forced file > synchronization (fsync/fdatasync), so the database engine can wait for > the data to be written to disk. > > 4) The underlying media (hard disk, SSD, USB stick, etc) must respond > to the fsync call by actually writing the content to persistent > storage before returning. Ok. > Failure at any level means the overall system is not ACID compliant. Roger... But google says sqlite is supposed to be ACID compliant (although maybe not "fully" as you indicate, I'm not sure about this)... > PostgreSQL has a huge amount of code in it to try to deal with (or at > least recognize) a level-3 failure, but nothing in the database engine > can deal with level 1 or 4 issues. > > You'd have to actually test it. The easiest way is to get two > computers, side by side, and run the database engine on one and a > monitor on the other. To test some SSDs at work, I knocked together a > little program that worked somewhat thus: > > * Connect to the database over TCP/IP (easy, as we were doing this > with PostgreSQL) > * Create a table with a number of rows with an ID and a counter, > initialized to 0 > * Repeatedly, in parallel, perform a transaction: > - Increment the counter on one of the rows (at random) > - Increment a "possible" in-memory counter for that row > - Commit the database transaction > - Increment a "confirmed" in-memory counter for that row > * When an error of "database seems to be down" is detected, wait for > it to come up again, then query the table. The counters must all be at > least their corresponding "possible" value and at most the > "confirmed". Ok, that doesn't sound to be so simple after all... > With that running, I simply pulled the plug on the database computer. > With a properly-configured hard disk, every one of the counters was > within its correct range. With a lying SSD, though, they could be > anywhere from "pretty close" (with a low workload - simulated by > having only a single thread doing transactions and having it sleep for > a few ms each iteration) to "pretty appalling" (with a bunch of > threads spinning tightly, keeping the workload high). Once the SSD > starts doing major write reordering, its throughput soars, but at the > cost of trustworthiness. Ok, it would be nice to hear/read the opinion from another in here who've been working (a lot?) with sqlite... >> Next question: Is it something I should worry about in my own programs (I'm >> not sure, I'm an SQL noob)... ? > > Yes, it most certainly is. If you have any data that you care about, > put together some kind of test that will allow you to literally pull > the plug on the database, while still knowing whether or not your > transaction was completed (so you'll most likely need some kind of > "possible" / "confirmed" counter pair as I used above). I'm not so rich, so I prefer to go for a free database solution rather than an expensive license... I've heard good things about oracle and that's also what they used at my previous company, but it's not something I am willing to pay for, from my private/own money for my sparetime-projects... Maybe what you've written explains why somebody got corrupted firefox sqlite files... I'll just practice a bit more and remember your advice about testing - at least for "important" projects, I'll remember how you tested this with pulling out the plug and monitoring the data... From walterhurry at lavabit.com Sat Apr 13 10:56:49 2013 From: walterhurry at lavabit.com (Walter Hurry) Date: Sat, 13 Apr 2013 14:56:49 +0000 (UTC) Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, 13 Apr 2013 16:39:12 +0200, someone wrote: > I'm not so rich, so I prefer to go for a free database solution rather > than an expensive license ( but I do care about ACID compliance) Sounds to me that PostgreSQL is your man, then. From newsboost at gmail.com Sat Apr 13 15:34:38 2013 From: newsboost at gmail.com (someone) Date: Sat, 13 Apr 2013 21:34:38 +0200 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04/13/2013 04:56 PM, Walter Hurry wrote: > On Sat, 13 Apr 2013 16:39:12 +0200, someone wrote: > >> I'm not so rich, so I prefer to go for a free database solution rather >> than an expensive license > ( but I do care about ACID compliance) > > Sounds to me that PostgreSQL is your man, then. Oh, ok. Thanks! BTW: I just read: "Yahoo runs a multi-petabyte modified PostgreSQL database that processes billions of events per day" - that's truely amazing, I think... I think maybe I'll experiment a bit with both mySql (small/medium sized databases) and for critical/important stuff I should go with PostgreSQL... Glad to hear this... Then I know what to look at... From walterhurry at lavabit.com Sat Apr 13 18:22:05 2013 From: walterhurry at lavabit.com (Walter Hurry) Date: Sat, 13 Apr 2013 22:22:05 +0000 (UTC) Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, 13 Apr 2013 21:34:38 +0200, someone wrote: > On 04/13/2013 04:56 PM, Walter Hurry wrote: >> On Sat, 13 Apr 2013 16:39:12 +0200, someone wrote: >> >>> I'm not so rich, so I prefer to go for a free database solution rather >>> than an expensive license >> ( but I do care about ACID compliance) >> >> Sounds to me that PostgreSQL is your man, then. > > Oh, ok. Thanks! BTW: I just read: "Yahoo runs a multi-petabyte modified > PostgreSQL database that processes billions of events per day" - that's > truely amazing, I think... > > I think maybe I'll experiment a bit with both mySql (small/medium sized > databases) and for critical/important stuff I should go with > PostgreSQL... Glad to hear this... Then I know what to look at... If it were me I wouldn't use MySQL for anything at all. I'd use sqlite for little non-critical local applications, and Postgres for the rest. Postgres is not difficult at all, provided you RTFM and follow the instructions (the documentation is superb). And whichever you use, you need to learn SQL anyway. From newsboost at gmail.com Sat Apr 13 18:31:05 2013 From: newsboost at gmail.com (someone) Date: Sun, 14 Apr 2013 00:31:05 +0200 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04/14/2013 12:22 AM, Walter Hurry wrote: > On Sat, 13 Apr 2013 21:34:38 +0200, someone wrote: > >> On 04/13/2013 04:56 PM, Walter Hurry wrote: >>> On Sat, 13 Apr 2013 16:39:12 +0200, someone wrote: >>> >>>> I'm not so rich, so I prefer to go for a free database solution rather >>>> than an expensive license >>> ( but I do care about ACID compliance) >>> >>> Sounds to me that PostgreSQL is your man, then. >> >> Oh, ok. Thanks! BTW: I just read: "Yahoo runs a multi-petabyte modified >> PostgreSQL database that processes billions of events per day" - that's >> truely amazing, I think... >> >> I think maybe I'll experiment a bit with both mySql (small/medium sized >> databases) and for critical/important stuff I should go with >> PostgreSQL... Glad to hear this... Then I know what to look at... > > If it were me I wouldn't use MySQL for anything at all. I'd use sqlite > for little non-critical local applications, and Postgres for the rest. Ok, thank you. I just came across a blog that said pytables is also a very good option? http://www.pytables.org/moin/PyTables?action=AttachFile&do=view&target=non-indexed.png > Postgres is not difficult at all, provided you RTFM and follow the > instructions (the documentation is superb). And whichever you use, you > need to learn SQL anyway. Good to hear... I'll dig more into it, thank you... From rosuav at gmail.com Sat Apr 13 18:54:28 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Apr 2013 08:54:28 +1000 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Apr 14, 2013 at 8:31 AM, someone wrote: > Ok, thank you. I just came across a blog that said pytables is also a very > good option? > > http://www.pytables.org/moin/PyTables?action=AttachFile&do=view&target=non-indexed.png >From what I gather, that's looking at performance of a non-indexable query on a 10,000,000-row table. That's going to suck whatever you do, and the exact level of suckitude doesn't really prove much. (Note that even the best options are taking half a second for this single query.) A better test of a database is transactions per second of something that approximates to your real workload. For instance, English Wikipedia has roughly a hundred edits per minute (assessed by me just now by looking at the Recent Changes), and some ridiculous number of page reads per minute (not assessed, but believed to be somewhere between 11 and Graham's number); so a test of a proposed new database would have to mimic this ratio. Most of the queries involved should be able to be answered using indexes; in some cases, ONLY using the index (eg if you just want to know whether or not a row exists). PyTables may well outperform PostgreSQL in real usage, but that one graph doesn't tell me that. (Not to mention that it's measuring a somewhat old PG.) ChrisA From newsboost at gmail.com Sat Apr 13 20:06:26 2013 From: newsboost at gmail.com (someone) Date: Sun, 14 Apr 2013 02:06:26 +0200 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04/14/2013 12:54 AM, Chris Angelico wrote: > On Sun, Apr 14, 2013 at 8:31 AM, someone wrote: >> Ok, thank you. I just came across a blog that said pytables is also a very >> good option? >> >> http://www.pytables.org/moin/PyTables?action=AttachFile&do=view&target=non-indexed.png > >>From what I gather, that's looking at performance of a non-indexable > query on a 10,000,000-row table. That's going to suck whatever you do, > and the exact level of suckitude doesn't really prove much. (Note that > even the best options are taking half a second for this single query.) Interesting... Thank you very much for that information... > A better test of a database is transactions per second of something > that approximates to your real workload. For instance, English > Wikipedia has roughly a hundred edits per minute (assessed by me just > now by looking at the Recent Changes), and some ridiculous number of > page reads per minute (not assessed, but believed to be somewhere > between 11 and Graham's number); so a test of a proposed new database > would have to mimic this ratio. Most of the queries involved should be > able to be answered using indexes; in some cases, ONLY using the index > (eg if you just want to know whether or not a row exists). > > PyTables may well outperform PostgreSQL in real usage, but that one > graph doesn't tell me that. (Not to mention that it's measuring a > somewhat old PG.) Ok, thank you very much... Sounds to me like PostgreSQL it is, then :-) From rosuav at gmail.com Sat Apr 13 18:34:51 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Apr 2013 08:34:51 +1000 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Apr 14, 2013 at 5:34 AM, someone wrote: > I think maybe I'll experiment a bit with both mySql (small/medium sized > databases) and for critical/important stuff I should go with PostgreSQL PostgreSQL isn't majorly slower than MySQL, and it's a lot more trustworthy in terms of database constraints and so on. MySQL is designed as a place for a single application to store its data, and it assumes that the application is king; PostgreSQL is designed as a database against which application(s) may execute queries, therefore it assumes that the database administrator is king. With heavy read/write workloads, I'd put my money on PostgreSQL every time; MySQL has a much greater problem with wide locks (eg table-level) and consequent loss of concurrency. ChrisA From newsboost at gmail.com Sat Apr 13 20:10:54 2013 From: newsboost at gmail.com (someone) Date: Sun, 14 Apr 2013 02:10:54 +0200 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04/14/2013 12:34 AM, Chris Angelico wrote: > On Sun, Apr 14, 2013 at 5:34 AM, someone wrote: >> I think maybe I'll experiment a bit with both mySql (small/medium sized >> databases) and for critical/important stuff I should go with PostgreSQL > > PostgreSQL isn't majorly slower than MySQL, and it's a lot more > trustworthy in terms of database constraints and so on. MySQL is > designed as a place for a single application to store its data, and it > assumes that the application is king; PostgreSQL is designed as a > database against which application(s) may execute queries, therefore > it assumes that the database administrator is king. > > With heavy read/write workloads, I'd put my money on PostgreSQL every > time; MySQL has a much greater problem with wide locks (eg > table-level) and consequent loss of concurrency. Ok, thank you very much... Sounds like PostgreSQL is the best option for me to go on to from here, after I've played a bit my sqlite... From rosuav at gmail.com Sat Apr 13 12:15:55 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Apr 2013 02:15:55 +1000 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Apr 14, 2013 at 12:39 AM, someone wrote: > On 04/13/2013 04:03 PM, Chris Angelico wrote: >> Failure at any level means the overall system is not ACID compliant. > > Roger... But google says sqlite is supposed to be ACID compliant (although > maybe not "fully" as you indicate, I'm not sure about this)... What your Google hits are telling you is that sqlite can (if configured correctly) pass level 2. But it doesn't guarantee anything about the other levels, so it's easy to have an, uhh, ACID leak. >> You'd have to actually test it. The easiest way is to get two >> computers, side by side, and run the database engine on one and a >> monitor on the other. > > Ok, that doesn't sound to be so simple after all... I gave a fairly wordy run-down of what I tested, but it's actually fairly simple in concept: Do a huge bunch of transactions, and keep a log of what's returned from the COMMIT query; then pull the power out. > Ok, it would be nice to hear/read the opinion from another in here who've > been working (a lot?) with sqlite... Agreed. I'm sure someone will chime in. > I'm not so rich, so I prefer to go for a free database solution rather than > an expensive license... I've heard good things about oracle and that's also > what they used at my previous company, but it's not something I am willing > to pay for, from my private/own money for my sparetime-projects... I concur with Walter's assessment: You want PostgreSQL. It's free/open source software (highly permissive MIT-like license), massively trusted, and scales up beautifully. (That last one may not be significant to you, but it's still good to know your database can handle hundreds or thousands of tps on basic hardware.) ChrisA From rustompmody at gmail.com Sat Apr 13 13:02:18 2013 From: rustompmody at gmail.com (rusi) Date: Sat, 13 Apr 2013 10:02:18 -0700 (PDT) Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2d737309-6608-4e2e-8ff1-2b8b020a418c@qc10g2000pbb.googlegroups.com> On Apr 13, 9:15?pm, Chris Angelico wrote: > On Sun, Apr 14, 2013 at 12:39 AM, someone wrote: > > On 04/13/2013 04:03 PM, Chris Angelico wrote: > >> Failure at any level means the overall system is not ACID compliant. > > > Roger... But google says sqlite is supposed to be ACID compliant (although > > maybe not "fully" as you indicate, I'm not sure about this)... > > What your Google hits are telling you is that sqlite can (if > configured correctly) pass level 2. But it doesn't guarantee anything > about the other levels, so it's easy to have an, uhh, ACID leak. > > >> You'd have to actually test it. The easiest way is to get two > >> computers, side by side, and run the database engine on one and a > >> monitor on the other. > > > Ok, that doesn't sound to be so simple after all... > > I gave a fairly wordy run-down of what I tested, but it's actually > fairly simple in concept: Do a huge bunch of transactions, and keep a > log of what's returned from the COMMIT query; then pull the power out. > > > Ok, it would be nice to hear/read the opinion from another in here who've > > been working (a lot?) with sqlite... > > Agreed. I'm sure someone will chime in. > > > I'm not so rich, so I prefer to go for a free database solution rather than > > an expensive license... I've heard good things about oracle and that's also > > what they used at my previous company, but it's not something I am willing > > to pay for, from my private/own money for my sparetime-projects... > > I concur with Walter's assessment: You want PostgreSQL. It's free/open > source software (highly permissive MIT-like license), massively > trusted, and scales up beautifully. (That last one may not be > significant to you, but it's still good to know your database can > handle hundreds or thousands of tps on basic hardware.) > > ChrisA Dunno why you guys are ACIDing a hapless python+SQL noob. As far as I can see he did not even know what ACID was... Just happened to start with mysql (without evidently knowing the DBMS area) and Cousin Stanley's recommendation to step a notch down from mysql to sqlite seems to me to be spot-on for his requirement. To the OP: Steven is welcome to his views about use of databases. Good to remember that everyone does not agree with him. This includes the firefox devs as well as python devs. In particular, sqlite in python is quite special. All the other databases have bridge modules to talk from python to the database. Which means that python runs and the database runs and the two talk asynchronously across the bridge using what is called a 'client-server model'. Now client-server is powerful and sophisticated and earlier it was the only option. That is the noob database programmer had to grapple with sql (the basic stuff) along with the transaction/ACID advanced stuff. Sqlite changed the rules of the game. Sqlite allows programmers to play with sql without having to deal with client server headaches at the same time. Python amplified that change by bundling it with python. In short Python+Sqlite is a boon for beginners to programming+DBMS From newsboost at gmail.com Sat Apr 13 15:49:55 2013 From: newsboost at gmail.com (someone) Date: Sat, 13 Apr 2013 21:49:55 +0200 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: <2d737309-6608-4e2e-8ff1-2b8b020a418c@qc10g2000pbb.googlegroups.com> References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> <2d737309-6608-4e2e-8ff1-2b8b020a418c@qc10g2000pbb.googlegroups.com> Message-ID: On 04/13/2013 07:02 PM, rusi wrote: > On Apr 13, 9:15 pm, Chris Angelico wrote: >> On Sun, Apr 14, 2013 at 12:39 AM, someone wrote: >>> On 04/13/2013 04:03 PM, Chris Angelico wrote: ..... ..... >>>> Failure at any level means the overall system is not ACID compliant. >>> Ok, it would be nice to hear/read the opinion from another in here who've >>> been working (a lot?) with sqlite... >> >> Agreed. I'm sure someone will chime in. >> >>> I'm not so rich, so I prefer to go for a free database solution rather than >>> an expensive license... I've heard good things about oracle and that's also >>> what they used at my previous company, but it's not something I am willing >>> to pay for, from my private/own money for my sparetime-projects... >> >> I concur with Walter's assessment: You want PostgreSQL. It's free/open >> source software (highly permissive MIT-like license), massively >> trusted, and scales up beautifully. (That last one may not be >> significant to you, but it's still good to know your database can >> handle hundreds or thousands of tps on basic hardware.) >> >> ChrisA > > Dunno why you guys are ACIDing a hapless python+SQL noob. That's ok - I'm very interested in hearing/reading this, so don't worry :-) > As far as I can see he did not even know what ACID was... Just I think I know it know (maybe not all the details, but generally I know that it should be ACID-compliant for critical data to avoid corruption and bad data) :-) > happened to start with mysql (without evidently knowing the DBMS area) > and Cousin Stanley's recommendation to step a notch down from mysql to > sqlite seems to me to be spot-on for his requirement. Agree - but after that I would like to play with a client/server-system, so that's also interesting to hear about... > To the OP: > Steven is welcome to his views about use of databases. Good to > remember that everyone does not agree with him. This includes the > firefox devs as well as python devs. Yes, I think I understand this discussion. I'm sorry to hear that the sqlite-database-files sometimes become corrupted. I haven't experienced this problem myself (AFAIR), because ~90% of the time I'm on chromium. > In particular, sqlite in python is quite special. All the other > databases have bridge modules to talk from python to the database. > Which means that python runs and the database runs and the two talk > asynchronously across the bridge using what is called a 'client-server > model'. Now client-server is powerful and sophisticated and earlier it Yes, got it :-) > was the only option. That is the noob database programmer had to > grapple with sql (the basic stuff) along with the transaction/ACID > advanced stuff. Yep, I understand your intentions... > Sqlite changed the rules of the game. Sqlite allows programmers to > play with sql without having to deal with client server headaches at > the same time. > Python amplified that change by bundling it with python. > > In short Python+Sqlite is a boon for beginners to programming+DBMS I completely agree with you that Python+Sqlite is really really great... But soon I'll also move on to using a client/server model and therefore I also appreciate the other comments/discussion related to e.g. failure or non-"fully-ACID compliance" of sqlite, which maybe can explain this firefox problem with corrupted database(s)... I think I learned a lot from this thread and know what I should be working on now... From steve+comp.lang.python at pearwood.info Sun Apr 14 03:56:21 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Apr 2013 07:56:21 GMT Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> <2d737309-6608-4e2e-8ff1-2b8b020a418c@qc10g2000pbb.googlegroups.com> Message-ID: <516a6125$0$29977$c3e8da3$5496439d@news.astraweb.com> On Sat, 13 Apr 2013 10:02:18 -0700, rusi wrote: > To the OP: > Steven is welcome to his views about use of databases. I haven't given any views about databases. I've given my view on application developers -- specifically, Firefox -- using a not-quite ACID database in a way that is fragile, can cause data loss, and adds lots more complexity to the application AND the end-user experience. And for what? Simple data that would be much better in a simpler format, such as bookmarks. > Good to remember > that everyone does not agree with him. This includes the firefox devs as > well as python devs. I don't see what the Python devs have to do with it. They don't use Sqlite for Python's internals, and the fact that there is a module for sqlite doesn't mean squat. There's a module for parsing Sun AU audio files, that doesn't mean the Python devs recommend that they are the best solution to your audio processing and multimedia needs. I'm not saying that Sqlite doesn't have it's uses, although I personally haven't found them yet. And as for the Firefox devs, well, I'll just let Jamie Zawinski show their l33t des1gn ski11z in context: http://www.jwz.org/blog/2003/01/more-khtml/ Okay, that's ten years old. What do you think the odds are that Firefox has a nice, clean design by now? Well, I suppose it's possible, but when it takes a minimum of NINE files to do the equivalent of "Hello World" in Firefox, I wouldn't put money on it: http://kb.mozillazine.org/Getting_started_with_extension_development I mean, really -- bookmarks, in a single-user application, and they store it in a database. You can't even have two instances of Firefox running at the same time. The consequences of this over-engineered solution is that Firefox is more complex and fragile than it needs be, and less reliable than it could be. When your bookmarks database gets corrupt, which is easy, the browser History and Back button stop working, which then pushes responsibility for fixing the database corruption back on the user. So the Firefox developers actually end up paying the costs of a non-lightweight implementation, but without the benefits. They don't even get to remove the old bookmarks to HTML code, since they still need it for manual exports and backups. Considering the rest of the Firefox architecture (XUL, XUL everywhere!), using sqlite probably feels like a lightweight solution to the devs. "The Mork database structure used by Mozilla Firefox v1-2 is unusual to say the least. It was originally developed by Netscape for their browser (Netscape v6) and the format was later adopted by Mozilla to be used in Firefox. It is a plain text format which is not easily human readable and is not efficient in its storage structures. For example, a single Unicode character can take many bytes to store. The developers themselves complained it was extremely difficult to parse correctly and from Firefox v3, it was replaced by MozStorage which is based on an SQLite database." http://wordpress.bladeforensics.com/?p=357 http://en.wikipedia.org/wiki/Mork_%28file_format%29 -- Steven From rustompmody at gmail.com Sun Apr 14 07:17:28 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 14 Apr 2013 04:17:28 -0700 (PDT) Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> <2d737309-6608-4e2e-8ff1-2b8b020a418c@qc10g2000pbb.googlegroups.com> <516a6125$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8555d9af-e52e-47d6-b2bd-ef7fe5dd61d9@pl9g2000pbb.googlegroups.com> On Apr 14, 12:56 pm, Steven D'Aprano wrote: > On Sat, 13 Apr 2013 10:02:18 -0700, rusi wrote: > > To the OP: > > Steven is welcome to his views about use of databases. > > I haven't given any views about databases. You are twisting "use of databases" to just "about databases" And heres what you said: > Using a database for such lightweight data as bookmarks is, in my > opinion, gross overkill and adds to the complexity of Firefox. More > complexity leads to more bugs? Not that I would disagree with that for general databases, just for something as atypical as sqlite. In short, you are being hypnotized by the word 'database' and not seeing that sqlite is a very strange instance of that species. http://en.wikipedia.org/wiki/Etymological_fallacy + http://en.wikipedia.org/wiki/Accident_%28fallacy%29 > I've given my view on > application developers -- specifically, Firefox -- using a not-quite ACID > database in a way that is fragile, can cause data loss, FUD Are you saying that flat-files dont lose data? > and adds lots > more complexity to the application AND the end-user experience. And for > what? Strange argument: If I call a one line re.match(..) that hooks into 5000 arcane lines of the re module, on whose account is the complexity -- mine or python's? >From a programmer's POV if 10 lines of flat-file munging are reduced to two lines of SQL its a reduction of 10 to 2. > Simple data that would be much better in a simpler format, such as > bookmarks. > > > Good to remember > > that everyone does not agree with him. This includes the firefox devs as > > well as python devs. > > I don't see what the Python devs have to do with it. They don't use > Sqlite for Python's internals, and the fact that there is a module for > sqlite doesn't mean squat. There's a module for parsing Sun AU audio > files, that doesn't mean the Python devs recommend that they are the best > solution to your audio processing and multimedia needs. Python made a choice to include AU file support when Sun existed and looked more respectable than MS. Today the support continues to exist probably for backward compatibility reasons. "The code's already written. Why remove it?" Sure but it has its costs -- memory footprint, sources-size etc -- which are deemed negligible enough to not bother. Likewise python 2.5 made a choice to include sqlite. Following RoR's D Hansson we may call it an 'opinionated choice.' That choice implies that the devs decided that a fixed-cost of bundling sqlite with python is deemed better than each programmer installing/rolling-his-own etc > > I'm not saying that Sqlite doesn't have it's uses, although I personally > haven't found them yet. And as for the Firefox devs, well, I'll just let > Jamie Zawinski show their l33t des1gn ski11z in context: > > http://www.jwz.org/blog/2003/01/more-khtml/ > Faulty generalization fallacy: http://en.wikipedia.org/wiki/Faulty_generalization Because some code in firefox is bad, every choice of firefox is bad? [Actually I am surprised that you agree with *that example*: Would you claim that a void returning, no-argument function is better than one with arguments and return values? Anyways thats really far away from this discussion?] To the OP: Lets deconstruct ACID. Consistency+Atomicity: Lets say you write some stack code like this stack[top] = newvalue top += 1 And if you catch the machine state between the two assignments, you will find an *inconsistent* stack because that code is *non-atomic* Should you bother? Yes if you have concurrency, no if not. Likewise Isolation is vacuously guaranteed if you are the sole guy running your code. As for Durability, if you randomly turn off your machine when your program is running, yes you may lose the results of your program. You may lose much else! IOW if you are alone on your machine, all discussion of ACID is moot From rosuav at gmail.com Sun Apr 14 09:22:03 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Apr 2013 23:22:03 +1000 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: <8555d9af-e52e-47d6-b2bd-ef7fe5dd61d9@pl9g2000pbb.googlegroups.com> References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> <2d737309-6608-4e2e-8ff1-2b8b020a418c@qc10g2000pbb.googlegroups.com> <516a6125$0$29977$c3e8da3$5496439d@news.astraweb.com> <8555d9af-e52e-47d6-b2bd-ef7fe5dd61d9@pl9g2000pbb.googlegroups.com> Message-ID: On Sun, Apr 14, 2013 at 9:17 PM, rusi wrote: > On Apr 14, 12:56 pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> I've given my view on >> application developers -- specifically, Firefox -- using a not-quite ACID >> database in a way that is fragile, can cause data loss, > > FUD > Are you saying that flat-files dont lose data? If they do, a human being can easily open them up and see what's inside. Suppose bookmarks are stored like this: r"""Some-Browser-Name web bookmarks file - edit with care url: http://www.google.com/ title: Search engine icon: whatever-format-you-want-to-use url: http://www.duckduckgo.com/ title: Another search engine url: http://www.python.org/ url: ftp://192.168.0.12/ title: My FTP Server desc: Photos are in photos/, videos are in videos/ Everything else is in other/ user: root pass: secret """ The parsing of this file is pretty simple. Blank line marks end of entry; indented line continues the previous attribute (like RFC822), everything else is "attribute: value". (You might even be able to abuse an RFC822 parser/compositor for the job.) The whole file has to be read and rewritten for any edits, so it's unsuited to gigabytes of content; but we're talking about *web browser bookmarks* here. I know some people have a lot of them, but hardly gigs and gigs. And if you think they will, then all you need to do is have multiple files, eg one for each folder in the bookmark tree. Now suppose it gets damaged somehow. Firstly, that's a lot less likely with a simple file format and a "write to temp file, then move temp file over main file" setup; but mainly, it's very easy to resynchronize - maybe there'll be one bookmark (or a group of bookmarks) that get flagged as corrupted, but everything after that can be parsed just fine - as soon as you get to a blank line, you start parsing again. Very simple. Well suited to a simple task. (Note, however, that the uber-simple concept I've posited here would have the same concurrency problems that Firefox has. At very least, it'd rely on some sort of filesystem-level lock when it starts rewriting the file. But this is approximately similar to running two instances of a text editor and trying to work with the same file.) > From a programmer's POV if 10 lines of flat-file munging are reduced > to two lines of SQL its a reduction of 10 to 2. The complexity exists in a variety of places. The two lines of SQL hide a morass of potential complexity; so would a massive regex. The file itself is way harder for external tools to manage. And all of it can be buggy. With a simple flat-file system, chances are you can turn it into a nested list structure and a dict for indexing (or possibly a collections.OrderedDict), and then you have the same reduction - it's just simple in-memory operations, possibly followed by a save() call. All the options available will do that, whether flat-file or database. >> I don't see what the Python devs have to do with it. They don't use >> Sqlite for Python's internals, and the fact that there is a module for >> sqlite doesn't mean squat. There's a module for parsing Sun AU audio >> files, that doesn't mean the Python devs recommend that they are the best >> solution to your audio processing and multimedia needs. > > Python made a choice to include AU file support when Sun existed and > looked more respectable than MS. Today the support continues to exist > probably for backward compatibility reasons. "The code's already > written. Why remove it?" > Sure but it has its costs -- memory footprint, sources-size etc -- > which are deemed negligible enough to not bother. Actually, this is one place where I disagree with the current decision of the Python core devs: I think bindings for other popular databases (most notably PostgreSQL, and probably MySQL since it's so widely used) ought to be included in core, rather than being shoved off to PyPI. Databasing is so important to today's world that it would really help if people had all the options right there in core, if only so they're more findable (if you're browsing docs.python.org, you won't know that psycopg is available). Currently the policy seems to be "we don't include the server so why should we include the client"; I disagree, I think the client would stand nicely on its own. (Does Python have a DNS server module? DNS client? I haven't dug deep, but I'm pretty sure I can do name lookups in Python, yet running a DNS server is sufficiently arcane that it can, quite rightly, be pushed off to PyPI.) But this is minor, and tangential to this discussion. > Faulty generalization fallacy: > http://en.wikipedia.org/wiki/Faulty_generalization > Because some code in firefox is bad, every choice of firefox is bad? It's a matter of windows into the philosophy, rather than specific examples. Requiring nine files to do a "Hello World" extension suggests a large corpus of mandatory boilerplate; imagine, for instance, that my example bookmarks file structure had demanded _every_ attribute be provided for _every_ bookmark, instead of permitting the defaults. That would demonstrate overkill in design, and the sort of person who would produce that is probably unable to simplify code for the same reasons. > As for Durability, if you randomly turn off your machine when your > program is running, yes you may lose the results of your program. You > may lose much else! > > IOW if you are alone on your machine, all discussion of ACID is moot No, no, a thousand times no! If I am doing financial transactions, even if I'm alone on my machine, I will demand full ACID compliance. Randomly turning off the machine is a simulation of the myriad possible failures - incoming power failure (or UPS failure, if you have one), power supply goes boom, motherboard gets fried, operating system encounters a hard failure condition, cleaning lady unplugs the server to put her vacuum cleaner onto the UPS... anything. The point of ACID compliance is that you might lose the results of *this run* of the program, but nothing more; and if any other program has been told "That's committed", then it really has been. Without some such guarantee, you might lose *all the data you have stored*, because something got corrupted. Partial guarantees of acidity are insufficient; imagine if power failure during ALTER TABLE can result in your whole database being unreadable. With the setup I described above, everything works beautifully if the OS guarantees an atomic mv() operation. Even if it doesn't, you can probably figure out what's going on by inspecting the file state; for instance, you can assume that a non-empty main file should be kept (discarding the temporary), but if the main file is empty or absent AND the temporary is readable and parseable, use the temporary. (This assumes that a fresh install creates a non-empty file, otherwise there's ambiguity at initial file creation which would need to be resolved. But you get the idea.) Of course, that uber-simple option does require a full file rewrite for every edit. But like I said, it's designed for simplicity, not concurrent writing. ChrisA From nad at acm.org Sun Apr 14 12:40:53 2013 From: nad at acm.org (Ned Deily) Date: Sun, 14 Apr 2013 09:40:53 -0700 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> <2d737309-6608-4e2e-8ff1-2b8b020a418c@qc10g2000pbb.googlegroups.com> <516a6125$0$29977$c3e8da3$5496439d@news.astraweb.com> <8555d9af-e52e-47d6-b2bd-ef7fe5dd61d9@pl9g2000pbb.googlegroups.com> Message-ID: In article , Chris Angelico wrote: > Actually, this is one place where I disagree with the current decision > of the Python core devs: I think bindings for other popular databases > (most notably PostgreSQL, and probably MySQL since it's so widely > used) ought to be included in core, rather than being shoved off to > PyPI. Databasing is so important to today's world that it would really > help if people had all the options right there in core, if only so > they're more findable (if you're browsing docs.python.org, you won't > know that psycopg is available). Currently the policy seems to be "we > don't include the server so why should we include the client"; I > disagree, I think the client would stand nicely on its own. (Does > Python have a DNS server module? DNS client? I haven't dug deep, but > I'm pretty sure I can do name lookups in Python, yet running a DNS > server is sufficiently arcane that it can, quite rightly, be pushed > off to PyPI.) But this is minor, and tangential to this discussion. For the bindings to be useful, Python batteries-included distributions (like python.org installers) would either need to also ship the various DB client libraries for all supported platforms (including Windows), which adds complexity and potentially intractable license issues, or there would need to be reverse-engineered implementations of the client libs or wire protocols, either option adding fragility and complex testing issues. DNS client lookups use published, well-understood Internet-standard protocols, not at all like talking to a third-party database, be it open-source or not. Sqlite3 is certainly an anomaly in that it is not-only open source but designed to be a lightweight, compatible library that runs on just about everything, and with a fanatical devotion to compatibility and documentation. These days just about every major product or operating system platform ships with or uses a copy of sqllite3 for something. -- Ned Deily, nad at acm.org From python.list at tim.thechases.com Sun Apr 14 16:16:08 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 14 Apr 2013 15:16:08 -0500 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> <2d737309-6608-4e2e-8ff1-2b8b020a418c@qc10g2000pbb.googlegroups.com> <516a6125$0$29977$c3e8da3$5496439d@news.astraweb.com> <8555d9af-e52e-47d6-b2bd-ef7fe5dd61d9@pl9g2000pbb.googlegroups.com> Message-ID: <20130414151608.0f7dedd7@bigbox.christie.dr> On 2013-04-14 09:40, Ned Deily wrote: > DNS client lookups use published, well-understood > Internet-standard protocols, not at all like talking to a > third-party database, be it open-source or not. That said, even though DNS is a publicly documented standard, I've reached for DNS code in the Python stdlib on multiple occasions (usually to try and snag the MX record for a customer, so smtplib can send stuff to it), and get disappointed each time. I'd really love if there was a simple DNS-lookup module available in the stdlib, especially if it allowed overriding the server to ask. I mean...POP, IMAP and SMTP are all publicly documented standards that Python makes easily accessible. DNS would be a good addition. -tkc From rosuav at gmail.com Sun Apr 14 17:43:47 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 15 Apr 2013 07:43:47 +1000 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> <2d737309-6608-4e2e-8ff1-2b8b020a418c@qc10g2000pbb.googlegroups.com> <516a6125$0$29977$c3e8da3$5496439d@news.astraweb.com> <8555d9af-e52e-47d6-b2bd-ef7fe5dd61d9@pl9g2000pbb.googlegroups.com> Message-ID: On Mon, Apr 15, 2013 at 2:40 AM, Ned Deily wrote: > In article > , > Chris Angelico wrote: > > Actually, this is one place where I disagree with the current decision >> of the Python core devs: I think bindings for other popular databases >> (most notably PostgreSQL, and probably MySQL since it's so widely >> used) ought to be included in core, rather than being shoved off to >> PyPI. Databasing is so important to today's world that it would really >> help if people had all the options right there in core, if only so >> they're more findable (if you're browsing docs.python.org, you won't >> know that psycopg is available). Currently the policy seems to be "we >> don't include the server so why should we include the client"; I >> disagree, I think the client would stand nicely on its own. (Does >> Python have a DNS server module? DNS client? I haven't dug deep, but >> I'm pretty sure I can do name lookups in Python, yet running a DNS >> server is sufficiently arcane that it can, quite rightly, be pushed >> off to PyPI.) But this is minor, and tangential to this discussion. > > For the bindings to be useful, Python batteries-included distributions > (like python.org installers) would either need to also ship the various > DB client libraries for all supported platforms (including Windows), > which adds complexity and potentially intractable license issues, or > there would need to be reverse-engineered implementations of the client > libs or wire protocols, either option adding fragility and complex > testing issues. DNS client lookups use published, well-understood > Internet-standard protocols, not at all like talking to a third-party > database, be it open-source or not. Sqlite3 is certainly an anomaly in > that it is not-only open source but designed to be a lightweight, > compatible library that runs on just about everything, and with a > fanatical devotion to compatibility and documentation. These days just > about every major product or operating system platform ships with or > uses a copy of sqllite3 for something. Understandable, but I'm actually referencing a discussion on either python-dev or python-ideas where the statement was made that it didn't make sense to include the client for something that the server for wasn't included. I can't find the discussion thread off-hand, but that, rather than the portability/complication issues, seemed to be the primary line of argument. I don't know about any others, but PostgreSQL's wire protocol isn't all that difficult to work with, and since we're talking about something where the far end is almost certainly going to consume some time, it wouldn't hurt to implement it in pure Python. Based on http://wiki.postgresql.org/wiki/Python it seems there are a few modules that do just that (unchecked, but if they work on any platform and don't require libpq, I strongly suspect they use Python's own networking); if one of those is of sufficient code quality for the stdlib, I think it would be an excellent addition. However, I am not a core dev, therefore sqlite is the only one included. ChrisA From roy at panix.com Sun Apr 14 17:48:17 2013 From: roy at panix.com (Roy Smith) Date: Sun, 14 Apr 2013 17:48:17 -0400 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> <2d737309-6608-4e2e-8ff1-2b8b020a418c@qc10g2000pbb.googlegroups.com> <516a6125$0$29977$c3e8da3$5496439d@news.astraweb.com> <8555d9af-e52e-47d6-b2bd-ef7fe5dd61d9@pl9g2000pbb.googlegroups.com> Message-ID: In article , Tim Chase wrote: > I'd really love if there was a simple DNS-lookup module available in > the stdlib, especially if it allowed overriding the server to ask. pip install dnspython From rustompmody at gmail.com Mon Apr 15 07:45:25 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 15 Apr 2013 04:45:25 -0700 (PDT) Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> <2d737309-6608-4e2e-8ff1-2b8b020a418c@qc10g2000pbb.googlegroups.com> <516a6125$0$29977$c3e8da3$5496439d@news.astraweb.com> <8555d9af-e52e-47d6-b2bd-ef7fe5dd61d9@pl9g2000pbb.googlegroups.com> Message-ID: I am trying to understand your points Chris. On the one hand you say: On Apr 14, 6:22 pm, Chris Angelico wrote: > No, no, a thousand times no! If I am doing financial transactions, > even if I'm alone on my machine, I will demand full ACID compliance. On the other you describe a bookmark storage scheme (which it seems you are recommending); to wit > Suppose bookmarks are stored like this: > > r"""Some-Browser-Name web bookmarks file - edit with care > url:http://www.google.com/ > title: Search engine > icon: whatever-format-you-want-to-use > > url:http://www.duckduckgo.com/ > title: Another search engine > > url:http://www.python.org/ > > url:ftp://192.168.0.12/ > title: My FTP Server > desc: Photos are in photos/, videos are in videos/ > ?Everything else is in other/ > user: root > pass: secret > """ > > The parsing of this file is pretty simple. Blank line marks end of > entry;? So are you saying that if one switches from the non-ACID compliant sqlite to your simple-text data-format, the new 'database' (note the quote marks) will now become ACID compliant? From rosuav at gmail.com Mon Apr 15 08:28:45 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 15 Apr 2013 22:28:45 +1000 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> <2d737309-6608-4e2e-8ff1-2b8b020a418c@qc10g2000pbb.googlegroups.com> <516a6125$0$29977$c3e8da3$5496439d@news.astraweb.com> <8555d9af-e52e-47d6-b2bd-ef7fe5dd61d9@pl9g2000pbb.googlegroups.com> Message-ID: On Mon, Apr 15, 2013 at 9:45 PM, rusi wrote: > I am trying to understand your points Chris. On the one hand you say: > > On Apr 14, 6:22 pm, Chris Angelico wrote: >> No, no, a thousand times no! If I am doing financial transactions, >> even if I'm alone on my machine, I will demand full ACID compliance. > > On the other you describe a bookmark storage scheme (which it seems > you are recommending); to wit > ... > So are you saying that if one switches from the non-ACID compliant > sqlite to your simple-text data-format, the new 'database' (note the > quote marks) will now become ACID compliant? Unlikely. It theoretically could be made ACID compliant (all it needs is an OS-guaranteed atomic move/rename operation), but my point is that some things don't _need_ full-on databases. Financial work *does* (if I'm accepting money from people, I'd better make pretty sure I know who's paid me and how much); bookmarks usually don't. Also, bookmarks are the exclusive property of the person who creates them, so it's helpful to store them in a way that can be edited; with money movements, you often want some kind of indelibility guarantee, too (you can't go back and edit a previous transaction, you have to put in a correcting transaction). Different tasks demand different storage schemes. ChrisA From newsboost at gmail.com Sat Apr 13 15:42:45 2013 From: newsboost at gmail.com (someone) Date: Sat, 13 Apr 2013 21:42:45 +0200 Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? In-Reply-To: References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04/13/2013 06:15 PM, Chris Angelico wrote: > On Sun, Apr 14, 2013 at 12:39 AM, someone wrote: >> On 04/13/2013 04:03 PM, Chris Angelico wrote: >>> Failure at any level means the overall system is not ACID compliant. >> >> Roger... But google says sqlite is supposed to be ACID compliant (although >> maybe not "fully" as you indicate, I'm not sure about this)... > > What your Google hits are telling you is that sqlite can (if > configured correctly) pass level 2. But it doesn't guarantee anything > about the other levels, so it's easy to have an, uhh, ACID leak. Ok, thank you very much, this is something I couldn't easily see in the first place... I think what I should do now is to play a bit with sqlite and then afterwards, when I'm happy I would begin to play with postgresql and be very happy with it, knowing that I can (hopefully) use that for all important projects in the rest of my life :-) I might also play a bit with mySql, because it's my impression that it also have a big user-group. But I read that postgresql is MUCH more "safe" to use (and a bit slower) than postgresql which on the other hand is VERY safe, being fully ACID-compliant... >>> You'd have to actually test it. The easiest way is to get two >>> computers, side by side, and run the database engine on one and a >>> monitor on the other. >> >> Ok, that doesn't sound to be so simple after all... > > I gave a fairly wordy run-down of what I tested, but it's actually > fairly simple in concept: Do a huge bunch of transactions, and keep a > log of what's returned from the COMMIT query; then pull the power out. I'll try it (or something similar) out one day in the future and see what happens with the "corrupted" changes due to pulling out the network cable while transmitting data... >> Ok, it would be nice to hear/read the opinion from another in here who've >> been working (a lot?) with sqlite... > > Agreed. I'm sure someone will chime in. > >> I'm not so rich, so I prefer to go for a free database solution rather than >> an expensive license... I've heard good things about oracle and that's also >> what they used at my previous company, but it's not something I am willing >> to pay for, from my private/own money for my sparetime-projects... > > I concur with Walter's assessment: You want PostgreSQL. It's free/open > source software (highly permissive MIT-like license), massively > trusted, and scales up beautifully. (That last one may not be > significant to you, but it's still good to know your database can > handle hundreds or thousands of tps on basic hardware.) I understand that scaling is VERY important and if I could choose between two "equally" opensource systems and one of them scales better than the other, I would definately work with the one that scales the most - that means that I don't have to learn how to use a whole new system, if I already learnt the system that scales best... And I just found on google that yahoo runs a HUGE PostgreSQL database... Very interesting - I'll definately try to play around with postgreSQL at some time in the future... From cousinstanley at gmail.com Sun Apr 14 14:20:17 2013 From: cousinstanley at gmail.com (Cousin Stanley) Date: Sun, 14 Apr 2013 18:20:17 +0000 (UTC) Subject: python-noob - which container is appropriate for later exporting into mySql + matplotlib ? References: <5168b87f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Fri, 12 Apr 2013 23:26:05 +0000, Cousin Stanley wrote: > >> The firefox browser keeps different sqlite database files for various >> uses .... > > Yes, and I *really* wish they wouldn't. > > It's my number 1 cause of major problems with Firefox. Problems with software of any flavor, especially software that is used regularly and upon which we are somewhat dependent, are always a source of frustration .... My own personal use of firefox over the years has been limited as I have not used it for my primary browser and have not experienced any problems with its bookmarks .... I use opera as my primary browser and would very much like to convert the plain-vanilla bookmark.adr file that opera uses into an sqlite data base for diversity in bookmark searches that would be independent of reglular browser usage .... $ grep FOLDER ~/.opera/bookmarks.adr | wc -l 631 $ grep URL ~/.opera/bookmarks.adr | wc -l 14944 > http://kb.mozillazine.org/Bookmarks_history_and_toolbar_buttons_not_working_-_Firefox Although there have been many reports entailing corruption of the places.sqlite file, it isn't apparent to me from the link above that sqlite itself is the culprit .... Could the complexity/bugginess of the firefox code possibly be the cause instead ? "If Firefox works normally when you first open it after starting up the computer but multiple symptoms arise after you close and later reopen Firefox, it's likely that a Firefox process from a previous session did not close properly and the Places database ( "places.sqlite" file ) is locked." If you check the headers of any of my posts here you will find that I post with a python-based news client named XPN that also uses sqlite for persistent storage, one sqlite database for each different newsgroup .... I've used xpn daily for many years and have never experienced a corrupted sqlite database file .... firefox + sqlite ----> buggy ? ....... :-( python + sqlite ----> ok, hooray .... :-) > Using a database for such lightweight data as bookmarks is, in my > opinion, gross overkill and adds to the complexity of Firefox. > > More complexity leads to more bugs, e.g.: > > https://bugzilla.mozilla.org/show_bug.cgi?id=465684#c11 > > https://bugzilla.mozilla.org/show_bug.cgi?id=431558 These pages show problems that are 4 and 5 years old from 2008 & 2009 and are marked as Status: RESOLVED FIXED at the top of the page .... Are you still having firefox bookmark problems today ? -- Stanley C. Kitching Human Being Phoenix, Arizona From mpwb500 at york.ac.uk Wed Apr 10 19:16:19 2013 From: mpwb500 at york.ac.uk (Max Bucknell) Date: Thu, 11 Apr 2013 00:16:19 +0100 Subject: Functional vs. Object oriented API Message-ID: Hi, I'm currently learning Python, and it's going great. I've dabbled before, but really getting into it is good fun. To test myself, and not detract too much from my actual studies (mathematics), I've been writing my own package to do linear algebra, and I am unsure about how best to structure my API. For example, I have a vector class, that works like so: >>> a = Vector([2, 7, 4]) >>> b = Vector.j # unit vector in 3D y direction I also have a function to generate the dot product of these two vectors. In Java, such a function would be put as a method on the class and I would do something like: >>> a.dot_product(b) 7 and that would be the end of it. But in Python, I can also have: >>> dot_product(a, b) 7 Which of these two are preferred in Python? And are there any general guidelines for choosing between the two styles, or is it largely a matter of personal preference? Thanks for reading, Max. From contact at xavierho.com Wed Apr 10 19:27:08 2013 From: contact at xavierho.com (Xavier Ho) Date: Thu, 11 Apr 2013 09:27:08 +1000 Subject: Functional vs. Object oriented API In-Reply-To: References: Message-ID: Hi Max, In Python, we prefer readability over anything else. The simpler you can write it, the better it can be understood. That said, I've never considered using (i, j, k) as a vector component before. I've always done something akin to: >>> vector = Vector(2, 4, 6) >>> print (vector.normalize().y) However, if you use the mathematical definition of a vector, with standard symbols: v = x*i + y*j + z*k Then I believe vector.j is a much choice. As long as your documentation states it's read-only, I think most mathematicians will love that notation. . As far as dot products go, there isn't really a big difference between the two forms you have there. Both are equally as readable. When C++ was invented people had already debated about the two forms. There isn't a general consensus on this debate, but most would probably agree that overloading the * operator of a vector to do dot product is a bad idea, since some people want cross product, or per-component multiplication. At the end of the day, dot() or dot_product() is more readable, and it doesn't matter if you have it as a function in or outside of a vector's class. Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Wed Apr 10 19:40:48 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 10 Apr 2013 17:40:48 -0600 Subject: Functional vs. Object oriented API In-Reply-To: References: Message-ID: On Wed, Apr 10, 2013 at 5:16 PM, Max Bucknell wrote: > I also have a function to generate the dot product of these two vectors. In Java, such a function would be put as a method on the class and I would do something like: > > >>> a.dot_product(b) > 7 > > and that would be the end of it. But in Python, I can also have: > > >>> dot_product(a, b) > 7 > > Which of these two are preferred in Python? And are there any general guidelines for choosing between the two styles, or is it largely a matter of personal preference? The advantage to the latter is that it potentially allows you to implement dot products for other types using the same function. Using the method, a must be a Vector instance, but using the function it remains unrestricted. This is useful because functions are first-class objects in Python. Suppose that you find yourself wanting to pass that dot_product operation to some other function, e.g. map(). Using the function version you just pass in dot_product -- map(dot_product, seq1, seq2) -- and the mapped sequences can then contain any types that dot_product has been implemented to handle. Using the method version, you would have to pass in the unbound Vector.dot_product method -- map(Vector.dot_product, seq1, seq2), and then the method will only accept Vector instances in seq1. From steve+comp.lang.python at pearwood.info Fri Apr 12 00:20:36 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Apr 2013 04:20:36 GMT Subject: Functional vs. Object oriented API References: Message-ID: <51678b94$0$29977$c3e8da3$5496439d@news.astraweb.com> On Thu, 11 Apr 2013 00:16:19 +0100, Max Bucknell wrote: > For example, I have a vector class, that works like so: > > >>> a = Vector([2, 7, 4]) > >>> b = Vector.j # unit vector in 3D y direction > > I also have a function to generate the dot product of these two vectors. > In Java, such a function would be put as a method on the class and I > would do something like: > > >>> a.dot_product(b) > 7 > > and that would be the end of it. But in Python, I can also have: > > >>> dot_product(a, b) > 7 > > Which of these two are preferred in Python? Both of them! Python is a pure Object Oriented language in that all values are objects. (Unlike Java, where some values are unboxed primitives, and some are objects.) But Python does not force you to use Object Oriented syntax. You can where it makes sense. If not, you aren't forced to. > And are there any general > guidelines for choosing between the two styles, or is it largely a > matter of personal preference? I would put it like this: - If you have a complicated interface, or data with complicated internal state, the best solution is to use a custom object with methods. - But if your interface is simple, and the data is simple, it is more efficient to stick to lightweight built-ins. For example, a simple three- tuple like (1, 4, 2) is probably more efficient than a Vector(1, 4, 2). (Although there are ways to make classes more lean, and still give them methods.) - If the *only* reason you use a class is to keep the data together, that's very much a Java design. In Python, you should put the functions in a module, and use that. E.g. if your class looks like this: class MyClass: def __init__(self, data): self.data def spam(self): return spamify(self.data) def eggs(self, n): return eggify(self.data, n) def aardvark(self): return aardvarkify(self.data) then using a class doesn't give you much, and you should expose spam, eggs and aardvark as top-level functions that take data as an argument. You might like to watch this video from PyCon: http://pyvideo.org/video/880/stop-writing-classes or www.youtube.com/watch?v=o9pEzgHorH0 and then read this response: http://lucumr.pocoo.org/2013/2/13/moar-classes/ Personally, I think that Armin Ronacher's response is important, but suffers from a fatal flaw. Monolithic code is Bad, agreed. But classes are not the only way to avoid monolithic code. Small, lightly coupled functions are just as good at breaking down monolithic code as classes. Some might even argue better. -- Steven From roy at panix.com Fri Apr 12 10:19:47 2013 From: roy at panix.com (Roy Smith) Date: Fri, 12 Apr 2013 10:19:47 -0400 Subject: Functional vs. Object oriented API References: <51678b94$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <51678b94$0$29977$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > - If you have a complicated interface, or data with complicated internal > state, the best solution is to use a custom object with methods. > > - But if your interface is simple, and the data is simple, it is more > efficient to stick to lightweight built-ins [...] > > - If the *only* reason you use a class is to keep the data together, > that's very much a Java design. As part of our initial interview screen, we give applicants some small coding problems to do. One of the things we see a lot is what you could call "Java code smell". This is our clue that the person is really a Java hacker at heart who just dabbles in Python but isn't really fluent. It's kind of like how I can walk into a Spanish restaurant and order dinner or enquire where the men's room is, but everybody knows I'm a gringo as soon as I open my mouth. It's not just LongVerboseFunctionNamesInCamelCase(). Nor is it code that looks like somebody bought the Gang of Four patterns book and is trying to get their money's worth out of the investment. The real dead giveaway is when they write classes which contain a single static method and nothing else. That being said, I've noticed in my own coding, it's far more often that I start out writing some functions and later regret not having initially made it a class, than the other way around. That's as true in my C++ code as it is in my Python. In my mind, classes are all about data. If there's no data (i.e. no stored state), you should be thinking a collection of functions. On the other hand, if there's ONLY data and no behavior, then you should be thinking namedtuple (which is really just a shortcut way to write a trivial class). Once you start having state (i.e. data) and behavior (i.e. functions) in the same thought, then you need a class. If you find yourself passing the same bunch of variables around to multiple functions, that's a hint that maybe there's a class struggling to be written. From msirenef at lightbird.net Fri Apr 12 10:29:45 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Fri, 12 Apr 2013 10:29:45 -0400 Subject: Functional vs. Object oriented API In-Reply-To: References: <51678b94$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51681A59.2080501@lightbird.net> On 04/12/2013 10:19 AM, Roy Smith wrote: > As part of our initial interview screen, we give applicants some small > coding problems to do. One of the things we see a lot is what you could > call "Java code smell". This is our clue that the person is really a > Java hacker at heart who just dabbles in Python but isn't really fluent. > It's kind of like how I can walk into a Spanish restaurant and order > dinner or enquire where the men's room is, but everybody knows I'm a > gringo as soon as I open my mouth. > > It's not just LongVerboseFunctionNamesInCamelCase(). Nor is it code > that looks like somebody bought the Gang of Four patterns book and is > trying to get their money's worth out of the investment. The real dead > giveaway is when they write classes which contain a single static method > and nothing else. > > That being said, I've noticed in my own coding, it's far more often that > I start out writing some functions and later regret not having initially > made it a class, than the other way around. I've absolutely noticed the same thing for myself, over and over again. I can't remember writing a class that I've regretted is not a few functions, although it must have happened a few times. -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ From chess at us.ibm.com Fri Apr 12 11:37:28 2013 From: chess at us.ibm.com (David M Chess) Date: Fri, 12 Apr 2013 11:37:28 -0400 Subject: Functional vs. Object oriented API In-Reply-To: References: <51678b94$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: > Roy Smith > As part of our initial interview screen, we give applicants some small > coding problems to do. One of the things we see a lot is what you could > call "Java code smell". This is our clue that the person is really a > Java hacker at heart who just dabbles in Python but isn't really fluent. > ... > It's not just LongVerboseFunctionNamesInCamelCase(). Nor is it code > that looks like somebody bought the Gang of Four patterns book and is > trying to get their money's worth out of the investment. The real dead > giveaway is when they write classes which contain a single static method > and nothing else. I may have some lingering Java smell myself, although I've been working mostly in Python lately, but my reaction here is that's really I don't know "BASIC smell" or something; a class that contains a single static method and nothing else isn't wonderful Java design style either. > That being said, I've noticed in my own coding, it's far more often that > I start out writing some functions and later regret not having initially > made it a class, than the other way around. That's as true in my C++ > code as it is in my Python. Definitely. > Once you start having state (i.e. data) and behavior (i.e. functions) in > the same thought, then you need a class. If you find yourself passing > the same bunch of variables around to multiple functions, that's a hint > that maybe there's a class struggling to be written. And I think equally to the point, even if you have only data, or only functions, right now, if the thing in question has that thing-like feel to it :) you will probably find yourself with both before you're done, so you might as well make it a class now... DC -------------- next part -------------- An HTML attachment was scrubbed... URL: From dihedral88888 at googlemail.com Sat Apr 13 01:25:30 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 12 Apr 2013 22:25:30 -0700 (PDT) Subject: Functional vs. Object oriented API In-Reply-To: References: <51678b94$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: David M Chess? 2013?4?12????UTC+8??11?37?28???? > > Roy Smith > > > > > > As part of our initial interview screen, we give > applicants some small > > > coding problems to do. ?One of the things we see a lot is what > you could > > > call "Java code smell". ?This is our clue that the > person is really a > > > Java hacker at heart who just dabbles in Python but isn't really fluent. > ? > > > ... > > > It's not just LongVerboseFunctionNamesInCamelCase(). ?Nor is > it code > > > that looks like somebody bought the Gang of Four patterns book and > is > > > that maybe there's a class struggling to be written. > > > > And I think equally to the point, even if you have > only data, or only functions, right now, if the thing in question has that > thing-like feel to it :) you will probably find yourself with both before > you're done, so you might as well make it a class now... > > > > DC If it is not time-critical and no needs to convert into CYTHON then it does not matter too much. But a well wrapped class structures with good documents can help others to use the python codes a lot. If the part is intended to be time-critical in the low level part, then avoiding seeking 4 levels of methods and properties inside a loop is helpful in python programs to be executed in the run time. From dihedral88888 at googlemail.com Sat Apr 13 01:25:30 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 12 Apr 2013 22:25:30 -0700 (PDT) Subject: Functional vs. Object oriented API In-Reply-To: References: <51678b94$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: David M Chess? 2013?4?12????UTC+8??11?37?28???? > > Roy Smith > > > > > > As part of our initial interview screen, we give > applicants some small > > > coding problems to do. ?One of the things we see a lot is what > you could > > > call "Java code smell". ?This is our clue that the > person is really a > > > Java hacker at heart who just dabbles in Python but isn't really fluent. > ? > > > ... > > > It's not just LongVerboseFunctionNamesInCamelCase(). ?Nor is > it code > > > that looks like somebody bought the Gang of Four patterns book and > is > > > that maybe there's a class struggling to be written. > > > > And I think equally to the point, even if you have > only data, or only functions, right now, if the thing in question has that > thing-like feel to it :) you will probably find yourself with both before > you're done, so you might as well make it a class now... > > > > DC If it is not time-critical and no needs to convert into CYTHON then it does not matter too much. But a well wrapped class structures with good documents can help others to use the python codes a lot. If the part is intended to be time-critical in the low level part, then avoiding seeking 4 levels of methods and properties inside a loop is helpful in python programs to be executed in the run time. From rui.maciel at gmail.com Sat Apr 13 04:51:25 2013 From: rui.maciel at gmail.com (Rui Maciel) Date: Sat, 13 Apr 2013 09:51:25 +0100 Subject: Functional vs. Object oriented API References: Message-ID: Max Bucknell wrote: > Hi, > I'm currently learning Python, and it's going great. I've dabbled before, > but really getting into it is good fun. > > To test myself, and not detract too much from my actual studies > (mathematics), I've been writing my own package to do linear algebra, and > I am unsure about how best to structure my API. > > For example, I have a vector class, that works like so: > > >>> a = Vector([2, 7, 4]) > >>> b = Vector.j # unit vector in 3D y direction > > I also have a function to generate the dot product of these two vectors. > In Java, such a function would be put as a method on the class and I would > do something like: > > >>> a.dot_product(b) > 7 Not necessarily. That would only happen if that code was designed that way. It's quite possible, and desirable, that the dot product isn't implemented as a member function of the vector data type, and instead is implemented as an operator to be applied to two object. > and that would be the end of it. But in Python, I can also have: > > >>> dot_product(a, b) > 7 > > Which of these two are preferred in Python? And are there any general > guidelines for choosing between the two styles, or is it largely a matter > of personal preference? The separation of concerns principle is a good guideline. This doesn't apply exclusively to Python; it essentiallyl applies to all programming languages. http://en.wikipedia.org/wiki/Separation_of_concerns There are significant advantages in separating the definition of a data type from the definition of the operations that are to be applied to it. If operations are decoupled from the data type then it's possible to preserve the definition of that data type eternally, while the operators that are written to operate on it can be added, tweaked and removed independently and at anyone's whims. Hope this helps, Rui Maciel From georgeryoung at gmail.com Wed Apr 10 21:21:51 2013 From: georgeryoung at gmail.com (gry) Date: Wed, 10 Apr 2013 18:21:51 -0700 (PDT) Subject: performance of script to write very long lines of random chars Message-ID: <24dc619b-7abd-4be3-aa92-f858eb4ab85f@n4g2000yqj.googlegroups.com> Dear pythonistas, I am writing a tiny utility to produce a file consisting of a specified number of lines of a given length of random ascii characters. I am hoping to find a more time and memory efficient way, that is still fairly simple clear, and _pythonic_. I would like to have something that I can use at both extremes of data: 32M chars per line * 100 lines or 5 chars per line * 1e8 lines. E.g., the output of bigrand.py for 10 characters, 2 lines might be: gw2+M/5t&. S[[db/l?Vx I'm using python 2.7.0 on linux. I need to use only out-of-the box modules, since this has to work on a bunch of different computers. At this point I'm especially concerned with the case of a few very long lines, since that seems to use a lot of memory, and take a long time. Characters are a slight subset of the printable ascii's, specified in the examples below. My first naive try was: from sys import stdout import random nchars = 32000000 rows = 10 avail_chrs = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%& \'()*+,-./:;<=>?@[\\]^_`{}' def make_varchar(nchars): return (''.join([random.choice(avail_chrs) for i in range(nchars)])) for l in range(rows): stdout.write(make_varchar(nchars)) stdout.write('\n') This version used around 1.2GB resident/1.2GB virtual of memory for 3min 38sec. My second try uses much less RAM, but more CPU time, and seems rather, umm, un-pythonic (the array module always seems a little un pythonic...) from sys import stdout from array import array import random nchars = 32000000 rows = 10 avail_chrs = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%& \'()*+,-./:;<=>?@[\\]^_`{}' a = array('c', 'X' * nchars) for l in range(rows): for i in xrange(nchars): a[i] = random.choice(avail_chrs) a.tofile(stdout) stdout.write('\n') This version using array took 4 min, 29 sec, using 34MB resident/110 virtual. So, much smaller than the first attempt, but a bit slower. Can someone suggest a better code? And help me understand the performance issues here? -- George From rosuav at gmail.com Wed Apr 10 21:45:31 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Apr 2013 11:45:31 +1000 Subject: performance of script to write very long lines of random chars In-Reply-To: <24dc619b-7abd-4be3-aa92-f858eb4ab85f@n4g2000yqj.googlegroups.com> References: <24dc619b-7abd-4be3-aa92-f858eb4ab85f@n4g2000yqj.googlegroups.com> Message-ID: On Thu, Apr 11, 2013 at 11:21 AM, gry wrote: > avail_chrs = > '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%& > \'()*+,-./:;<=>?@[\\]^_`{}' Is this exact set of characters a requirement? For instance, would it be acceptable to instead use this set of characters? avail_chrs = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' Your alphabet has 92 characters, this one only 64... the advantage is that it's really easy to work with a 64-character set; in fact, for this specific set, it's the standard called Base 64, and Python already has a module for working with it. All you need is a random stream of eight-bit characters, which can be provided by os.urandom(). So here's a much simpler version of your program, following the cut-down character set I offer: import os import base64 nchars = 32000000 rows = 10 # Note: If nchars is one higher than a multiple of 4 (eg 5, 9, 101), # the lines will be one character short (4, 8, 100). nchars = nchars * 3 // 4 for l in range(rows): print(base64.b64encode(os.urandom(nchars)).strip(b'=')) If you can guarantee that your nchars will always be a multiple of 4, you can drop the .strip() call. This is going to be *immensely* faster than calling random.choice() for every character, but it depends on a working os.urandom (it'll raise NotImplementedError if there's no suitable source). I know it's available on OS/2, Windows, and Linux, but don't have others handy to test. If by "a bunch of different computers" you mean exclusively Linux computers, this should be fine. ChrisA From torriem at gmail.com Wed Apr 10 21:52:22 2013 From: torriem at gmail.com (Michael Torrie) Date: Wed, 10 Apr 2013 19:52:22 -0600 Subject: performance of script to write very long lines of random chars In-Reply-To: <24dc619b-7abd-4be3-aa92-f858eb4ab85f@n4g2000yqj.googlegroups.com> References: <24dc619b-7abd-4be3-aa92-f858eb4ab85f@n4g2000yqj.googlegroups.com> Message-ID: <51661756.3010700@gmail.com> On 04/10/2013 07:21 PM, gry wrote: > from sys import stdout > from array import array > import random > nchars = 32000000 > rows = 10 > avail_chrs = > '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%& > \'()*+,-./:;<=>?@[\\]^_`{}' > a = array('c', 'X' * nchars) > > for l in range(rows): > for i in xrange(nchars): > a[i] = random.choice(avail_chrs) > a.tofile(stdout) > stdout.write('\n') > > This version using array took 4 min, 29 sec, using 34MB resident/110 > virtual. So, much smaller than the first attempt, but a bit slower. > Can someone suggest a better code? And help me understand the > performance issues here? Why are you using an array? Why not just rely on the OS to buffer the output. Just write your characters straight to stdout instead of placing them in an array. At that point I believe this program will be as fast as is possible in Python. From georgeryoung at gmail.com Wed Apr 10 22:40:40 2013 From: georgeryoung at gmail.com (gry) Date: Wed, 10 Apr 2013 19:40:40 -0700 (PDT) Subject: performance of script to write very long lines of random chars References: <24dc619b-7abd-4be3-aa92-f858eb4ab85f@n4g2000yqj.googlegroups.com> Message-ID: <15b233c5-f961-479e-aec1-fe1467bd99d3@e8g2000yqg.googlegroups.com> On Apr 10, 9:52?pm, Michael Torrie wrote: > On 04/10/2013 07:21 PM, gry wrote: > > > > > > > > > > > from sys import stdout > > from array import array > > import random > > nchars = 32000000 > > rows = 10 > > avail_chrs = > > '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%& > > \'()*+,-./:;<=>?@[\\]^_`{}' > > a = array('c', 'X' * nchars) > > > for l in range(rows): > > ? ? for i in xrange(nchars): > > ? ? ? ? a[i] = random.choice(avail_chrs) > > ? ? a.tofile(stdout) > > ? ? stdout.write('\n') > > > This version using array took 4 min, 29 sec, using 34MB resident/110 > > virtual. So, much smaller than the first attempt, but a bit slower. > > Can someone suggest a better code? ?And help me understand the > > performance issues here? > > Why are you using an array? ?Why not just rely on the OS to buffer the > output. ?Just write your characters straight to stdout instead of > placing them in an array. > > At that point I believe this program will be as fast as is possible in > Python. Appealing idea, but it's slower than the array solution: 5min 13 secs. vs 4min 30sec for the array: for l in range(rows): for i in xrange(nchars): stdout.write(random.choice(avail_chrs)) stdout.write('\n') os.urandom does look promising -- I have to have full control over the charset, but urandom is very fast at generating big random strings... stay tuned... From rosuav at gmail.com Wed Apr 10 23:14:37 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Apr 2013 13:14:37 +1000 Subject: performance of script to write very long lines of random chars In-Reply-To: <15b233c5-f961-479e-aec1-fe1467bd99d3@e8g2000yqg.googlegroups.com> References: <24dc619b-7abd-4be3-aa92-f858eb4ab85f@n4g2000yqj.googlegroups.com> <15b233c5-f961-479e-aec1-fe1467bd99d3@e8g2000yqg.googlegroups.com> Message-ID: On Thu, Apr 11, 2013 at 12:40 PM, gry wrote: > Appealing idea, but it's slower than the array solution: 5min 13 > secs. vs 4min 30sec for the array: > > for l in range(rows): > for i in xrange(nchars): > stdout.write(random.choice(avail_chrs)) > stdout.write('\n') > > > os.urandom does look promising -- I have to have full control over the > charset, but urandom is very fast at generating big random strings... > stay tuned... Without actually profiling it, my first guess would be that calling random.choice() for every character is an optimization target. (NOTE: Do profile it, if the urandom method isn't sufficient straight-off.) You may want to consider, for instance, generating larger random numbers and doing some kind of translation on them - which is fundamentally what the urandom/b64encode method is doing. ChrisA From python at mrabarnett.plus.com Wed Apr 10 23:09:51 2013 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Apr 2013 04:09:51 +0100 Subject: performance of script to write very long lines of random chars In-Reply-To: <24dc619b-7abd-4be3-aa92-f858eb4ab85f@n4g2000yqj.googlegroups.com> References: <24dc619b-7abd-4be3-aa92-f858eb4ab85f@n4g2000yqj.googlegroups.com> Message-ID: <5166297F.8000204@mrabarnett.plus.com> On 11/04/2013 02:21, gry wrote: > Dear pythonistas, > I am writing a tiny utility to produce a file consisting of a > specified number of lines of a given length of random ascii > characters. I am hoping to find a more time and memory efficient way, > that is still fairly simple clear, and _pythonic_. > > I would like to have something that I can use at both extremes of > data: > > 32M chars per line * 100 lines > or > 5 chars per line * 1e8 lines. > > E.g., the output of bigrand.py for 10 characters, 2 lines might be: > > gw2+M/5t&. > S[[db/l?Vx > > I'm using python 2.7.0 on linux. I need to use only out-of-the box > modules, since this has to work on a bunch of different computers. > At this point I'm especially concerned with the case of a few very > long lines, since that seems to use a lot of memory, and take a long > time. > Characters are a slight subset of the printable ascii's, specified in > the examples below. My first naive try was: > > from sys import stdout > import random > nchars = 32000000 > rows = 10 > avail_chrs = > '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%& > \'()*+,-./:;<=>?@[\\]^_`{}' > > def make_varchar(nchars): > return (''.join([random.choice(avail_chrs) for i in > range(nchars)])) > > for l in range(rows): > stdout.write(make_varchar(nchars)) > stdout.write('\n') > > This version used around 1.2GB resident/1.2GB virtual of memory for > 3min 38sec. > > > My second try uses much less RAM, but more CPU time, and seems rather, > umm, un-pythonic (the array module always seems a little un > pythonic...) > > from sys import stdout > from array import array > import random > nchars = 32000000 > rows = 10 > avail_chrs = > '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%& > \'()*+,-./:;<=>?@[\\]^_`{}' > a = array('c', 'X' * nchars) > > for l in range(rows): > for i in xrange(nchars): > a[i] = random.choice(avail_chrs) > a.tofile(stdout) > stdout.write('\n') > > This version using array took 4 min, 29 sec, using 34MB resident/110 > virtual. So, much smaller than the first attempt, but a bit slower. > Can someone suggest a better code? And help me understand the > performance issues here? > Names in the global scope are stored in a dict, but local to a function are stored in slots and can be accessed more quickly. 'avail_chrs' and 'random.choice' are referred to many times, so making 'avail_chrs' local and making a local reference to 'random.choice' will help. from sys import stdout from array import array import random def generate(): avail_chrs = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{}' rnd = random.choice for l in range(rows): stdout.write(''.join([rnd(avail_chrs) for i in xrange(nchars)])) stdout.write('\n') nchars = 32000000 rows = 10 generate() From steve+comp.lang.python at pearwood.info Thu Apr 11 01:33:55 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Apr 2013 05:33:55 GMT Subject: performance of script to write very long lines of random chars References: <24dc619b-7abd-4be3-aa92-f858eb4ab85f@n4g2000yqj.googlegroups.com> Message-ID: <51664b43$0$29977$c3e8da3$5496439d@news.astraweb.com> On Thu, 11 Apr 2013 11:45:31 +1000, Chris Angelico wrote: > On Thu, Apr 11, 2013 at 11:21 AM, gry wrote: >> avail_chrs = >> '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%& >> \'()*+,-./:;<=>?@[\\]^_`{}' > > Is this exact set of characters a requirement? For instance, would it be > acceptable to instead use this set of characters? > > avail_chrs = > 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' > > Your alphabet has 92 characters, this one only 64... the advantage is > that it's really easy to work with a 64-character set; in fact, for this > specific set, it's the standard called Base 64, and Python already has a > module for working with it. All you need is a random stream of eight-bit > characters, which can be provided by os.urandom(). I was originally going to write that using the base64 module would introduce bias into the random strings, but after a little investigation, I don't think it does. Or at least, if it does, it's a fairly subtle bias, and not detectable by the simple technique I used: inspect the mean, and the mean deviation from the mean. from os import urandom from base64 import b64encode data = urandom(1000000) m = sum(data)/len(data) md = sum(abs(v - m) for v in data)/len(data) print("Mean and mean deviation of urandom:", m, md) encoded = b64encode(data).strip(b'=') chars = (b'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef' b'ghijklmnopqrstuvwxyz0123456789+/') values = [chars.index(v) for v in encoded] m = sum(values)/len(values) md = sum(abs(v - m) for v in values)/len(values) print("Mean and mean deviation of encoded data:", m, md) When I run this, it prints: Mean and mean deviation of urandom: 127.451652 63.95331188965717 Mean and mean deviation of encoded data: 31.477027511486245 15.991177272527072 I would expect 127 64 and 32 16, so we're pretty close. That's not to say that there aren't any other biases or correlations in the encoded data, but after a simplistic test, it looks okay to me. -- Steven From rosuav at gmail.com Thu Apr 11 01:53:30 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Apr 2013 15:53:30 +1000 Subject: performance of script to write very long lines of random chars In-Reply-To: <51664b43$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <24dc619b-7abd-4be3-aa92-f858eb4ab85f@n4g2000yqj.googlegroups.com> <51664b43$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Apr 11, 2013 at 3:33 PM, Steven D'Aprano wrote: > I was originally going to write that using the base64 module would > introduce bias into the random strings, but after a little investigation, > I don't think it does. Assuming that os.urandom() returns bytes with perfectly fair distribution (exactly equal chance of any value 00-FF - it probably does, or close to it), and assuming that you work with exact multiples of 3 bytes and 4 output characters, base64 will give you perfectly fair distribution of result characters. You take three bytes (24 bits) and turn them into four characters (6 bits per character, = 24 bits). You might see some bias if you use less than a full set of four output characters, though; I haven't dug into the details to check that. ChrisA From steve+comp.lang.python at pearwood.info Thu Apr 11 03:47:58 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Apr 2013 07:47:58 GMT Subject: performance of script to write very long lines of random chars References: <24dc619b-7abd-4be3-aa92-f858eb4ab85f@n4g2000yqj.googlegroups.com> Message-ID: <51666aae$0$29977$c3e8da3$5496439d@news.astraweb.com> On Wed, 10 Apr 2013 18:21:51 -0700, gry wrote: > Dear pythonistas, > I am writing a tiny utility to produce a file consisting of a > specified number of lines of a given length of random ascii characters. > I am hoping to find a more time and memory efficient way, that is still > fairly simple clear, and _pythonic_. Here's another option: use string.translate to map random bytes to the printable ASCII bytes. import string all_bytes = ''.join(map(chr, range(256))) printable = all_bytes[33:127] n = 127 + len(printable) extras = all_bytes[127:n] _deletions = all_bytes[:33] + all_bytes[n:] _table = string.maketrans(extras, printable) def random_chars(length, size=1000): # Make local bindings for speed. import string, os table, deletions = _table, _deletions # Generate random strings. buffer = [] while True: while len(buffer) < length: bytes = string.translate(os.urandom(size), table, deletions) buffer.extend(bytes) yield ''.join(buffer[:length]) buffer = buffer[length:] Then use it like this: # I want seven lines of twelve char strings. make = random_chars(12) for i in range(7): print next(make) One thing to be aware of: urandom may run out of entropy, and then it will slow down a lot. If you don't care about cryptographic randomness, you could use this instead: import random def myrandom(n): return [random.randint(0, 255) for i in xrange(n)] although that will actually be slower unless urandom has run out of entropy. -- Steven From oscar.j.benjamin at gmail.com Thu Apr 11 05:47:43 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 11 Apr 2013 10:47:43 +0100 Subject: performance of script to write very long lines of random chars In-Reply-To: <51666aae$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <24dc619b-7abd-4be3-aa92-f858eb4ab85f@n4g2000yqj.googlegroups.com> <51666aae$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11 April 2013 08:47, Steven D'Aprano wrote: > One thing to be aware of: urandom may run out of entropy, and then it > will slow down a lot. If you don't care about cryptographic randomness, > you could use this instead: Reading this I'm realising that I don't really know what os.urandom is. How exactly is it generating random numbers and what do you mean by it running out of entropy? Oscar From steve+comp.lang.python at pearwood.info Thu Apr 11 06:50:31 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Apr 2013 10:50:31 GMT Subject: performance of script to write very long lines of random chars References: <24dc619b-7abd-4be3-aa92-f858eb4ab85f@n4g2000yqj.googlegroups.com> <51666aae$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51669576$0$29977$c3e8da3$5496439d@news.astraweb.com> On Thu, 11 Apr 2013 10:47:43 +0100, Oscar Benjamin wrote: > On 11 April 2013 08:47, Steven D'Aprano > wrote: > >> One thing to be aware of: urandom may run out of entropy, and then it >> will slow down a lot. If you don't care about cryptographic randomness, >> you could use this instead: > > Reading this I'm realising that I don't really know what os.urandom is. > How exactly is it generating random numbers and what do you mean by it > running out of entropy? I am not an expert, but here goes... Some (most?) modern operating systems provide a cryptographically strong source of non-deterministic randomness. The non-deterministic part comes from external "stuff", which is called "entropy". Typical sources of entropy include network events, user key-presses, moving the mouse, and (presumably in machines with special hardware), even thermal noise in electrical components. If the OS hasn't collected enough entropy, urandom can block until it has. This can be a problem, e.g. I've experienced issues where scripts relying indirectly on urandom that run at system reboot can block for minutes at a time, waiting for entropy. If those scripts run before the networking software, and before any users log in and start running apps, the script can block forever waiting for entropy that never arrives. (Where "forever" == "70 minute boot times".) Entropy is used and discarded, so urandom needs the OS to continually replenish the amount of entropy. Under normal circumstances, this it does, but if you grab lots of urandom output on a system which is otherwise quiet and not doing anything, it could run out. If I've got any of this wrong, corrections will be gratefully acceptable. -- Steven From robert.kern at gmail.com Thu Apr 11 07:19:07 2013 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 11 Apr 2013 16:49:07 +0530 Subject: performance of script to write very long lines of random chars In-Reply-To: <51669576$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <24dc619b-7abd-4be3-aa92-f858eb4ab85f@n4g2000yqj.googlegroups.com> <51666aae$0$29977$c3e8da3$5496439d@news.astraweb.com> <51669576$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-04-11 16:20, Steven D'Aprano wrote: > On Thu, 11 Apr 2013 10:47:43 +0100, Oscar Benjamin wrote: > >> On 11 April 2013 08:47, Steven D'Aprano >> wrote: >> >>> One thing to be aware of: urandom may run out of entropy, and then it >>> will slow down a lot. If you don't care about cryptographic randomness, >>> you could use this instead: >> >> Reading this I'm realising that I don't really know what os.urandom is. >> How exactly is it generating random numbers and what do you mean by it >> running out of entropy? > > I am not an expert, but here goes... > > Some (most?) modern operating systems provide a cryptographically strong > source of non-deterministic randomness. The non-deterministic part comes > from external "stuff", which is called "entropy". Typical sources of > entropy include network events, user key-presses, moving the mouse, and > (presumably in machines with special hardware), even thermal noise in > electrical components. > > If the OS hasn't collected enough entropy, urandom can block until it > has. This can be a problem, e.g. I've experienced issues where scripts > relying indirectly on urandom that run at system reboot can block for > minutes at a time, waiting for entropy. If those scripts run before the > networking software, and before any users log in and start running apps, > the script can block forever waiting for entropy that never arrives. > > (Where "forever" == "70 minute boot times".) > > Entropy is used and discarded, so urandom needs the OS to continually > replenish the amount of entropy. Under normal circumstances, this it > does, but if you grab lots of urandom output on a system which is > otherwise quiet and not doing anything, it could run out. > > If I've got any of this wrong, corrections will be gratefully acceptable. Just one important thing: os.urandom() does not block to wait for more entropy. Only os.random() does. http://en.wikipedia.org/wiki//dev/random -- 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 oscar.j.benjamin at gmail.com Thu Apr 11 08:05:45 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 11 Apr 2013 13:05:45 +0100 Subject: performance of script to write very long lines of random chars In-Reply-To: <51669576$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <24dc619b-7abd-4be3-aa92-f858eb4ab85f@n4g2000yqj.googlegroups.com> <51666aae$0$29977$c3e8da3$5496439d@news.astraweb.com> <51669576$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11 April 2013 11:50, Steven D'Aprano wrote: > On Thu, 11 Apr 2013 10:47:43 +0100, Oscar Benjamin wrote: > >> On 11 April 2013 08:47, Steven D'Aprano >> wrote: >> >>> One thing to be aware of: urandom may run out of entropy, and then it >>> will slow down a lot. If you don't care about cryptographic randomness, >>> you could use this instead: >> >> Reading this I'm realising that I don't really know what os.urandom is. >> How exactly is it generating random numbers and what do you mean by it >> running out of entropy? > > Some (most?) modern operating systems provide a cryptographically strong > source of non-deterministic randomness. The non-deterministic part comes > from external "stuff", which is called "entropy". Typical sources of > entropy include network events, user key-presses, moving the mouse, and > (presumably in machines with special hardware), even thermal noise in > electrical components. > Entropy is used and discarded, so urandom needs the OS to continually > replenish the amount of entropy. Under normal circumstances, this it > does, but if you grab lots of urandom output on a system which is > otherwise quiet and not doing anything, it could run out. Okay, so I understand what entropy is in the thermodynamic sense and also in the mathematical (Shannon) sense but I'm still confused about what it means that the OS is somehow storing entropy. Do you mean that it is always maintaining a buffer of what it considers to be random bytes that it slowly builds up from noise that is made accessible to the OS from the hardware? Oscar From robert.kern at gmail.com Thu Apr 11 09:36:57 2013 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 11 Apr 2013 19:06:57 +0530 Subject: performance of script to write very long lines of random chars In-Reply-To: References: <24dc619b-7abd-4be3-aa92-f858eb4ab85f@n4g2000yqj.googlegroups.com> <51666aae$0$29977$c3e8da3$5496439d@news.astraweb.com> <51669576$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-04-11 17:35, Oscar Benjamin wrote: > On 11 April 2013 11:50, Steven D'Aprano > wrote: >> On Thu, 11 Apr 2013 10:47:43 +0100, Oscar Benjamin wrote: >> >>> On 11 April 2013 08:47, Steven D'Aprano >>> wrote: >>> >>>> One thing to be aware of: urandom may run out of entropy, and then it >>>> will slow down a lot. If you don't care about cryptographic randomness, >>>> you could use this instead: >>> >>> Reading this I'm realising that I don't really know what os.urandom is. >>> How exactly is it generating random numbers and what do you mean by it >>> running out of entropy? >> >> Some (most?) modern operating systems provide a cryptographically strong >> source of non-deterministic randomness. The non-deterministic part comes >> from external "stuff", which is called "entropy". Typical sources of >> entropy include network events, user key-presses, moving the mouse, and >> (presumably in machines with special hardware), even thermal noise in >> electrical components. > >> Entropy is used and discarded, so urandom needs the OS to continually >> replenish the amount of entropy. Under normal circumstances, this it >> does, but if you grab lots of urandom output on a system which is >> otherwise quiet and not doing anything, it could run out. > > Okay, so I understand what entropy is in the thermodynamic sense and > also in the mathematical (Shannon) sense but I'm still confused about > what it means that the OS is somehow storing entropy. Do you mean that > it is always maintaining a buffer of what it considers to be random > bytes that it slowly builds up from noise that is made accessible to > the OS from the hardware? Yes. -- 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 rosuav at gmail.com Thu Apr 11 09:56:27 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Apr 2013 23:56:27 +1000 Subject: performance of script to write very long lines of random chars In-Reply-To: References: <24dc619b-7abd-4be3-aa92-f858eb4ab85f@n4g2000yqj.googlegroups.com> <51666aae$0$29977$c3e8da3$5496439d@news.astraweb.com> <51669576$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Apr 11, 2013 at 10:05 PM, Oscar Benjamin wrote: > On 11 April 2013 11:50, Steven D'Aprano > wrote: >> Some (most?) modern operating systems provide a cryptographically strong >> source of non-deterministic randomness. The non-deterministic part comes >> from external "stuff", which is called "entropy". Typical sources of >> entropy include network events, user key-presses, moving the mouse, and >> (presumably in machines with special hardware), even thermal noise in >> electrical components. > >> Entropy is used and discarded, so urandom needs the OS to continually >> replenish the amount of entropy. Under normal circumstances, this it >> does, but if you grab lots of urandom output on a system which is >> otherwise quiet and not doing anything, it could run out. > > Okay, so I understand what entropy is in the thermodynamic sense and > also in the mathematical (Shannon) sense but I'm still confused about > what it means that the OS is somehow storing entropy. Do you mean that > it is always maintaining a buffer of what it considers to be random > bytes that it slowly builds up from noise that is made accessible to > the OS from the hardware? Correct. And Steven's right about most of what he says (modulo the urandom vs random distinction, as Robert Kern pointed out - urandom won't block, but it's not guaranteed to be cryptographically secure); I'll just add that one of the best sources of entropy is a solid cylinder, rotated at high velocity in a sealed container filled with a fluid, and entropy is found in the eddies. Many computers have a device of this nature - the solid cylinder is thin and flat and referred to as a "disk", the fluid it's in is air, and the sealed container is your hard disk drive. The details will vary, but broadly speaking, the /dev/random driver (or its equivalent) maintains an ever-increasing buffer of entropic bits, accumulated as they arrive from the various sources, and often saved to disk on shutdown to permit faster boot (which helps to avoid the problem Steven described of 70-minute boot times - on an all-SSD computer with no human being attached, entropy really can be very hard to obtain); whenever a program asks for bytes from it, it delivers them and removes that much "recorded entropy" from its buffer. For many purposes, it's sufficient to take 4 or 8 bytes of /dev/random entropy and use that to seed a PRNG, but if you're using /dev/urandom and it's not a critical server, I wouldn't worry too much about drawing too much off it. (On a web server that's constantly serving HTTPS requests, for instance, I'd be cautious about reading too much from /dev/urandom as it might cause the web server to block waiting for /dev/random. Might kill your TPS for a while.) ChrisA From oscar.j.benjamin at gmail.com Thu Apr 11 05:47:05 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 11 Apr 2013 10:47:05 +0100 Subject: performance of script to write very long lines of random chars In-Reply-To: <24dc619b-7abd-4be3-aa92-f858eb4ab85f@n4g2000yqj.googlegroups.com> References: <24dc619b-7abd-4be3-aa92-f858eb4ab85f@n4g2000yqj.googlegroups.com> Message-ID: On 11 April 2013 02:21, gry wrote: > Dear pythonistas, > I am writing a tiny utility to produce a file consisting of a > specified number of lines of a given length of random ascii > characters. I am hoping to find a more time and memory efficient way, > that is still fairly simple clear, and _pythonic_. > > I would like to have something that I can use at both extremes of > data: > > 32M chars per line * 100 lines > or > 5 chars per line * 1e8 lines. I would definitely use numpy for this. The script below seems to be io-bound on my machine: #!/usr/bin/env python from sys import stdout import numpy as np from numpy import random CHARS = ( '0123456789' 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' '!#$%& \'()*+,-./:;<=>?@[\\]^_`{}' ) ARRAY_CHARS = np.frombuffer(CHARS, np.uint8) NCHARS = len(CHARS) CHUNK_SIZE = 4096 NCOLS = 32000000 NROWS = 10 def chunk_sizes(total, chunk_size): numchunks, remainder = divmod(total, chunk_size) for n in range(numchunks): yield chunk_size if remainder: yield remainder def chunks(): bytes_per_line = NCOLS + 1 total_bytes = bytes_per_line * NROWS newline_index = NCOLS newline = ord('\n') for size in chunk_sizes(total_bytes, CHUNK_SIZE): chars = ARRAY_CHARS[random.randint(0, NCHARS, size)] chars[newline_index::bytes_per_line] = newline newline_index = (newline_index - CHUNK_SIZE) % bytes_per_line yield chars for chunk in chunks(): chunk.tofile(stdout) From moraa.lovetakes2 at gmail.com Thu Apr 11 05:06:42 2013 From: moraa.lovetakes2 at gmail.com (Ombongi Moraa Fe) Date: Thu, 11 Apr 2013 12:06:42 +0300 Subject: Return a value from a function result Message-ID: Hello Team, My perl script "a.pl" calls python script "b.py" and passes arguments to it; expecting a return value; "b.py" uses suds to facilitate soap-based communication with another server which then returns some value (deliveryStatus) basically, my b.py script has these 3 major parts; #part 1 of code to receive arguments from perl script and process them accordingly .......... ......... #part 2 of code - function to get delivery status def deliveryStatus(): ..... return parameters # or return client.last_received() #part 3- print output of the function print deliveryStatus() running b.py script with the "return parameters" prints this output: [(DeliveryInformation){ address = "phone_number" deliveryStatus = "DeliveredToNetwork" }] running the same script with "return client.last_received() " instead prints the soap output
phone_number
DeliveredToNetwork
With either kind of output returned to my perl script, my table entry is updated as "failed" since the returned value is basically an undefined value; what I need therefore is a way to return only the value "DeliveredToNetwork" so that the database update on my perl script could be correct; A solution using either the soap output or the array output will be appreciated. Someone help me. Thanks in advance. Saludos Ombongi Moraa Faith -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Apr 11 10:00:12 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Apr 2013 00:00:12 +1000 Subject: Return a value from a function result In-Reply-To: References: Message-ID: On Thu, Apr 11, 2013 at 7:06 PM, Ombongi Moraa Fe wrote: > My perl script "a.pl" calls python script "b.py" and passes arguments to it; > expecting a return value; Can you clarify this part, please? What kind of "return value" is your Perl script expecting? Presumably you actually mean something written to stdout; what format? How do you decode it? Ultimately, stdout is simply a stream of bytes, though with some small magic you can treat it as a string of characters. All its meaning is between the sender and receiver. ChrisA From insideshoes at gmail.com Thu Apr 11 05:48:06 2013 From: insideshoes at gmail.com (inshu chauhan) Date: Thu, 11 Apr 2013 15:18:06 +0530 Subject: Can I iterate over a dictionary outside a function ? Message-ID: I have a prog in which a functions returns a dict but when I try to iterate over the dict using iterkeys, It shows an error. I think its because only address of the dictionary is returned so cannot be iterated upon. Please suggest some way by which it can be made possible to iterate over the dictionary using iterkeys outside the function ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From oscar.j.benjamin at gmail.com Thu Apr 11 05:58:54 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 11 Apr 2013 10:58:54 +0100 Subject: Can I iterate over a dictionary outside a function ? In-Reply-To: References: Message-ID: On 11 April 2013 10:48, inshu chauhan wrote: > I have a prog in which a functions returns a dict but when I try to iterate > over the dict using iterkeys, It shows an error. I think its because only > address of the dictionary is returned so cannot be iterated upon. > > Please suggest some way by which it can be made possible to iterate over the > dictionary using iterkeys outside the function ? You would probably get a more helpful answer if you showed the code that is giving you a problem. See here: http://sscce.org/ Your question makes no sense to me. It is perfectly possible to iterate over a dict returned from a function: >>> def function(): ... d = {'asd':123, 'qwe': 456} ... return d ... >>> a = function() >>> a {'qwe': 456, 'asd': 123} >>> for x in a.iterkeys(): ... print(x) ... qwe asd Oscar From breamoreboy at yahoo.co.uk Thu Apr 11 07:53:06 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 11 Apr 2013 12:53:06 +0100 Subject: Can I iterate over a dictionary outside a function ? In-Reply-To: References: Message-ID: On 11/04/2013 10:48, inshu chauhan wrote: > I have a prog in which a functions returns a dict but when I try to > iterate over the dict using iterkeys, It shows an error. I think its > because only address of the dictionary is returned so cannot be iterated > upon. > > Please suggest some way by which it can be made possible to iterate over > the dictionary using iterkeys outside the function ? > > If you're using Python 3 iterkeys has been renamed keys. -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From neilc at norwich.edu Thu Apr 11 08:18:18 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 11 Apr 2013 12:18:18 GMT Subject: Can I iterate over a dictionary outside a function ? References: Message-ID: On 2013-04-11, Mark Lawrence wrote: > On 11/04/2013 10:48, inshu chauhan wrote: >> I have a prog in which a functions returns a dict but when I >> try to iterate over the dict using iterkeys, It shows an >> error. I think its because only address of the dictionary is >> returned so cannot be iterated upon. >> >> Please suggest some way by which it can be made possible to >> iterate over the dictionary using iterkeys outside the >> function ? > > If you're using Python 3 iterkeys has been renamed keys. Also, using a dict *as* an iterator results in iterating over the keys. -- Neil Cerutti From news at blinne.net Thu Apr 11 17:33:42 2013 From: news at blinne.net (Alexander Blinne) Date: Thu, 11 Apr 2013 23:33:42 +0200 Subject: Can I iterate over a dictionary outside a function ? In-Reply-To: References: Message-ID: <51672c36$0$6623$9b4e6d93@newsspool2.arcor-online.net> Am 11.04.2013 11:48, schrieb inshu chauhan: > I have a prog in which a functions returns a dict but when I try to > iterate over the dict using iterkeys, It shows an error. 1) Show us your code in form of a minimal "working" example, "working" means that it should show us what you expect it to do but at the same time shows the behaviour you complain about. 2) Show us your actual error message! > I think its > because only address of the dictionary is returned so cannot be iterated > upon. Python does not use addresses, it uses references. And as long as you have a valid reference to a dict assigned to some name in some namespace you should be able to iterate over its keys using some_dict.iterkeys(). From djdexter1389 at gmail.com Thu Apr 11 08:14:46 2013 From: djdexter1389 at gmail.com (Dexter Deejay) Date: Thu, 11 Apr 2013 05:14:46 -0700 (PDT) Subject: Problems with sockets and threads Message-ID: <347b9197-b409-4651-8c01-26af4c3461ca@googlegroups.com> When i try to run this code and to connect to server (server is written in java that part of code is ok) everything stalls. Thread that i created here occupies processor all the time and GUI freezes. It's supposed to be waiting for message from server. (asynchronous one) Is there something that i did wrong here, or is there better way to do this? from tkinter import * from threading import * import time import socket import sys comPort=0 msg="" name=socket.gethostbyname(socket.gethostname()) sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM) testArea=0 thread=0 def threadFunc(): global sock global textArea data="" while(data==""): try: data=str((sock.recvfrom(256)),"UTF-8") except BlockingIOError: print("failed") time.sleep(1) data="" textArea.add((data+"\n")) def sendMsg(): global sock message=name+": "+msg.get()+"\n" sock.send(bytes(message,"UTF-8")) def aboutCommand(): messagebox.showinfo(title="About",message="This is first (serious) aplication in python.") def helpCommand(): messagebox.showinfo(title="Help",message="BAZINGA!") def Connect(): global sock global thread sock.connect((serverIPString.get(), 16000)) sock.send(bytes("#connect request#\n",'UTF-8')) data=sock.recvfrom(256) reply=str(data[0],"UTF-8") answer=(reply.split("#",3)) if(answer[1]!="connected"): messagebox.showinfo(title="Error",message="Connection failed!") return sock.close(); sock=None comPort=int(answer[2]) #for new connection sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((serverIPString.get(), comPort)) sock.setblocking(0) thread=Thread(target=threadFunc()) thread.start() def Disconnect(): global sock sock.send(bytes("#END#\n","UTF-8")) sock.close() def ExitApplication(): Disconnect() mGui.destroy() return mGui=Tk() msg=StringVar() serverIPString=StringVar() mGui.geometry("400x600+200+20") mGui.title("Chat client v1.0") labServer=Label(mGui,text="Server IP adress: ").pack() entServer=Entry(mGui,textvariable=serverIPString).pack() btnConnect=Button(mGui,text="Connect",fg="red",bg="blue",command=Connect).pack() btnDisconnect=Button(mGui,text="Disconnect",fg="red",bg="blue",command=Disconnect).pack() textArea=Text(mGui,bg="yellow").pack() entMessage=Entry(mGui,textvariable=msg).pack() btnSendMsg=Button(mGui,text="Send message",fg="white",bg="black",command=sendMsg).pack() menuBar=Menu(mGui) fileMenu=Menu(menuBar,tearoff=0) fileMenu.add_command(label="Exit",command=ExitApplication) menuBar.add_cascade(label="File",menu=fileMenu) optionsMenu=Menu(menuBar,tearoff=0) optionsMenu.add_command(label="Change chat name") optionsMenu.add_command(label="Connect",command=Connect) optionsMenu.add_command(label="Disconnect",command=Disconnect) menuBar.add_cascade(label="Options",menu=optionsMenu) helpMenu=Menu(menuBar,tearoff=0) helpMenu.add_command(label="Help",command=helpCommand) helpMenu.add_command(label="About",command=aboutCommand) menuBar.add_cascade(label="Info",menu=helpMenu) mGui.config(menu=menuBar) mGui.mainloop() From wayne at waynewerner.com Thu Apr 11 08:27:34 2013 From: wayne at waynewerner.com (Wayne Werner) Date: Thu, 11 Apr 2013 07:27:34 -0500 (CDT) Subject: Problems with sockets and threads In-Reply-To: <347b9197-b409-4651-8c01-26af4c3461ca@googlegroups.com> References: <347b9197-b409-4651-8c01-26af4c3461ca@googlegroups.com> Message-ID: On Thu, 11 Apr 2013, Dexter Deejay wrote: > When i try to run this code and to connect to server (server is written in java that part of code is ok) everything stalls. Thread that i created here occupies processor all the time and GUI freezes. It's supposed to be waiting for message from server. (asynchronous one) Is there something that i did wrong here, or is there better way to do this? > > > from tkinter import * > from threading import * Everything I've read or used suggests to me that threading+tkinter is a dangerous combination. Mainly because tkinter already has an event loop, so when you start mixing threads things tend to go sideways. Instead what you'll want to do is put processing in the .after or .after_idle callbacks - just make sure that whatever is doing is quick (or can do a portion of the activity quickly). HTH, -W From djdexter1389 at gmail.com Thu Apr 11 08:34:30 2013 From: djdexter1389 at gmail.com (Dexter Deejay) Date: Thu, 11 Apr 2013 05:34:30 -0700 (PDT) Subject: Problems with sockets and threads In-Reply-To: <347b9197-b409-4651-8c01-26af4c3461ca@googlegroups.com> References: <347b9197-b409-4651-8c01-26af4c3461ca@googlegroups.com> Message-ID: Yeah, that seems to be problem. Waiting for message is in theory infinite. But why doesn't this separate thread leave processor while it is sleeping? From wayne at waynewerner.com Thu Apr 11 09:03:12 2013 From: wayne at waynewerner.com (Wayne Werner) Date: Thu, 11 Apr 2013 08:03:12 -0500 (CDT) Subject: Problems with sockets and threads In-Reply-To: References: <347b9197-b409-4651-8c01-26af4c3461ca@googlegroups.com> Message-ID: On Thu, 11 Apr 2013, Dexter Deejay wrote: > Yeah, that seems to be problem. Waiting for message is in theory infinite. But why doesn't this separate thread leave processor while it is sleeping? As far as I've been able to tell? Magic ;) But I haven't really dug into it. If you're really doing some waiting stuff you might want to look into some other type of message passing mechanism, e.g. launch a subprocess to do ths listening and then writing to a file and checking that from within Tkinter. I expect there are other possibilities that more advanced people may be able to recommend and are probably better. But that seems like it would work. HTH, -W From djdexter1389 at gmail.com Thu Apr 11 09:10:16 2013 From: djdexter1389 at gmail.com (Dexter Deejay) Date: Thu, 11 Apr 2013 06:10:16 -0700 (PDT) Subject: Problems with sockets and threads In-Reply-To: <347b9197-b409-4651-8c01-26af4c3461ca@googlegroups.com> References: <347b9197-b409-4651-8c01-26af4c3461ca@googlegroups.com> Message-ID: <4b51036f-f62a-4f84-af90-8ee5fb82a346@googlegroups.com> Thanks for help. Do you have any reference to pint me out for that subprocess creation? From djdexter1389 at gmail.com Thu Apr 11 09:11:33 2013 From: djdexter1389 at gmail.com (Dexter Deejay) Date: Thu, 11 Apr 2013 06:11:33 -0700 (PDT) Subject: Problems with sockets and threads In-Reply-To: <347b9197-b409-4651-8c01-26af4c3461ca@googlegroups.com> References: <347b9197-b409-4651-8c01-26af4c3461ca@googlegroups.com> Message-ID: <998328fa-9975-4a1c-950d-014f964dc1cf@googlegroups.com> Thanks for help. Do you have any reference to direct me for that subprocess creation? From djdexter1389 at gmail.com Thu Apr 11 10:21:39 2013 From: djdexter1389 at gmail.com (Dexter Deejay) Date: Thu, 11 Apr 2013 07:21:39 -0700 (PDT) Subject: Problems with sockets and threads In-Reply-To: <998328fa-9975-4a1c-950d-014f964dc1cf@googlegroups.com> References: <347b9197-b409-4651-8c01-26af4c3461ca@googlegroups.com> <998328fa-9975-4a1c-950d-014f964dc1cf@googlegroups.com> Message-ID: <37e39221-f1ef-4140-99ce-87fac4197cf7@googlegroups.com> FOUND ERROR! :D In creatin method of thread i wrote treadFunc() and should have said threadFunc (as pointer). Now i have problem with Text component. How to append string at end of it? From __peter__ at web.de Thu Apr 11 10:41:40 2013 From: __peter__ at web.de (Peter Otten) Date: Thu, 11 Apr 2013 16:41:40 +0200 Subject: Problems with sockets and threads References: <347b9197-b409-4651-8c01-26af4c3461ca@googlegroups.com> Message-ID: Dexter Deejay wrote: > When i try to run this code and to connect to server (server is written in > java that part of code is ok) everything stalls. Thread that i created > here occupies processor all the time and GUI freezes. It's supposed to be > waiting for message from server. (asynchronous one) Is there something > that i did wrong here, or is there better way to do this? Fredrik Lundh has an example that shows how to update a Text widget from another thread: http://effbot.org/zone/tkinter-threads.htm From djdexter1389 at gmail.com Thu Apr 11 11:39:22 2013 From: djdexter1389 at gmail.com (Dexter Deejay) Date: Thu, 11 Apr 2013 08:39:22 -0700 (PDT) Subject: Problems with sockets and threads In-Reply-To: References: <347b9197-b409-4651-8c01-26af4c3461ca@googlegroups.com> Message-ID: <53c8d613-a215-4076-aa5e-f55b9856873e@googlegroups.com> Thanks! :D From djdexter1389 at gmail.com Thu Apr 11 11:39:22 2013 From: djdexter1389 at gmail.com (Dexter Deejay) Date: Thu, 11 Apr 2013 08:39:22 -0700 (PDT) Subject: Problems with sockets and threads In-Reply-To: References: <347b9197-b409-4651-8c01-26af4c3461ca@googlegroups.com> Message-ID: <53c8d613-a215-4076-aa5e-f55b9856873e@googlegroups.com> Thanks! :D From lambandme at gmail.com Thu Apr 11 11:30:27 2013 From: lambandme at gmail.com (Lamb) Date: Thu, 11 Apr 2013 08:30:27 -0700 (PDT) Subject: My string module doesn't have maketrans or translate functions Message-ID: <338cca79-08c6-4c6f-89a4-d3a50ece3dee@googlegroups.com> Hi all, I'm really new to python and trying to figure out the basic rule and settings of it. I'm using python 3.3 and I was trying this code in python: import string s = "string. With. Punctuation?" out = s.translate(string.maketrans("",""), string.punctuation) And I got the following error: Traceback (most recent call last): File "C:/Python33/trials/ls.py", line 5, in out = s.translate(string.maketrans("",""), string.punctuation) AttributeError: 'module' object has no attribute 'maketrans' So I used the following to see functions inside string e=dir(string) >>> print(e) ['ChainMap', 'Formatter', 'Template', '_TemplateMetaclass', '__builtins__', '__cached__', '__doc__', '__file__', '__initializing__', '__loader__', '__name__', '__package__', '_re', '_string', 'ascii_letters', 'ascii_lowercase', 'ascii_uppercase', 'capwords', 'digits', 'hexdigits', 'octdigits', 'printable', 'punctuation', 'whitespace'] It doesn't have translate(), maketrans(), rstrip() and a whole lot of other things. What's the problem? Thanks! From rosuav at gmail.com Thu Apr 11 11:45:05 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Apr 2013 01:45:05 +1000 Subject: My string module doesn't have maketrans or translate functions In-Reply-To: <338cca79-08c6-4c6f-89a4-d3a50ece3dee@googlegroups.com> References: <338cca79-08c6-4c6f-89a4-d3a50ece3dee@googlegroups.com> Message-ID: On Fri, Apr 12, 2013 at 1:30 AM, Lamb wrote: > import string > s = "string. With. Punctuation?" > out = s.translate(string.maketrans("",""), string.punctuation) Try this instead: import string s = "string. With. Punctuation?" out = s.translate(str.maketrans("", "", string.punctuation)) Due to the changes in string handling (s is a Unicode string in Python 3, not a string of bytes), str.translate() got changed. Check out help(str.maketrans) and help(str.translate) in interactive Python for more details. ChrisA From lambandme at gmail.com Thu Apr 11 12:05:18 2013 From: lambandme at gmail.com (Lamb) Date: Thu, 11 Apr 2013 09:05:18 -0700 (PDT) Subject: My string module doesn't have maketrans or translate functions In-Reply-To: References: <338cca79-08c6-4c6f-89a4-d3a50ece3dee@googlegroups.com> Message-ID: <5dbca83a-f976-4582-8022-8f8c67f759e6@googlegroups.com> Thanks! It worked! But why didn't I see functions : translate(), maketrans(), rstrip(), etc. listed when I called print(dir(string))? On Thursday, April 11, 2013 11:45:05 AM UTC-4, Chris Angelico wrote: > > > import string > > > s = "string. With. Punctuation?" > > > out = s.translate(string.maketrans("",""), string.punctuation) > > > > Try this instead: > > > > import string > > s = "string. With. Punctuation?" > > out = s.translate(str.maketrans("", "", string.punctuation)) > > > > Due to the changes in string handling (s is a Unicode string in Python > > 3, not a string of bytes), str.translate() got changed. Check out > > help(str.maketrans) and help(str.translate) in interactive Python for > > more details. > > > > ChrisA From rosuav at gmail.com Thu Apr 11 12:09:39 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Apr 2013 02:09:39 +1000 Subject: My string module doesn't have maketrans or translate functions In-Reply-To: <5dbca83a-f976-4582-8022-8f8c67f759e6@googlegroups.com> References: <338cca79-08c6-4c6f-89a4-d3a50ece3dee@googlegroups.com> <5dbca83a-f976-4582-8022-8f8c67f759e6@googlegroups.com> Message-ID: On Fri, Apr 12, 2013 at 2:05 AM, Lamb wrote: > Thanks! It worked! But why didn't I see functions : translate(), maketrans(), rstrip(), etc. listed when I called print(dir(string))? Because they're not in the string module any more - they're methods on str (and bytes). Try checking out dir(str) - str being the class of your basic Unicode string now, rather than being the type of a string of bytes - and you should see them all. ChrisA From lambandme at gmail.com Thu Apr 11 12:05:18 2013 From: lambandme at gmail.com (Lamb) Date: Thu, 11 Apr 2013 09:05:18 -0700 (PDT) Subject: My string module doesn't have maketrans or translate functions In-Reply-To: References: <338cca79-08c6-4c6f-89a4-d3a50ece3dee@googlegroups.com> Message-ID: <5dbca83a-f976-4582-8022-8f8c67f759e6@googlegroups.com> Thanks! It worked! But why didn't I see functions : translate(), maketrans(), rstrip(), etc. listed when I called print(dir(string))? On Thursday, April 11, 2013 11:45:05 AM UTC-4, Chris Angelico wrote: > > > import string > > > s = "string. With. Punctuation?" > > > out = s.translate(string.maketrans("",""), string.punctuation) > > > > Try this instead: > > > > import string > > s = "string. With. Punctuation?" > > out = s.translate(str.maketrans("", "", string.punctuation)) > > > > Due to the changes in string handling (s is a Unicode string in Python > > 3, not a string of bytes), str.translate() got changed. Check out > > help(str.maketrans) and help(str.translate) in interactive Python for > > more details. > > > > ChrisA From breamoreboy at yahoo.co.uk Thu Apr 11 12:56:51 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 11 Apr 2013 17:56:51 +0100 Subject: My string module doesn't have maketrans or translate functions In-Reply-To: <338cca79-08c6-4c6f-89a4-d3a50ece3dee@googlegroups.com> References: <338cca79-08c6-4c6f-89a4-d3a50ece3dee@googlegroups.com> Message-ID: On 11/04/2013 16:30, Lamb wrote: > Hi all, > I'm really new to python and trying to figure out the basic rule and settings of it. I'm using python 3.3 and I was trying this code in python: > > import string > s = "string. With. Punctuation?" > out = s.translate(string.maketrans("",""), string.punctuation) > > And I got the following error: > Traceback (most recent call last): > File "C:/Python33/trials/ls.py", line 5, in > out = s.translate(string.maketrans("",""), string.punctuation) > AttributeError: 'module' object has no attribute 'maketrans' > > So I used the following to see functions inside string > e=dir(string) >>>> print(e) > ['ChainMap', 'Formatter', 'Template', '_TemplateMetaclass', '__builtins__', '__cached__', '__doc__', '__file__', '__initializing__', '__loader__', '__name__', '__package__', '_re', '_string', 'ascii_letters', 'ascii_lowercase', 'ascii_uppercase', 'capwords', 'digits', 'hexdigits', 'octdigits', 'printable', 'punctuation', 'whitespace'] > > It doesn't have translate(), maketrans(), rstrip() and a whole lot of other things. What's the problem? > > Thanks! > The string module is effectively dead. Many functions were deprecated back in 2.6, maketrans in 3.1, just use string methods instead. -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From steve+comp.lang.python at pearwood.info Thu Apr 11 20:17:10 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Apr 2013 00:17:10 GMT Subject: My string module doesn't have maketrans or translate functions References: <338cca79-08c6-4c6f-89a4-d3a50ece3dee@googlegroups.com> Message-ID: <51675286$0$29977$c3e8da3$5496439d@news.astraweb.com> On Thu, 11 Apr 2013 17:56:51 +0100, Mark Lawrence wrote: > The string module is effectively dead. It's not dead, it's pining for the fjords. But seriously, the string module holds a collection of useful string constants and the Template class. -- Steven From hossamalagmy at gmail.com Thu Apr 11 12:35:09 2013 From: hossamalagmy at gmail.com (23alagmy) Date: Thu, 11 Apr 2013 09:35:09 -0700 (PDT) Subject: Frances President Hollande Eradicate tax havens Message-ID: <49909c9c-9378-4e44-9092-b992dbb185c6@j14g2000vbk.googlegroups.com> Frances President Hollande Eradicate tax havens http://natigtas7ab.blogspot.com/2013/04/frances-president-hollande-eradicate.html From rmschne at gmail.com Thu Apr 11 14:12:47 2013 From: rmschne at gmail.com (Rob Schneider) Date: Thu, 11 Apr 2013 11:12:47 -0700 (PDT) Subject: shutil.copyfile is incomplete (truncated) Message-ID: Using Python 2.7.2 on OSX, I have created a file in temp space, then use the function "shutil.copyfile(fn,loc+fname)" from "fn" to "loc+fname". At the destination location, the file is truncated. About 10% of the file is lost. Original file is unchanged. I added calls to "statinfo" immediately after the copy, and all looks ok (correct file size). filecmp.cmp(fn,loc+fname) print "Statinfo :"+fn+":\n", os.stat(fn) print "Statinfo :"+loc+fname+":\n", os.stat(loc+fname) But when I look at the file in Finder, destination is smaller and even looking at the file (with text editor) file is truncated. What could be causing this? From neilc at norwich.edu Thu Apr 11 14:53:30 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 11 Apr 2013 18:53:30 GMT Subject: shutil.copyfile is incomplete (truncated) References: Message-ID: On 2013-04-11, Rob Schneider wrote: > Using Python 2.7.2 on OSX, I have created a file in temp space, > then use the function "shutil.copyfile(fn,loc+fname)" from "fn" > to "loc+fname". > > At the destination location, the file is truncated. About 10% > of the file is lost. Original file is unchanged. > > I added calls to "statinfo" immediately after the copy, and all > looks ok (correct file size). > > filecmp.cmp(fn,loc+fname) > print "Statinfo :"+fn+":\n", os.stat(fn) > print "Statinfo :"+loc+fname+":\n", os.stat(loc+fname) > > But when I look at the file in Finder, destination is smaller > and even looking at the file (with text editor) file is > truncated. > > What could be causing this? Could fn be getting some changes written after the copy is made? Is the file flushed/closed before you copy it? -- Neil Cerutti From rmschne at gmail.com Thu Apr 11 15:07:57 2013 From: rmschne at gmail.com (Rob Schneider) Date: Thu, 11 Apr 2013 12:07:57 -0700 (PDT) Subject: shutil.copyfile is incomplete (truncated) In-Reply-To: References: Message-ID: <5363f8ea-f2a6-4a08-a216-18c6666ba698@googlegroups.com> Thanks. Yes, there is a close function call before the copy is launched. No other writes. Does Python wait for file close command to complete before proceeding? From neilc at norwich.edu Thu Apr 11 15:55:53 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 11 Apr 2013 19:55:53 GMT Subject: shutil.copyfile is incomplete (truncated) References: <5363f8ea-f2a6-4a08-a216-18c6666ba698@googlegroups.com> Message-ID: On 2013-04-11, Rob Schneider wrote: > Thanks. Yes, there is a close function call before the copy is > launched. No other writes. Does Python wait for file close > command to complete before proceeding? The close method is defined and flushing and closing a file, so it should not return until that's done. What command are you using to create the temp file? -- Neil Cerutti From steve+comp.lang.python at pearwood.info Thu Apr 11 20:06:21 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 12 Apr 2013 00:06:21 GMT Subject: shutil.copyfile is incomplete (truncated) References: <5363f8ea-f2a6-4a08-a216-18c6666ba698@googlegroups.com> Message-ID: <51674ffc$0$29977$c3e8da3$5496439d@news.astraweb.com> On Thu, 11 Apr 2013 19:55:53 +0000, Neil Cerutti wrote: > On 2013-04-11, Rob Schneider wrote: >> Thanks. Yes, there is a close function call before the copy is >> launched. No other writes. Does Python wait for file close command to >> complete before proceeding? > > The close method is defined and flushing and closing a file, so it > should not return until that's done. But note that "done" in this case means "the file system thinks it is done", not *actually* done. Hard drives, especially the cheaper ones, lie. They can say the file is written when in fact the data is still in the hard drive's internal cache and not written to the disk platter. Also, in my experience, hardware RAID controllers will eat your data, and then your brains when you try to diagnose the problem. I would consider the chance that the disk may be faulty, or the file system is corrupt. Does the problem go away if you write to a different file system or a different disk? -- Steven From cs at zip.com.au Thu Apr 11 21:15:50 2013 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 12 Apr 2013 11:15:50 +1000 Subject: shutil.copyfile is incomplete (truncated) In-Reply-To: <51674ffc$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <51674ffc$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20130412011550.GA80724@cskk.homeip.net> On 12Apr2013 00:06, Steven D'Aprano wrote: | On Thu, 11 Apr 2013 19:55:53 +0000, Neil Cerutti wrote: | > On 2013-04-11, Rob Schneider wrote: | >> Thanks. Yes, there is a close function call before the copy is | >> launched. No other writes. Does Python wait for file close command to | >> complete before proceeding? | > | > The close method is defined and flushing and closing a file, so it | > should not return until that's done. | | But note that "done" in this case means "the file system thinks it is | done", not *actually* done. Unless there's a reboot (or crash) in between, the view from the app should be consistent and correct. | Hard drives, especially the cheaper ones, | lie. They can say the file is written when in fact the data is still in | the hard drive's internal cache and not written to the disk platter. | Also, in my experience, hardware RAID controllers will eat your data, and | then your brains when you try to diagnose the problem. | | I would consider the chance that the disk may be faulty, or the file | system is corrupt. Does the problem go away if you write to a different | file system or a different disk? Or that the filesystem may be full? Of course, that's usually obvious more widely when it happens... Question: is the size of the incomplete file a round number? (Like a multiple of a decent sized power of 2>) Cheers, -- Cameron Simpson I am now convinced that theoretical physics is actual philosophy. - Max Born From nad at acm.org Thu Apr 11 21:33:29 2013 From: nad at acm.org (Ned Deily) Date: Thu, 11 Apr 2013 18:33:29 -0700 Subject: shutil.copyfile is incomplete (truncated) References: <51674ffc$0$29977$c3e8da3$5496439d@news.astraweb.com> <20130412011550.GA80724@cskk.homeip.net> Message-ID: In article <20130412011550.GA80724 at cskk.homeip.net>, Cameron Simpson wrote: > Or that the filesystem may be full? Of course, that's usually obvious > more widely when it happens... > > Question: is the size of the incomplete file a round number? (Like > a multiple of a decent sized power of 2>) Also on what OS X file system type does the file being created reside, in particular, is it a network file system? -- Ned Deily, nad at acm.org From rmschne at gmail.com Fri Apr 12 02:32:51 2013 From: rmschne at gmail.com (Rob Schneider) Date: Thu, 11 Apr 2013 23:32:51 -0700 (PDT) Subject: shutil.copyfile is incomplete (truncated) In-Reply-To: References: <51674ffc$0$29977$c3e8da3$5496439d@news.astraweb.com> <20130412011550.GA80724@cskk.homeip.net> Message-ID: > > > Or that the filesystem may be full? Of course, that's usually obvious > > > more widely when it happens... > > > > > > Question: is the size of the incomplete file a round number? (Like > > > a multiple of a decent sized power of 2>) > > > > Also on what OS X file system type does the file being created reside, > > in particular, is it a network file system? > File system not full (2/3 of disk is free) Source (correct one) is 47,970 bytes. Target after copy of 45,056 bytes. I've tried changing what gets written to change the file size. It is usually this sort of difference. The file system is Mac OS Extended Journaled (default as out of the box). From rmschne at gmail.com Fri Apr 12 02:53:18 2013 From: rmschne at gmail.com (Rob Schneider) Date: Thu, 11 Apr 2013 23:53:18 -0700 (PDT) Subject: shutil.copyfile is incomplete (truncated) In-Reply-To: References: <51674ffc$0$29977$c3e8da3$5496439d@news.astraweb.com> <20130412011550.GA80724@cskk.homeip.net> Message-ID: <6eeabeb2-e6dd-49fc-bd64-8de53965189b@googlegroups.com> > The file system is Mac OS Extended Journaled (default as out of the box). I ran a repair disk .. .while it found and fixed what it called "minor" problems, it did something. However, the repair did not fix the problem. I just ran the program again and the source is 47,970 bytes and target after copy if 45,056. Interestingly, the test I run just after the copy , i run a file compare: code: if showproperties: print "Filecompare :",filecmp.cmp(fn,loc+fname) print "Statinfo :"+fn+":\n", os.stat(fn) print "Statinfo :"+loc+fname+":\n", os.stat(loc+fname) results: Filecompare : True Statinfo :/var/folders/p_/n5lktj2n0r938_46jyqb52g40000gn/T/speakers.htm: posix.stat_result(st_mode=33188, st_ino=32205850, st_dev=16777218L, st_nlink=1, st_uid=501, st_gid=20, st_size=45056, st_atime=1365749178, st_mtime=1365749178, st_ctime=1365749178) Statinfo :/Users/rmschne/Documents/ScottishOilClub/SOC Board Doc Sharing Folder/Meetings/speakers.htm: posix.stat_result(st_mode=33188, st_ino=32144179, st_dev=16777218L, st_nlink=1, st_uid=501, st_gid=20, st_size=45056, st_atime=1365749178, st_mtime=1365749178, st_ctime=1365749178) It shows file size 45,056 on both source and target, which is the file size of the flawed target, and is not what Finder shows for source. Sigh. From rmschne at gmail.com Fri Apr 12 02:53:18 2013 From: rmschne at gmail.com (Rob Schneider) Date: Thu, 11 Apr 2013 23:53:18 -0700 (PDT) Subject: shutil.copyfile is incomplete (truncated) In-Reply-To: References: <51674ffc$0$29977$c3e8da3$5496439d@news.astraweb.com> <20130412011550.GA80724@cskk.homeip.net> Message-ID: <6eeabeb2-e6dd-49fc-bd64-8de53965189b@googlegroups.com> > The file system is Mac OS Extended Journaled (default as out of the box). I ran a repair disk .. .while it found and fixed what it called "minor" problems, it did something. However, the repair did not fix the problem. I just ran the program again and the source is 47,970 bytes and target after copy if 45,056. Interestingly, the test I run just after the copy , i run a file compare: code: if showproperties: print "Filecompare :",filecmp.cmp(fn,loc+fname) print "Statinfo :"+fn+":\n", os.stat(fn) print "Statinfo :"+loc+fname+":\n", os.stat(loc+fname) results: Filecompare : True Statinfo :/var/folders/p_/n5lktj2n0r938_46jyqb52g40000gn/T/speakers.htm: posix.stat_result(st_mode=33188, st_ino=32205850, st_dev=16777218L, st_nlink=1, st_uid=501, st_gid=20, st_size=45056, st_atime=1365749178, st_mtime=1365749178, st_ctime=1365749178) Statinfo :/Users/rmschne/Documents/ScottishOilClub/SOC Board Doc Sharing Folder/Meetings/speakers.htm: posix.stat_result(st_mode=33188, st_ino=32144179, st_dev=16777218L, st_nlink=1, st_uid=501, st_gid=20, st_size=45056, st_atime=1365749178, st_mtime=1365749178, st_ctime=1365749178) It shows file size 45,056 on both source and target, which is the file size of the flawed target, and is not what Finder shows for source. Sigh. From nad at acm.org Fri Apr 12 03:53:29 2013 From: nad at acm.org (Ned Deily) Date: Fri, 12 Apr 2013 00:53:29 -0700 Subject: shutil.copyfile is incomplete (truncated) References: <51674ffc$0$29977$c3e8da3$5496439d@news.astraweb.com> <20130412011550.GA80724@cskk.homeip.net> <6eeabeb2-e6dd-49fc-bd64-8de53965189b@googlegroups.com> Message-ID: In article <6eeabeb2-e6dd-49fc-bd64-8de53965189b at googlegroups.com>, Rob Schneider wrote: > > The file system is Mac OS Extended Journaled (default as out of the box). > It shows file size 45,056 on both source and target, which is the file size > of the flawed target, and is not what Finder shows for source. Perhaps the source file has an OS X resource fork or other extended attribute metadata. shutil's copy functions won't handle those. One way to see if that is the case is to examine the source file in a terminal window with: ls -l@ $ ls -l@ test.jpg -rw-r--r--@ 1 nad staff 40359 Jul 15 2009 test.jpg com.apple.FinderInfo 32 com.apple.ResourceFork 899489 -- Ned Deily, nad at acm.org From rmschne at gmail.com Fri Apr 12 02:32:51 2013 From: rmschne at gmail.com (Rob Schneider) Date: Thu, 11 Apr 2013 23:32:51 -0700 (PDT) Subject: shutil.copyfile is incomplete (truncated) In-Reply-To: References: <51674ffc$0$29977$c3e8da3$5496439d@news.astraweb.com> <20130412011550.GA80724@cskk.homeip.net> Message-ID: > > > Or that the filesystem may be full? Of course, that's usually obvious > > > more widely when it happens... > > > > > > Question: is the size of the incomplete file a round number? (Like > > > a multiple of a decent sized power of 2>) > > > > Also on what OS X file system type does the file being created reside, > > in particular, is it a network file system? > File system not full (2/3 of disk is free) Source (correct one) is 47,970 bytes. Target after copy of 45,056 bytes. I've tried changing what gets written to change the file size. It is usually this sort of difference. The file system is Mac OS Extended Journaled (default as out of the box). From cs at zip.com.au Fri Apr 12 04:26:21 2013 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 12 Apr 2013 18:26:21 +1000 Subject: shutil.copyfile is incomplete (truncated) In-Reply-To: References: Message-ID: <20130412082621.GA42695@cskk.homeip.net> On 11Apr2013 23:32, Rob Schneider wrote: | > > Question: is the size of the incomplete file a round number? (Like | > > a multiple of a decent sized power of 2>) [...] | Source (correct one) is 47,970 bytes. Target after copy of 45,056 | bytes. I've tried changing what gets written to change the file | size. It is usually this sort of difference. 45046 is exactly 11 * 4096. I'd say your I/O is using 4KB blocks, and the last partial block (to make it up to 47970) didn't get written (at the OS level). Earlier you wrote: | I have created a file in temp space, then use the function | "shutil.copyfile(fn,loc+fname)" from "fn" to "loc+fname". and: | Yes, there is a close function call before the copy is launched. No other writes. | Does Python wait for file close command to complete before proceeding? Please show us the exact code used to make the temp file. I would guess the temp file has not been closed (or flushed) before the call to copyfile. If you're copying data to a tempfile, it will only have complete buffers (i.e. multiples of 4096 bytes) in it until the final flush or close. So I'm imagining something like: tfp = open(tempfilename, "w") ... lots of tfp.write() ... shutil.copyfile(tempfilename, newfilename) Note above no flush or close of tfp. So the final incomplete I/O buffer is still in Python's memory; it hasn't been actually written to the temp file because the buffer has not been filled, and the file has not been closed. Anyway, can you show us the relevant bits of code involved? Cheers, -- Cameron Simpson Processes are like potatoes. - NCR device driver manual From rmschne at gmail.com Fri Apr 12 05:18:17 2013 From: rmschne at gmail.com (Rob Schneider) Date: Fri, 12 Apr 2013 02:18:17 -0700 (PDT) Subject: shutil.copyfile is incomplete (truncated) In-Reply-To: References: Message-ID: <439121e2-ecc0-4f4d-b75f-0154102cc128@googlegroups.com> On Friday, 12 April 2013 09:26:21 UTC+1, Cameron Simpson wrote: > > | > > Question: is the size of the incomplete file a round number? (Like > > | > > a multiple of a decent sized power of 2>) > > [...] > > | Source (correct one) is 47,970 bytes. Target after copy of 45,056 > > | bytes. I've tried changing what gets written to change the file > > | size. It is usually this sort of difference. > > > > 45046 is exactly 11 * 4096. I'd say your I/O is using 4KB blocks, > > and the last partial block (to make it up to 47970) didn't get > > written (at the OS level). > > > > Earlier you wrote: > > | I have created a file in temp space, then use the function > > | "shutil.copyfile(fn,loc+fname)" from "fn" to "loc+fname". > > and: > > | Yes, there is a close function call before the copy is launched. No other writes. > > | Does Python wait for file close command to complete before proceeding? > > > > Please show us the exact code used to make the temp file. > > > > I would guess the temp file has not been closed (or flushed) before > > the call to copyfile. > > > > If you're copying data to a tempfile, it will only have complete > > buffers (i.e. multiples of 4096 bytes) in it until the final flush > > or close. > > > > So I'm imagining something like: > > > > tfp = open(tempfilename, "w") > > ... lots of tfp.write() ... > > shutil.copyfile(tempfilename, newfilename) > > > > Note above no flush or close of tfp. So the final incomplete I/O > > buffer is still in Python's memory; it hasn't been actually written > > to the temp file because the buffer has not been filled, and the file > > has not been closed. > > > > Anyway, can you show us the relevant bits of code involved? > > > > Cheers, > > -- > > Cameron Simpson > > > > Processes are like potatoes. - NCR device driver manual Thanks for the observation. Code (simplified but results in same flaw) (which a close, far as I can tell). def CreateSpeakerList1(): import shutil import filecmp import os.path t=get_template('speaker_list.html') fn=TEMP_DIR+SOC_SPEAKER_LIST fn=tempfile.gettempdir()+"/"+SOC_SPEAKER_LIST f=open(fn,'w') speaker_list=Speaker.objects.order_by('status__order','targetmtg__date') print " Creating " + SOC_SPEAKER_LIST + " ..." html=(smart_str(t.render(Context( { 'css_include_file':CSS_INCLUDE_FILE, 'css_link':False, 'title': ORG_NAME+" Speaker List", 'speaker_list': speaker_list, })))) f.write(html) f.close print " Wrote "+fn shutil.copyfile(fn,SOC_GENERAL_OUTPUT_FOLDER+SOC_SPEAKER_LIST) print "Filecompare :",filecmp.cmp(fn,SOC_GENERAL_OUTPUT_FOLDER+SOC_SPEAKER_LIST) print "Statinfo :"+fn+":\n", os.stat(fn) print "Statinfo :"+SOC_GENERAL_OUTPUT_FOLDER+SOC_SPEAKER_LIST+"\n", os.stat(SOC_GENERAL_OUTPUT_FOLDER+SOC_SPEAKER_LIST) return Output on latest run: Creating speakers.htm ... Wrote /var/folders/p_/n5lktj2n0r938_46jyqb52g40000gn/T/speakers.htm Filecompare : True Statinfo :/var/folders/p_/n5lktj2n0r938_46jyqb52g40000gn/T/speakers.htm: posix.stat_result(st_mode=33188, st_ino=32332374, st_dev=16777218L, st_nlink=1, st_uid=501, st_gid=20, st_size=45056, st_atime=1365758139, st_mtime=1365758139, st_ctime=1365758139) Statinfo :/Users/rmschne/Documents/ScottishOilClub/Output/speakers.htm posix.stat_result(st_mode=33188, st_ino=32143886, st_dev=16777218L, st_nlink=1, st_uid=501, st_gid=20, st_size=45056, st_atime=1365758029, st_mtime=1365758139, st_ctime=1365758139) From rmschne at gmail.com Fri Apr 12 05:18:17 2013 From: rmschne at gmail.com (Rob Schneider) Date: Fri, 12 Apr 2013 02:18:17 -0700 (PDT) Subject: shutil.copyfile is incomplete (truncated) In-Reply-To: References: Message-ID: <439121e2-ecc0-4f4d-b75f-0154102cc128@googlegroups.com> On Friday, 12 April 2013 09:26:21 UTC+1, Cameron Simpson wrote: > > | > > Question: is the size of the incomplete file a round number? (Like > > | > > a multiple of a decent sized power of 2>) > > [...] > > | Source (correct one) is 47,970 bytes. Target after copy of 45,056 > > | bytes. I've tried changing what gets written to change the file > > | size. It is usually this sort of difference. > > > > 45046 is exactly 11 * 4096. I'd say your I/O is using 4KB blocks, > > and the last partial block (to make it up to 47970) didn't get > > written (at the OS level). > > > > Earlier you wrote: > > | I have created a file in temp space, then use the function > > | "shutil.copyfile(fn,loc+fname)" from "fn" to "loc+fname". > > and: > > | Yes, there is a close function call before the copy is launched. No other writes. > > | Does Python wait for file close command to complete before proceeding? > > > > Please show us the exact code used to make the temp file. > > > > I would guess the temp file has not been closed (or flushed) before > > the call to copyfile. > > > > If you're copying data to a tempfile, it will only have complete > > buffers (i.e. multiples of 4096 bytes) in it until the final flush > > or close. > > > > So I'm imagining something like: > > > > tfp = open(tempfilename, "w") > > ... lots of tfp.write() ... > > shutil.copyfile(tempfilename, newfilename) > > > > Note above no flush or close of tfp. So the final incomplete I/O > > buffer is still in Python's memory; it hasn't been actually written > > to the temp file because the buffer has not been filled, and the file > > has not been closed. > > > > Anyway, can you show us the relevant bits of code involved? > > > > Cheers, > > -- > > Cameron Simpson > > > > Processes are like potatoes. - NCR device driver manual Thanks for the observation. Code (simplified but results in same flaw) (which a close, far as I can tell). def CreateSpeakerList1(): import shutil import filecmp import os.path t=get_template('speaker_list.html') fn=TEMP_DIR+SOC_SPEAKER_LIST fn=tempfile.gettempdir()+"/"+SOC_SPEAKER_LIST f=open(fn,'w') speaker_list=Speaker.objects.order_by('status__order','targetmtg__date') print " Creating " + SOC_SPEAKER_LIST + " ..." html=(smart_str(t.render(Context( { 'css_include_file':CSS_INCLUDE_FILE, 'css_link':False, 'title': ORG_NAME+" Speaker List", 'speaker_list': speaker_list, })))) f.write(html) f.close print " Wrote "+fn shutil.copyfile(fn,SOC_GENERAL_OUTPUT_FOLDER+SOC_SPEAKER_LIST) print "Filecompare :",filecmp.cmp(fn,SOC_GENERAL_OUTPUT_FOLDER+SOC_SPEAKER_LIST) print "Statinfo :"+fn+":\n", os.stat(fn) print "Statinfo :"+SOC_GENERAL_OUTPUT_FOLDER+SOC_SPEAKER_LIST+"\n", os.stat(SOC_GENERAL_OUTPUT_FOLDER+SOC_SPEAKER_LIST) return Output on latest run: Creating speakers.htm ... Wrote /var/folders/p_/n5lktj2n0r938_46jyqb52g40000gn/T/speakers.htm Filecompare : True Statinfo :/var/folders/p_/n5lktj2n0r938_46jyqb52g40000gn/T/speakers.htm: posix.stat_result(st_mode=33188, st_ino=32332374, st_dev=16777218L, st_nlink=1, st_uid=501, st_gid=20, st_size=45056, st_atime=1365758139, st_mtime=1365758139, st_ctime=1365758139) Statinfo :/Users/rmschne/Documents/ScottishOilClub/Output/speakers.htm posix.stat_result(st_mode=33188, st_ino=32143886, st_dev=16777218L, st_nlink=1, st_uid=501, st_gid=20, st_size=45056, st_atime=1365758029, st_mtime=1365758139, st_ctime=1365758139) From rosuav at gmail.com Fri Apr 12 05:22:21 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Apr 2013 19:22:21 +1000 Subject: shutil.copyfile is incomplete (truncated) In-Reply-To: <439121e2-ecc0-4f4d-b75f-0154102cc128@googlegroups.com> References: <439121e2-ecc0-4f4d-b75f-0154102cc128@googlegroups.com> Message-ID: On Fri, Apr 12, 2013 at 7:18 PM, Rob Schneider wrote: > f.close Yep, there's the problem! See my previous post for details. Change this to: f.close() and you should be sorted. ChrisA From rmschne at gmail.com Fri Apr 12 08:07:49 2013 From: rmschne at gmail.com (Rob Schneider) Date: Fri, 12 Apr 2013 05:07:49 -0700 (PDT) Subject: shutil.copyfile is incomplete (truncated) In-Reply-To: References: <439121e2-ecc0-4f4d-b75f-0154102cc128@googlegroups.com> Message-ID: <61dcdc73-08de-4727-bdfc-fa3e99bd303e@googlegroups.com> On Friday, 12 April 2013 10:22:21 UTC+1, Chris Angelico wrote: > On Fri, Apr 12, 2013 at 7:18 PM, Rob Schneider wrote: > > > f.close > > > > Yep, there's the problem! See my previous post for details. Change this to: > > > > f.close() > > > > and you should be sorted. > > > > ChrisA Slapping forehead ... hard. Thanks! From rmschne at gmail.com Fri Apr 12 08:07:49 2013 From: rmschne at gmail.com (Rob Schneider) Date: Fri, 12 Apr 2013 05:07:49 -0700 (PDT) Subject: shutil.copyfile is incomplete (truncated) In-Reply-To: References: <439121e2-ecc0-4f4d-b75f-0154102cc128@googlegroups.com> Message-ID: <61dcdc73-08de-4727-bdfc-fa3e99bd303e@googlegroups.com> On Friday, 12 April 2013 10:22:21 UTC+1, Chris Angelico wrote: > On Fri, Apr 12, 2013 at 7:18 PM, Rob Schneider wrote: > > > f.close > > > > Yep, there's the problem! See my previous post for details. Change this to: > > > > f.close() > > > > and you should be sorted. > > > > ChrisA Slapping forehead ... hard. Thanks! From breamoreboy at yahoo.co.uk Fri Apr 12 08:18:58 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 12 Apr 2013 13:18:58 +0100 Subject: shutil.copyfile is incomplete (truncated) In-Reply-To: <61dcdc73-08de-4727-bdfc-fa3e99bd303e@googlegroups.com> References: <439121e2-ecc0-4f4d-b75f-0154102cc128@googlegroups.com> <61dcdc73-08de-4727-bdfc-fa3e99bd303e@googlegroups.com> Message-ID: On 12/04/2013 13:07, Rob Schneider wrote: > On Friday, 12 April 2013 10:22:21 UTC+1, Chris Angelico wrote: >> On Fri, Apr 12, 2013 at 7:18 PM, Rob Schneider wrote: >> >>> f.close >> >> Yep, there's the problem! See my previous post for details. Change this to: >> >> f.close() >> >> and you should be sorted. >> >> ChrisA > > Slapping forehead ... hard. Thanks! > a) We've all done it :) b) The print function/statement or Python's interactive mode are awesome in situations like this. -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From roy at panix.com Fri Apr 12 10:54:34 2013 From: roy at panix.com (Roy Smith) Date: Fri, 12 Apr 2013 10:54:34 -0400 Subject: shutil.copyfile is incomplete (truncated) References: Message-ID: In article , Cameron Simpson wrote: > 45046 is exactly 11 * 4096. I'd say your I/O is using 4KB blocks, > and the last partial block (to make it up to 47970) didn't get > written (at the OS level). Yeah, this sounds like a good diagnosis. BTW, the dtruss command I recommended in my earlier post would confirm this. But, to be honest, it's such a likely scenario that it hardly needs confirmation. From roy at panix.com Fri Apr 12 10:57:00 2013 From: roy at panix.com (Roy Smith) Date: Fri, 12 Apr 2013 10:57:00 -0400 Subject: shutil.copyfile is incomplete (truncated) References: Message-ID: In article , Rob Schneider wrote: > f.close Well, there's your problem. You're not calling close. You forgot the ()'s after the function name! From roy at panix.com Fri Apr 12 10:47:31 2013 From: roy at panix.com (Roy Smith) Date: Fri, 12 Apr 2013 10:47:31 -0400 Subject: shutil.copyfile is incomplete (truncated) References: <51674ffc$0$29977$c3e8da3$5496439d@news.astraweb.com> <20130412011550.GA80724@cskk.homeip.net> Message-ID: In article , Rob Schneider wrote: > Source (correct one) is 47,970 bytes. Target after copy of 45,056 bytes. > I've tried changing what gets written to change the file size. It is usually > this sort of difference. > > The file system is Mac OS Extended Journaled (default as out of the box). Is it always the tail end of the file that gets truncated, or is it missing (or mutating) data in the middle of the file? I'm just grasping at straws here, but maybe it's somehow messing up line endings (turning CRLF pairs into just LF), or using some other kind of encoding for unicode characters? If you compare the files with cmp, does it say: $ cmp original truncated cmp: EOF on truncated that's what I would expect if it's a strict truncation. If it says anything else, you've got a data munging problem. What I would normally do around this time is run a system call trace on the process to watch all the descriptor related (i.e. open, create, write) system calls. On OSX, that means dtruss. Unfortunately, I'm not that familiar with the OSX variant so I can't give you specific advice about which options to use. When you can see the system calls, you know exactly what your process is doing. You should be able to see the output file being opened and a descriptor returned, then find all the write() calls to that descriptor. You'll also be able to find any other system calls on that pathname after the descriptor is closed. Please report back what you find! Oh, another trick you might want to try is making the output file path /dev/stdout and redirecting the output into a file with the shell. See if that makes any difference. Or, try something like (assuming the -o option to your script sets the output filename): python my_prog.py -o /dev/stdout | dd bs=1 of=xxx That will do a couple of things. First, dd will report how many bytes it read and wrote, so you can see if that's the correct number. Also, since your process will no longer be writing to a real file, if anything is doing something weird like a seek() after you're done writing, that will fail since you can't seek() on a pipe. From rmschne at gmail.com Fri Apr 12 02:27:14 2013 From: rmschne at gmail.com (Rob Schneider) Date: Thu, 11 Apr 2013 23:27:14 -0700 (PDT) Subject: shutil.copyfile is incomplete (truncated) In-Reply-To: <51674ffc$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <5363f8ea-f2a6-4a08-a216-18c6666ba698@googlegroups.com> <51674ffc$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: > I would consider the chance that the disk may be faulty, or the file > > system is corrupt. Does the problem go away if you write to a different > > file system or a different disk? > It's a relatively new MacBook Pro with a solid state disk. I've not noticed any other disk problems. I did a "repair permissions" (for what it's worth). Maybe I'll have it tested at the Genius Bar. I don't have the full system on another computer to try that; but will work on that today. From roy at panix.com Fri Apr 12 10:51:00 2013 From: roy at panix.com (Roy Smith) Date: Fri, 12 Apr 2013 10:51:00 -0400 Subject: shutil.copyfile is incomplete (truncated) References: <5363f8ea-f2a6-4a08-a216-18c6666ba698@googlegroups.com> <51674ffc$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <51674ffc$0$29977$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > On Thu, 11 Apr 2013 19:55:53 +0000, Neil Cerutti wrote: > > > On 2013-04-11, Rob Schneider wrote: > >> Thanks. Yes, there is a close function call before the copy is > >> launched. No other writes. Does Python wait for file close command to > >> complete before proceeding? > > > > The close method is defined and flushing and closing a file, so it > > should not return until that's done. > > But note that "done" in this case means "the file system thinks it is > done", not *actually* done. Hard drives, especially the cheaper ones, > lie. They can say the file is written when in fact the data is still in > the hard drive's internal cache and not written to the disk platter. > Also, in my experience, hardware RAID controllers will eat your data, and > then your brains when you try to diagnose the problem. > > I would consider the chance that the disk may be faulty, or the file > system is corrupt. Does the problem go away if you write to a different > file system or a different disk? It is *possible* that this is the problem, but it's really way far out on the long tail of possibilities. If the file system were corrupted or the disk faulty, the odds are you would be seeing all sorts of other problems. And this would not be anywhere near as repeatable as the OP is describing. Think horses, not zebras. From dihedral88888 at googlemail.com Fri Apr 12 11:49:13 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 12 Apr 2013 08:49:13 -0700 (PDT) Subject: shutil.copyfile is incomplete (truncated) In-Reply-To: <51674ffc$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <5363f8ea-f2a6-4a08-a216-18c6666ba698@googlegroups.com> <51674ffc$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <423f86d9-445b-4578-a845-208d003a7587@googlegroups.com> Steven D'Aprano? 2013?4?12????UTC+8??8?06?21???? > On Thu, 11 Apr 2013 19:55:53 +0000, Neil Cerutti wrote: > > > > > On 2013-04-11, Rob Schneider wrote: > > >> Thanks. Yes, there is a close function call before the copy is > > >> launched. No other writes. Does Python wait for file close command to > > >> complete before proceeding? > > > > > > The close method is defined and flushing and closing a file, so it > > > should not return until that's done. > > > > But note that "done" in this case means "the file system thinks it is > > done", not *actually* done. Hard drives, especially the cheaper ones, > > lie. They can say the file is written when in fact the data is still in > > the hard drive's internal cache and not written to the disk platter. > > Also, in my experience, hardware RAID controllers will eat your data, and > > then your brains when you try to diagnose the problem. > > Don't you model this as a non-blocking operation in your program? > > I would consider the chance that the disk may be faulty, or the file > > system is corrupt. Does the problem go away if you write to a different > > file system or a different disk? > > > > > > > > -- > > Steven Back-ups and read-back verifications are important for those who care. From nobody at nowhere.com Fri Apr 12 22:33:29 2013 From: nobody at nowhere.com (Nobody) Date: Sat, 13 Apr 2013 03:33:29 +0100 Subject: shutil.copyfile is incomplete (truncated) References: <5363f8ea-f2a6-4a08-a216-18c6666ba698@googlegroups.com> <51674ffc$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 12 Apr 2013 00:06:21 +0000, Steven D'Aprano wrote: >> The close method is defined and flushing and closing a file, so it >> should not return until that's done. > > But note that "done" in this case means "the file system thinks it is > done", not *actually* done. Hard drives, especially the cheaper ones, > lie. They can say the file is written when in fact the data is still in > the hard drive's internal cache and not written to the disk platter. > Also, in my experience, hardware RAID controllers will eat your data, and > then your brains when you try to diagnose the problem. None of which is likely to be relevant here, as any subsequent access to the file will reference the in-memory copy; the disk will only get involved if the data has already been flushed from the OS' cache and has to be read back in from disk. write(), close(), etc return once the data has been written to the OS' disk cache. At that point, the OS usually won't have even started sending the data to the drive, let alone waited for the drive to report (or claim) that the data has been written to the physical disk. If you want to wait for the data written to be written to the physical disk (in order to obtain specific behaviour with respect to an unclean shutdown), use f.flush() followed by os.fsync(f.fileno()). But most of the time, there's no point. If you actually care about what happens in the event of an unclean shutdown, you typically also need to sync the directory, otherwise the file's contents will get sync'd but the file's very existence might not be. From rosuav at gmail.com Fri Apr 12 23:05:56 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 13 Apr 2013 13:05:56 +1000 Subject: shutil.copyfile is incomplete (truncated) In-Reply-To: References: <5363f8ea-f2a6-4a08-a216-18c6666ba698@googlegroups.com> <51674ffc$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Apr 13, 2013 at 12:33 PM, Nobody wrote: > But most of the time, there's no point. If you actually care about what > happens in the event of an unclean shutdown, you typically also need to > sync the directory, otherwise the file's contents will get sync'd but the > file's very existence might not be. Or just store your content in a PostgreSQL database, and let it worry about all the platform-specific details of how to fsync reliably. ChrisA From steve+comp.lang.python at pearwood.info Fri Apr 12 23:17:57 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Apr 2013 03:17:57 GMT Subject: [OT] Lying hard drives [was Re: shutil.copyfile is incomplete (truncated)] References: <5363f8ea-f2a6-4a08-a216-18c6666ba698@googlegroups.com> <51674ffc$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5168ce64$0$29977$c3e8da3$5496439d@news.astraweb.com> On Sat, 13 Apr 2013 03:33:29 +0100, Nobody wrote: > On Fri, 12 Apr 2013 00:06:21 +0000, Steven D'Aprano wrote: > >>> The close method is defined and flushing and closing a file, so it >>> should not return until that's done. >> >> But note that "done" in this case means "the file system thinks it is >> done", not *actually* done. Hard drives, especially the cheaper ones, >> lie. They can say the file is written when in fact the data is still in >> the hard drive's internal cache and not written to the disk platter. >> Also, in my experience, hardware RAID controllers will eat your data, >> and then your brains when you try to diagnose the problem. > > None of which is likely to be relevant here, Since we've actually identified the bug (the OP was using file.close without actually calling it), that's certainly the case :-) [...] > If you want to wait for the data written to be written to the physical > disk (in order to obtain specific behaviour with respect to an unclean > shutdown), use f.flush() followed by os.fsync(f.fileno()). If only it were that simple. It has been documented that some disks will lie, even when told to sync. When I say "some", I mean *most*. There's probably nothing you can do about it, apart from not using that model or brand of disk, so you have to just live with the risk. http://queue.acm.org/detail.cfm?id=2367378 USB sticks are especially nasty. I've got quite a few USB thumb drives where the "write" light keeps flickering for anything up to five minutes after the OS reports that the drive has been unmounted and is safe to unplug. I corrupted the data on these quite a few times until I noticed the light. And let's not even mention the drives that have no light at all... But my favourite example of lying hard drives of all time is this: http://blog.jitbit.com/2011/04/chinese-magic-drive.html I want one of those! -- Steven From rosuav at gmail.com Fri Apr 12 23:43:57 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 13 Apr 2013 13:43:57 +1000 Subject: [OT] Lying hard drives [was Re: shutil.copyfile is incomplete (truncated)] In-Reply-To: <5168ce64$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <5363f8ea-f2a6-4a08-a216-18c6666ba698@googlegroups.com> <51674ffc$0$29977$c3e8da3$5496439d@news.astraweb.com> <5168ce64$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Apr 13, 2013 at 1:17 PM, Steven D'Aprano wrote: > On Sat, 13 Apr 2013 03:33:29 +0100, Nobody wrote: >> If you want to wait for the data written to be written to the physical >> disk (in order to obtain specific behaviour with respect to an unclean >> shutdown), use f.flush() followed by os.fsync(f.fileno()). > > If only it were that simple. It has been documented that some disks will > lie, even when told to sync. When I say "some", I mean *most*. There's > probably nothing you can do about it, apart from not using that model or > brand of disk, so you have to just live with the risk. It's often close to that simple. With most hard disks, you can make them 100% reliable, but you may have to check some disk parameters (on Linux, that's just a matter of writing to something in /proc somewhere, don't remember the details but it's easy to check). The worst offenders I've met are SSDs... > USB sticks are especially nasty. I've got quite a few USB thumb drives > where the "write" light keeps flickering for anything up to five minutes > after the OS reports that the drive has been unmounted and is safe to > unplug. I corrupted the data on these quite a few times until I noticed > the light. And let's not even mention the drives that have no light at > all... ... but you've met worse. > But my favourite example of lying hard drives of all time is this: > > http://blog.jitbit.com/2011/04/chinese-magic-drive.html > > I want one of those! Awesome! It's the new version of DoubleSpace / DriveSpace! http://en.wikipedia.org/wiki/DriveSpace (And its problems, according to that Wikipedia article, actually had the same root cause - write caching that the user wasn't aware of. Great.) ChrisA From rmschne at gmail.com Fri Apr 12 02:25:03 2013 From: rmschne at gmail.com (Rob Schneider) Date: Thu, 11 Apr 2013 23:25:03 -0700 (PDT) Subject: shutil.copyfile is incomplete (truncated) In-Reply-To: References: <5363f8ea-f2a6-4a08-a216-18c6666ba698@googlegroups.com> Message-ID: > The close method is defined and flushing and closing a file, so > > it should not return until that's done. > > > > What command are you using to create the temp file? > > re command to write the file: f=open(fn,'w') ... then create HTML text in a string f.write(html) f.close From rosuav at gmail.com Fri Apr 12 03:32:20 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Apr 2013 17:32:20 +1000 Subject: shutil.copyfile is incomplete (truncated) In-Reply-To: References: <5363f8ea-f2a6-4a08-a216-18c6666ba698@googlegroups.com> Message-ID: On Fri, Apr 12, 2013 at 4:25 PM, Rob Schneider wrote: > >> The close method is defined and flushing and closing a file, so >> >> it should not return until that's done. >> >> >> >> What command are you using to create the temp file? >> >> > > re command to write the file: > f=open(fn,'w') > ... then create HTML text in a string > f.write(html) > f.close Hold it one moment... You're not actually calling close. The file's still open. Is that a copy/paste problem, or is that your actual code? In Python, a function call ALWAYS has parentheses after it. Evaluating a function's name like that returns the function (or method) object, which you then do nothing with. (You could assign it someplace, for instance, and call it later.) Try adding empty parens: f.close() and see if that solves the problem. Alternatively, look into the 'with' statement and the block syntax that it can give to I/O operations. ChrisA From tjreedy at udel.edu Fri Apr 12 10:48:38 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Fri, 12 Apr 2013 10:48:38 -0400 Subject: shutil.copyfile is incomplete (truncated) In-Reply-To: References: <5363f8ea-f2a6-4a08-a216-18c6666ba698@googlegroups.com> Message-ID: On 4/12/2013 3:32 AM, Chris Angelico wrote: > On Fri, Apr 12, 2013 at 4:25 PM, Rob Schneider wrote: >> >>> The close method is defined and flushing and closing a file, so >>> >>> it should not return until that's done. >>> >>> >>> >>> What command are you using to create the temp file? >>> >>> >> >> re command to write the file: >> f=open(fn,'w') >> ... then create HTML text in a string >> f.write(html) >> f.close > > Hold it one moment... You're not actually calling close. The file's > still open. Is that a copy/paste problem, or is that your actual code? > > In Python, a function call ALWAYS has parentheses after it. Evaluating > a function's name like that returns the function (or method) object, > which you then do nothing with. (You could assign it someplace, for > instance, and call it later.) Try adding empty parens: > > f.close() > > and see if that solves the problem. Alternatively, look into the > 'with' statement and the block syntax that it can give to I/O > operations. I say *definitely* use a 'with' statement. Part of its purpose is to avoid close bugs. From matt.topolinski at gmail.com Thu Apr 11 14:17:13 2013 From: matt.topolinski at gmail.com (matt.topolinski at gmail.com) Date: Thu, 11 Apr 2013 11:17:13 -0700 (PDT) Subject: splinter web browser simulator causing constant BSODs Message-ID: <1b032cd8-a782-4326-9e47-18251feafe16@googlegroups.com> Hello, I'm trying to torubleshoot this issue for a user I support. He is running the splinter web browser simulator trough Google Chrome, and it appears to be causing his workstation to constantly BSOD. His machine has the following hardware: Dual Xeon E5-2637 Processors NVIDIA Quadro 600 - connected to 3 24" LCDs via displayport 24GB DDR3 ECC RAM Seagate ST2000DM001 2TB Data Drive Crucial 512GB SSD CT5-CT512M4SSD1 Boot drive Windows 7 x64 Enterprise We have experienced absolutely no BSODs when troubleshooting this machine ourselves, however we're obviously not running the software he uses. We've swapped out the motherboard and the video card, as the BSODs "suggest" an issue related to the PCI bus. I think this script is somehow causing his display driver to crash, or maybe the dual CPUs is an issue, but I don't know much about Python. Does anyone have any experience with this? Any additional help would be greatly appreciated. From kevin.p.dwyer at gmail.com Sat Apr 13 12:45:28 2013 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sat, 13 Apr 2013 17:45:28 +0100 Subject: splinter web browser simulator causing constant BSODs References: <1b032cd8-a782-4326-9e47-18251feafe16@googlegroups.com> Message-ID: matt.topolinski at gmail.com wrote: > Hello, > > I'm trying to torubleshoot this issue for a user I support. He is running > the splinter web browser simulator trough Google Chrome, and it appears to > be causing his workstation to constantly BSOD. > > His machine has the following hardware: > > Dual Xeon E5-2637 Processors > NVIDIA Quadro 600 - connected to 3 24" LCDs via displayport > 24GB DDR3 ECC RAM > Seagate ST2000DM001 2TB Data Drive > Crucial 512GB SSD CT5-CT512M4SSD1 Boot drive > Windows 7 x64 Enterprise > > We have experienced absolutely no BSODs when troubleshooting this machine > ourselves, however we're obviously not running the software he uses. We've > swapped out the motherboard and the video card, as the BSODs "suggest" an > issue related to the PCI bus. I think this script is somehow causing his > display driver to crash, or maybe the dual CPUs is an issue, but I don't > know much about Python. > > Does anyone have any experience with this? Any additional help would be > greatly appreciated. Hello, You might be better off asking at the splinter user list on Google Groups (https://groups.google.com/forum/?fromgroups#!forum/splinter-users). I expect they might like to see some sopecifics on the BSOD too. Cheers, Kev From dreamingforward at gmail.com Thu Apr 11 20:29:56 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Thu, 11 Apr 2013 17:29:56 -0700 Subject: OOPv2 -- Was: [Python-ideas] Reviving PEP 3140 - "str(container) should call str(item), not repr(item)" Message-ID: On Sat, Apr 6, 2013 at 7:35 PM, Ned Batchelder wrote: > Mark, so I can understand your mindset better, what do you mean by "let's > update the OOP paradigm"? Do you mean, 1) "let's change Python in the next > release," or 2) "let's see if we can imagine a different way of doing > things, even though it won't ever change the Python language in actuality," > or 3) something in between? Sorry for not responding. What I'm suggesting is an update to the OOP paradigm -- it would affect all languages that have OOP elements. Wikipedia suggests that there are four main types of programming languages. OOP language and imperative languages are the first two. I'm suggesting a synthesis and unification of both those into single language. To do that will require a data/object model that makes a single taxonomy of the data/machine architecture with the abstraction architecture -- two ends of the spectrum. I call it a unified data model. We started on one end of the spectrum (at the machine architecture) and then swung to an opposite extreme with OOP. But that put us too deep in everyone's personal data ontologies. I'm suggesting that something in the middle will re-build the object ecosystem from the ground up. > This change you mention here is fundamental enough that realistically, #2 is > the only interpretation I can see. You are right. It might not be realistic given the Python developer environment at present. In fact, I'm moving the thread out of python-ideas into python-list since Guido doesn't want to discuss it. -- MarkJ Tacoma, Washington From breamoreboy at yahoo.co.uk Thu Apr 11 20:34:51 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 12 Apr 2013 01:34:51 +0100 Subject: OOPv2 -- Was: [Python-ideas] Reviving PEP 3140 - "str(container) should call str(item), not repr(item)" In-Reply-To: References: Message-ID: On 12/04/2013 01:29, Mark Janssen wrote: > > You are right. It might not be realistic given the Python developer > environment at present. In fact, I'm moving the thread out of > python-ideas into python-list since Guido doesn't want to discuss it. > Please don't. -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From dreamingforward at gmail.com Thu Apr 11 20:54:45 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Thu, 11 Apr 2013 17:54:45 -0700 Subject: OOPv2 -- Was: [Python-ideas] Reviving PEP 3140 - "str(container) should call str(item), not repr(item)" In-Reply-To: References: Message-ID: On Thu, Apr 11, 2013 at 5:34 PM, Mark Lawrence wrote: > On 12/04/2013 01:29, Mark Janssen wrote: >> >> >> You are right. It might not be realistic given the Python developer >> environment at present. In fact, I'm moving the thread out of >> python-ideas into python-list since Guido doesn't want to discuss it. > > Please don't. Sorry, not the whole repr() vs str() thread, just the inquiry about rethinking OOP.... Mark From breamoreboy at yahoo.co.uk Thu Apr 11 21:16:23 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 12 Apr 2013 02:16:23 +0100 Subject: OOPv2 -- Was: [Python-ideas] Reviving PEP 3140 - "str(container) should call str(item), not repr(item)" In-Reply-To: References: Message-ID: On 12/04/2013 01:54, Mark Janssen wrote: > > Sorry, not the whole repr() vs str() thread, just the inquiry about > rethinking OOP.... > > Mark > IMHO an adequate summary of your views in the last paragraph here http://mail.python.org/pipermail/python-ideas/2013-March/020034.html -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From dreamingforward at gmail.com Thu Apr 11 22:05:32 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Thu, 11 Apr 2013 19:05:32 -0700 Subject: OOPv2 -- Was: [Python-ideas] Reviving PEP 3140 - "str(container) should call str(item), not repr(item)" In-Reply-To: <516763EE.1010300@nedbatchelder.com> References: <516763EE.1010300@nedbatchelder.com> Message-ID: > But there is no single "OOP" paradigm. Java vs Python vs Ruby vs > Javascript, they're all subtly different. "Subtly" is the keyword there. Predominately, they are the same -- they try to make a pure OOP object model in an imagined abstract space. >> Wikipedia suggests that there are four main types of programming >> languages. OOP language and imperative languages are the first two. >> I'm suggesting a synthesis and unification of both those into single >> language. To do that will require a data/object model that makes a >> single taxonomy of the data/machine architecture with the abstraction >> architecture -- two ends of the spectrum. I call it a unified data >> model. > > This sounds a lot like Java, which has primitive values and objects. Are > you familiar with it? I'm not sure what you're suggesting is so > revolutionary. Lol, apparently you're not all that familiar with Python history, because Python had it also, it called them types and objects (see the docs on v2.2). If you read my thread I just sent out, you'll get what I'm after a bit more. But basically, is that python ignored its Zen: that practicality beats purity. Mark From dreamingforward at gmail.com Thu Apr 11 21:57:03 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Thu, 11 Apr 2013 18:57:03 -0700 Subject: Message passing syntax for objects | OOPv2 Message-ID: Okay peeps, I'm re-opening this thread, because despite being hijacked by naysayers, the merit of the underlying idea I think still has not been communicated or perceived adequately. As a personal request from the BDFL, which I begrudge him for, I've removed the thread from python-ideas. If you want to tail him and ignore it fine, but I will be addressing the naysayers one-by-one and (since no one was willing to do a modicum of interference for me) presumably by myself. For reference of how this topic began, see http://qr.ae/TM1Vb and http://qr.ae/TMh7A which were questions from the programming community not astroturfed nor sockpuppeted by/for me. For the underlying itch being scratched which motivates this whole thread, see http://qr.ae/TM1Vb. But basically, I'm proposing a programming language *synthesis* and unification of the object-oriented and imperative language paradigms (two of the four paradigms recognized on wikipedia: http://en.wikipedia.org/wiki/Programming_paradigm) to create what I'm calling a "unified data ecosystem". I'm going to admit from the beginning that I am not deeply researched with the many varied explorations of the programming language *ontology*, BUT I have followed the main "trunk", if not gone out on every branch. I *will* say that I am degreed in Computer Engineering (PLU '92) and have a fairly solid theoretical background in the art and the science of CS. Further, I will admit that I am not deeply experienced in application or Internet programming -- I have stayed on the outside watching those developments so that I can fulfill a vision I have of what the Internet can be (a world-changing technology to make a balanced socio-political platform and thereby a healthy planet). So my use of the term "message-passing" is not so much laden with its use in programming language theory as much as the more pedestrian notion of passing notes -- a conceptual model familiar to everybody. My interest in pursuing the topic isn't to "radically change" Python, to grind an axe or personal whim, nor to alter the spirit of Python in any way (a spirit which drew me to it back in 2001), but to consider a fairly large "re-factoring" or our current *programming ecosystem* while preserving and enhancing what I consider Python's main superpower: simplifying the complex. The real issue, then, is not changing *Python*, but something deeper: refactoring the OOP paradigm itself. ...Why? First, let it be noted clearly that OOP has not delivered on one its two main selling points: re-usable, sharable code. (The other main selling point being the ability to abstract away the details of the underlying machine -- which it still does well.) The proof of this is that we have *libraries* of code bundled with languages so that everyone uses the same "vetted" code base. Anything outside this,. though, feels, to most, like wearing other people's underwear. You'll note, even within the python library itself, that modules are hardly unified in coding *style*, showing the programming personality of the various developer histories that each library is representing. We accept this, because our benevolent dictator accepts it, and it's not easy to unify it further (despite an attempt with Pythonv3), because the issue, I'm arguing, is really about an inadequacy in the OOP model itself. What I'm proposing *should* create a data/object ecosystem much like Unix created a "command ecosystem". An environment in which people could combine simple, modular commands into powerful, complex para-applications. In the case I'm proposing, the *Python* environment becomes a sort of "lingua franca" for the data ecosystem, not because of a war of whose language is better but because of the simple issue of practicality. In this data ecosystem, a network of objects becomes available and re-usable across the network (not a new idea). So, where are we now? Well we have this huge resource called the Internet, which has loads of data that no one has really exploited to its potential. Its value is scattered across the globe: warehoused in various databases, spreadsheets, blog silos, personal computers and whatnot. The OOP paradigm has not solved the problem, which it, in theory, could or SHOULD have. Instead, we have balkanization across many language platforms and data formats. XML, RDF, none of these really solves the problem, because the relationship to data is still too personal to everyone's private taxonomies. Of all the pages out there maybe 5% is incorporated into these attempts at data standardization. As for Python, its community has sort of splintered. Various language attempts to solve certain problems complexified the language and created a kind of "growth knot" on Python's tree. They weren't bad solutions, they were just the best solutions outside a refactoring of the OOP methodology. So what is OOP refactored? Building upon Alan Kay's tentative(?) description of the OOP "essence" (see http://c2.com/cgi/wiki?AlanKaysDefinitionOfObjectOriented -- note that there are two enumerations of his OOP definitions there), I'm going to refactor the view presented there and distill what I argue are the main points interest. 1) Everything is an object. (Purity) That's a great idea, and this is where the OOP paradigm has taken us. It made a fabulous abstraction away from the machine. But did it get us what we wanted? I argue no and apparently others are asking the same questions. 2) Objects communicate by sending and receiving messages Great, so why don't we have a standardized way to do this? Currently, every programmer invents their own mini "domain language" for their objects and modules and it's generally not obvious at all what methods are designed to be message passers. ***Why not have a standardized syntax for this? 3) Objects have their own memory, which consists of other objects. Ah, but here the object model has not been adequately defined. There has to be a "base case" to this infinite regress. What objects do integers consist of? I'm suggesting that the OOP paradigm needs to define atomic objects, which are not defined by other objects, and then start the data taxonomy from there with the first object/grouping/container from that. Prototypes, to me, seem quite an interesting development here. They make it clear, just like C structs, that your building your data upwards, not trying to make "castles in the sky". The machine forms a standard basis for interaction, over everyone's meta-abstractions. 4) Every object is an instance of a class (which must be an object) Here, I read the world "class" much like prototypes or C structs. Here's again, there must be a clear view here to avoid the infinite regress. C++ makes this distinction by having types separate from the instantiation of same. But that regress must end somewhere, and for C++ it's types. One does not ask: "Well, then what is the type of type?" There isn't one! The object model in C++ ends there! Types are rooted in the machine architecture, but Python and "pure" OOP languages are not. And this is where things get hairy and burly. 5) The class holds the shared behavior for its instances (in the form of objects in a program list) In other words, the "class" holds the template or the definition of each object instantiated (or "created") from it. Hence, I think the word prototype is very apropos. 6) Classes are organized into a singly-rooted tree structure, called the inheritance hierarchy. Memory and behavior associated with instances of a class are available to any class associated with a descendent in this tree structure. There is an argument over Kay's meaning here. But the above-worded one is the one I'm going to work from. Beginning in v2.2, the "great type/class unification" started happening, ultimately leading to everything rooted in the Object object. ***BUT*** this is also where, I argue, where practicality DID NOT beat purity -- purity hammered practicality into oblivion. It was a great idea at first, to get completely away from the machine -- wouldn't that make inter-operability so much easier? But no, it hasn't happened. After the unification things got more complex in most ways. And the reason: because the object model must be rooted in data, something concrete, not in the abstract which means many things to everybody and anything to most others. We're not making physical objects or making a simulated environment, so lets not pretend anymore. What's to replace it? 1) Objects exists within the concreteness and limitations of the machine. (I'm going to limit myself to Turing machines and not deal at all with lamba calculii and abstract programming environments that exist in the imagination.) 2) Everything outside the concrete types is an object. 3) Objects (not the concrete types) talk to other Objects, **otherwise they would be a machine type**. 4) Objects communicate to other objects via a standardized syntax, like >> and << for sending and receiving. Here endeth the lesson. Mark Janssen Tacoma, Washington P.S. It might be worthwhile to also examine a nice taxonomy of the OOP conceptual landscape, found from there, at which also partly makes my argument for a refactoring of the paradigm. If others find better taxonomies, please forward. From ethan at stoneleaf.us Thu Apr 11 22:13:33 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 11 Apr 2013 19:13:33 -0700 Subject: Message passing syntax for objects | OOPv2 In-Reply-To: References: Message-ID: <51676DCD.8030707@stoneleaf.us> On 04/11/2013 06:57 PM, Mark Janssen wrote: [blah blah not python blah blah] Mark, this list if for Python, about Python, helping with Python. If you want to discuss whatever this idea is, you should do it somewhere else, as it is *not* Python. -- ~Ethan~ From wuwei23 at gmail.com Fri Apr 12 01:22:00 2013 From: wuwei23 at gmail.com (alex23) Date: Thu, 11 Apr 2013 22:22:00 -0700 (PDT) Subject: Message passing syntax for objects | OOPv2 References: Message-ID: <94ed3253-5d13-44f2-9ff0-b54f8839fddc@v2g2000pbx.googlegroups.com> On Apr 12, 11:57?am, Mark Janssen wrote: > hijacked by naysayers Says the man who wrote: - "I blame the feminists for being too loyal to atheism and G-d for being too loyal to the Jews. Torture happened." - "The world is insane because people loved snakes more than G-d, and believed in homosexuals more than Adam." It's frightening to see that your grip on theology and, hell, *basic humanity* is as tenuous as your understanding of computer science. Calling out blatant pap as pap is not being a "naysayer". Shouldn't you be off single-handedly saving "the creative economy"? What happened to your "simple rules to create a self-organized system and re-organize the Internet"? > Here endeth the lesson. I'd love to believe this is true but I bet it isn't; I'm pretty sure you've got plenty more delusional grandeur to inflict on us. From rosuav at gmail.com Fri Apr 12 03:16:08 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Apr 2013 17:16:08 +1000 Subject: Message passing syntax for objects | OOPv2 In-Reply-To: References: Message-ID: On Fri, Apr 12, 2013 at 11:57 AM, Mark Janssen wrote: > Further, I will admit that I am not deeply > experienced in application or Internet programming Would you listen to someone who is, by his own admission, not experienced as a surgeon, and tries to tell you that your liver and heart would be better placed the other way around? You may well have some insight that nobody else has yet seen, but you do yourself no service by trying to argue without first-hand experience, and lots of it. I'm not going to go to a LISP mailing list and try to tell them that functional programming is better done with some different syntax, because I am not an experienced LISPer. (Dabbled in Scheme, that's about as close as I get. And only dabbled. And only because GNU LilyPond uses it.) Things are the way they are because someone's spent decades working with them. Sure, not everything's perfect... but it takes someone with actual coding experience and expertise to point out improvements. Read the python-list and python-tutor archives and listen to people like Peter Otten and Steven D'Aprano, both of whom have been using the language for, uhh... 3.5 millenia, probably. (Me? I'm a n00b. Haven't seriously used Python for even a decade yet, though I think I met it in the late 90s or early 00s. Got my coding experience on other languages.) Listen to them when they explain to people why Python is how it is, and you'll gain a much greater comprehension of what actually works. ChrisA From breamoreboy at yahoo.co.uk Fri Apr 12 06:30:30 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 12 Apr 2013 11:30:30 +0100 Subject: Message passing syntax for objects | OOPv2 In-Reply-To: References: Message-ID: On 12/04/2013 02:57, Mark Janssen wrote: [dross snipped] A summary here http://pinterest.com/pin/464293042804330899/ -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From ned at nedbatchelder.com Fri Apr 12 07:42:31 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 12 Apr 2013 07:42:31 -0400 Subject: Message passing syntax for objects | OOPv2 In-Reply-To: References: Message-ID: <5167F327.3030803@nedbatchelder.com> On 4/11/2013 9:57 PM, Mark Janssen wrote: > Okay peeps, I'm re-opening this thread, because despite being hijacked > by naysayers, the merit of the underlying idea I think still has not > been communicated or perceived adequately. Mark, this proposal is out of place on a Python list, because it proposes an object methodology radically different from any that is implemented in Python now, or is even remotely likely to be implemented in Python in the future. Everyone else, there's no need to skewer Mark for off-topic things like tweets on topics other than Python. We can be civil, surely. --Ned. From dreamingforward at gmail.com Sat Apr 13 02:28:18 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Fri, 12 Apr 2013 23:28:18 -0700 Subject: Message passing syntax for objects | OOPv2 In-Reply-To: <5167F327.3030803@nedbatchelder.com> References: <5167F327.3030803@nedbatchelder.com> Message-ID: > Mark, this proposal is out of place on a Python list, because it proposes an > object methodology radically different from any that is implemented in > Python now, or is even remotely likely to be implemented in Python in the > future. Wow, you guys are a bunch of ninnies. I'm going to find some theoretical folks.... MarkJ From rosuav at gmail.com Sat Apr 13 02:55:50 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 13 Apr 2013 16:55:50 +1000 Subject: Message passing syntax for objects | OOPv2 In-Reply-To: References: <5167F327.3030803@nedbatchelder.com> Message-ID: On Sat, Apr 13, 2013 at 4:28 PM, Mark Janssen wrote: >> Mark, this proposal is out of place on a Python list, because it proposes an >> object methodology radically different from any that is implemented in >> Python now, or is even remotely likely to be implemented in Python in the >> future. > > Wow, you guys are a bunch of ninnies. I'm going to find some > theoretical folks.... Allow me to offer a serious suggestion: Just as C++ was originally implemented as a preprocessor that produced C code (Cfront), implement your language as a preprocessor that outputs Python (Pyfront?). Then you can explore your ideas relatively cheaply (since you don't have to implement a whole language) and portably (especially if you write your front-end in Python itself)... and, most importantly, you'll have *code* to show people, instead of half-baked theories. Get some real solid code, then start demonstrating how your new system is more expressive, or clearer, or what-have-you. It's much more effective when you can discuss something that actually exists. ChrisA From torriem at gmail.com Sat Apr 13 13:14:01 2013 From: torriem at gmail.com (Michael Torrie) Date: Sat, 13 Apr 2013 11:14:01 -0600 Subject: Message passing syntax for objects | OOPv2 In-Reply-To: References: <5167F327.3030803@nedbatchelder.com> Message-ID: <51699259.2070505@gmail.com> On 04/13/2013 12:28 AM, Mark Janssen wrote: >> Mark, this proposal is out of place on a Python list, because it proposes an >> object methodology radically different from any that is implemented in >> Python now, or is even remotely likely to be implemented in Python in the >> future. > > Wow, you guys are a bunch of ninnies. I'm going to find some > theoretical folks.... Insulting list members is not a great way to gain traction. Ned is correct, though. Your discussion is best held in another place where theoretical folks do hang out. Perhaps you should get together with Ranting Rick. Like you he lacks a formal background in language development, but also like you has strong opinions on how things should be done differently. Maybe you can roll your ideas into his Rython language. On this list I think the vast majority of us simply want to discuss how to effectively use Python to solve our problems. From anadionisio257 at gmail.com Fri Apr 12 10:22:01 2013 From: anadionisio257 at gmail.com (=?ISO-8859-1?Q?Ana_Dion=EDsio?=) Date: Fri, 12 Apr 2013 07:22:01 -0700 (PDT) Subject: CSV to matrix array Message-ID: <2506a155-40b6-4040-bc12-a08ce0d79cd7@googlegroups.com> Hello! I have a CSV file with 20 rows and 12 columns and I need to store it as a matrix. I already created an array with zeros, but I don't know how to fill it with the data from the csv file. I have this script: import numpy from numpy import array from array import * import csv input = open('Cenarios.csv','r') cenario = csv.reader(input) array=numpy.zeros([20, 12]) I know I have to use for loops but I don't know how to use it to put the data the way I want. Can you help me? Thanks! From breamoreboy at yahoo.co.uk Fri Apr 12 11:25:48 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 12 Apr 2013 16:25:48 +0100 Subject: CSV to matrix array In-Reply-To: <2506a155-40b6-4040-bc12-a08ce0d79cd7@googlegroups.com> References: <2506a155-40b6-4040-bc12-a08ce0d79cd7@googlegroups.com> Message-ID: On 12/04/2013 15:22, Ana Dion?sio wrote: > Hello! > > I have a CSV file with 20 rows and 12 columns and I need to store it as a matrix. I already created an array with zeros, but I don't know how to fill it with the data from the csv file. I have this script: > > import numpy > from numpy import array > from array import * > import csv > > input = open('Cenarios.csv','r') > cenario = csv.reader(input) > > array=numpy.zeros([20, 12]) > > > I know I have to use for loops but I don't know how to use it to put the data the way I want. Can you help me? > > Thanks! > I'm no expert on numpy but there is a loadtxt function see http://docs.scipy.org/doc/numpy/reference/generated/numpy.loadtxt.html -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From anadionisio257 at gmail.com Fri Apr 12 13:12:42 2013 From: anadionisio257 at gmail.com (=?ISO-8859-1?Q?Ana_Dion=EDsio?=) Date: Fri, 12 Apr 2013 10:12:42 -0700 (PDT) Subject: CSV to matrix array In-Reply-To: References: <2506a155-40b6-4040-bc12-a08ce0d79cd7@googlegroups.com> Message-ID: <45bfb6db-fb1a-478d-8c97-7ddd44167076@googlegroups.com> Hi, thanks for yor answer! ;) Anyone has more suggestions? From anadionisio257 at gmail.com Fri Apr 12 13:12:42 2013 From: anadionisio257 at gmail.com (=?ISO-8859-1?Q?Ana_Dion=EDsio?=) Date: Fri, 12 Apr 2013 10:12:42 -0700 (PDT) Subject: CSV to matrix array In-Reply-To: References: <2506a155-40b6-4040-bc12-a08ce0d79cd7@googlegroups.com> Message-ID: <45bfb6db-fb1a-478d-8c97-7ddd44167076@googlegroups.com> Hi, thanks for yor answer! ;) Anyone has more suggestions? From rustompmody at gmail.com Fri Apr 12 13:34:59 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 12 Apr 2013 10:34:59 -0700 (PDT) Subject: CSV to matrix array References: <2506a155-40b6-4040-bc12-a08ce0d79cd7@googlegroups.com> <45bfb6db-fb1a-478d-8c97-7ddd44167076@googlegroups.com> Message-ID: On Apr 12, 10:12?pm, Ana Dion?sio wrote: > Hi, thanks for yor answer! ;) > > Anyone has more suggestions? My suggestions: 1. Tell us what was lacking in Mark's suggestion (to use loadtxt) 2. Read his postscript (for googlegroup posters). [In case you did not notice your posts are arriving in doubles] From jeanmichel at sequans.com Fri Apr 12 13:23:56 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 12 Apr 2013 19:23:56 +0200 (CEST) Subject: CSV to matrix array In-Reply-To: <2506a155-40b6-4040-bc12-a08ce0d79cd7@googlegroups.com> Message-ID: <616480876.10930279.1365787436263.JavaMail.root@sequans.com> ----- Original Message ----- > Hello! > > I have a CSV file with 20 rows and 12 columns and I need to store it > as a matrix. I already created an array with zeros, but I don't know > how to fill it with the data from the csv file. I have this script: > > import numpy > from numpy import array > from array import * > import csv > > input = open('Cenarios.csv','r') > cenario = csv.reader(input) > > array=numpy.zeros([20, 12]) > > > I know I have to use for loops but I don't know how to use it to put > the data the way I want. Can you help me? > > Thanks! did you try array = numpy.array(list(cenario)) ? JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From anadionisio257 at gmail.com Fri Apr 12 13:29:05 2013 From: anadionisio257 at gmail.com (=?ISO-8859-1?Q?Ana_Dion=EDsio?=) Date: Fri, 12 Apr 2013 10:29:05 -0700 (PDT) Subject: CSV to matrix array In-Reply-To: References: <2506a155-40b6-4040-bc12-a08ce0d79cd7@googlegroups.com> Message-ID: That only puts the data in one column, I wanted to separate it. For example: data in csv file: 1 2 3 4 5 7 8 9 10 11 a b c d e I wanted an array where I could pick an element in each position. In the case above if I did print array[0][3] it would pick 4 From anadionisio257 at gmail.com Fri Apr 12 13:29:05 2013 From: anadionisio257 at gmail.com (=?ISO-8859-1?Q?Ana_Dion=EDsio?=) Date: Fri, 12 Apr 2013 10:29:05 -0700 (PDT) Subject: CSV to matrix array In-Reply-To: References: <2506a155-40b6-4040-bc12-a08ce0d79cd7@googlegroups.com> Message-ID: That only puts the data in one column, I wanted to separate it. For example: data in csv file: 1 2 3 4 5 7 8 9 10 11 a b c d e I wanted an array where I could pick an element in each position. In the case above if I did print array[0][3] it would pick 4 From davea at davea.name Fri Apr 12 13:46:22 2013 From: davea at davea.name (Dave Angel) Date: Fri, 12 Apr 2013 13:46:22 -0400 Subject: CSV to matrix array In-Reply-To: References: <2506a155-40b6-4040-bc12-a08ce0d79cd7@googlegroups.com> Message-ID: <5168486E.9000009@davea.name> On 04/12/2013 01:29 PM, Ana Dion?sio wrote: > That only puts the data in one column, I wanted to separate it. > > For example: > data in csv file: > > 1 2 3 4 5 > 7 8 9 10 11 > a b c d e > > I wanted an array where I could pick an element in each position. In the case above if I did print array[0][3] it would pick 4 > I know nothing about numpy. How about something like: import csv myreader = csv.reader(....) mylist = list(myreader) Presumably you can fill in the details. Anyway, I think this will give you a list of lists, and perhaps you can convert that to a numpy array, if you really need one of those. -- DaveA From javier at codecoa.com Fri Apr 12 18:45:24 2013 From: javier at codecoa.com (Javier Miranda) Date: Fri, 12 Apr 2013 17:45:24 -0500 Subject: CSV to matrix array In-Reply-To: <5168486E.9000009@davea.name> References: <2506a155-40b6-4040-bc12-a08ce0d79cd7@googlegroups.com> <5168486E.9000009@davea.name> Message-ID: Keep the flattened data array others suggested, and then just split it like this: *(replace `example_data`, `_array`, and `columns`)* >>> example_data = range(15) >>> split_array = lambda _array, colums: \ . . . [_array[i:i + colums] for i in \ . . . xrange(0, len(_array), colums)] >>> print split_array(example_data, 5) [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14]] Gist What do you guys think? On Fri, Apr 12, 2013 at 12:46 PM, Dave Angel wrote: > On 04/12/2013 01:29 PM, Ana Dion?sio wrote: > >> That only puts the data in one column, I wanted to separate it. >> >> For example: >> data in csv file: >> >> 1 2 3 4 5 >> 7 8 9 10 11 >> a b c d e >> >> I wanted an array where I could pick an element in each position. In the >> case above if I did print array[0][3] it would pick 4 >> >> > I know nothing about numpy. > > How about something like: > import csv > myreader = csv.reader(....) > mylist = list(myreader) > > > Presumably you can fill in the details. Anyway, I think this will give > you a list of lists, and perhaps you can convert that to a numpy array, if > you really need one of those. > > > -- > DaveA > -- > http://mail.python.org/**mailman/listinfo/python-list > -- Javier Miranda Mobile: +52 333 129 20 70 -------------- next part -------------- An HTML attachment was scrubbed... URL: From cantorp at gmail.com Sat Apr 13 13:06:15 2013 From: cantorp at gmail.com (cantorp at gmail.com) Date: Sat, 13 Apr 2013 10:06:15 -0700 (PDT) Subject: CSV to matrix array In-Reply-To: References: <2506a155-40b6-4040-bc12-a08ce0d79cd7@googlegroups.com> Message-ID: Dear Ana, your example data could be transformed into a matrix with >>>import csv >>>rows = csv.reader(open("your_data_file.csv"), delimiter=" ") >>>array = [row for row in rows] >>>array[0][3] 4 HTH Paolo Am Freitag, 12. April 2013 19:29:05 UTC+2 schrieb Ana Dion?sio: > That only puts the data in one column, I wanted to separate it. > > > > For example: > > data in csv file: > > > > 1 2 3 4 5 > > 7 8 9 10 11 > > a b c d e > > > > I wanted an array where I could pick an element in each position. In the case above if I did print array[0][3] it would pick 4 From cantorp at gmail.com Sat Apr 13 13:06:15 2013 From: cantorp at gmail.com (cantorp at gmail.com) Date: Sat, 13 Apr 2013 10:06:15 -0700 (PDT) Subject: CSV to matrix array In-Reply-To: References: <2506a155-40b6-4040-bc12-a08ce0d79cd7@googlegroups.com> Message-ID: Dear Ana, your example data could be transformed into a matrix with >>>import csv >>>rows = csv.reader(open("your_data_file.csv"), delimiter=" ") >>>array = [row for row in rows] >>>array[0][3] 4 HTH Paolo Am Freitag, 12. April 2013 19:29:05 UTC+2 schrieb Ana Dion?sio: > That only puts the data in one column, I wanted to separate it. > > > > For example: > > data in csv file: > > > > 1 2 3 4 5 > > 7 8 9 10 11 > > a b c d e > > > > I wanted an array where I could pick an element in each position. In the case above if I did print array[0][3] it would pick 4 From miki.tebeka at gmail.com Fri Apr 12 19:10:57 2013 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Fri, 12 Apr 2013 16:10:57 -0700 (PDT) Subject: CSV to matrix array In-Reply-To: <2506a155-40b6-4040-bc12-a08ce0d79cd7@googlegroups.com> References: <2506a155-40b6-4040-bc12-a08ce0d79cd7@googlegroups.com> Message-ID: > I have a CSV file with 20 rows and 12 columns and I need to store it as a matrix. If you can use pandas, the pandas.read_csv is what you want. From pecore at pascolo.net Sat Apr 13 08:06:43 2013 From: pecore at pascolo.net (giacomo boffi) Date: Sat, 13 Apr 2013 14:06:43 +0200 Subject: CSV to matrix array References: <2506a155-40b6-4040-bc12-a08ce0d79cd7@googlegroups.com> Message-ID: <87li8m7hyk.fsf@pascolo.net> Ana Dion?sio writes: > Hello! > > I have a CSV file with 20 rows and 12 columns and I need to store it > as a matrix. array=numpy.array([row for row in csv.reader(open('Cenarios.csv'))]) NB: i used "array=" as in your sample code, BUT From anadionisio257 at gmail.com Sat Apr 13 11:30:23 2013 From: anadionisio257 at gmail.com (=?ISO-8859-1?Q?Ana_Dion=EDsio?=) Date: Sat, 13 Apr 2013 08:30:23 -0700 (PDT) Subject: CSV to matrix array In-Reply-To: <87li8m7hyk.fsf@pascolo.net> References: <2506a155-40b6-4040-bc12-a08ce0d79cd7@googlegroups.com> <87li8m7hyk.fsf@pascolo.net> Message-ID: It's still not working. I still have one column with all the data inside, like this: 2999;T3;3;1;1;Off;ON;OFF;ON;ON;ON;ON;Night;;;;;; How can I split this data in a way that if I want to print "T3" I would just do "print array[0][1]"? From breamoreboy at yahoo.co.uk Sat Apr 13 12:52:23 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 13 Apr 2013 17:52:23 +0100 Subject: CSV to matrix array In-Reply-To: References: <2506a155-40b6-4040-bc12-a08ce0d79cd7@googlegroups.com> <87li8m7hyk.fsf@pascolo.net> Message-ID: On 13/04/2013 16:30, Ana Dion?sio wrote: > It's still not working. I still have one column with all the data inside, like this: > > 2999;T3;3;1;1;Off;ON;OFF;ON;ON;ON;ON;Night;;;;;; > > How can I split this data in a way that if I want to print "T3" I would just do "print array[0][1]"? > I said before I'm no expert on numpy but my understanding is that all arrays are homogeneous, hence you can't load the data you show above without some form of mapping. In that case you'd have to read the data with the csv module as others have already suggested, apply your mapping and then write this to your array. The obvious alternative is to use a list of lists. -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From oscar.j.benjamin at gmail.com Sat Apr 13 15:01:34 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sat, 13 Apr 2013 20:01:34 +0100 Subject: CSV to matrix array In-Reply-To: References: <2506a155-40b6-4040-bc12-a08ce0d79cd7@googlegroups.com> <87li8m7hyk.fsf@pascolo.net> Message-ID: On 13 April 2013 16:30, Ana Dion?sio wrote: > It's still not working. I still have one column with all the data inside, like this: > > 2999;T3;3;1;1;Off;ON;OFF;ON;ON;ON;ON;Night;;;;;; > > How can I split this data in a way that if I want to print "T3" I would just do "print array[0][1]"? You initially reported that your data was a CSV file, which normally means that the values in each row are separated by comma characters e.g. ','. Actually the data here are separated by semicolons e.g. ';'. This means that whether you use numpy or the csv module you will need to specify that the data is separated by semicolons. In numpy you would do this with import numpy data = numpy.loadtxt('file.csv', dtype=int, delimiter=';') You need to set dtype to be whatever data type you want to convert the values to e.g. int or float. This is because numpy arrays are homogeneous. In your case the data (presumably a channel/event header from an EEG file) is not homogeneous as you have integer data '2999' followed by the channel name 'T3' which is a string. You can load all values as strings with data = numpy.loadtxt('file.csv', dtype=str, delimiter=';') It is possible to have heterogeneous types in a numpy array using dtype=object but if you use that with the loadtxt function it will just use strings for all values. Alternatively you can use the csv module in the standard library to load all the data as strings import csv with open('file.csv', 'rb') as csvfile: data = list(csv.reader(csvfile, delimiter=';')) This will give you a list of lists of strings rather than a numpy array. Afterwards you can convert the integer values to int if you want like so: for row in data: row[0] = int(row[0]) This works because lists can store heterogeneous data, unlike numpy arrays. Either of the above will let you access the data with e.g. data[2][7] to get the value from the 8th column of the 3rd row. However, I think that the better thing to do though would be to use a csv.DictReader and store your data as a list of dicts. This would look like: # Change this to names that actually describe each column of your data columns = ['sample_rate', 'channel_name', 'electrode_number', 'lowpass_filter',...] data = [] with open('file.csv') as csvfile: for row in csv.DictReader(csvfile, fieldnames=columns, delimiter=';'): # Convert non-string data here e.g.: row['sample_rate'] = int(row['sample_rate']) data.append(row) Now you can access the data using e.g. data[0]['channel_name'] which I think is better than data[0][1] and you can store data of heterogeneous type e.g. int, str, etc. in the same row. Oscar From g.rodola at gmail.com Fri Apr 12 11:01:03 2013 From: g.rodola at gmail.com (=?ISO-8859-1?Q?Giampaolo_Rodol=E0?=) Date: Fri, 12 Apr 2013 17:01:03 +0200 Subject: ANN: psutil 0.7.0 released Message-ID: Hi there folks, I'm pleased to announce the 0.7.0 release of psutil: http://code.google.com/p/psutil/ This is mainly a bugfix release addressing a couple of high priority issues on Linux and FreeBSD. Complete list of bugfixes and enhancements is here: https://psutil.googlecode.com/hg/HISTORY === New features === - psutil.get_boot_time() - get/set process IO priority on Windows - psutil.cpu_times() on Linux now includes new 'steal', 'guest' and guest_nice' fields available on recent kernels - psutil.cpu_times_percent() which provides utilization percentages for each specific CPU time as is returned by cpu_times() - source code has been migrated from SVN to Mercurial === Compatitility notes === - Process cmdline and ppid properties are no longer cached after first access - psutil.error module is deprecated and scheduled for removal === Links === - Home: http://code.google.com/p/psutil - Sources: http://psutil.googlecode.com/files/psutil-0.7.0.tar.gz - Docs: http://code.google.com/p/psutil/wiki/Documentation Please try out this new release and let me know if you experience any problem by filing issues on the bug tracker. Thanks in advance. --- Giampaolo Rodola' http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ http://code.google.com/p/pysendfile/ From roy at panix.com Fri Apr 12 11:33:54 2013 From: roy at panix.com (Roy Smith) Date: Fri, 12 Apr 2013 11:33:54 -0400 Subject: ANN: psutil 0.7.0 released References: Message-ID: In article , Giampaolo Rodol? wrote: > Hi there folks, > I'm pleased to announce the 0.7.0 release of psutil: > http://code.google.com/p/psutil/ I see a lot of these types of announcements. May I suggest that people add a short description of what that package is. From the name, I can't tell is this is about process status, or PostScript, or what. In this case, after clicking on the link, I see that "psutil is [...] for retrieving information on all running processes and system utilization". Putting that one-liner up front in the announcement makes it easier for people to know if it's worth exploring further. From stefan_ml at behnel.de Fri Apr 12 11:57:34 2013 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 12 Apr 2013 17:57:34 +0200 Subject: ANN: psutil 0.7.0 released In-Reply-To: References: Message-ID: Roy Smith, 12.04.2013 17:33: > Giampaolo Rodol? wrote: > >> Hi there folks, >> I'm pleased to announce the 0.7.0 release of psutil: >> http://code.google.com/p/psutil/ > > I see a lot of these types of announcements. May I suggest that people > add a short description of what that package is. From the name, I can't > tell is this is about process status, or PostScript, or what. And while we're at it, there's also a dedicated mailing list for Python related announcements, which people commonly use for announcing important releases of software packages: http://mail.python.org/mailman/listinfo/python-announce-list (And no, it's not that the unimportant ones should go here...) Stefan From p at google-groups-2013.dobrogost.net Fri Apr 12 16:46:39 2013 From: p at google-groups-2013.dobrogost.net (Piotr Dobrogost) Date: Fri, 12 Apr 2013 13:46:39 -0700 (PDT) Subject: SimpleHTTPRequestHandler used with HTTP/1.1 hangs after the second resource on a page. Message-ID: Hi! I'd like to bring your attention to the question titled "Use HTTP/1.1 with SimpleHTTPRequestHandler" at http://stackoverflow.com/q/15839718/95735 which reads; "When I use HTTP/1.1 with SimpleHTTPRequestHandler, loading a page that pulls in other resources will hang after the second resource." and there's a tiny test showing the problem. It's hard to believe that SimpleHTTPServer doesn't handle such a simple task, does it? If I checked correctly code is stuck in handle_one_request() method at line 370 of server.py (http://hg.python.org/cpython/file/d9893d13c628/Lib/http/server.py#l370) but I can't see what's wrong. Any ideas? Best regards, Piotr Dobrogost From tjreedy at udel.edu Fri Apr 12 18:21:33 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Fri, 12 Apr 2013 18:21:33 -0400 Subject: SimpleHTTPRequestHandler used with HTTP/1.1 hangs after the second resource on a page. In-Reply-To: References: Message-ID: On 4/12/2013 4:46 PM, Piotr Dobrogost wrote: > Hi! > > I'd like to bring your attention to the question titled "Use HTTP/1.1 > with SimpleHTTPRequestHandler" at > http://stackoverflow.com/q/15839718/95735 which reads; "When I use I find the doc slightly confusing. The SO code uses BaseHTTPServer. The doc says "Usually, this module isn?t used directly," On the other hand, SimpleHTTPServer only defines a request handler and not a server itself. > HTTP/1.1 with SimpleHTTPRequestHandler, loading a page that pulls in > other resources will hang after the second resource." and there's a What does 'hang' mean? Does the page get displayed? If so, server.serve_forever is supposes to 'hang'. > tiny test showing the problem. It's hard to believe that > SimpleHTTPServer doesn't handle such a simple task, does it? If I > checked correctly code is stuck in handle_one_request() method at > line 370 of server.py > (http://hg.python.org/cpython/file/d9893d13c628/Lib/http/server.py#l370) > but I can't see what's wrong. Any ideas? The SO post says class MyRequestHandler(SimpleHTTPRequestHandler): #protocol_version = "HTTP/1.0" # works protocol_version = "HTTP/1.1" # hangs so this should be some sort of clue. The code says 569 # The version of the HTTP protocol we support. 570 # Set this to HTTP/1.1 to enable automatic keepalive 571 protocol_version = "HTTP/1.0" The only substantive code I found using protocol_version (in the CPython default branch you linked to) is 300 if version_number >= (1, 1) and self.protocol_version >= "HTTP/1.1": 301 self.close_connection = 0 331 elif (conntype.lower() == 'keep-alive' and 332 self.protocol_version >= "HTTP/1.1"): 333 self.close_connection = 0 334 # Examine the headers and look for an Expect directive 335 expect = self.headers.get('Expect', "") 336 if (expect.lower() == "100-continue" and 337 self.protocol_version >= "HTTP/1.1" and 338 self.request_version >= "HTTP/1.1"): 339 if not self.handle_expect_100(): 340 return False I would re-test with the recently released 3.3.1 (and/or 2.7.4) to make sure nothing has changed From p at google-groups-2013.dobrogost.net Sat Apr 13 13:21:20 2013 From: p at google-groups-2013.dobrogost.net (Piotr Dobrogost) Date: Sat, 13 Apr 2013 10:21:20 -0700 (PDT) Subject: SimpleHTTPRequestHandler used with HTTP/1.1 hangs after the second resource on a page. In-Reply-To: References: Message-ID: <37d93b17-134c-4cae-ba9c-781cb86cba00@googlegroups.com> On Saturday, April 13, 2013 12:21:33 AM UTC+2, Terry Jan Reedy wrote: > I find the doc slightly confusing. The SO code uses BaseHTTPServer. The > doc says "Usually, this module isn?t used directly," On the other hand, > SimpleHTTPServer only defines a request handler and not a server itself. Thanks for taking time to reply. Well, I've seen presentations where BaseHTTPServer is a recommended way of running simple, ad-hoc web server. In addition the documentation of http.server module in Python 3.3 (which contains implementation of the same HTTPServer class as found in BaseHTTPServer module in Python 2.x) does not contain the statement you cited which I take to mean it can safely be used directly. As Python 3.3.1 exhibits the same behavior let's focus on the following Python 3 version of the code from the original question: from http.server import SimpleHTTPRequestHandler from http.server import HTTPServer class MyRequestHandler(SimpleHTTPRequestHandler): #protocol_version = "HTTP/1.0" # works protocol_version = "HTTP/1.1" # hangs server = HTTPServer(("localhost", 7080), MyRequestHandler) server.serve_forever() > What does 'hang' mean? Does the page get displayed? If so, > server.serve_forever is supposes to 'hang'. I increased the number of resources to 7 to be able to detect possible patterns. The page and some of the resources are being displayed almost instantly. However browser waits for the requests to get remaining resources to finish and so those resources naturally are not being displayed. When browser waits the code is stuck at the line I showed in my original post. What's interesting is that after some time the request to get the second resource (in case there are only 2 on the page) finishes. However the time spent waiting for the second resource is ridiculously long compared to time spend waiting for the first resource. For example in one of my tests Firebug showed waiting time for the first resource to be 4ms whereas the waiting time for the second resource to be 1m 55s. > The SO post says > > class MyRequestHandler(SimpleHTTPRequestHandler): > #protocol_version = "HTTP/1.0" # works > protocol_version = "HTTP/1.1" # hangs > > so this should be some sort of clue. The code says > > 569 # The version of the HTTP protocol we support. > 570 # Set this to HTTP/1.1 to enable automatic keepalive > 571 protocol_version = "HTTP/1.0" Sure, in version 1.1 of http the connection is not closed by default unless 'Connection: Close' header was sent in request. Firefox sends all requests with 'Connection: keep-alive' header. I don't really know how to debug this... From p at google-groups-2013.dobrogost.net Sat Apr 13 13:21:20 2013 From: p at google-groups-2013.dobrogost.net (Piotr Dobrogost) Date: Sat, 13 Apr 2013 10:21:20 -0700 (PDT) Subject: SimpleHTTPRequestHandler used with HTTP/1.1 hangs after the second resource on a page. In-Reply-To: References: Message-ID: <37d93b17-134c-4cae-ba9c-781cb86cba00@googlegroups.com> On Saturday, April 13, 2013 12:21:33 AM UTC+2, Terry Jan Reedy wrote: > I find the doc slightly confusing. The SO code uses BaseHTTPServer. The > doc says "Usually, this module isn?t used directly," On the other hand, > SimpleHTTPServer only defines a request handler and not a server itself. Thanks for taking time to reply. Well, I've seen presentations where BaseHTTPServer is a recommended way of running simple, ad-hoc web server. In addition the documentation of http.server module in Python 3.3 (which contains implementation of the same HTTPServer class as found in BaseHTTPServer module in Python 2.x) does not contain the statement you cited which I take to mean it can safely be used directly. As Python 3.3.1 exhibits the same behavior let's focus on the following Python 3 version of the code from the original question: from http.server import SimpleHTTPRequestHandler from http.server import HTTPServer class MyRequestHandler(SimpleHTTPRequestHandler): #protocol_version = "HTTP/1.0" # works protocol_version = "HTTP/1.1" # hangs server = HTTPServer(("localhost", 7080), MyRequestHandler) server.serve_forever() > What does 'hang' mean? Does the page get displayed? If so, > server.serve_forever is supposes to 'hang'. I increased the number of resources to 7 to be able to detect possible patterns. The page and some of the resources are being displayed almost instantly. However browser waits for the requests to get remaining resources to finish and so those resources naturally are not being displayed. When browser waits the code is stuck at the line I showed in my original post. What's interesting is that after some time the request to get the second resource (in case there are only 2 on the page) finishes. However the time spent waiting for the second resource is ridiculously long compared to time spend waiting for the first resource. For example in one of my tests Firebug showed waiting time for the first resource to be 4ms whereas the waiting time for the second resource to be 1m 55s. > The SO post says > > class MyRequestHandler(SimpleHTTPRequestHandler): > #protocol_version = "HTTP/1.0" # works > protocol_version = "HTTP/1.1" # hangs > > so this should be some sort of clue. The code says > > 569 # The version of the HTTP protocol we support. > 570 # Set this to HTTP/1.1 to enable automatic keepalive > 571 protocol_version = "HTTP/1.0" Sure, in version 1.1 of http the connection is not closed by default unless 'Connection: Close' header was sent in request. Firefox sends all requests with 'Connection: keep-alive' header. I don't really know how to debug this... From andygong.happy at gmail.com Sat Apr 13 12:03:17 2013 From: andygong.happy at gmail.com (andygong.happy at gmail.com) Date: Sat, 13 Apr 2013 09:03:17 -0700 (PDT) Subject: Invalid syntax with print "Hello World" In-Reply-To: References: Message-ID: <6443b0bb-34dc-452b-a0bd-5544b129fed7@googlegroups.com> On Thursday, March 12, 2009 3:25:53 PM UTC+8, John Machin wrote: > On Mar 12, 5:57?pm, Henrik Bechmann wrote: > > obviously total mewbiew: > > > > My first program in Python Windows > > What is that you are callind "Python Windows"? What version of Python > are you running? > > 2.X: print "Hello World" > should work. > > 3.X: print is now a function, > print("Hello World") > should work. > > If that gets you going: read the tutorial that belongs to the version > of Python that you are using. > If it doesn't, come back here with a bit more detail. > > BTW, don't indent your first line. Make sure it starts in column 1. > > HTH, > John > > > > print "Hello World" > > > > I select Run/Run Module and get an error: > > > > Syntax error, with the closing quote highlighted. > > > > Tried with single quotes as well. Same problem. > > > > Can someone explain my mistake? > > > > Thanks, > > > > - Henrik Thank you.I got the same error.And your suggestion is so useful. From sschwarzer at sschwarzer.net Sat Apr 13 12:36:25 2013 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Sat, 13 Apr 2013 18:36:25 +0200 Subject: API design for Python 2 / 3 compatibility Message-ID: <51698989.2070805@sschwarzer.net> Hello, I'm currently changing the FTP client library ftputil [1] so that the same code of the library works with Python 2 (2.6 and up) and Python 3. (At the moment the code is for Python 2 only.) I've run into a API design issue where I don't know which API I should offer ftputil users under Python 2 and Python 3. [1] http://ftputil.sschwarzer.net/ Some important background information: A key idea in ftputil is that it uses the same APIs as the Python standard library where possible. For example, with ftputil you can write code like this: with ftputil.FTPHost(host, user, password) as ftp_host: # Like `os.path.isdir`, but works on the FTP server. if ftp_host.path.isdir("hello_dir"): # Like `os.chdir`, but works on the FTP server. ftp_host.chdir("hello_dir") # Like the `open` builtin, but opens a remote file. with ftp_host.open("new_file", "w") as fobj: # Like `file.write` and `file.close` fobj.write("Hello world!") fobj.close() Since most of Python 2's and Python 3's filesystem-related APIs accept either bytes and character strings (and return the same type if they return anything string-like at all), the design here is rather clear to me. However, I have some difficulty with ftputil's counterpart of the `open` builtin function when files are opened for reading in text mode. Here are the approaches I've been thinking of so far: * Approach 1 When opening remote text files for reading, ftputil will return byte strings from `read(line/s)` when run under Python 2 and unicode strings when run under Python 3. Pro: Each of the Python versions has ftputil behavior which matches the Python standard library behavior of the respective Python version. Con: Developers who want to use ftputil under Python 2 _and_ 3 have to program against two different APIs since their code "inherits" ftputil's duality. Con: Support for two different APIs will make the ftputil code (at least a bit) more complicated than just returning unicode strings under both Python versions. * Approach 2 When opening remote text files for reading, ftputil will always return unicode strings from `read(line/s)`, regardless of whether it runs under Python 2 or Python 3. Pro: Uniform API, independent on underlying Python version. Pro: Supporting a single API will result in cleaner code in ftputil than when supporting different APIs (see above). Con: This approach might break some code which expects the returned strings under Python 2 to be byte strings. Con: Developers who only use Python 2 might be confused if ftputil returns unicode strings from `read(line/s)` since this behavior doesn't match files opened with `open` in Python 2. Which approach do you recommend and why do you prefer that approach? Are there other approaches I have overlooked? Do you have other suggestions? Best regards, Stefan From tjreedy at udel.edu Sat Apr 13 13:32:51 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Sat, 13 Apr 2013 13:32:51 -0400 Subject: API design for Python 2 / 3 compatibility In-Reply-To: <51698989.2070805@sschwarzer.net> References: <51698989.2070805@sschwarzer.net> Message-ID: On 4/13/2013 12:36 PM, Stefan Schwarzer wrote: > Hello, > > I'm currently changing the FTP client library ftputil [1] > so that the same code of the library works with Python > 2 (2.6 and up) and Python 3. (At the moment the code is for > Python 2 only.) I've run into a API design issue where I > don't know which API I should offer ftputil users under > Python 2 and Python 3. > > [1] http://ftputil.sschwarzer.net/ > > Some important background information: A key idea in ftputil > is that it uses the same APIs as the Python standard library > where possible. For example, with ftputil you can write code > like this: > > with ftputil.FTPHost(host, user, password) as ftp_host: > # Like `os.path.isdir`, but works on the FTP server. > if ftp_host.path.isdir("hello_dir"): > # Like `os.chdir`, but works on the FTP server. > ftp_host.chdir("hello_dir") > # Like the `open` builtin, but opens a remote file. > with ftp_host.open("new_file", "w") as fobj: > # Like `file.write` and `file.close` > fobj.write("Hello world!") > fobj.close() > > Since most of Python 2's and Python 3's filesystem-related > APIs accept either bytes and character strings (and return > the same type if they return anything string-like at all), > the design here is rather clear to me. > > However, I have some difficulty with ftputil's counterpart > of the `open` builtin function when files are opened for > reading in text mode. Here are the approaches I've been > thinking of so far: > > * Approach 1 > > When opening remote text files for reading, ftputil will > return byte strings from `read(line/s)` when run under > Python 2 and unicode strings when run under Python 3. > > Pro: Each of the Python versions has ftputil behavior > which matches the Python standard library behavior of > the respective Python version. > > Con: Developers who want to use ftputil under Python 2 > _and_ 3 have to program against two different APIs since > their code "inherits" ftputil's duality. > > Con: Support for two different APIs will make the > ftputil code (at least a bit) more complicated than just > returning unicode strings under both Python versions. > > * Approach 2 > > When opening remote text files for reading, ftputil will > always return unicode strings from `read(line/s)`, > regardless of whether it runs under Python 2 or Python 3. > > Pro: Uniform API, independent on underlying Python > version. > > Pro: Supporting a single API will result in cleaner code > in ftputil than when supporting different APIs (see > above). > > Con: This approach might break some code which expects > the returned strings under Python 2 to be byte strings. > > Con: Developers who only use Python 2 might be confused > if ftputil returns unicode strings from `read(line/s)` > since this behavior doesn't match files opened with > `open` in Python 2. > > Which approach do you recommend and why do you prefer that > approach? Are there other approaches I have overlooked? Do > you have other suggestions? Approach 2 matches (or should match) io.open, which became builtin open in Python 3. I would simply document that ftp_host.open mimics io.open in the same way that ftp_host.chdir, etcetera, match os.chdir, etc. Your principle will remain intact. Anyone writing *new* Py 2 code with any idea of ever running on Py 3 should be using io.open anyway. That is why it was backported. You might be able to reuse some io code or subclass some io classes for your implementation. From ethan at stoneleaf.us Sat Apr 13 14:03:15 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 13 Apr 2013 11:03:15 -0700 Subject: API design for Python 2 / 3 compatibility In-Reply-To: <51698989.2070805@sschwarzer.net> References: <51698989.2070805@sschwarzer.net> Message-ID: <51699DE3.7070505@stoneleaf.us> On 04/13/2013 09:36 AM, Stefan Schwarzer wrote: > * Approach 2 > > When opening remote text files for reading, ftputil will > always return unicode strings from `read(line/s)`, > regardless of whether it runs under Python 2 or Python 3. > > Pro: Uniform API, independent on underlying Python > version. > > Pro: Supporting a single API will result in cleaner code > in ftputil than when supporting different APIs (see > above). > > Con: This approach might break some code which expects > the returned strings under Python 2 to be byte strings. > > Con: Developers who only use Python 2 might be confused > if ftputil returns unicode strings from `read(line/s)` > since this behavior doesn't match files opened with > `open` in Python 2. > > Which approach do you recommend and why do you prefer that > approach? Approach 2, because it is much saner to deal with unicode inside the program, and only switch back to some kind of encoding when writing to files/pipes/etc. Since you are going to support python 3 as well you can bump the major version number and note the backward incompatibility. -- ~Ethan~ From sschwarzer at sschwarzer.net Sun Apr 14 07:11:59 2013 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Sun, 14 Apr 2013 13:11:59 +0200 Subject: API design for Python 2 / 3 compatibility In-Reply-To: <51698989.2070805@sschwarzer.net> References: <51698989.2070805@sschwarzer.net> Message-ID: <516A8EFF.40400@sschwarzer.net> Terry, Ethan: Thanks a lot for your excellent advice. :-) On 2013-04-13 19:32, Terry Jan Reedy wrote: > Approach 2 matches (or should match) io.open, which became > builtin open in Python 3. I would simply document that > ftp_host.open mimics io.open in the same way that > ftp_host.chdir, etcetera, match os.chdir, etc. Your > principle will remain intact. I didn't know about `io.open` (or had forgotten it). > Anyone writing *new* Py 2 code with any idea of ever > running on Py 3 should be using io.open anyway. That is > why it was backported. You might be able to reuse some io > code or subclass some io classes for your implementation. Since I use `socket.makefile` to create the underlying file objects, I can use `BufferedReader`/`BufferedWriter` and `TextIOWrapper` to supply buffering and encoding/decoding. On 2013-04-13 20:03, Ethan Furman wrote: > Approach 2, because it is much saner to deal with unicode > inside the program, and only switch back to some kind of > encoding when writing to files/pipes/etc. Yes, this is a much saner design. I just was hesitant because of the introduced backward incompatibility and wanted to get other's opinions. > Since you are going to support python 3 as well you can > bump the major version number and note the backward > incompatibility. Actually I plan to increase the version number from 2.8 to 3.0 because of the Python 3 support and already intend to change some module names that will be visible to client code. So this is also a good opportunity to clean up the file interface. :) Best regards, Stefan From sntshkmr60 at gmail.com Sat Apr 13 16:25:20 2013 From: sntshkmr60 at gmail.com (Santosh Kumar) Date: Sun, 14 Apr 2013 01:55:20 +0530 Subject: How to install/uninstall manpages with distutils/setuptools? Message-ID: Hey, I have an app hosted on PyPi, it actually is a small script which is in bin/ directory of the project. Here is the part of setup.py file of my app: #!/usr/bin/env python #-*- coding: utf-8 -*- import sys, os, shutil try: from setuptools import setup except ImportError: from distutils.core import setup __AUTHOR__ = 'Santosh Kumar' __AUTHOR_EMAIL__ = 'user at domain.com' setup( name='sampleapp', version='1.02.02', author=__AUTHOR__, author_email=__AUTHOR_EMAIL__, packages=['sampler'], scripts=['bin/sampler'], url='https://github.com/sampleapp/sampleapp', zip_safe=False, include_package_data=True, license=open('LICENSE').read(), description='A sample application', long_description=open('README.rst').read() ) if 'install' in sys.argv: man_path = '/usr/share/man/man1/' if os.path.exists(man_path): print("Installing man pages") man_page = "doc/sampleapp.1.gz" shutil.copy2(man_page, man_path) os.chmod(man_path + 'sampleapp.1.gz', int('444', 8)) When uploaded on PyPi, this app can be installed either by downloading the archive form https://pypi.python.org/pypi/ and doing python setup.py install or by easy_install or pip. pip is my favorite because it supports uninstall option. I can install this app (script) with pip with no problem (to /usr/bin/). But I can't install the manpage to /usr/share/man/man1/. That is why I created installation of manpages in my setup.py. So with the installation of manpages my installation is complete. But the problem is I can't uninstall the manpages with `pip uninstall sampleapp`, that will only uninstall the script. So my final question is there any patch to make distutils install and uninstall man pages? Please don't tell me about any other packages, I want to stick with Python's own http://guide.python-distribute.org/ From hossamalagmy at gmail.com Sat Apr 13 16:38:08 2013 From: hossamalagmy at gmail.com (23alagmy) Date: Sat, 13 Apr 2013 13:38:08 -0700 (PDT) Subject: Microsoft accuses Google of pushing services to Android Message-ID: <5c78d44e-6eac-40c7-a432-2b5eb2023749@f18g2000vbs.googlegroups.com> Microsoft accuses Google of pushing services to Android http://natigtas7ab.blogspot.com/2013/04/microsoft-accuses-google-of-pushing.html From breamoreboy at yahoo.co.uk Sat Apr 13 17:38:08 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 13 Apr 2013 22:38:08 +0100 Subject: Issue 16061 performance regression in string replace for 3.3 Message-ID: Fixed full details here http://bugs.python.org/issue16061 -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From missive at hotmail.com Sat Apr 13 19:24:47 2013 From: missive at hotmail.com (Lee Harr) Date: Sun, 14 Apr 2013 03:54:47 +0430 Subject: [ANNC] pynguin-0.14 python turtle graphics application Message-ID: Pynguin is a python-based turtle graphics application. ??? It combines an editor, interactive interpreter, and ??? graphics display area. It is meant to be an easy environment for introducing ??? some programming concepts to beginning programmers. http://pynguin.googlecode.com/ This release adds several user-requested features, including ??? circular arcs, SVG export, and undo. Pynguin is tested with Python 3.2.3 and PyQt 4.9.3 and ??? will use Pygments syntax highlighting if available. Pynguin is released under GPLv3. Changes in pynguin-0.14: ??? Important fixes ??? Other fixes ??? Pynguin API ??????? - Added font() to change font for use with write() ??????? - Added move parameter for write() ??????? - Added align and valign parameters for write() ??????? - Added arc() for circular arcs ??? Canvas ??????? - Added SVG Export ??? UI ??????? - Added ability to use translations ??????? - Added (basic) undo capability (ctrl-z) ??? Integrated Editor ??????? - Added shortcut (ctrl-w) for removing doc pages ??????? - Stop asking for confirmation to remove empty doc page ??????? - Stop autosave from modifying empty doc page ??? Integrated Console ??? Examples ??????? - Added arc examples From miki.tebeka at gmail.com Sat Apr 13 20:10:27 2013 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sat, 13 Apr 2013 17:10:27 -0700 (PDT) Subject: [ANNC] pynguin-0.14 python turtle graphics application In-Reply-To: References: Message-ID: > Pynguin is a python-based turtle graphics application. I wonder why Pynguin does not get more traction in the teaching sector. Looks ideal for teaching kids. From miki.tebeka at gmail.com Sat Apr 13 20:10:27 2013 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sat, 13 Apr 2013 17:10:27 -0700 (PDT) Subject: [ANNC] pynguin-0.14 python turtle graphics application In-Reply-To: References: Message-ID: > Pynguin is a python-based turtle graphics application. I wonder why Pynguin does not get more traction in the teaching sector. Looks ideal for teaching kids. From dreamingforward at gmail.com Sun Apr 14 00:56:43 2013 From: dreamingforward at gmail.com (zipher) Date: Sat, 13 Apr 2013 21:56:43 -0700 (PDT) Subject: [LONG] docstring-driven testing In-Reply-To: <000001be679b$0b263e00$a99e2299@tim> References: <000001be679b$0b263e00$a99e2299@tim> Message-ID: On Saturday, March 6, 1999 12:00:00 AM UTC-8, Tim Peters wrote: > If you're like me, you've been using Python since '91, and every scheme > you've come up with for testing basically sucked. Some observations: > > + Examples are priceless. > > + Examples that don't work are worse than worthless. > > + Examples that work eventually turn into examples that don't. > > + Docstrings too often don't get written. > > + Docstrings that do get written rarely contain those priceless examples. > > + The rare written docstrings that do contain priceless examples eventually > turn into rare docstrings with examples that don't work. I think this one > may follow from the above ... > > + Module unit tests too often don't get written. > > + The best Python testing gets done in interactive mode, esp. trying > endcases that almost never make it into a test suite because they're so > tedious to code up. > > + The endcases that were tested interactively-- but never coded up --also > fail to work after time. > > About a month ago, I tried something new: take those priceless interactive > testing sessions, paste them into docstrings, and write a module to do all > the rest by magic (find the examples, execute them, and verify they still > work exactly as advertised). > > Wow -- it turned out to be the only scheme I've ever really liked, and I > like it a lot! With almost no extra work beyond what I was doing before, > tests and docstrings get written now, and I'm certain the docstring examples > are accurate. It's also caught an amazing number of formerly-insidious > buglets in my modules, from accidental changes in endcase behavior, to hasty > but inconsistent renamings. > > doctest.py is attached, and it's the whole banana. Give it a try, if you > like. After another month or so of ignoring your groundless complaints, > I'll upload it to the python.org FTP contrib site. Note that it serves as > an example of its own use, albeit an artificially strained example. Doctests are so cool, I think it should be integrated into the interpreter environment with a test() built-in to encourage people documenting their code and Test-Driven-Development. A companion to help(). Oh wait, this thread is 14 years old... ;^) From hossamalagmy at gmail.com Sun Apr 14 04:41:25 2013 From: hossamalagmy at gmail.com (23alagmy) Date: Sun, 14 Apr 2013 01:41:25 -0700 (PDT) Subject: =?windows-1256?B?3+3dIMrax+HMIMfh5cfhx8ogx+HT5s/HwSDD0w==?= =?windows-1256?B?3eEgx+Ha7eQ=?= Message-ID: <580bb907-2441-4cda-ab3c-499fd08711ed@y14g2000vbk.googlegroups.com> ??? ????? ??????? ??????? ???? ????? http://natigtas7ab.blogspot.com/2013/04/blog-post_5060.html ????? ??? ????? ?? https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fnatigtas7ab.blogspot.com%2F2013%2F04%2Fblog-post_5060.html%23.UWpinJbOYeo.facebook ?????? ??? ????? https://twitter.com/intent/tweet?text=%D9%83%D9%8A%D9%81+%D8%AA%D8%B9%D8%A7%D9%84%D8%AC+%D8%A7%D9%84%D9%87%D8%A7%D9%84%D8%A7%D8%AA+%D8%A7%D9%84%D8%B3%D9%88%D8%AF%D8%A7%D8%A1+%D8%A3%D8%B3%D9%81%D9%84+%D8%A7%D9%84%D8%B9%D9%8A%D9%86+~+%D9%86%D8%AA%D8%A7%D8%A6%D8%AC+%D8%A7%D9%84%D8%A5%D9%85%D8%AA%D8%AD%D8%A7%D9%86%D8%A7%D8%AA+%D9%84%D9%84%D8%B4%D9%87%D8%A7%D8%AF%D8%A7%D8%AA+%D9%88%D8%A7%D9%84%D8%AC%D8%A7%D9%85%D8%B9%D8%A7%D8%AA&url=http%3A%2F%2Fnatigtas7ab.blogspot.com%2F2013%2F04%2Fblog-post_5060.html%23.UWpittQQGIo.twitter&related= From m.b at gmail.com Sun Apr 14 05:24:48 2013 From: m.b at gmail.com (Marco) Date: Sun, 14 Apr 2013 11:24:48 +0200 Subject: python setup.py install and dependencies Message-ID: I have a some confusion about the package installation process. Let's say I have manually installed Python 3.3, so I don't have distribute and pip. Now I want to install the bpython shell, so I download the source code and after I try to do "python3.3 setup.py install". I did so, and all it'is ok, but I don't have the dependencies (pygments), so when I run bpython, Python complains with an ImportError: No module named 'pygments'. So I installed distribute, and after I removed and reinstalled bpython, and now "python3.3 setup.py install" has installed pygments too. So my question is: if I want "python3.3 setup.py install" installs the dependencies of a package I need to have distribute? And pip installs the dependencies because of it uses distribute? Thanks in advance, -- Marco From pyth0n3r at gmail.com Sun Apr 14 14:57:35 2013 From: pyth0n3r at gmail.com (pyth0n3r) Date: Mon, 15 Apr 2013 02:57:35 +0800 Subject: howto remove the thousand separator Message-ID: <201304150257331336590@gmail.com> Hi, I came across a problem that when i deal with int data with ',' as thousand separator, such as 12,916, i can not change it into int() or float(). How can i remove the comma in int data? Any reply will be appreciated!! Best, Chen -------------- next part -------------- An HTML attachment was scrubbed... URL: From dreamingforward at gmail.com Sun Apr 14 15:06:12 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Sun, 14 Apr 2013 12:06:12 -0700 Subject: howto remove the thousand separator In-Reply-To: <201304150257331336590@gmail.com> References: <201304150257331336590@gmail.com> Message-ID: On Sun, Apr 14, 2013 at 11:57 AM, pyth0n3r wrote: > I came across a problem that when i deal with int data with ',' as thousand > separator, such as 12,916, i can not change it into int() or float(). > How can i remove the comma in int data? > Any reply will be appreciated!! cleaned='' for c in myStringNumber: if c != ',': cleaned+=c int(cleaned) mark From msirenef at lightbird.net Sun Apr 14 15:16:52 2013 From: msirenef at lightbird.net (Mitya Sirenef) Date: Sun, 14 Apr 2013 15:16:52 -0400 Subject: howto remove the thousand separator In-Reply-To: <201304150257331336590@gmail.com> References: <201304150257331336590@gmail.com> Message-ID: <516B00A4.7070503@lightbird.net> On 04/14/2013 02:57 PM, pyth0n3r wrote: > Hi, > I came across a problem that when i deal with int data with ',' as thousand separator, such as 12,916, i can not change it into int() or float(). > How can i remove the comma in int data? > Any reply will be appreciated!! > > Best, > Chen > > > I would do int(num.replace(',', '')) -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ When a friend succeeds, I die a little. Gore Vidal From dreamingforward at gmail.com Sun Apr 14 15:22:27 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Sun, 14 Apr 2013 12:22:27 -0700 Subject: howto remove the thousand separator In-Reply-To: <516B00A4.7070503@lightbird.net> References: <201304150257331336590@gmail.com> <516B00A4.7070503@lightbird.net> Message-ID: > I would do int(num.replace(',', '')) That's much more pythonic than my C-ish version Mark From darcy at druid.net Sun Apr 14 15:17:49 2013 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sun, 14 Apr 2013 15:17:49 -0400 Subject: howto remove the thousand separator In-Reply-To: <201304150257331336590@gmail.com> References: <201304150257331336590@gmail.com> Message-ID: <20130414151749.29608713@imp> On Mon, 15 Apr 2013 02:57:35 +0800 "pyth0n3r" wrote: > float(). How can i remove the comma in int data? Any reply will be int(n.replace(',', '')) -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 788 2246 (DoD#0082) (eNTP) | what's for dinner. IM: darcy at Vex.Net, VOIP: sip:darcy at Vex.Net From pyth0n3r at gmail.com Sun Apr 14 15:33:43 2013 From: pyth0n3r at gmail.com (pyth0n3r) Date: Mon, 15 Apr 2013 03:33:43 +0800 Subject: howto remove the thousand separator References: <201304150257331336590@gmail.com>, <20130414151749.29608713@imp> Message-ID: <201304150333407472650@gmail.com> Hi D'A, Thanks alot for your reply, it works for me perfectly. Best, Chen On Mon, 15 Apr 2013 02:57:35 +0800 "pyth0n3r" wrote: > float(). How can i remove the comma in int data? Any reply will be int(n.replace(',', '')) -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 788 2246 (DoD#0082) (eNTP) | what's for dinner. IM: darcy at Vex.Net, VOIP: sip:darcy at Vex.Net -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Sun Apr 14 15:29:13 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 14 Apr 2013 20:29:13 +0100 Subject: howto remove the thousand separator In-Reply-To: <201304150257331336590@gmail.com> References: <201304150257331336590@gmail.com> Message-ID: On 14/04/2013 19:57, pyth0n3r wrote: > Hi, > I came across a problem that when i deal with int data with ',' as > thousand separator, such as 12,916, i can not change it into int() or > float(). > How can i remove the comma in int data? > Any reply will be appreciated!! > Best, > Chen > > Use the string replace method thus. >>> '12,916'.replace(',', '') '12916' -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From steve+comp.lang.python at pearwood.info Sun Apr 14 20:29:16 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Apr 2013 00:29:16 GMT Subject: howto remove the thousand separator References: <201304150257331336590@gmail.com> Message-ID: <516b49dc$0$29977$c3e8da3$5496439d@news.astraweb.com> On Sun, 14 Apr 2013 12:06:12 -0700, Mark Janssen wrote: > cleaned='' > for c in myStringNumber: > if c != ',': > cleaned+=c > int(cleaned) Please don't write code like that. Firstly, it's long and bloated, and runs at the speed of Python, not C. Second, it runs at the speed of SLLLLOOOOOOOOOOWWWW Python, not fast Python, due to being an O(N**2) algorithm. If you don't know what O(N**2) means, you should read this for an introduction: http://www.joelonsoftware.com/articles/fog0000000319.html -- Steven From dreamingforward at gmail.com Sun Apr 14 20:44:28 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Sun, 14 Apr 2013 17:44:28 -0700 Subject: howto remove the thousand separator In-Reply-To: <516b49dc$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <201304150257331336590@gmail.com> <516b49dc$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Apr 14, 2013 at 5:29 PM, Steven D'Aprano wrote: > On Sun, 14 Apr 2013 12:06:12 -0700, Mark Janssen wrote: > >> cleaned='' >> for c in myStringNumber: >> if c != ',': >> cleaned+=c >> int(cleaned) > > ....due to being an O(N**2) algorithm. What on earth makes you think that is an O(n**2) algorithm and not O(n)? Mark From steve+comp.lang.python at pearwood.info Sun Apr 14 21:14:25 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Apr 2013 01:14:25 GMT Subject: howto remove the thousand separator References: <201304150257331336590@gmail.com> <516b49dc$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <516b5471$0$29977$c3e8da3$5496439d@news.astraweb.com> On Sun, 14 Apr 2013 17:44:28 -0700, Mark Janssen wrote: > On Sun, Apr 14, 2013 at 5:29 PM, Steven D'Aprano > wrote: >> On Sun, 14 Apr 2013 12:06:12 -0700, Mark Janssen wrote: >> >>> cleaned='' >>> for c in myStringNumber: >>> if c != ',': >>> cleaned+=c >>> int(cleaned) >> >> ....due to being an O(N**2) algorithm. > > What on earth makes you think that is an O(n**2) algorithm and not O(n)? Strings are immutable. Consider building up a single string from four substrings: s = '' s += 'fe' s += 'fi' s += 'fo' s += 'fum' Python *might* optimize the first concatenation, '' + 'fe', to just reuse 'fe', (but it might not). Let's assume it does, so that no copying is needed. Then it gets to the second concatenation, and now it has to copy characters, because strings are immutable and cannot be modified in place. Showing the *running* total of characters copied: 'fe' + 'fi' => 'fefi' # four characters copied 'fefi' + 'fo' => 'fefifo' # 4 + 6 = ten characters copied 'fefifo' + 'fum' => 'fefifofum' # 10 + 9 = nineteen characters copied Notice how each intermediate substring gets copied repeatedly? In order to build up a string of length 9, we've had to copy at least 19 characters. With only four substrings, it's not terribly obvious how badly this performs. So let's add some more substrings, and see how the running total increases: 'fefifofum' + 'foo' => 'fefifofumfoo' # 19 + 12 = 31 'fefifofumfoo' + 'bar' => 'fefifofumfoobar' # 31 + 15 = 46 'fefifofumfoobar' + 'baz' => 'fefifofumfoobarbaz' # 46 + 18 = 64 'fefifofumfoobarbaz' + 'spam' => 'fefifofumfoobarbazspam' # 64 + 22 = 86 To build up a string of length 22, we've had to copy, and re-copy, and re- re-copy, 86 characters in total. And the string gets bigger, the inefficiency gets worse. Each substring (except the very last one) gets copied multiple times; the number of times it gets copied is proportional to the number of substrings. If the substrings are individual characters, then each character is copied a number of times proportional to the number of characters N; since there are N characters, each being copied (proportional to) N times, that makes N*N or N**2. -- Steven From rosuav at gmail.com Sun Apr 14 21:29:17 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 15 Apr 2013 11:29:17 +1000 Subject: howto remove the thousand separator In-Reply-To: <516b5471$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <201304150257331336590@gmail.com> <516b49dc$0$29977$c3e8da3$5496439d@news.astraweb.com> <516b5471$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Apr 15, 2013 at 11:14 AM, Steven D'Aprano wrote: > On Sun, 14 Apr 2013 17:44:28 -0700, Mark Janssen wrote: >> What on earth makes you think that is an O(n**2) algorithm and not O(n)? > > Python *might* optimize the first concatenation, '' + 'fe', to just reuse > 'fe', (but it might not). Let's assume it does, so that no copying is > needed. Then it gets to the second concatenation, and now it has to copy > characters, because strings are immutable and cannot be modified in > place. There are actually a lot of optimizations done, so it might turn out to be O(n) in practice. But strictly in the Python code, yes, this is definitely O(n*n). ChrisA From sg552 at hotmail.co.uk Sun Apr 14 22:19:43 2013 From: sg552 at hotmail.co.uk (Rotwang) Date: Mon, 15 Apr 2013 03:19:43 +0100 Subject: howto remove the thousand separator In-Reply-To: <516b5471$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <201304150257331336590@gmail.com> <516b49dc$0$29977$c3e8da3$5496439d@news.astraweb.com> <516b5471$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 15/04/2013 02:14, Steven D'Aprano wrote: > On Sun, 14 Apr 2013 17:44:28 -0700, Mark Janssen wrote: > >> On Sun, Apr 14, 2013 at 5:29 PM, Steven D'Aprano >> wrote: >>> On Sun, 14 Apr 2013 12:06:12 -0700, Mark Janssen wrote: >>> >>>> cleaned='' >>>> for c in myStringNumber: >>>> if c != ',': >>>> cleaned+=c >>>> int(cleaned) >>> >>> ....due to being an O(N**2) algorithm. >> >> What on earth makes you think that is an O(n**2) algorithm and not O(n)? > > Strings are immutable. Consider building up a single string from four > substrings: > > s = '' > s += 'fe' > s += 'fi' > s += 'fo' > s += 'fum' > > Python *might* optimize the first concatenation, '' + 'fe', to just reuse > 'fe', (but it might not). Let's assume it does, so that no copying is > needed. Then it gets to the second concatenation, and now it has to copy > characters, because strings are immutable and cannot be modified in > place. Actually, I believe that CPython is optimised to modify strings in place where possible, so that the above would surprisingly turn out to be O(n). See the following thread where I asked about this: http://groups.google.com/group/comp.lang.python/browse_thread/thread/990a695fe2d85c52 (Sorry for linking to Google Groups. Does anyone know of a better c.l.p. web archive?) From nad at acm.org Mon Apr 15 01:15:22 2013 From: nad at acm.org (Ned Deily) Date: Sun, 14 Apr 2013 22:15:22 -0700 Subject: howto remove the thousand separator References: <201304150257331336590@gmail.com> <516b49dc$0$29977$c3e8da3$5496439d@news.astraweb.com> <516b5471$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Rotwang wrote: > (Sorry for linking to Google Groups. Does anyone know of a better c.l.p. > web archive?) http://dir.gmane.org/gmane.comp.python.general -- Ned Deily, nad at acm.org From steve+comp.lang.python at pearwood.info Mon Apr 15 03:03:15 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Apr 2013 07:03:15 GMT Subject: howto remove the thousand separator References: <201304150257331336590@gmail.com> <516b49dc$0$29977$c3e8da3$5496439d@news.astraweb.com> <516b5471$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <516ba633$0$29872$c3e8da3$5496439d@news.astraweb.com> On Mon, 15 Apr 2013 03:19:43 +0100, Rotwang wrote: > On 15/04/2013 02:14, Steven D'Aprano wrote: >> On Sun, 14 Apr 2013 17:44:28 -0700, Mark Janssen wrote: >> >>> On Sun, Apr 14, 2013 at 5:29 PM, Steven D'Aprano >>> wrote: >>>> On Sun, 14 Apr 2013 12:06:12 -0700, Mark Janssen wrote: >>>> >>>>> cleaned='' >>>>> for c in myStringNumber: >>>>> if c != ',': >>>>> cleaned+=c >>>>> int(cleaned) >>>> >>>> ....due to being an O(N**2) algorithm. >>> >>> What on earth makes you think that is an O(n**2) algorithm and not >>> O(n)? >> >> Strings are immutable. Consider building up a single string from four >> substrings: >> >> s = '' >> s += 'fe' >> s += 'fi' >> s += 'fo' >> s += 'fum' >> >> Python *might* optimize the first concatenation, '' + 'fe', to just >> reuse 'fe', (but it might not). Let's assume it does, so that no >> copying is needed. Then it gets to the second concatenation, and now it >> has to copy characters, because strings are immutable and cannot be >> modified in place. > > Actually, I believe that CPython is optimised to modify strings in place > where possible, so that the above would surprisingly turn out to be > O(n). See the following thread where I asked about this: I deliberately didn't open that can of worms, mostly because I was in a hurry, but also because it's not an optimization you can rely on. It depends on the version, implementation, operating system, and the exact code running. 1) It only applies to code running under some, but not all, versions of CPython. It does not apply to PyPy, Jython, IronPython, and probably not other implementations. 2) Even under CPython, it can fail. It *will* fail if you have multiple references to the same strings. And it *may* fail depending on the vagaries of the memory management system in place, e.g. code that is optimized on Linux may fail to optimize under Windows, leading to slow code. As far as I'm concerned, the best advice regarding this optimization is: - always program as if it doesn't exist; - but be glad it does when you're writing quick and dirty code in the interactive interpreter, where the convenience of string concatenation may be just too darn convenient to bother doing the right thing. > http://groups.google.com/group/comp.lang.python/browse_thread/ thread/990a695fe2d85c52 > > (Sorry for linking to Google Groups. Does anyone know of a better c.l.p. > web archive?) The canonical (although possibly not the best) archive for c.l.p. is the python-list mailing list archive: http://mail.python.org/mailman/listinfo/python-list -- Steven From rosuav at gmail.com Mon Apr 15 03:39:25 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 15 Apr 2013 17:39:25 +1000 Subject: howto remove the thousand separator In-Reply-To: <516ba633$0$29872$c3e8da3$5496439d@news.astraweb.com> References: <201304150257331336590@gmail.com> <516b49dc$0$29977$c3e8da3$5496439d@news.astraweb.com> <516b5471$0$29977$c3e8da3$5496439d@news.astraweb.com> <516ba633$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Apr 15, 2013 at 5:03 PM, Steven D'Aprano wrote: > On Mon, 15 Apr 2013 03:19:43 +0100, Rotwang wrote: > >> On 15/04/2013 02:14, Steven D'Aprano wrote: >>> Strings are immutable. Consider building up a single string from four >>> substrings: >> >> Actually, I believe that CPython is optimised to modify strings in place >> where possible, so that the above would surprisingly turn out to be >> O(n). See the following thread where I asked about this: > > I deliberately didn't open that can of worms, mostly because I was in a > hurry, but also because it's not an optimization you can rely on. It > depends on the version, implementation, operating system, and the exact > code running. > > As far as I'm concerned, the best advice regarding this optimization is: > > - always program as if it doesn't exist; > > - but be glad it does when you're writing quick and dirty code in the > interactive interpreter, where the convenience of string concatenation > may be just too darn convenient to bother doing the right thing. Agreed; that's why, in my reply, I emphasized that the pure Python code IS quadratic, even though the actual implementation might turn out linear. (I love that word "might". Covers myriad possibilities on both sides.) Same goes for all sorts of other possibilities. I wouldn't test string equality with 'is' without explicit interning, even if I'm testing a constant against another constant in the same module - but I might get a big performance boost if the system's interned all its constants for me. ChrisA From sg552 at hotmail.co.uk Mon Apr 15 18:16:04 2013 From: sg552 at hotmail.co.uk (Rotwang) Date: Mon, 15 Apr 2013 23:16:04 +0100 Subject: howto remove the thousand separator In-Reply-To: <516ba633$0$29872$c3e8da3$5496439d@news.astraweb.com> References: <201304150257331336590@gmail.com> <516b49dc$0$29977$c3e8da3$5496439d@news.astraweb.com> <516b5471$0$29977$c3e8da3$5496439d@news.astraweb.com> <516ba633$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 15/04/2013 08:03, Steven D'Aprano wrote: > On Mon, 15 Apr 2013 03:19:43 +0100, Rotwang wrote: >> [...] >> >> (Sorry for linking to Google Groups. Does anyone know of a better c.l.p. >> web archive?) > > The canonical (although possibly not the best) archive for c.l.p. is the > python-list mailing list archive: > > http://mail.python.org/mailman/listinfo/python-list Thanks to both you and Ned. From walterhurry at lavabit.com Sun Apr 14 22:25:03 2013 From: walterhurry at lavabit.com (Walter Hurry) Date: Mon, 15 Apr 2013 02:25:03 +0000 (UTC) Subject: howto remove the thousand separator References: <201304150257331336590@gmail.com> <516b49dc$0$29977$c3e8da3$5496439d@news.astraweb.com> <516b5471$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, 15 Apr 2013 11:29:17 +1000, Chris Angelico wrote: > There are actually a lot of optimizations done, so it might turn out to > be O(n) in practice. But strictly in the Python code, yes, this is > definitely O(n*n). In any event, Janssen should cease and desist offering advice here if he can't do better than that. From roy at panix.com Sun Apr 14 22:35:42 2013 From: roy at panix.com (Roy Smith) Date: Sun, 14 Apr 2013 22:35:42 -0400 Subject: howto remove the thousand separator References: <201304150257331336590@gmail.com> <516b49dc$0$29977$c3e8da3$5496439d@news.astraweb.com> <516b5471$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Walter Hurry wrote: > On Mon, 15 Apr 2013 11:29:17 +1000, Chris Angelico wrote: > > > There are actually a lot of optimizations done, so it might turn out to > > be O(n) in practice. But strictly in the Python code, yes, this is > > definitely O(n*n). > > In any event, Janssen should cease and desist offering advice here if he > can't do better than that. That's a little harsh. Sure, it was a "sub-optimal" way to write the code (for all the reasons people mentioned), but it engendered a good discussion. From steve+comp.lang.python at pearwood.info Mon Apr 15 03:04:22 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Apr 2013 07:04:22 GMT Subject: howto remove the thousand separator References: <201304150257331336590@gmail.com> <516b49dc$0$29977$c3e8da3$5496439d@news.astraweb.com> <516b5471$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <516ba676$0$29872$c3e8da3$5496439d@news.astraweb.com> On Sun, 14 Apr 2013 22:35:42 -0400, Roy Smith wrote: > In article , > Walter Hurry wrote: > >> On Mon, 15 Apr 2013 11:29:17 +1000, Chris Angelico wrote: >> >> > There are actually a lot of optimizations done, so it might turn out >> > to be O(n) in practice. But strictly in the Python code, yes, this is >> > definitely O(n*n). >> >> In any event, Janssen should cease and desist offering advice here if >> he can't do better than that. > > That's a little harsh. Sure, it was a "sub-optimal" way to write the > code (for all the reasons people mentioned), but it engendered a good > discussion. Agreed. I'd rather people come out with poor code, and LEARN from the answers, than feel that they dare not reply until they're an expert. -- Steven From duncan.booth at invalid.invalid Fri Apr 19 11:04:57 2013 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 19 Apr 2013 15:04:57 GMT Subject: howto remove the thousand separator References: Message-ID: "pyth0n3r" wrote: > I came across a problem that when i deal with int data with ',' as > thousand separator, such as 12,916, i can not change it into int() or > float(). How can i remove the comma in int data? > Any reply will be appreciated!! > Parse it using the locale module, just be sure to set the correct locale first: >>> import locale >>> locale.setlocale(locale.LC_ALL, '') 'English_United Kingdom.1252' >>> locale.atoi('1,000') 1000 >>> locale.atof('1,000') 1000.0 >>> locale.setlocale(locale.LC_ALL, 'French_France') 'French_France.1252' >>> locale.atof('1,000') 1.0 -- Duncan Booth http://kupuguy.blogspot.com From rosuav at gmail.com Sun Apr 14 17:50:21 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 15 Apr 2013 07:50:21 +1000 Subject: Grammar question: Englisn and Python: qualified names Message-ID: Quirky question time! When you read out a qualified name, eg collections.OrderedDict, do you read the qualifier ("collections dot ordered dict"), or do you elide it ("ordered dict")? I ask because it makes a difference to talking about just one of them: ... or possibly a collections.OrderedDict... ... or possibly an collections.OrderedDict... Written, the latter looks completely wrong; but if the name is read in its short form, with the "collections" part being implicit, then "an" is clearly correct! What do you think, experts and others? ChrisA From python at mrabarnett.plus.com Sun Apr 14 19:11:37 2013 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 15 Apr 2013 00:11:37 +0100 Subject: Grammar question: Englisn and Python: qualified names In-Reply-To: References: Message-ID: <516B37A9.9000100@mrabarnett.plus.com> On 14/04/2013 22:50, Chris Angelico wrote: > Quirky question time! > > When you read out a qualified name, eg collections.OrderedDict, do you > read the qualifier ("collections dot ordered dict"), or do you elide > it ("ordered dict")? I ask because it makes a difference to talking > about just one of them: > > ... or possibly a collections.OrderedDict... > ... or possibly an collections.OrderedDict... > > Written, the latter looks completely wrong; but if the name is read in > its short form, with the "collections" part being implicit, then "an" > is clearly correct! What do you think, experts and others? > I read what's there: "a collections.OrderedDict" vs "an OrderedDict". From ethan at stoneleaf.us Sun Apr 14 20:13:43 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 14 Apr 2013 17:13:43 -0700 Subject: Grammar question: Englisn and Python: qualified names In-Reply-To: References: Message-ID: <516B4637.5080200@stoneleaf.us> On 04/14/2013 02:50 PM, Chris Angelico wrote: > Quirky question time! > > When you read out a qualified name, eg collections.OrderedDict, do you > read the qualifier ("collections dot ordered dict"), or do you elide > it ("ordered dict")? I ask because it makes a difference to talking > about just one of them: > > ... or possibly a collections.OrderedDict... > ... or possibly an collections.OrderedDict... > > Written, the latter looks completely wrong; but if the name is read in > its short form, with the "collections" part being implicit, then "an" > is clearly correct! What do you think, experts and others? Explicit is better than implicit. ;) "collections dot ordereddict" From sschwarzer at sschwarzer.net Mon Apr 15 01:47:36 2013 From: sschwarzer at sschwarzer.net (Stefan Schwarzer) Date: Mon, 15 Apr 2013 07:47:36 +0200 Subject: Grammar question: Englisn and Python: qualified names In-Reply-To: References: Message-ID: <516B9478.6020607@sschwarzer.net> Hi Chris, On 2013-04-14 23:50, Chris Angelico wrote: > Quirky question time! > > When you read out a qualified name, eg collections.OrderedDict, do you > read the qualifier ("collections dot ordered dict"), or do you elide > it ("ordered dict")? I ask because it makes a difference to talking > about just one of them: > > ... or possibly a collections.OrderedDict... > ... or possibly an collections.OrderedDict... > > Written, the latter looks completely wrong; but if the name is read in > its short form, with the "collections" part being implicit, then "an" > is clearly correct! What do you think, experts and others? I think if you _write_ "collections.OrderedDict", the article you _write_ in front should match this. The phrase "an collections.OrderedDict" looks odd to me, and if I read it somewhere, it wouldn't cross my mind that the writer used "an collections.OrderedDict" with the idea not to pronounce "collections". ;-) In my opinion, this is too subtle. On the other hand, when you _speak_ about the ordered dict, use the article matching what you actually say. Best regards, Stefan From python.list at tim.thechases.com Mon Apr 15 08:28:21 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 15 Apr 2013 07:28:21 -0500 Subject: Grammar question: Englisn and Python: qualified names In-Reply-To: References: Message-ID: <20130415072821.2543ceee@bigbox.christie.dr> On 2013-04-15 07:50, Chris Angelico wrote: > Quirky question time! > ... or possibly a collections.OrderedDict... > ... or possibly an collections.OrderedDict... If you're smart enough to elide the "collections [dot]" from your pronunciation, you're smart enough to adjust the a/an accordingly. Use the first one :-) -tkc From rosuav at gmail.com Mon Apr 15 08:33:00 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 15 Apr 2013 22:33:00 +1000 Subject: Grammar question: Englisn and Python: qualified names In-Reply-To: <20130415072821.2543ceee@bigbox.christie.dr> References: <20130415072821.2543ceee@bigbox.christie.dr> Message-ID: On Mon, Apr 15, 2013 at 10:28 PM, Tim Chase wrote: > On 2013-04-15 07:50, Chris Angelico wrote: >> Quirky question time! >> ... or possibly a collections.OrderedDict... >> ... or possibly an collections.OrderedDict... > > If you're smart enough to elide the "collections [dot]" from your > pronunciation, you're smart enough to adjust the a/an accordingly. > Use the first one :-) I like that reasoning. :) Thanks, all! ChrisA From cs at zip.com.au Mon Apr 15 22:44:19 2013 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 16 Apr 2013 12:44:19 +1000 Subject: Grammar question: Englisn and Python: qualified names In-Reply-To: References: Message-ID: <20130416024419.GA5691@cskk.homeip.net> On 15Apr2013 07:50, Chris Angelico wrote: | Quirky question time! | | When you read out a qualified name, eg collections.OrderedDict, do you | read the qualifier ("collections dot ordered dict"), or do you elide | it ("ordered dict")? I ask because it makes a difference to talking | about just one of them: | | ... or possibly a collections.OrderedDict... | ... or possibly an collections.OrderedDict... | | Written, the latter looks completely wrong; but if the name is read in | its short form, with the "collections" part being implicit, then "an" | is clearly correct! What do you think, experts and others? I do the former. -- Cameron Simpson Nothing is so smiple that it can't get screwed up. From vasudevram at gmail.com Sun Apr 14 18:12:20 2013 From: vasudevram at gmail.com (vasudevram) Date: Sun, 14 Apr 2013 15:12:20 -0700 (PDT) Subject: Using xtopdf and pypyodbc to publish MS Access database data to PDF Message-ID: <685ed55f-1b0b-4977-aae6-03b77fee2472@googlegroups.com> Wrote a program that lets you publish your MS Access database data to PDF, using Python, ReportLab, xtopdf (my toolkit) and pypyodbc. Sharing it here. Link: http://jugad2.blogspot.in/2013/04/using-xtopdf-and-pypyodbc-to-publish-ms.html Note: Saw some comments about my blog post on the Python Reddit, which made me realize that I had not explained that similar code can be used to publish data from any ODBC database (for which you have an ODBC driver, and which is supported by pypyodbc), to PDF. All you have to do is change the connection string in the code, and maybe a few other small tweaks for differences between SQL dialects of different RDBMS's. Enjoy. - Vasudev Ram www.dancingbison.com jugad2.blogspot.com From charleshixsn at earthlink.net Sun Apr 14 19:12:11 2013 From: charleshixsn at earthlink.net (Charles Hixson) Date: Sun, 14 Apr 2013 16:12:11 -0700 Subject: Threadpool item mailboxes design problem Message-ID: <516B37CB.1020607@earthlink.net> What is the best approach to implementing actors that accept and post messages (and have no other external contacts). So far what I've come up with is something like: actors = {} mailboxs = {} Stuff actors with actor instances, mailboxes with multiprocessing.queue instances. (Actors and mailboxes will have identical keys, which are id#, but it's got to be a dict rather than a list, because too many are rolled out to disk.) And I'm planning of having the actors running simultaneously and continually in a threadpool that just loops through the actors that are assigned to each thread of the pool. This lets any actor post messages to the mailbox of any other actor that it has the id of, and lets him read his own mail without multi-processing clashes. But I'm quite uncertain that this is the best way, because, if nothing else, it means that each mailbox needs to be allocated large enough to handle the maximum amount of mail it could possibly receive. (I suppose I could implement some sort of "wait awhile and try again" method.) It would, however, be better if the mailbox could be specific to the threadpool instance, so less space would be wasted. Or if the queues could dynamically resize. Or if there was a threadsafe dict. Or... But I don't know that any of these are feasible. (I mean, yes, I could write all the mail to a database, but is that a better answer, or even a good one?) -- Charles Hixson From clp2 at rebertia.com Sun Apr 14 22:32:54 2013 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 14 Apr 2013 19:32:54 -0700 Subject: Threadpool item mailboxes design problem In-Reply-To: <516B37CB.1020607@earthlink.net> References: <516B37CB.1020607@earthlink.net> Message-ID: On Apr 14, 2013 4:27 PM, "Charles Hixson" wrote: > > What is the best approach to implementing actors that accept and post messages (and have no other external contacts). You might look at how some of the existing Python actor libraries are implemented (perhaps one of these might even save you from reinventing the wheel): http://www.pykka.org/en/latest/ http://www.kamaelia.org/Docs/Axon/Axon.html https://pypi.python.org/pypi/pulsar Kinda old: http://candygram.sourceforge.net/contents.html http://osl.cs.uiuc.edu/parley/ > So far what I've come up with is something like: > actors = {} > mailboxs = {} > > Stuff actors with actor instances, mailboxes with multiprocessing.queue instances. (Actors and mailboxes will have identical keys, which are id#, but it's got to be a dict rather than a list, because too many are rolled out to disk.) And I'm planning of having the actors running simultaneously and continually in a threadpool that just loops through the actors that are assigned to each thread of the pool. > It would, however, be better if the mailbox could be specific to the threadpool instance, so less space would be wasted. Or if the queues could dynamically resize. Or if there was a threadsafe dict. Or... But I don't know that any of these are feasible. (I mean, yes, I could write all the mail to a database, but is that a better answer, or even a good one?) My recollection is that the built-in collection types are threadsafe at least to the limited extent that the operations exposed by their APIs (e.g. dict.setdefault) are atomic. Perhaps someone will be able to chime in with more details. -------------- next part -------------- An HTML attachment was scrubbed... URL: From charleshixsn at earthlink.net Mon Apr 15 13:14:14 2013 From: charleshixsn at earthlink.net (Charles Hixson) Date: Mon, 15 Apr 2013 10:14:14 -0700 Subject: Threadpool item mailboxes design problem In-Reply-To: References: <516B37CB.1020607@earthlink.net> Message-ID: <516C3566.7000402@earthlink.net> On 04/14/2013 07:32 PM, Chris Rebert wrote: > > On Apr 14, 2013 4:27 PM, "Charles Hixson" > wrote: > > > > What is the best approach to implementing actors that accept and > post messages (and have no other external contacts). > > You might look at how some of the existing Python actor libraries are > implemented (perhaps one of these might even save you from reinventing > the wheel): > > http://www.pykka.org/en/latest/ > http://www.kamaelia.org/Docs/Axon/Axon.html > https://pypi.python.org/pypi/pulsar > > Kinda old: > http://candygram.sourceforge.net/contents.html > http://osl.cs.uiuc.edu/parley/ > Candygram looks interesting. I'd forgotten about it. The others look either a bit limited (in different ways), or overly general, with the costs that that brings. I'll need to study Candygram a bit more. However, even Candygram seems to have a RAM centric model that I'd need to work around. (Well, the mailbox synchronization must clearly be RAM centric, but the storage shouldn't be.) > > > So far what I've come up with is something like: > > actors = {} > > mailboxs = {} > > > > Stuff actors with actor instances, mailboxes with > multiprocessing.queue instances. (Actors and mailboxes will have > identical keys, which are id#, but it's got to be a dict rather than a > list, because too many are rolled out to disk.) And I'm planning of > having the actors running simultaneously and continually in a > threadpool that just loops through the actors that are assigned to > each thread of the pool. > > > It would, however, be better if the mailbox could be specific to the > threadpool instance, so less space would be wasted. Or if the queues > could dynamically resize. Or if there was a threadsafe dict. Or... > But I don't know that any of these are feasible. (I mean, yes, I > could write all the mail to a database, but is that a better answer, > or even a good one?) > > My recollection is that the built-in collection types are threadsafe > at least to the limited extent that the operations exposed by their > APIs (e.g. dict.setdefault) are atomic. > Perhaps someone will be able to chime in with more details. > If list operations were threadsafe, why would multiprocessing.queue have been created? I don't recall any claim that they were. Still, I've found an assertion on StackOverflow that they are...at least for simple assignment and reading. And the same would appear to be true of dicts from that post. This *does* require that either the index be constant, and the stored value be constant, or that the code section be locked during the access. Fortunately I'm intending to have id#s be unchangable, and the messages to be tuples, and thus constant. OTOH, to use this approach I'll need to find some way to guarantee that removing messages and posting messages don't occur at the same time. So that still means I'll need to lock each access. The answer that seems best is for each thread to have a mailbox that cells within the thread post and read messages from. This will automatically deal with internal to thread synchronization. Then I'll need a mailman thread that... This seems a promising approach, that avoids the problem of fixed length queues, but I'll still need to do a lot of synchronization. Still, it's a lot less, and each thread would be locked for shorter amounts of time. -- Charles Hixson -------------- next part -------------- An HTML attachment was scrubbed... URL: From charleshixsn at earthlink.net Mon Apr 15 21:38:48 2013 From: charleshixsn at earthlink.net (Charles Hixson) Date: Mon, 15 Apr 2013 18:38:48 -0700 Subject: Threadpool item mailboxes design problem In-Reply-To: <516C3566.7000402@earthlink.net> References: <516B37CB.1020607@earthlink.net> <516C3566.7000402@earthlink.net> Message-ID: <516CABA8.3040009@earthlink.net> On 04/15/2013 10:14 AM, Charles Hixson wrote: > On 04/14/2013 07:32 PM, Chris Rebert wrote: >> >> On Apr 14, 2013 4:27 PM, "Charles Hixson" > > wrote: >> > >> > What is the best approach to implementing actors that accept and >> post messages (and have no other external contacts). >> >> You might look at how some of the existing Python actor libraries are >> implemented (perhaps one of these might even save you from >> reinventing the wheel): >> >> http://www.pykka.org/en/latest/ >> http://www.kamaelia.org/Docs/Axon/Axon.html >> https://pypi.python.org/pypi/pulsar >> >> Kinda old: >> http://candygram.sourceforge.net/contents.html >> http://osl.cs.uiuc.edu/parley/ >> > Candygram looks interesting. I'd forgotten about it. The others look > either a bit limited (in different ways), or overly general, with the > costs that that brings. I'll need to study Candygram a bit more. > However, even Candygram seems to have a RAM centric model that I'd > need to work around. (Well, the mailbox synchronization must clearly > be RAM centric, but the storage shouldn't be.) >> >> > So far what I've come up with is something like: >> > actors = {} >> > mailboxs = {} >> > >> > Stuff actors with actor instances, mailboxes with >> multiprocessing.queue instances. (Actors and mailboxes will have >> identical keys, which are id#, but it's got to be a dict rather than >> a list, because too many are rolled out to disk.) And I'm planning >> of having the actors running simultaneously and continually in a >> threadpool that just loops through the actors that are assigned to >> each thread of the pool. >> >> > It would, however, be better if the mailbox could be specific to >> the threadpool instance, so less space would be wasted. Or if the >> queues could dynamically resize. Or if there was a threadsafe dict. >> Or... But I don't know that any of these are feasible. (I mean, >> yes, I could write all the mail to a database, but is that a better >> answer, or even a good one?) >> >> My recollection is that the built-in collection types are threadsafe >> at least to the limited extent that the operations exposed by their >> APIs (e.g. dict.setdefault) are atomic. >> Perhaps someone will be able to chime in with more details. >> > If list operations were threadsafe, why would multiprocessing.queue > have been created? I don't recall any claim that they were. Still, > I've found an assertion on StackOverflow that they are...at least for > simple assignment and reading. And the same would appear to be true > of dicts from that post. This *does* require that either the index be > constant, and the stored value be constant, or that the code section > be locked during the access. Fortunately I'm intending to have id#s > be unchangable, and the messages to be tuples, and thus constant. > > OTOH, to use this approach I'll need to find some way to guarantee > that removing messages and posting messages don't occur at the same > time. So that still means I'll need to lock each access. The answer > that seems best is for each thread to have a mailbox that cells within > the thread post and read messages from. This will automatically deal > with internal to thread synchronization. Then I'll need a mailman > thread that... > > This seems a promising approach, that avoids the problem of fixed > length queues, but I'll still need to do a lot of synchronization. > Still, it's a lot less, and each thread would be locked for shorter > amounts of time. > -- > Charles Hixson > Currently it looks as if Pyro is the best option. It appears that Python threads are very contentious, so I'll need to run in processes rather than in threads, but I'll still need to transfer messages back and forth. I'll probably use UnixSockets rather than IP, but this could change...and using Pyro would make changing it easy. Still, pickle is used in code transmission, and that makes IP a questionable choice. -- Charles Hixson -------------- next part -------------- An HTML attachment was scrubbed... URL: From dihedral88888 at googlemail.com Sun Apr 14 22:41:39 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sun, 14 Apr 2013 19:41:39 -0700 (PDT) Subject: Threadpool item mailboxes design problem In-Reply-To: References: Message-ID: Charles Hixson? 2013?4?15????UTC+8??7?12?11???? > What is the best approach to implementing actors that accept and post > > messages (and have no other external contacts). > > > > So far what I've come up with is something like: > > actors = {} > > mailboxs = {} > > > > Stuff actors with actor instances, mailboxes with multiprocessing.queue > > instances. (Actors and mailboxes will have identical keys, which are > > id#, but it's got to be a dict rather than a list, because too many are > > rolled out to disk.) And I'm planning of having the actors running > > simultaneously and continually in a threadpool that just loops through > > the actors that are assigned to each thread of the pool. > > > > This lets any actor post messages to the mailbox of any other actor that > > it has the id of, and lets him read his own mail without > > multi-processing clashes. But I'm quite uncertain that this is the best > > way, because, if nothing else, it means that each mailbox needs to be > > allocated large enough to handle the maximum amount of mail it could > > possibly receive. (I suppose I could implement some sort of "wait > > awhile and try again" method.) It would, however, be better if the > > mailbox could be specific to the threadpool instance, so less space > > would be wasted. Or if the queues could dynamically resize. Or if > > there was a threadsafe dict. Or... But I don't know that any of these > > are feasible. (I mean, yes, I could write all the mail to a database, > > but is that a better answer, or even a good one?) > > > > -- > > Charles Hixson Actors can receive and response to messages to take actions accordingly in time in one or more cores. The timer is required and the message read/write operations are required. Do you want the actors to gain new methods to evolve in the long run? From dihedral88888 at googlemail.com Sun Apr 14 22:41:39 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sun, 14 Apr 2013 19:41:39 -0700 (PDT) Subject: Threadpool item mailboxes design problem In-Reply-To: References: Message-ID: Charles Hixson? 2013?4?15????UTC+8??7?12?11???? > What is the best approach to implementing actors that accept and post > > messages (and have no other external contacts). > > > > So far what I've come up with is something like: > > actors = {} > > mailboxs = {} > > > > Stuff actors with actor instances, mailboxes with multiprocessing.queue > > instances. (Actors and mailboxes will have identical keys, which are > > id#, but it's got to be a dict rather than a list, because too many are > > rolled out to disk.) And I'm planning of having the actors running > > simultaneously and continually in a threadpool that just loops through > > the actors that are assigned to each thread of the pool. > > > > This lets any actor post messages to the mailbox of any other actor that > > it has the id of, and lets him read his own mail without > > multi-processing clashes. But I'm quite uncertain that this is the best > > way, because, if nothing else, it means that each mailbox needs to be > > allocated large enough to handle the maximum amount of mail it could > > possibly receive. (I suppose I could implement some sort of "wait > > awhile and try again" method.) It would, however, be better if the > > mailbox could be specific to the threadpool instance, so less space > > would be wasted. Or if the queues could dynamically resize. Or if > > there was a threadsafe dict. Or... But I don't know that any of these > > are feasible. (I mean, yes, I could write all the mail to a database, > > but is that a better answer, or even a good one?) > > > > -- > > Charles Hixson Actors can receive and response to messages to take actions accordingly in time in one or more cores. The timer is required and the message read/write operations are required. Do you want the actors to gain new methods to evolve in the long run? From dreamingforward at gmail.com Sun Apr 14 23:48:05 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Sun, 14 Apr 2013 20:48:05 -0700 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages Message-ID: Hello, I'm new to the list and hoping this might be the right place to introduce something that has provoked a bit of an argument in my programming community. I'm from the Python programming community. Python is an "interpreted" language. Since 2001, Python's has migrated towards a "pure" Object model (ref: http://www.python.org/download/releases/2.2/descrintro/). Prior to then, it had both types and classes and these types were anchored to the underlying C code and the machine/hardware architecture itself. After the 2001 "type/class unification" , it went towards Alan Kay's ideal of "everything is an object". From then, every user-defined class inherited from the abstract Object, rooted in nothing but a pure abstract ideal. The parser, lexer, and such spin these abstrations into something that can be run on the actual hardware. As a contrast, this is very distinct from C++, where everything is concretely rooted in the language's type model which in *itself* is rooted (from it's long history) in the CPU architecture. The STL, for example, has many Container types, but each of them requires using a single concrete type for homogenous containers or uses machine pointers to hold arbitrary items in heterogeneous containers (caveat: I haven't programmed in C++ for a long time, so it's possible this might not be correct anymore). My question is: Is there something in the Computer Science literature that has noticed this distinction/development in programming language design and history? It's very significant to me, because as languages went higher and higher to this pure OOP model, the programmer+data ecosystem tended towards very personal object hierarchies because now the hardware no longer formed a common basis of interaction (note also, OOPs promise of re-usable code never materialized). It's not unlike LISP, where the power of its general language architecture tended towards hyperpersonal mini macro languages -- making it hardly used, in practice, though it was and is so powerful, in theory. That all being said, the thrust of this whole effort is to possibly advance Computer Science and language design, because in-between the purely concrete "object" architecture of the imperative programming languages and the purely abstract object architecture of object-oriented programming languages is a possible middle ground that could unite them all. Thank you for your time. Mark Janssen Tacoma, Washington From tjreedy at udel.edu Mon Apr 15 00:56:02 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Mon, 15 Apr 2013 00:56:02 -0400 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: Message-ID: Note: cross-posting to mailing lists does not work well. Hence the reply only to python-list and the gmane mirror. On 4/14/2013 11:48 PM, Mark Janssen wrote: > Python is an "interpreted" language. I consider this a useless or even deceptive statement. Python is an object-based algorithm language. The CPython implementation (currently) *compiles* Python code to a virtual machine bytecode, similar to Java bytecode. This could change. Jython translates to Java, which is then compiled to Java bytecode. Do you call Java an 'interpreted' language? There are compilers that compile Python to the same 'object code' that C is compiled to. >Since 2001, Python's has migrated towards a "pure" Object model. It migrated towards a pure class model. > model (ref: http://www.python.org/download/releases/2.2/descrintro/). > Prior to then, it had both types and classes and these types were > anchored to the underlying C code and the machine/hardware > architecture itself. I started with Python 1.3 and I have no idea what you mean by this. I think you are heavily confusing Python the language and CPython the implementation. > After the 2001 "type/class unification" , it > went towards Alan Kay's ideal of "everything is an object". Everything has always been an object with value and identity. This stands in contrast to the assemble/C model that everything (except registers) is a block of linear memory with an address. > My question is: Is there something in the Computer Science literature > that has noticed this distinction/development in programming language > design and history? To me, there should be, since this is a fundamental distinction in data models. I think the biggest problem in shifting from C to Python is 'getting' the data model difference. For Lispers, the difference is the syntax. -- Terry Jan Reedy From delesley at gmail.com Mon Apr 15 01:55:59 2013 From: delesley at gmail.com (DeLesley Hutchins) Date: Sun, 14 Apr 2013 22:55:59 -0700 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: Message-ID: I'm not quite sure I understand your question, but I'll give it a shot. :-) The C/C++ model, in which the types are anchored to the machine hardware, in the exception, not the rule. In the academic literature, "type theory" is almost entirely focused on studying abstract models of computation that are purely mathematical, and bear no resemblance to the underlying hardware. The lambda calculus is the most general, and most commonly used formalism, but there are many others; e.g. Featherweight Java provides a formal model of objects and classes as they are used in Java. "Types and Programming Languages", by Benjamin Pierce, is an excellent introductory textbook which describes how various language features, including objects, can be formalized. If you are interested in OOP, Abadi and Cardelli's "Theory of Objects" is the obvious place to start, although I'd recommend reading Pierce's book first if you want to understand it. :-) Abadi and Cardelli discuss both class-based languages, and pure object languages. If you are interested in the type/object distinction in particular, then I'll shamelessly plug my own thesis: "Pure Subtype Systems" (available online), which describes a formal model in which types are objects, and objects are types. If you are familiar with the Self language, then you can think of it as a type system for Self. Once you have a type system in place, it's usually fairly straightforward to compile a language down to actual hardware. An interpreter, like that used in Python, is generally needed only for untyped or "dynamic" languages. There are various practical considerations -- memory layout, boxed or unboxed data types, garbage collection, etc. -- but the basic techniques are described in any compiler textbook. Research in the areas of "typed assembly languages" and "proof carrying code" are concerned with ensuring that the translation from high-level language to assembly language is sound, and well-typed at all stages. -DeLesley On Sun, Apr 14, 2013 at 8:48 PM, Mark Janssen wrote: > [ The Types Forum, http://lists.seas.upenn.edu/mailman/listinfo/types-list] > > Hello, > > I'm new to the list and hoping this might be the right place to > introduce something that has provoked a bit of an argument in my > programming community. > > I'm from the Python programming community. Python is an "interpreted" > language. Since 2001, Python's has migrated towards a "pure" Object > model (ref: http://www.python.org/download/releases/2.2/descrintro/). > Prior to then, it had both types and classes and these types were > anchored to the underlying C code and the machine/hardware > architecture itself. After the 2001 "type/class unification" , it > went towards Alan Kay's ideal of "everything is an object". From > then, every user-defined class inherited from the abstract Object, > rooted in nothing but a pure abstract ideal. The parser, lexer, and > such spin these abstrations into something that can be run on the > actual hardware. > > As a contrast, this is very distinct from C++, where everything is > concretely rooted in the language's type model which in *itself* is > rooted (from it's long history) in the CPU architecture. The STL, > for example, has many Container types, but each of them requires using > a single concrete type for homogenous containers or uses machine > pointers to hold arbitrary items in heterogeneous containers (caveat: > I haven't programmed in C++ for a long time, so it's possible this > might not be correct anymore). > > My question is: Is there something in the Computer Science literature > that has noticed this distinction/development in programming language > design and history? > > It's very significant to me, because as languages went higher and > higher to this pure OOP model, the programmer+data ecosystem tended > towards very personal object hierarchies because now the hardware no > longer formed a common basis of interaction (note also, OOPs promise > of re-usable code never materialized). > > It's not unlike LISP, where the power of its general language > architecture tended towards hyperpersonal mini macro languages -- > making it hardly used, in practice, though it was and is so powerful, > in theory. > > That all being said, the thrust of this whole effort is to possibly > advance Computer Science and language design, because in-between the > purely concrete "object" architecture of the imperative programming > languages and the purely abstract object architecture of > object-oriented programming languages is a possible middle ground that > could unite them all. > > Thank you for your time. > > Mark Janssen > Tacoma, Washington > -------------- next part -------------- An HTML attachment was scrubbed... URL: From moezadel at outlook.com Mon Apr 15 05:53:38 2013 From: moezadel at outlook.com (Moez AbdelGawad) Date: Mon, 15 Apr 2013 04:53:38 -0500 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: , Message-ID: > Date: Sun, 14 Apr 2013 22:55:59 -0700 > From: delesley at gmail.com > To: dreamingforward at gmail.com > CC: types-list at lists.seas.upenn.edu; python-list at python.org > Subject: Re: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages > > [ The Types Forum, http://lists.seas.upenn.edu/mailman/listinfo/types-list ] > > I'm not quite sure I understand your question, but I'll give it a shot. :-) > I'm in this same camp too :) > The C/C++ model, in which the types are anchored to the machine hardware, > in the exception, not the rule. In the academic literature, "type theory" > is almost entirely focused on studying abstract models of computation that > are purely mathematical, and bear no resemblance to the underlying > hardware. The lambda calculus is the most general, and most commonly used > formalism, but there are many others; e.g. Featherweight Java provides a > formal model of objects and classes as they are used in Java. > > "Types and Programming Languages", by Benjamin Pierce, is an excellent > introductory textbook which describes how various language features, > including objects, can be formalized. If you are interested in OOP, Abadi > and Cardelli's "Theory of Objects" is the obvious place to start, although > I'd recommend reading Pierce's book first if you want to understand it. > :-) Abadi and Cardelli discuss both class-based languages, and pure > object languages. If you are interested in the type/object distinction in > particular, then I'll shamelessly plug my own thesis: "Pure Subtype > Systems" (available online), which describes a formal model in which types > are objects, and objects are types. If you are familiar with the Self > language, then you can think of it as a type system for Self. > Offering a different view, I'd like to (also, shamelessly) plug my own thesis: "NOOP: A Mathematical Model of OOP" (available online) in which I denotationally model nominally-typed (ie, statically-typed class-based) OO languages such as Java, C#, C++ and Scala (but not Python). In agreement with the most common tradition in PL research, types in NOOP are modeled abstractly as (certain) sets (of objects). NOOP largely mimics, for nominally-typed OO languages, what Cardelli, Cook, and others earlier did for structurally-typed OO languages. Regards, -Moez > Once you have a type system in place, it's usually fairly straightforward > to compile a language down to actual hardware. An interpreter, like that > used in Python, is generally needed only for untyped or "dynamic" > languages. There are various practical considerations -- memory layout, > boxed or unboxed data types, garbage collection, etc. -- but the basic > techniques are described in any compiler textbook. Research in the areas > of "typed assembly languages" and "proof carrying code" are concerned with > ensuring that the translation from high-level language to assembly language > is sound, and well-typed at all stages. > > -DeLesley > > > > On Sun, Apr 14, 2013 at 8:48 PM, Mark Janssen wrote: > > > [ The Types Forum, http://lists.seas.upenn.edu/mailman/listinfo/types-list] > > > > Hello, > > > > I'm new to the list and hoping this might be the right place to > > introduce something that has provoked a bit of an argument in my > > programming community. > > > > I'm from the Python programming community. Python is an "interpreted" > > language. Since 2001, Python's has migrated towards a "pure" Object > > model (ref: http://www.python.org/download/releases/2.2/descrintro/). > > Prior to then, it had both types and classes and these types were > > anchored to the underlying C code and the machine/hardware > > architecture itself. After the 2001 "type/class unification" , it > > went towards Alan Kay's ideal of "everything is an object". From > > then, every user-defined class inherited from the abstract Object, > > rooted in nothing but a pure abstract ideal. The parser, lexer, and > > such spin these abstrations into something that can be run on the > > actual hardware. > > > > As a contrast, this is very distinct from C++, where everything is > > concretely rooted in the language's type model which in *itself* is > > rooted (from it's long history) in the CPU architecture. The STL, > > for example, has many Container types, but each of them requires using > > a single concrete type for homogenous containers or uses machine > > pointers to hold arbitrary items in heterogeneous containers (caveat: > > I haven't programmed in C++ for a long time, so it's possible this > > might not be correct anymore). > > > > My question is: Is there something in the Computer Science literature > > that has noticed this distinction/development in programming language > > design and history? > > > > It's very significant to me, because as languages went higher and > > higher to this pure OOP model, the programmer+data ecosystem tended > > towards very personal object hierarchies because now the hardware no > > longer formed a common basis of interaction (note also, OOPs promise > > of re-usable code never materialized). > > > > It's not unlike LISP, where the power of its general language > > architecture tended towards hyperpersonal mini macro languages -- > > making it hardly used, in practice, though it was and is so powerful, > > in theory. > > > > That all being said, the thrust of this whole effort is to possibly > > advance Computer Science and language design, because in-between the > > purely concrete "object" architecture of the imperative programming > > languages and the purely abstract object architecture of > > object-oriented programming languages is a possible middle ground that > > could unite them all. > > > > Thank you for your time. > > > > Mark Janssen > > Tacoma, Washington > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dreamingforward at gmail.com Thu Apr 18 18:53:15 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Thu, 18 Apr 2013 15:53:15 -0700 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: Message-ID: On Mon, Apr 15, 2013 at 2:53 AM, Moez AbdelGawad wrote: >> I'm not quite sure I understand your question, but I'll give it a shot. >> :-) > > I'm in this same camp too :) I am very thankful for the references given by everyone. Unfortunately my library does not have the titles and it will be some time before I can acquire them. I hope it not too intrusive to offer a few points that I've garnered from this conversation until I can study the history further. The main thing that I notice is that there is a heavy "bias" in academia towards mathematical models. I understand that Turing Machines, for example, were originally abstract computational concepts before there was an implementation in hardware, so I have some sympathies with that view, yet, should not the "Science" of "Computer Science" concern itself with how to map these abstract computational concepts into actual computational hardware? Otherwise, why not keep the field within mathematics and philosophy (where Logic traditionally has been)? I find it remarkable, for example, that the simple continued application of And/Or/Not gates can perform all the computation that C.S. concerns itself with and these form the basis for computer science in my mind, along with Boolean logic. (The implementation of digital logic into physical hardware is where C.S. stops and Engineering begins, I would argue.) But still, it seems that there are two ends, two poles, to the whole computer science enterprise that haven't been sufficiently *separated* so that they can be appreciated: logic gates vs. logical "calculus" and symbols. There is very little crossover as I can see. Perhaps the problem is the common use of the Greek root "logikos"; in the former, it pertains to binary arithmetic, where in the latter, it retains it's original Greek pertaining to *speech* and symbols, "logos"). Further, one can notice that in the former, the progression has been towards more sophisticated Data Structures (hence the evolution towards Object-Orientation), where in the latter (I'm guessing, since it's not my area of expertise) the progression has been towards function sophistication (where recursion seems to be paramount). In any case, I look forward to diving into the books and references you've all offered so generously so that I can appreciate the field and its history better. Mark Janssen Pacific Lutheran University Tacoma, Washington From ian.g.kelly at gmail.com Thu Apr 18 19:30:48 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 18 Apr 2013 17:30:48 -0600 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: Message-ID: On Thu, Apr 18, 2013 at 4:53 PM, Mark Janssen wrote: > The main thing that I notice is that there is a heavy "bias" in > academia towards mathematical models. I understand that Turing > Machines, for example, were originally abstract computational concepts > before there was an implementation in hardware, so I have some > sympathies with that view, yet, should not the "Science" of "Computer > Science" concern itself with how to map these abstract computational > concepts into actual computational hardware? Why? You seem to have a notion that theoretical computer science is ultimately about programming. It's not, any more than theoretical physics is ultimately about how to build skyscrapers. Theoreticians don't discuss complicated languages like Python because it would be difficult to prove anything about computation using them. Programmers don't use constructs like Turing machines because they're not practical or useful for doing actual programming with. We're talking about two different groups of people who use different tools because they have very different objectives. > Otherwise, why not keep > the field within mathematics and philosophy (where Logic traditionally > has been)? Well now, that's an age-old debate. Ultimately what we call "computer science" does not encompass one single discipline. But I think they are generally kept under one academic umbrella because they are closely related, and there is value in working with colleagues in separate sub-fields. Certainly there is value in being passingly familiar with the theory side of things if one is going to be designing languages and writing parsers. Less so if one is primarily occupied with building inventory systems. > But still, it seems that there are two ends, two poles, to the whole > computer science enterprise that haven't been sufficiently *separated* > so that they can be appreciated: logic gates vs. logical "calculus" > and symbols. There is very little crossover as I can see. Perhaps > the problem is the common use of the Greek root "logikos"; in the > former, it pertains to binary arithmetic, where in the latter, it > retains it's original Greek pertaining to *speech* and symbols, > "logos"). Further, one can notice that in the former, the progression > has been towards more sophisticated Data Structures (hence the > evolution towards Object-Orientation), where in the latter (I'm > guessing, since it's not my area of expertise) the progression has > been towards function sophistication (where recursion seems to be > paramount). Okay, you've lost me again. What do logic gates have to do with data structures and OOP? What does symbolic logic have to do with functional programming? From moezadel at outlook.com Fri Apr 19 02:09:50 2013 From: moezadel at outlook.com (Moez AbdelGawad) Date: Fri, 19 Apr 2013 01:09:50 -0500 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: , , , Message-ID: > Date: Thu, 18 Apr 2013 15:53:15 -0700 > From: dreamingforward at gmail.com > To: types-list at lists.seas.upenn.edu > Subject: Re: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages > > I am very thankful for the references given by everyone. > Unfortunately my library does not have the titles and it will be some > time before I can acquire them. The official version of my PhD thesis is available at https://scholarship.rice.edu/handle/1911/70199 (A version more suitable for electronic browsing and online distribution is available at http://sdrv.ms/15qsJ5x ) -Moez -------------- next part -------------- An HTML attachment was scrubbed... URL: From jason.a.wilkins at gmail.com Fri Apr 19 02:31:08 2013 From: jason.a.wilkins at gmail.com (Jason Wilkins) Date: Fri, 19 Apr 2013 01:31:08 -0500 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: Message-ID: I don't quite think I understand what you are saying. Are you saying that mathematical models are not a good foundation for computer science because computers are really made out of electronic gates? All I need to do is show that my model reduces to some basic physical implementation (with perhaps some allowances for infinity) and then I can promptly forget about that messy business and proceed to use my clean mathematical model. The reason any model of computation exists is that it is easier to think about a problem in some terms than in others. By showing how to transform one model to another you make it possible to choose exactly how you wish to solve a problem. The reason we do not work directly in what are called "von Neumann machines" is that they are not convenient for all kinds of problems. However we can build a compiler to translate anything to anything else so we I don't see why anybody would care. On Thu, Apr 18, 2013 at 5:53 PM, Mark Janssen wrote: > [ The Types Forum, http://lists.seas.upenn.edu/mailman/listinfo/types-list] > > On Mon, Apr 15, 2013 at 2:53 AM, Moez AbdelGawad > wrote: > >> I'm not quite sure I understand your question, but I'll give it a shot. > >> :-) > > > > I'm in this same camp too :) > > I am very thankful for the references given by everyone. > Unfortunately my library does not have the titles and it will be some > time before I can acquire them. I hope it not too intrusive to offer > a few points that I've garnered from this conversation until I can > study the history further. > > The main thing that I notice is that there is a heavy "bias" in > academia towards mathematical models. I understand that Turing > Machines, for example, were originally abstract computational concepts > before there was an implementation in hardware, so I have some > sympathies with that view, yet, should not the "Science" of "Computer > Science" concern itself with how to map these abstract computational > concepts into actual computational hardware? Otherwise, why not keep > the field within mathematics and philosophy (where Logic traditionally > has been)? I find it remarkable, for example, that the simple > continued application of And/Or/Not gates can perform all the > computation that C.S. concerns itself with and these form the basis > for computer science in my mind, along with Boolean logic. (The > implementation of digital logic into physical hardware is where C.S. > stops and Engineering begins, I would argue.) > > But still, it seems that there are two ends, two poles, to the whole > computer science enterprise that haven't been sufficiently *separated* > so that they can be appreciated: logic gates vs. logical "calculus" > and symbols. There is very little crossover as I can see. Perhaps > the problem is the common use of the Greek root "logikos"; in the > former, it pertains to binary arithmetic, where in the latter, it > retains it's original Greek pertaining to *speech* and symbols, > "logos"). Further, one can notice that in the former, the progression > has been towards more sophisticated Data Structures (hence the > evolution towards Object-Orientation), where in the latter (I'm > guessing, since it's not my area of expertise) the progression has > been towards function sophistication (where recursion seems to be > paramount). > > In any case, I look forward to diving into the books and references > you've all offered so generously so that I can appreciate the field > and its history better. > > Mark Janssen > Pacific Lutheran University > Tacoma, Washington > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dreamingforward at gmail.com Sat Apr 20 02:02:22 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Fri, 19 Apr 2013 23:02:22 -0700 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: Message-ID: On Thu, Apr 18, 2013 at 11:31 PM, Jason Wilkins wrote: > I don't quite think I understand what you are saying. Are you saying that > mathematical models are not a good foundation for computer science because > computers are really made out of electronic gates? No, I'm really trying to point out that models based on Digital Logic vs. models based on Symbolic Logic are completely different -- they have different basiis. They are both types of "Maths", and that you can interchange them as a demonstration doesn't actually help the practical issue of keeping the two domains separate -- they have differing logics. It's like the domain of Natural numbers vs. the Complex, or perhaps the Natural and the Real. Yes you can translate back and forth, but they are for all practical purposes distinct and can't be mixed. > All I need to do is show that my model reduces to some basic physical > implementation (with perhaps some allowances for infinity) and then I can > promptly forget about that messy business and proceed to use my clean > mathematical model. If that's all you want to do, you can stick with Boolean Logic. > The reason any model of computation exists is that it is easier to think > about a problem in some terms than in others. By showing how to transform > one model to another you make it possible to choose exactly how you wish to > solve a problem. Yes, and I'm attempting to provide an argument that the (historically?) dominant model of symbolic calculus is misinforming the practical domain of working out differences and arguments within my own domain of the programming community. Unfortunately, my inexperience with the literature is actually betraying the validity of my point. > The reason we do not work directly in what are called "von Neumann machines" > is that they are not convenient for all kinds of problems. However we can > build a compiler to translate anything to anything else so we I don't see > why anybody would care. I'm trying to say that *I* care, because I can't seem to find the common ground that affects 1000's of people in the applied C.S. domain with the 1000's of people in the theoretical C.S. domain. MarkJ Tacoma From u.s.reddy at cs.bham.ac.uk Fri Apr 19 03:21:09 2013 From: u.s.reddy at cs.bham.ac.uk (Uday S Reddy) Date: Fri, 19 Apr 2013 08:21:09 +0100 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: Message-ID: <20848.61541.156000.365368@gargle.gargle.HOWL> Mark Janssen writes: > The main thing that I notice is that there is a heavy "bias" in > academia towards mathematical models. I understand that Turing > Machines, for example, were originally abstract computational concepts > before there was an implementation in hardware, so I have some > sympathies with that view, yet, should not the "Science" of "Computer > Science" concern itself with how to map these abstract computational > concepts into actual computational hardware? I think there is some misunderstanding here. Being "mathematical" in academic work is a way of making our ideas rigorous and precise, instead of trying to peddle wooly nonsense. Providing a mathematical description does not imply in any way that these ideas are not implementable on machines. In fact, very often these mathematical descriptions state precisely how to implement the concepts (called operational semantics), but using mathematical notation instead of program code. The mathematical notation used here is usually no more than high school set theory, used in a stylized way. In contrast, there are deeper "mathematical models" (called denotational semantics and axiomatic semantics) which are invented to describe how programming language features work in a deep, intrinsic way. This is similar to, for instance, how Physics invents mathematical models to capture how the nature around us works. Physicists don't need to "implement" nature. It has already been "implemented" for us before we are born. However, to understand how it works, and how to design systems using physical materials in a predictable way, we need the mathematical models that Physics has develeped. Similarly, the mathematical models of programming languages help us to obtain a deep understanding of how languages work and how to build systems in a predictable, reliable way. It seems too much to expect, at the present stage of our field, that all programmers should understand the mathematical models. But I would definitely expect that programming language designers who are trying to build new languages should understand the mathematical models. Otherwise, they would be like automotive engineers trying to build cars without knowing any Mechanics. Cheers, Uday Reddy -- Prof. Uday Reddy Tel: +44 121 414 2740 Professor of Computer Science Fax: +44 121 414 4281 School of Computer Science University of Birmingham Email: U.S.Reddy at cs.bham.ac.uk Edgbaston Birmingham B15 2TT Web: http://www.cs.bham.ac.uk/~udr From dreamingforward at gmail.com Sat Apr 20 02:37:56 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Fri, 19 Apr 2013 23:37:56 -0700 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: <20848.61541.156000.365368@gargle.gargle.HOWL> References: <20848.61541.156000.365368@gargle.gargle.HOWL> Message-ID: > I think there is some misunderstanding here. Being "mathematical" in > academic work is a way of making our ideas rigorous and precise, instead of > trying to peddle wooly nonsense. I'm sorry. I am responsible for the misunderstanding. I used the word "math" when I really mean symbolic logic (which, historically, was part of philosophy). My point is that the field is confusing because it seems to ignore binary logic in favor of symbolic logic. Is binary logic not "rigorous and precise" enough? -- MarkJ Tacoma, Washington From claus.reinke at talk21.com Fri Apr 19 04:25:42 2013 From: claus.reinke at talk21.com (Claus Reinke) Date: Fri, 19 Apr 2013 10:25:42 +0200 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: Message-ID: <53160CDFC4344A68B946665DE7281152@VAIO> > The main thing that I notice is that there is a heavy "bias" in > academia towards mathematical models. I understand that Turing > Machines, for example, were originally abstract computational concepts > before there was an implementation in hardware, so I have some > sympathies with that view, yet, should not the "Science" of "Computer > Science" concern itself with how to map these abstract computational > concepts into actual computational hardware? I prefer to think of Turing machines as an attempt to model existing and imagined hardware (at the time, mostly human computers, or groups of them with comparatively simple tools). See sections 1. and 9. in Turing, "On computable numbers, with an application to the Entscheidungsproblem", http://web.comlab.ox.ac.uk/oucl/research/areas/ieg/e-library/sources/tp2-ie.pdf Modeling existing systems, in order to be able to reason about them, is essential for science, as is translating models into experiments, in order to compare predictions to reality. Claus From rustompmody at gmail.com Thu Apr 18 23:35:17 2013 From: rustompmody at gmail.com (rusi) Date: Thu, 18 Apr 2013 20:35:17 -0700 (PDT) Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages References: Message-ID: <10511876-84bf-41f5-ad96-cf4ee5a6973e@di5g2000pbc.googlegroups.com> On Apr 19, 3:53?am, Mark Janssen wrote: > On Mon, Apr 15, 2013 at 2:53 AM, Moez AbdelGawad wrote: > >> I'm not quite sure I understand your question, but I'll give it a shot. > >> :-) > > > I'm in this same camp too :) > > I am very thankful for the references given by everyone. > Unfortunately my library does not have the titles and it will be some > time before I can acquire them. ?I hope it not too intrusive to offer > a few points that I've garnered from this conversation until I can > study the history further. You may want to see this: http://www.infoq.com/presentations/Functional-Thinking > > The main thing that I notice is that there is a heavy "bias" in > academia towards mathematical models. Yeah wonderful observation. Lets clean up! If I have a loop: while i < len(a) and a[i] != x: i++ I need to understand that at the end of the loop: i >= len(a) or a[i] == x and not i >= len(a) and a[i] == x nor i == len(a) or a[i] == x # What if I forgot to initialize i? Now why bother to teach students such a silly thing (and silly name) as deMorgan? So all hail to your project of cleaning up the useless math from CS. And to whet your appetite for the grandeur and glory of your visionings why not start with making music schools enroll tone-deaf students? Why wasn't Beethoven deaf? > ?I understand that Turing > Machines, for example, were originally abstract computational concepts > before there was an implementation in hardware, so I have some > sympathies with that view, yet, should not the "Science" of "Computer > Science" concern itself with how to map these abstract computational > concepts into actual computational hardware? ?Otherwise, why not keep > the field within mathematics and philosophy (where Logic traditionally > has been)? ? I find it remarkable, for example, that the simple > continued application of And/Or/Not gates can perform all the > computation that C.S. concerns itself with and these form the basis > for computer science in my mind, along with Boolean logic. ?(The > implementation of digital logic into physical hardware is where C.S. > stops and Engineering begins, I would argue.) You need to study some history (or is that irrelevant like math?) The Turing who invented the Turing machine in 1936 led the code- cracking efforts of the allies a couple of years later. Do you allow for the fact that he may have had abilities that were common to both aka 'math' 'theory' etc? Or do you believe that winning wars is a theoretical and irrelevant exercise? > > But still, it seems that there are two ends, two poles, to the whole > computer science enterprise that haven't been sufficiently *separated* > so that they can be appreciated: ?logic gates vs. logical "calculus" > and symbols. ? There is very little crossover as I can see. ?Perhaps > the problem is the common use of the Greek root "logikos"; in the > former, it pertains to binary arithmetic, where in the latter, it > retains it's original Greek pertaining to *speech* and symbols, > "logos"). Yes there is some truth in what you say. Just call it logic as object- language (what you call logic-gates) and logic as meta-language ie logic for reasoning [the above line is not sarcastic] > Further, one can notice that in the former, the progression > has been towards more sophisticated Data Structures (hence the > evolution towards Object-Orientation), where in the latter (I'm > guessing, since it's not my area of expertise) the progression has > been towards function sophistication (where recursion seems to be > paramount). Also good to study the views of one of the doyens of OOP: http://en.wikipedia.org/wiki/Alexander_Stepanov#Criticism_of_OOP From dreamingforward at gmail.com Thu Apr 18 23:58:20 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Thu, 18 Apr 2013 20:58:20 -0700 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: <10511876-84bf-41f5-ad96-cf4ee5a6973e@di5g2000pbc.googlegroups.com> References: <10511876-84bf-41f5-ad96-cf4ee5a6973e@di5g2000pbc.googlegroups.com> Message-ID: >> The main thing that I notice is that there is a heavy "bias" in >> academia towards mathematical models. > > Yeah wonderful observation. Lets clean up! > > If I have a loop: > > while i < len(a) and a[i] != x: > i++ > > I need to understand that at the end of the loop: > i >= len(a) or a[i] == x > and not > i >= len(a) and a[i] == x > nor > i == len(a) or a[i] == x # What if I forgot to initialize i? You know in my world, we have what's called Input/Output, rather than punchcards or switchbanks where you come from. Why not: "print i,a[i]". Done! > Now why bother to teach students such a silly thing (and silly name) > as deMorgan? Well deMorgan falls into BooleanLogic which I'm arguing is distinct from the the mathematical realm where the lambda calculus wizards come from. So that's my camp, thanks. > So all hail to your project of cleaning up the useless math from CS. Yes, on useless math, no on *useful* math. Thanks. > And to whet your appetite for the grandeur and glory of your > visionings why not start with making music schools enroll tone-deaf > students? Why wasn't Beethoven deaf? Beethoven was deaf. > You need to study some history (or is that irrelevant like math?) > The Turing who invented the Turing machine in 1936 led the code- > cracking efforts of the allies a couple of years later. > Do you allow for the fact that he may have had abilities that were > common to both aka 'math' 'theory' etc? > Or do you believe that winning wars is a theoretical and irrelevant > exercise? Please, I don't dismiss math anymore than a number theorist might dismiss the realm of complex numbers. > Yes there is some truth in what you say. Just call it logic as object- > language (what you call logic-gates) and logic as meta-language ie > logic for reasoning Right, and I'm arguing that there hasn't been enough conceptual separation between the two. So why are you arguing? > Also good to study the views of one of the doyens of OOP: > http://en.wikipedia.org/wiki/Alexander_Stepanov#Criticism_of_OOP That's a very good reference. It voices some of my points that are in criticism of python's object architecture. -- MarkJ Tacoma, Washington From rosuav at gmail.com Fri Apr 19 03:05:41 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 19 Apr 2013 17:05:41 +1000 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: <10511876-84bf-41f5-ad96-cf4ee5a6973e@di5g2000pbc.googlegroups.com> References: <10511876-84bf-41f5-ad96-cf4ee5a6973e@di5g2000pbc.googlegroups.com> Message-ID: On Fri, Apr 19, 2013 at 1:35 PM, rusi wrote: > If I have a loop: > > while i < len(a) and a[i] != x: > i++ > > I need to understand that at the end of the loop: > i >= len(a) or a[i] == x > and not > i >= len(a) and a[i] == x > nor > i == len(a) or a[i] == x # What if I forgot to initialize i? Or your program has crashed out with an exception. >>> i,a,x=-10,"test","q" >>> while i < len(a) and a[i] != x: i+=1 Traceback (most recent call last): File "", line 1, in while i < len(a) and a[i] != x: IndexError: string index out of range Or if that had been in C, it could have bombed with a segfault rather than a nice tidy exception. Definitely initialize i. But yeah, the basis of algebra is helpful, even critical, to understanding most expression evaluators. ChrisA From dreamingforward at gmail.com Tue Apr 16 19:16:42 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Tue, 16 Apr 2013 16:16:42 -0700 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: Message-ID: > I'm not quite sure I understand your question, but I'll give it a shot. :-) Thank you, and my apologies for my late reply. > The C/C++ model, in which the types are anchored to the machine hardware, in > the exception, not the rule. In the academic literature, "type theory" is > almost entirely focused on studying abstract models of computation that are > purely mathematical, and bear no resemblance to the underlying hardware. > The lambda calculus is the most general, and most commonly used formalism, > but there are many others; e.g. Featherweight Java provides a formal model > of objects and classes as they are used in Java. Understood, but I feel this is where theory has gone too far away from reality. Wikipedia (admittedly not an authoritative resource), lists a clear distinction between languages rooted to the Turing machine, and those rooted in lambda calculus: From: en.wikipedia.org: Programming_paradigm: "A programming paradigm is a fundamental style of computer programming. There are four main paradigms: object-oriented, imperative, functional and declarative. Their foundations are distinct models of computation: Turing machine for object-oriented and imperative programming, lambda calculus for functional programming, and first order logic for logic programming." While I understand the interest in purely theoretical models, I wonder two things: 1) Are these distinct models of computation valid? And, 2) If so, shouldn't a theory of types announce what model of computation they are working from? You say the C/C++ model is the exception, but in the programmer community (excepting web-based languages) it is the opposite. The machine model dominates. In fact, I'm not even sure how Java operates, but through some sorcery I don't want to take part in. > "Types and Programming Languages", by Benjamin Pierce, is an excellent > introductory textbook which describes how various language features, > including objects, can be formalized. If you are interested in OOP, Abadi > and Cardelli's "Theory of Objects" is the obvious place to start, although > I'd recommend reading Pierce's book first if you want to understand it. :-) > Abadi and Cardelli discuss both class-based languages, and pure object > languages. If you are interested in the type/object distinction in > particular, then I'll shamelessly plug my own thesis: "Pure Subtype Systems" > (available online), which describes a formal model in which types are > objects, and objects are types. If you are familiar with the Self language, > then you can think of it as a type system for Self. Thank you very much. I will look for them. > Once you have a type system in place, it's usually fairly straightforward to > compile a language down to actual hardware. An interpreter, like that used > in Python, is generally needed only for untyped or "dynamic" languages. > There are various practical considerations -- memory layout, boxed or > unboxed data types, garbage collection, etc. -- but the basic techniques are > described in any compiler textbook. Research in the areas of "typed > assembly languages" and "proof carrying code" are concerned with ensuring > that the translation from high-level language to assembly language is sound, > and well-typed at all stages. Very interesting. I appreciate the those leads.... -- MarkJ Tacoma, Washington From ian.g.kelly at gmail.com Tue Apr 16 19:52:46 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 16 Apr 2013 17:52:46 -0600 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: Message-ID: On Tue, Apr 16, 2013 at 5:16 PM, Mark Janssen wrote: > Understood, but I feel this is where theory has gone too far away from > reality. How so? Turing machines and lambda calculus were both invented in the 30s, before any real mechanical computers existed. If anything, it is programming that has strayed too far from theory. ;-) > While I understand the interest in purely theoretical models, I wonder > two things: 1) Are these distinct models of computation valid? If they provide an algorithmic/mechanical means of solving problems, then they are valid models of computation. An abacus is a valid model of computation, although I wouldn't want to compute a million digits of pi on it. I may be missing what you really mean by "valid" here. > 2) If so, shouldn't a theory of types announce what model of > computation they are working from? > > You say the C/C++ model is the exception, but in the programmer > community (excepting web-based languages) it is the opposite. The > machine model dominates. In C/C++ the types are based on the hardware. You have 16-bit ints and 32-bit ints and 64-bit floats and what not because those are the types that fit neatly in the storage units of the hardware. In higher-level languages like Python, the types are abstract, not based on the hardware. Python doesn't have 32-bit ints, except as an implementation detail that the programmer need not be aware of. Python ints have arbitrary precision. > In fact, I'm not even sure how Java > operates, but through some sorcery I don't want to take part in. It compiles to an intermediate language that is executed by a virtual machine, much like Python. From u.s.reddy at cs.bham.ac.uk Wed Apr 17 05:30:36 2013 From: u.s.reddy at cs.bham.ac.uk (Uday S Reddy) Date: Wed, 17 Apr 2013 10:30:36 +0100 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: Message-ID: <20846.27580.375000.899631@gargle.gargle.HOWL> Mark Janssen writes: > From: en.wikipedia.org: Programming_paradigm: > > "A programming paradigm is a fundamental style of computer > programming. There are four main paradigms: object-oriented, > imperative, functional and declarative. Their foundations are distinct > models of computation: Turing machine for object-oriented and > imperative programming, lambda calculus for functional programming, > and first order logic for logic programming." > > While I understand the interest in purely theoretical models, I wonder > two things: 1) Are these distinct models of computation valid? And, > 2) If so, shouldn't a theory of types announce what model of > computation they are working from? These distinctions are not fully valid. - Functional programming, logic programming and imperative programming are three different *computational mechanisms*. - Object-orientation and abstract data types are two different ways of building higher-level *abstractions*. The authors of this paragraph did not understand that computational mechanisms and higher-level abstractions are separate, orthogonal dimensions in programming language design. All six combinations, obtained by picking a computational mechanism from the first bullet and an abstraction mechanism from the second bullet, are possible. It is a mistake to put object-orientation in the first bullet. Their idea of "paradigm" is vague and ill-defined. Cheers, Uday Reddy From nikhil at acm.org Wed Apr 17 10:04:02 2013 From: nikhil at acm.org (Rishiyur Nikhil) Date: Wed, 17 Apr 2013 10:04:02 -0400 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: <20846.27580.375000.899631@gargle.gargle.HOWL> References: <20846.27580.375000.899631@gargle.gargle.HOWL> Message-ID: > If you have trouble getting hold of "The Essence of Algol", ... There seems to be a downloadable copy at: www.cs.cmu.edu/~crary/819-f09/Reynolds81.ps It's in PostScript, which is easily convertible to PDF if you wish. Nikhil On Wed, Apr 17, 2013 at 5:30 AM, Uday S Reddy wrote: > [ The Types Forum, http://lists.seas.upenn.edu/mailman/listinfo/types-list] > > Mark Janssen writes: > > > From: en.wikipedia.org: Programming_paradigm: > > > > "A programming paradigm is a fundamental style of computer > > programming. There are four main paradigms: object-oriented, > > imperative, functional and declarative. Their foundations are distinct > > models of computation: Turing machine for object-oriented and > > imperative programming, lambda calculus for functional programming, > > and first order logic for logic programming." > > > > While I understand the interest in purely theoretical models, I wonder > > two things: 1) Are these distinct models of computation valid? And, > > 2) If so, shouldn't a theory of types announce what model of > > computation they are working from? > > These distinctions are not fully valid. > > - Functional programming, logic programming and imperative programming are > three different *computational mechanisms*. > > - Object-orientation and abstract data types are two different ways of > building higher-level *abstractions*. > > The authors of this paragraph did not understand that computational > mechanisms and higher-level abstractions are separate, orthogonal > dimensions > in programming language design. All six combinations, obtained by picking > a > computational mechanism from the first bullet and an abstraction mechanism > from the second bullet, are possible. It is a mistake to put > object-orientation in the first bullet. Their idea of "paradigm" is vague > and ill-defined. > > Cheers, > Uday Reddy > -------------- next part -------------- An HTML attachment was scrubbed... URL: From andreas.abel at ifi.lmu.de Wed Apr 17 10:42:25 2013 From: andreas.abel at ifi.lmu.de (Andreas Abel) Date: Wed, 17 Apr 2013 16:42:25 +0200 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: <20846.27580.375000.899631@gargle.gargle.HOWL> References: <20846.27580.375000.899631@gargle.gargle.HOWL> Message-ID: <516EB4D1.1020103@ifi.lmu.de> On 17.04.2013 11:30, Uday S Reddy wrote: > Mark Janssen writes: > >> From: en.wikipedia.org: Programming_paradigm: >> >> "A programming paradigm is a fundamental style of computer >> programming. There are four main paradigms: object-oriented, >> imperative, functional and declarative. Their foundations are distinct >> models of computation: Turing machine for object-oriented and >> imperative programming, lambda calculus for functional programming, >> and first order logic for logic programming." I removed the second sentence relating paradigms to computation models and put it on the talk page instead. It does not make sense to connect imperative programming to Turing machines like functional programming to lambda calculus. A better match would be random access machines, but the whole idea of a connection between a programming paradigm and a computation model is misleading. >> While I understand the interest in purely theoretical models, I wonder >> two things: 1) Are these distinct models of computation valid? And, >> 2) If so, shouldn't a theory of types announce what model of >> computation they are working from? > > These distinctions are not fully valid. > > - Functional programming, logic programming and imperative programming are > three different *computational mechanisms*. > > - Object-orientation and abstract data types are two different ways of > building higher-level *abstractions*. > > The authors of this paragraph did not understand that computational > mechanisms and higher-level abstractions are separate, orthogonal dimensions > in programming language design. All six combinations, obtained by picking a > computational mechanism from the first bullet and an abstraction mechanism > from the second bullet, are possible. It is a mistake to put > object-orientation in the first bullet. Their idea of "paradigm" is vague > and ill-defined. > > Cheers, > Uday Reddy > -- Andreas Abel <>< Du bist der geliebte Mensch. Theoretical Computer Science, University of Munich Oettingenstr. 67, D-80538 Munich, GERMANY andreas.abel at ifi.lmu.de http://www2.tcs.ifi.lmu.de/~abel/ From jason.a.wilkins at gmail.com Thu Apr 18 14:48:20 2013 From: jason.a.wilkins at gmail.com (Jason Wilkins) Date: Thu, 18 Apr 2013 13:48:20 -0500 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: <516EB4D1.1020103@ifi.lmu.de> References: <20846.27580.375000.899631@gargle.gargle.HOWL> <516EB4D1.1020103@ifi.lmu.de> Message-ID: Warning, this is a bit of a rant. That paragraph from Wikipedia seems to be confused. It gives the fourth paradigm as "declarative" but then says "first order logic for logic programming". It seems somebody did an incomplete replacement of "declarative" for "logic". Wikipedia is often schizophrenic like that. Personally, I think that object oriented and logical programming only became official paradigms because there was a certain level of hype for them in the 1980s and nobody has thought to strike them off the list after the hype died down. Object-oriented, as constituted today, is just a layer of abstraction over imperative programming (or imperative style programming in functional languages, because objects require side-effects). What "object-oriented" language actually in use now isn't just an imperative language with fancy abstraction mechanisms? The problem with having declarative languages as a paradigm (which logical languages would be a part) is that it feels like it should be a "miscellaneous" category. Being declarative doesn't tell you much except that some machine is going to turn your descriptions of something into some kind of action. In logical programming it is a set of predicates, but it could just as easily be almost anything else. In a way all languages are "declarative", it is just that we have some standard interpretations of what is declared that are very common (imperative and functional). My wish is that the idea of there being four paradigms would be abandoned the same we the idea of four food groups has been abandoned (which may surprise some of you). We have more than four different modes of thinking when programming and some are much more important than others and some are subsets of others. We should teach students a more sophisticated view. Ironically Wikipedia also shows us this complexity. The programming language paradigm side bar actually reveals the wealth of different styles that are available. There is simply no clean and useful way to overlay the four paradigms over what we see there, so it should be abandoned because it gives students a false idea. On Wed, Apr 17, 2013 at 9:42 AM, Andreas Abel wrote: > [ The Types Forum, http://lists.seas.upenn.edu/** > mailman/listinfo/types-list] > > On 17.04.2013 11:30, Uday S Reddy wrote: > >> Mark Janssen writes: >> >> From: en.wikipedia.org: Programming_paradigm: >>> >>> "A programming paradigm is a fundamental style of computer >>> programming. There are four main paradigms: object-oriented, >>> imperative, functional and declarative. Their foundations are distinct >>> models of computation: Turing machine for object-oriented and >>> imperative programming, lambda calculus for functional programming, >>> and first order logic for logic programming." >>> >> > I removed the second sentence relating paradigms to computation models > and put it on the talk page instead. It does not make sense to connect > imperative programming to Turing machines like functional programming to > lambda calculus. A better match would be random access machines, but the > whole idea of a connection between a programming paradigm and a computation > model is misleading. > > > While I understand the interest in purely theoretical models, I wonder >>> two things: 1) Are these distinct models of computation valid? And, >>> 2) If so, shouldn't a theory of types announce what model of >>> computation they are working from? >>> >> >> These distinctions are not fully valid. >> >> - Functional programming, logic programming and imperative programming are >> three different *computational mechanisms*. >> >> - Object-orientation and abstract data types are two different ways of >> building higher-level *abstractions*. >> >> The authors of this paragraph did not understand that computational >> mechanisms and higher-level abstractions are separate, orthogonal >> dimensions >> in programming language design. All six combinations, obtained by >> picking a >> computational mechanism from the first bullet and an abstraction mechanism >> from the second bullet, are possible. It is a mistake to put >> object-orientation in the first bullet. Their idea of "paradigm" is vague >> and ill-defined. >> >> Cheers, >> Uday Reddy >> >> > > -- > Andreas Abel <>< Du bist der geliebte Mensch. > > Theoretical Computer Science, University of Munich > Oettingenstr. 67, D-80538 Munich, GERMANY > > andreas.abel at ifi.lmu.de > http://www2.tcs.ifi.lmu.de/~**abel/ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rwh at cs.cmu.edu Thu Apr 18 17:14:13 2013 From: rwh at cs.cmu.edu (Robert Harper) Date: Thu, 18 Apr 2013 17:14:13 -0400 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: <20846.27580.375000.899631@gargle.gargle.HOWL> <516EB4D1.1020103@ifi.lmu.de> Message-ID: In short, there is no such thing as a "paradigm". I agree fully. This term is a holdover from the days when people spent time and space trying to build taxonomies based on ill-defined superficialities. See Steve Gould's essay "What, If Anything, Is A Zebra?". You'll enjoy learning that there is, in fact, no such thing as a zebra---there are, rather, three different striped horse-like mammals, two of which are genetically related, and one of which is not. The propensity to be striped, like the propensity to have five things (fingers, segments, whatever) is a deeply embedded genetic artifact that expresses itself in various ways. Bob Harper On Apr 18, 2013, at 2:48 PM, Jason Wilkins wrote: > [ The Types Forum, http://lists.seas.upenn.edu/mailman/listinfo/types-list ] > > Warning, this is a bit of a rant. > > That paragraph from Wikipedia seems to be confused. It gives the fourth > paradigm as "declarative" but then says "first order logic for logic > programming". It seems somebody did an incomplete replacement of > "declarative" for "logic". Wikipedia is often schizophrenic like that. > > Personally, I think that object oriented and logical programming only > became official paradigms because there was a certain level of hype for > them in the 1980s and nobody has thought to strike them off the list after > the hype died down. > > Object-oriented, as constituted today, is just a layer of abstraction over > imperative programming (or imperative style programming in functional > languages, because objects require side-effects). What "object-oriented" > language actually in use now isn't just an imperative language with fancy > abstraction mechanisms? > > The problem with having declarative languages as a paradigm (which logical > languages would be a part) is that it feels like it should be a > "miscellaneous" category. Being declarative doesn't tell you much except > that some machine is going to turn your descriptions of something into some > kind of action. In logical programming it is a set of predicates, but it > could just as easily be almost anything else. In a way all languages are > "declarative", it is just that we have some standard interpretations of > what is declared that are very common (imperative and functional). > > My wish is that the idea of there being four paradigms would be abandoned > the same we the idea of four food groups has been abandoned (which may > surprise some of you). We have more than four different modes of thinking > when programming and some are much more important than others and some are > subsets of others. We should teach students a more sophisticated view. > > Ironically Wikipedia also shows us this complexity. The > programming language paradigm side bar actually reveals the wealth > of different styles that are available. There is simply no clean and > useful way to overlay the four paradigms over what we see there, so it > should be abandoned because it gives students a false idea. > > > On Wed, Apr 17, 2013 at 9:42 AM, Andreas Abel wrote: > >> [ The Types Forum, http://lists.seas.upenn.edu/** >> mailman/listinfo/types-list] >> >> On 17.04.2013 11:30, Uday S Reddy wrote: >> >>> Mark Janssen writes: >>> >>> From: en.wikipedia.org: Programming_paradigm: >>>> >>>> "A programming paradigm is a fundamental style of computer >>>> programming. There are four main paradigms: object-oriented, >>>> imperative, functional and declarative. Their foundations are distinct >>>> models of computation: Turing machine for object-oriented and >>>> imperative programming, lambda calculus for functional programming, >>>> and first order logic for logic programming." >>>> >>> >> I removed the second sentence relating paradigms to computation models >> and put it on the talk page instead. It does not make sense to connect >> imperative programming to Turing machines like functional programming to >> lambda calculus. A better match would be random access machines, but the >> whole idea of a connection between a programming paradigm and a computation >> model is misleading. >> >> >> While I understand the interest in purely theoretical models, I wonder >>>> two things: 1) Are these distinct models of computation valid? And, >>>> 2) If so, shouldn't a theory of types announce what model of >>>> computation they are working from? >>>> >>> >>> These distinctions are not fully valid. >>> >>> - Functional programming, logic programming and imperative programming are >>> three different *computational mechanisms*. >>> >>> - Object-orientation and abstract data types are two different ways of >>> building higher-level *abstractions*. >>> >>> The authors of this paragraph did not understand that computational >>> mechanisms and higher-level abstractions are separate, orthogonal >>> dimensions >>> in programming language design. All six combinations, obtained by >>> picking a >>> computational mechanism from the first bullet and an abstraction mechanism >>> from the second bullet, are possible. It is a mistake to put >>> object-orientation in the first bullet. Their idea of "paradigm" is vague >>> and ill-defined. >>> >>> Cheers, >>> Uday Reddy >>> >>> >> >> -- >> Andreas Abel <>< Du bist der geliebte Mensch. >> >> Theoretical Computer Science, University of Munich >> Oettingenstr. 67, D-80538 Munich, GERMANY >> >> andreas.abel at ifi.lmu.de >> http://www2.tcs.ifi.lmu.de/~**abel/ >> From rwh at cs.cmu.edu Thu Apr 18 17:15:15 2013 From: rwh at cs.cmu.edu (Robert Harper) Date: Thu, 18 Apr 2013 17:15:15 -0400 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: <20846.27580.375000.899631@gargle.gargle.HOWL> <516EB4D1.1020103@ifi.lmu.de> Message-ID: The term "declarative" never meant a damn thing, but was often used, absurdly, to somehow lump together functional programming with logic programming, and separate it from imperative programming. It never made a lick of sense; it's just a marketing term. Bob Harper On Apr 18, 2013, at 2:48 PM, Jason Wilkins wrote: > [ The Types Forum, http://lists.seas.upenn.edu/mailman/listinfo/types-list ] > > Warning, this is a bit of a rant. > > That paragraph from Wikipedia seems to be confused. It gives the fourth > paradigm as "declarative" but then says "first order logic for logic > programming". It seems somebody did an incomplete replacement of > "declarative" for "logic". Wikipedia is often schizophrenic like that. > > Personally, I think that object oriented and logical programming only > became official paradigms because there was a certain level of hype for > them in the 1980s and nobody has thought to strike them off the list after > the hype died down. > > Object-oriented, as constituted today, is just a layer of abstraction over > imperative programming (or imperative style programming in functional > languages, because objects require side-effects). What "object-oriented" > language actually in use now isn't just an imperative language with fancy > abstraction mechanisms? > > The problem with having declarative languages as a paradigm (which logical > languages would be a part) is that it feels like it should be a > "miscellaneous" category. Being declarative doesn't tell you much except > that some machine is going to turn your descriptions of something into some > kind of action. In logical programming it is a set of predicates, but it > could just as easily be almost anything else. In a way all languages are > "declarative", it is just that we have some standard interpretations of > what is declared that are very common (imperative and functional). > > My wish is that the idea of there being four paradigms would be abandoned > the same we the idea of four food groups has been abandoned (which may > surprise some of you). We have more than four different modes of thinking > when programming and some are much more important than others and some are > subsets of others. We should teach students a more sophisticated view. > > Ironically Wikipedia also shows us this complexity. The > programming language paradigm side bar actually reveals the wealth > of different styles that are available. There is simply no clean and > useful way to overlay the four paradigms over what we see there, so it > should be abandoned because it gives students a false idea. > > > On Wed, Apr 17, 2013 at 9:42 AM, Andreas Abel wrote: > >> [ The Types Forum, http://lists.seas.upenn.edu/** >> mailman/listinfo/types-list] >> >> On 17.04.2013 11:30, Uday S Reddy wrote: >> >>> Mark Janssen writes: >>> >>> From: en.wikipedia.org: Programming_paradigm: >>>> >>>> "A programming paradigm is a fundamental style of computer >>>> programming. There are four main paradigms: object-oriented, >>>> imperative, functional and declarative. Their foundations are distinct >>>> models of computation: Turing machine for object-oriented and >>>> imperative programming, lambda calculus for functional programming, >>>> and first order logic for logic programming." >>>> >>> >> I removed the second sentence relating paradigms to computation models >> and put it on the talk page instead. It does not make sense to connect >> imperative programming to Turing machines like functional programming to >> lambda calculus. A better match would be random access machines, but the >> whole idea of a connection between a programming paradigm and a computation >> model is misleading. >> >> >> While I understand the interest in purely theoretical models, I wonder >>>> two things: 1) Are these distinct models of computation valid? And, >>>> 2) If so, shouldn't a theory of types announce what model of >>>> computation they are working from? >>>> >>> >>> These distinctions are not fully valid. >>> >>> - Functional programming, logic programming and imperative programming are >>> three different *computational mechanisms*. >>> >>> - Object-orientation and abstract data types are two different ways of >>> building higher-level *abstractions*. >>> >>> The authors of this paragraph did not understand that computational >>> mechanisms and higher-level abstractions are separate, orthogonal >>> dimensions >>> in programming language design. All six combinations, obtained by >>> picking a >>> computational mechanism from the first bullet and an abstraction mechanism >>> from the second bullet, are possible. It is a mistake to put >>> object-orientation in the first bullet. Their idea of "paradigm" is vague >>> and ill-defined. >>> >>> Cheers, >>> Uday Reddy >>> >>> >> >> -- >> Andreas Abel <>< Du bist der geliebte Mensch. >> >> Theoretical Computer Science, University of Munich >> Oettingenstr. 67, D-80538 Munich, GERMANY >> >> andreas.abel at ifi.lmu.de >> http://www2.tcs.ifi.lmu.de/~**abel/ >> From steve+comp.lang.python at pearwood.info Fri Apr 19 08:00:14 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Apr 2013 12:00:14 GMT Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages References: <20846.27580.375000.899631@gargle.gargle.HOWL> <516EB4D1.1020103@ifi.lmu.de> Message-ID: <517131cd$0$29977$c3e8da3$5496439d@news.astraweb.com> On Thu, 18 Apr 2013 17:14:13 -0400, Robert Harper wrote: > In short, there is no such thing as a "paradigm". Of course there is. A paradigm is a distinct way of thinking, a philosophy if you will. To say that there is no such thing as a paradigm is to say that all ways of thinking about a topic are the same, and that's clearly nonsense. OOP is a distinct paradigm from procedural programming, even though the distinctions are minor when compared to those between imperative and functional programming. Java's "everything in a class" style of programming is very distinct from Pascal's "functions and records" style of programming, even though both are examples of imperative programming. They lead to different styles of coding, they have different strengths and weaknesses, and even taking into account differences of syntax, they differ in what you can do simply and naturally without the language getting in the way. > I agree fully. This > term is a holdover from the days when people spent time and space trying > to build taxonomies based on ill-defined superficialities. See Steve > Gould's essay "What, If Anything, Is A Zebra?". You'll enjoy learning > that there is, in fact, no such thing as a zebra---there are, rather, > three different striped horse-like mammals, two of which are genetically > related, and one of which is not. All life on earth is genetically related. Even if the so-called "tree of life" doesn't have a single common ancestor, it has a single set of common ancestors. In the case of the three species of zebra, they are all members of the genus Equus, so they are actually *extremely* closely related. The argument that "zebra is not a genealogical group" (which is very different from the false statement that there is no such thing as a zebra!) is that one of the three species of zebra is in fact more closely related to non-zebras than the other two species of zebra. Something like this tree: Common ancestor of all Equus | +-- Common ancestor of Burchell's Zebras and Grevy's Zebras | +-- Burchell's Zebra | +-- Grevy's Zebra | +-- Common ancestor of horses and Mountain Zebras +-- Horse +-- Mountain Zebra (I've left out asses and donkeys because I'm not sure where they fit in relation to the others.) There's no natural genealogical group that includes all three species of zebra that doesn't also include horses. But that doesn't mean that there's no reasonable non-genealogical groups! For example, all three species of zebra have fewer than 50 chromosome pairs, while all other Equus species have more than 50 pairs. Based on physical characteristics rather than ancestry, zebras make up a perfectly good group, distinct from other members of Equus. To put it another way, the three species of zebra may not make up a natural group when considered by lines of descent, but they do make up a natural group when considered by other factors. > The propensity to be striped, like > the propensity to have five things (fingers, segments, whatever) is a > deeply embedded genetic artifact that expresses itself in various ways. "Zebra" is not a classification of "thing that is striped", but a specific subset of such things, and stripes are only one of many distinguishing features. Cladistics is an important classification scheme, but it is not the only valid such scheme. -- Steven From roy at panix.com Fri Apr 19 09:07:15 2013 From: roy at panix.com (Roy Smith) Date: Fri, 19 Apr 2013 09:07:15 -0400 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages References: <20846.27580.375000.899631@gargle.gargle.HOWL> <516EB4D1.1020103@ifi.lmu.de> <517131cd$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <517131cd$0$29977$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > On Thu, 18 Apr 2013 17:14:13 -0400, Robert Harper wrote: > > > In short, there is no such thing as a "paradigm". > > Of course there is. A paradigm is a distinct way of thinking, a > philosophy if you will. To say that there is no such thing as a paradigm > is to say that all ways of thinking about a topic are the same, and > that's clearly nonsense. This thread has gone off in a strange direction. When I said: > One of the nice things about OOP is it means so many different things to > different people. All of whom believe with religious fervor that they > know the true answer. I was indeed talking about the ways people think about programming. For example, OOP in C++ is very much about encapsulation. People declare all data private, and writing setter/getter functions which carefully control what access outside entities have to your data. Often, when you talk to C++ people, they will tell you that encapsulation is what OOP is all about. What they are doing is saying, C++ isa OOPL, and C++ has encapsulation, therefore OOPL implies encapsulation. When they look at something like Python, they say, "That's not object oriented because you don't have private data". I suppose people who grew up learning Python as their first language look at something like C++ and say, "That's not OOP because classes aren't objects", or something equally silly. From rosuav at gmail.com Fri Apr 19 09:33:01 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 19 Apr 2013 23:33:01 +1000 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: <20846.27580.375000.899631@gargle.gargle.HOWL> <516EB4D1.1020103@ifi.lmu.de> <517131cd$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Apr 19, 2013 at 11:07 PM, Roy Smith wrote: > I was indeed talking about the ways people think about programming. For > example, OOP in C++ is very much about encapsulation. People declare > all data private, and writing setter/getter functions which carefully > control what access outside entities have to your data. The funny thing about that notion is that, even in C++, it's completely optional. I've subclassed someone else's class using a struct and just left everything public. In fact, I've gotten so used to the Python way of doing things that now I'm quite happy to run everything public anyway. Is OOP truly about X if X is optional? ChrisA From roy at panix.com Fri Apr 19 11:31:48 2013 From: roy at panix.com (Roy Smith) Date: Fri, 19 Apr 2013 11:31:48 -0400 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages References: <20846.27580.375000.899631@gargle.gargle.HOWL> <516EB4D1.1020103@ifi.lmu.de> <517131cd$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Chris Angelico wrote: > On Fri, Apr 19, 2013 at 11:07 PM, Roy Smith wrote: > > I was indeed talking about the ways people think about programming. For > > example, OOP in C++ is very much about encapsulation. People declare > > all data private, and writing setter/getter functions which carefully > > control what access outside entities have to your data. > > The funny thing about that notion is that, even in C++, it's > completely optional. Well, yeah: #define private public #define protected public #include Not to mention all sorts of horrible things you can do with pointers and const_cast, etc. But that doesn't stop people from thinking that somehow they've built some uber-protected cocoon around their data, and that this is part and parcel of what OOPL is all about. From rosuav at gmail.com Fri Apr 19 11:40:26 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 20 Apr 2013 01:40:26 +1000 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: <20846.27580.375000.899631@gargle.gargle.HOWL> <516EB4D1.1020103@ifi.lmu.de> <517131cd$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Apr 20, 2013 at 1:31 AM, Roy Smith wrote: > #define private public > #define protected public > #include And: #define class struct But what I mean is that, _in my design_, I make everything public. No getters/setters, just direct member access. The theory behind getters and setters is that you can change the implementation without changing the interface... but I cannot remember a *single time* when I have made use of that flexibility. Not one. Nor a time when I've wished for that flexibility, after coding without it. No no, not one! ChrisA (He's telling the truth, he is not Mabel.) From roy at panix.com Fri Apr 19 12:02:00 2013 From: roy at panix.com (Roy Smith) Date: Fri, 19 Apr 2013 12:02:00 -0400 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages References: <20846.27580.375000.899631@gargle.gargle.HOWL> <516EB4D1.1020103@ifi.lmu.de> <517131cd$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Chris Angelico wrote: > On Sat, Apr 20, 2013 at 1:31 AM, Roy Smith wrote: > > #define private public > > #define protected public > > #include > > And: > #define class struct I suppose, while we're at it: # define const "" (I think that works, not sure). PS: a great C++ interview question is, "What's the difference between a class and a struct?" Amazing how few self-professed C++ experts have no clue. From steve+comp.lang.python at pearwood.info Fri Apr 19 12:16:18 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Apr 2013 16:16:18 GMT Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages References: <20846.27580.375000.899631@gargle.gargle.HOWL> <516EB4D1.1020103@ifi.lmu.de> <517131cd$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51716dd1$0$29977$c3e8da3$5496439d@news.astraweb.com> On Fri, 19 Apr 2013 12:02:00 -0400, Roy Smith wrote: > PS: a great C++ interview question is, "What's the difference between a > class and a struct?" Amazing how few self-professed C++ experts have no > clue. I'm not a C++ expert, but I am an inquiring mind, and I want to know the answer! -- Steven From ned at nedbatchelder.com Fri Apr 19 12:41:03 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 19 Apr 2013 12:41:03 -0400 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: <51716dd1$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <20846.27580.375000.899631@gargle.gargle.HOWL> <516EB4D1.1020103@ifi.lmu.de> <517131cd$0$29977$c3e8da3$5496439d@news.astraweb.com> <51716dd1$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5171739F.1030605@nedbatchelder.com> On 4/19/2013 12:16 PM, Steven D'Aprano wrote: > On Fri, 19 Apr 2013 12:02:00 -0400, Roy Smith wrote: > >> PS: a great C++ interview question is, "What's the difference between a >> class and a struct?" Amazing how few self-professed C++ experts have no >> clue. > I'm not a C++ expert, but I am an inquiring mind, and I want to know the > answer! > > The only difference between a class and a struct is that classes default to "private" access for their members, and structs default to "public". --Ned. From ian.g.kelly at gmail.com Fri Apr 19 12:38:31 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 19 Apr 2013 16:38:31 +0000 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: <51716dd1$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <20846.27580.375000.899631@gargle.gargle.HOWL> <516EB4D1.1020103@ifi.lmu.de> <517131cd$0$29977$c3e8da3$5496439d@news.astraweb.com> <51716dd1$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Apr 19, 2013 at 4:16 PM, Steven D'Aprano wrote: > On Fri, 19 Apr 2013 12:02:00 -0400, Roy Smith wrote: > >> PS: a great C++ interview question is, "What's the difference between a >> class and a struct?" Amazing how few self-professed C++ experts have no >> clue. > > I'm not a C++ expert, but I am an inquiring mind, and I want to know the > answer! C++ class members are private by default; struct members are public by default. That's the only difference as I recall. From dihedral88888 at googlemail.com Sat Apr 20 03:50:52 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sat, 20 Apr 2013 00:50:52 -0700 (PDT) Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: <20846.27580.375000.899631@gargle.gargle.HOWL> <516EB4D1.1020103@ifi.lmu.de> <517131cd$0$29977$c3e8da3$5496439d@news.astraweb.com> <51716dd1$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: Ned Batchelder? 2013?4?20????UTC+8??12?41?03???? > On 4/19/2013 12:16 PM, Steven D'Aprano wrote: > > > On Fri, 19 Apr 2013 12:02:00 -0400, Roy Smith wrote: > > > > > >> PS: a great C++ interview question is, "What's the difference between a > > >> class and a struct?" Amazing how few self-professed C++ experts have no > > >> clue. > > > I'm not a C++ expert, but I am an inquiring mind, and I want to know the > > > answer! > > > > > > > > The only difference between a class and a struct is that classes default > > to "private" access for their members, and structs default to "public". > > > > --Ned. In python even a class can be decorated. Also features of instances can be added at run time from programs by different programmers or even programs from machines by the code generation scheme used in many CAD tools. Nowadays the concept of a structure is not clear without specifying the language used in programming. A list is a structure of non-homogeneous types of items in LISP, PERL and PYTHON. But the cases are different in C++, PASCAL, ADDA, JAVA .... From roy at panix.com Fri Apr 19 19:40:22 2013 From: roy at panix.com (Roy Smith) Date: Fri, 19 Apr 2013 19:40:22 -0400 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages References: <516EB4D1.1020103@ifi.lmu.de> <517131cd$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Dennis Lee Bieber wrote: > On Fri, 19 Apr 2013 12:02:00 -0400, Roy Smith declaimed > the following in gmane.comp.python.general: > > > PS: a great C++ interview question is, "What's the difference between a > > class and a struct?" Amazing how few self-professed C++ experts have no > > clue. > > It's been 15+ years but... > > "class" defaults to private; " struct" defaults to public... (very > simplified ) You were doing well until you added the "very simplified" part :-) That is indeed the only difference. Many people are surprised that you can write member functions for structs. Or that you can subclass (substruct?) them. From steve+comp.lang.python at pearwood.info Fri Apr 19 12:37:59 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Apr 2013 16:37:59 GMT Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages References: <20846.27580.375000.899631@gargle.gargle.HOWL> <516EB4D1.1020103@ifi.lmu.de> <517131cd$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <517172e7$0$29977$c3e8da3$5496439d@news.astraweb.com> On Fri, 19 Apr 2013 09:07:15 -0400, Roy Smith wrote: > Often, when you talk to C++ people, they will tell you that > encapsulation is what OOP is all about. What they are doing is saying, > C++ isa OOPL, and C++ has encapsulation, therefore OOPL implies > encapsulation. When they look at something like Python, they say, > "That's not object oriented because you don't have private data". > > I suppose people who grew up learning Python as their first language > look at something like C++ and say, "That's not OOP because classes > aren't objects", or something equally silly. You might say that, but I find in my experience that Python users don't tend to fall for the "No True Scotsman" fallacy anywhere near as often as (say) Java or C++ users. I'm not sure what the reason for this is. Perhaps it is that the Python community as a whole is more open to other languages and paradigms, and less stuffed to the gills with code monkeys who only know how to copy and paste code from StackOverflow. The Python community frequently tosses around references to other languages, compares how Python would do something to other languages, or relates how certain features were borrowed from language X (e.g. list comprehensions are taken from Haskell; map, filter and reduce are taken from Lisp). But when I read forums and blogs about (say) Java, it's nearly always about Java in isolation, and one would be forgiven for thinking it was the only programming language in existence. I don't think that there is One True Way to design an OOP language, but I do think there are *degrees* of OOP. Java, for instance, I would say is only moderately OOP, since classes aren't objects, and it supports unboxed native types. I think the first part of that is a weakness, and the second is a pragmatic decision that on balance probably is a strength. Yes, Python's "everything is an object" is a cleaner design, but Java's unboxed types leads to faster code. It also depends on what you mean by OOP. If we judge Python by the fact that everything is an object, then it is strongly OOP. But if we judge Python by its syntax and idioms, it is only weakly OOP, even less than Java. -- Steven From roy at panix.com Fri Apr 19 19:37:38 2013 From: roy at panix.com (Roy Smith) Date: Fri, 19 Apr 2013 19:37:38 -0400 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages References: <20846.27580.375000.899631@gargle.gargle.HOWL> <516EB4D1.1020103@ifi.lmu.de> <517131cd$0$29977$c3e8da3$5496439d@news.astraweb.com> <517172e7$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: I wrote: > > I suppose people who grew up learning Python as their first language > > look at something like C++ and say, "That's not OOP because classes > > aren't objects", or something equally silly. > In article <517172e7$0$29977$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > You might say that, but I find in my experience that Python users don't > tend to fall for the "No True Scotsman" fallacy anywhere near as often as > (say) Java or C++ users. Now that I think about it, I suspect relatively few people learned Python as their first programming language. Java, for example, is very popular as a teaching language in colleges and universities. There are lots of people who go through a 4-year program, do all of their coursework in Java, and come out as one-trick ponies. There aren't many schools who teach Python as a first (and only language), but I suppose it's starting to catch on. 5 years from now, we may see waves of kids graduating from college knowing nothing but Python, with a similarly narrow view of the universe. From steve+comp.lang.python at pearwood.info Fri Apr 19 19:47:11 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Apr 2013 23:47:11 GMT Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages References: <20846.27580.375000.899631@gargle.gargle.HOWL> <516EB4D1.1020103@ifi.lmu.de> <517131cd$0$29977$c3e8da3$5496439d@news.astraweb.com> <517172e7$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5171d77f$0$29977$c3e8da3$5496439d@news.astraweb.com> On Fri, 19 Apr 2013 19:37:38 -0400, Roy Smith wrote: > There aren't many schools who teach Python as a first (and only > language), but I suppose it's starting to catch on. 5 years from now, > we may see waves of kids graduating from college knowing nothing but > Python, with a similarly narrow view of the universe. Send the young whipper-snappers here, we'll soon learn 'em better! -- Steven From u.s.reddy at cs.bham.ac.uk Mon Apr 15 05:06:21 2013 From: u.s.reddy at cs.bham.ac.uk (Uday S Reddy) Date: Mon, 15 Apr 2013 10:06:21 +0100 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: Message-ID: <20843.49933.673000.183228@gargle.gargle.HOWL> Mark Janssen writes: > After the 2001 "type/class unification" , it went towards Alan Kay's ideal > of "everything is an object".... > > As a contrast, this is very distinct from C++, where everything is > concretely rooted in the language's type model which in *itself* is > rooted (from it's long history) in the CPU architecture. ... > > My question is: Is there something in the Computer Science literature > that has noticed this distinction/development in programming language > design and history? In programming language theory, there is no law to the effect that "everything" should be of one kind or another. So, we would not go with Alan Kay's ideal. Having said that, theorists do want to unify concepts wherever possible and wherever they make sense. Imperative programming types, which I will call "storage types", are semantically the same as classes. Bare storage types have predefined operations for 'getting' and 'setting' whereas classes allow user-defined operations. So, the distinction made between them in typical programming languages is artificial and implementation-focused. C and C++ are especially prone to this problem because they were designed for writing compilers and operating systems where proximity to the machine architecture seems quite necessary. The higher-level languages such as Java are moving towards abolishing the distinction. Scala might be the best model in this respect, though I do not know its type system fully. Here are a couple of references in theoretical work that might be helpful in understanding these connections: - John Reynolds, The Essence of Algol, in de Bakker and van Vliet (eds) Algorithmic Languages, 1981. Also published in O'Hearn and Tennent (eds) Algol-like Languages, Vol. A, 1997. - Uday Reddy, Objects and Classes in Algol-like Languages, Information and Computation, 172:63-97, 2002. (previously in FOOL workshop 1998.) http://www.cs.bham.ac.uk/~udr/papers/classes.pdf However, there are properties that are special to storage types, which are not shared by all class types. Sometimes, they simplify some theoretical aspects. It is not uncommon for authors to make a distinction between storage types and general types. An example is one of our own papers: - Swarup, Reddy and Ireland: Assignments for applicative languages, FPCA 1991. http://www.cs.bham.ac.uk/~udr/papers/assign.pdf Cheers, Uday Reddy From dreamingforward at gmail.com Tue Apr 16 19:40:16 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Tue, 16 Apr 2013 16:40:16 -0700 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: <20843.49933.673000.183228@gargle.gargle.HOWL> References: <20843.49933.673000.183228@gargle.gargle.HOWL> Message-ID: On Mon, Apr 15, 2013 at 2:06 AM, Uday S Reddy wrote: > In programming language theory, there is no law to the effect that > "everything" should be of one kind or another. So, we would not go with > Alan Kay's ideal. I understand. I state Kay's points to show how the evolution of (this part of) the programming language world *in practice* has gone in its explorations. > Having said that, theorists do want to unify concepts wherever possible and > wherever they make sense. Imperative programming types, which I will call > "storage types", are semantically the same as classes. I like that word "storage type", it makes it much clearer what one is referring to. I feel like I'm having to "come up to speed" of the academic community, but wonder how and why this large chasm happened between the applied community and the theoretical. In my mind, despite the ideals of academia, students graduate and they inevitably come to work on Turing machines of some kind (Intel hardware, for example, currently dominates). If this is not in some way part of some "ideal", why did the business community adopt and deploy these most successfully? Or is it, in some *a priori* way, not possible to apply the abstract notions in academia into the real-world? > Bare storage types > have predefined operations for 'getting' and 'setting' whereas classes allow > user-defined operations. So, the distinction made between them in typical > programming languages is artificial and implementation-focused. C and C++ > are especially prone to this problem because they were designed for writing > compilers and operating systems where proximity to the machine architecture > seems quite necessary. The higher-level languages such as Java are moving > towards abolishing the distinction. Right, same with Python, but IMO this is where the evolution of programming languages is going awry. As languages move away from the machine, they're getting more based in different and disparate notions of types. From a practical standpoint, this makes interoperability and OOPs desire for "re-useability" recede. > Here are a couple of references in theoretical work that might be helpful in > understanding these connections: Thank you for those references. I will look into them. -- MarkJ Tacoma, Washington From ian.g.kelly at gmail.com Tue Apr 16 20:00:54 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 16 Apr 2013 18:00:54 -0600 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: <20843.49933.673000.183228@gargle.gargle.HOWL> Message-ID: On Tue, Apr 16, 2013 at 5:40 PM, Mark Janssen wrote: > I feel like I'm having to "come up to speed" of the academic > community, but wonder how and why this large chasm happened between > the applied community and the theoretical. In my mind, despite the > ideals of academia, students graduate and they inevitably come to work > on Turing machines of some kind (Intel hardware, for example, > currently dominates). Modern computers are based on the Von Neumann architecture, not Turing machines. > If this is not in some way part of some > "ideal", why did the business community adopt and deploy these most > successfully? Or is it, in some *a priori* way, not possible to apply > the abstract notions in academia into the real-world? Theory of computation is mostly about determining what kinds of problems fundamentally can or cannot be solved by computation. The models used are designed to be reasoned about, not to be used for solving real-world programming tasks. From u.s.reddy at cs.bham.ac.uk Wed Apr 17 05:10:58 2013 From: u.s.reddy at cs.bham.ac.uk (Uday S Reddy) Date: Wed, 17 Apr 2013 10:10:58 +0100 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: <20843.49933.673000.183228@gargle.gargle.HOWL> Message-ID: <20846.26402.656000.31662@gargle.gargle.HOWL> Mark Janssen writes: > > Having said that, theorists do want to unify concepts wherever possible > > and wherever they make sense. Imperative programming types, which I > > will call "storage types", are semantically the same as classes. > > I like that word "storage type", it makes it much clearer what one is > referring to. Indeed. However, this is not the only notion of type in imperative programming languages. For example, a function type in C or its descendants is not there to describe storage, but to describe the interface of an abstraction. I will use Reynolds's term "phrase types" to refer to such types. Reynolds's main point in "The Essence of Algol" was to say that phrase types are much more general, and a language can be built around them in a streamlined way. Perhaps "Streamlining Algol" would have been a more descriptive title for his paper. Nobody should be designing an imperative programming language without having read "The Essence of Algol", but they do. Whether storage types (and their generalization, class types) should be there in a type system at all is an open question. I can think of arguments both ways. In Java, classes are types. So are interfaces (i.e., phrase types). I think Java does a pretty good job of combining the two in a harmonious way. If you have trouble getting hold of "The Essence of Algol", please write to me privately and I can send you a scanned copy. The Handout 5B in my "Principles of Programming Languages" lecture notes is a quick summary of the Reynolds's type system. http://www.cs.bham.ac.uk/~udr/popl/index.html > I feel like I'm having to "come up to speed" of the academic > community, but wonder how and why this large chasm happened between > the applied community and the theoretical. In my mind, despite the > ideals of academia, students graduate and they inevitably come to work > on Turing machines of some kind (Intel hardware, for example, > currently dominates). If this is not in some way part of some > "ideal", why did the business community adopt and deploy these most > successfully? Or is it, in some *a priori* way, not possible to apply > the abstract notions in academia into the real-world? The chasms are too many, not only between theoretical and applied communities, but within each of them. My feeling is that this is inevitable. Our field progresses too fast for people to sit back, take stock of what we have and reconcile the multiple points of view. There is nothing wrong with "Turing machines". But the question in programming language design is how to integrate the Turing machine concepts with all the other abstractions we need (functions/procedures, modules, abstract data types etc.), i.e., how to fit the Turing machine concepts into the "big picture". That is not an easy question to resolve, and there isn't a single way of doing it. So you see multiple approaches being used in the practical programming languages, some cleaner than the others. The abstract notions of academia do make it into the real world, but rather more slowly than one would hope. Taking Java for example, the initial versions of Java treated interfaces in a half-hearted way, ignored generics/polymorphism, and ignored higher-order functions. But all of them are slowly making their way into Java, with pressure not only from the academic community but also through competition from other "practical" languages like Python, C# and Scala. If this kind of progress continues, that is the best we can hope for in a fast-paced field like ours. Cheers, Uday Reddy -- Prof. Uday Reddy Tel: +44 121 414 2740 Professor of Computer Science Fax: +44 121 414 4281 School of Computer Science University of Birmingham Email: U.S.Reddy at cs.bham.ac.uk Edgbaston Birmingham B15 2TT Web: http://www.cs.bham.ac.uk/~udr From dihedral88888 at googlemail.com Sun Apr 21 02:38:12 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sat, 20 Apr 2013 23:38:12 -0700 (PDT) Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: <20843.49933.673000.183228@gargle.gargle.HOWL> Message-ID: Uday S Reddy? 2013?4?17????UTC+8??5?10?58???? > Mark Janssen writes: > > > > > > Having said that, theorists do want to unify concepts wherever possible > > > > and wherever they make sense. Imperative programming types, which I > > > > will call "storage types", are semantically the same as classes. > > > The imperative part is supported in Python by tuples only. The name binding assignment of an object is perative in Python. Anyway it is not so difficult to mimic the behaviors and to gain the benefits of imperative languages at least in the c-python implementation by those who can play with the Python language in programming. From steve+comp.lang.python at pearwood.info Mon Apr 15 06:11:14 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Apr 2013 10:11:14 GMT Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages References: Message-ID: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> On Sun, 14 Apr 2013 20:48:05 -0700, Mark Janssen wrote: > Hello, > > I'm new to the list and hoping this might be the right place to > introduce something that has provoked a bit of an argument in my > programming community. > > I'm from the Python programming community. Python is an "interpreted" > language. Since 2001, Python's has migrated towards a "pure" Object > model (ref: http://www.python.org/download/releases/2.2/descrintro/). > Prior to then, it had both types and classes and these types were > anchored to the underlying C code and the machine/hardware architecture > itself. Incorrect. Python's data model has always been 100% object oriented. Prior to the "class/type" unification, it simply had *two distinct* implementations of objects: types, which were written in C, and classes, which were written in Python. After unification, the two kinds of object were no longer entirely distinct -- you could then subclass types in Python code, using the same "class" keyword as you would use for a pure-Python class. And starting with Python 3, the last vestiges of the distinction have disappeared. Now, "class" and "type" are mere synonyms. Both built-in types and custom classes use the same mechanism. > After the 2001 "type/class unification" , it went towards Alan > Kay's ideal of "everything is an object". From then, every user-defined > class inherited from the abstract Object, rooted in nothing but a pure > abstract ideal. Incorrect. In Python 2.7: py> class AClass: ... pass ... py> issubclass(AClass, object) False -- Steven From antoon.pardon at rece.vub.ac.be Mon Apr 15 13:43:32 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 15 Apr 2013 19:43:32 +0200 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: <516C3C44.6010706@rece.vub.ac.be> Op 15-04-13 12:11, Steven D'Aprano schreef: > > Python's data model has always been 100% object oriented. Prior to the > "class/type" unification, it simply had *two distinct* implementations of > objects: types, which were written in C, and classes, which were written > in Python. > > After unification, the two kinds of object were no longer entirely > distinct -- you could then subclass types in Python code, using the same > "class" keyword as you would use for a pure-Python class. > > And starting with Python 3, the last vestiges of the distinction have > disappeared. Now, "class" and "type" are mere synonyms. Both built-in > types and custom classes use the same mechanism. I had gotten my hopes up after reading this but then I tried: $ python3 Python 3.2.3 (default, Feb 20 2013, 17:02:41) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class vslice (slice): ... pass ... Traceback (most recent call last): File "", line 1, in TypeError: type 'slice' is not an acceptable base type It seems types and classes are still not mere synonyms. From davea at davea.name Mon Apr 15 17:13:44 2013 From: davea at davea.name (Dave Angel) Date: Mon, 15 Apr 2013 17:13:44 -0400 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: <516C3C44.6010706@rece.vub.ac.be> References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> Message-ID: <516C6D88.80808@davea.name> On 04/15/2013 01:43 PM, Antoon Pardon wrote: > Op 15-04-13 12:11, Steven D'Aprano schreef: > >> >> Python's data model has always been 100% object oriented. Prior to the >> "class/type" unification, it simply had *two distinct* implementations of >> objects: types, which were written in C, and classes, which were written >> in Python. >> >> After unification, the two kinds of object were no longer entirely >> distinct -- you could then subclass types in Python code, using the same >> "class" keyword as you would use for a pure-Python class. >> >> And starting with Python 3, the last vestiges of the distinction have >> disappeared. Now, "class" and "type" are mere synonyms. Both built-in >> types and custom classes use the same mechanism. > > I had gotten my hopes up after reading this but then I tried: > > > $ python3 > Python 3.2.3 (default, Feb 20 2013, 17:02:41) > [GCC 4.7.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> class vslice (slice): > ... pass > ... > Traceback (most recent call last): > File "", line 1, in > TypeError: type 'slice' is not an acceptable base type > > > It seems types and classes are still not mere synonyms. No, it seems you're trying to use an internal detail as though it were a supported feature. From page: http://docs.python.org/3.3/reference/datamodel.html#types """Internal types A few types used internally by the interpreter are exposed to the user. Their definitions may change with future versions of the interpreter, but they are mentioned here for completeness. """ -- DaveA From sg552 at hotmail.co.uk Mon Apr 15 18:12:05 2013 From: sg552 at hotmail.co.uk (Rotwang) Date: Mon, 15 Apr 2013 23:12:05 +0100 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> Message-ID: On 15/04/2013 22:13, Dave Angel wrote: > On 04/15/2013 01:43 PM, Antoon Pardon wrote: >> [...] >> >> I had gotten my hopes up after reading this but then I tried: >> >> >> $ python3 >> Python 3.2.3 (default, Feb 20 2013, 17:02:41) >> [GCC 4.7.2] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> class vslice (slice): >> ... pass >> ... >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: type 'slice' is not an acceptable base type >> >> >> It seems types and classes are still not mere synonyms. > > No, it seems you're trying to use an internal detail as though it were a > supported feature. > > From page: > http://docs.python.org/3.3/reference/datamodel.html#types > > """Internal types > A few types used internally by the interpreter are exposed to the user. > Their definitions may change with future versions of the interpreter, > but they are mentioned here for completeness. > """ To be fair, one can't do this either: Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> class C(type(lambda: None)): pass Traceback (most recent call last): File "", line 1, in class C(type(lambda: None)): TypeError: type 'function' is not an acceptable base type and I don't think that FunctionType would be considered an "internal detail", would it? Not that I'd cite the fact that not all types can be inherited from as evidence that types and classes are not synonyms, mind. From rosuav at gmail.com Mon Apr 15 18:32:45 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 16 Apr 2013 08:32:45 +1000 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> Message-ID: On Tue, Apr 16, 2013 at 8:12 AM, Rotwang wrote: > Traceback (most recent call last): > File "", line 1, in > class C(type(lambda: None)): > TypeError: type 'function' is not an acceptable base type > > > and I don't think that FunctionType would be considered an "internal > detail", would it? Not that I'd cite the fact that not all types can be > inherited from as evidence that types and classes are not synonyms, mind. Actually, I'm not sure how you'd go about inheriting from a function. Why not just create a bare class, then assign its __call__ to be the function you're inheriting from? ChrisA From dreamingforward at gmail.com Tue Apr 16 18:38:29 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Tue, 16 Apr 2013 15:38:29 -0700 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> Message-ID: On Mon, Apr 15, 2013 at 3:32 PM, Chris Angelico wrote: > On Tue, Apr 16, 2013 at 8:12 AM, Rotwang wrote: >> Traceback (most recent call last): >> File "", line 1, in >> class C(type(lambda: None)): >> TypeError: type 'function' is not an acceptable base type >> >> >> and I don't think that FunctionType would be considered an "internal >> detail", would it? Not that I'd cite the fact that not all types can be >> inherited from as evidence that types and classes are not synonyms, mind. > > Actually, I'm not sure how you'd go about inheriting from a function. > Why not just create a bare class, then assign its __call__ to be the > function you're inheriting from? I think his point remains valid, from a theoretical pov. Python prides itself on the idea of "first-class functions" and such, but unlike the world of lambda calculus, this selling point is a bit invalid. Because for Python (and any C-based language), it is roots squarely in the Turing machine and its real-word implementation. (Note this contrasts starkly with Java(script), which doesn't seem to be based on anything -- can anyone clarify where Java actually comes from?) -- MarkJ Tacoma, Washington From ian.g.kelly at gmail.com Tue Apr 16 19:14:45 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 16 Apr 2013 17:14:45 -0600 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> Message-ID: On Tue, Apr 16, 2013 at 4:38 PM, Mark Janssen wrote: > I think his point remains valid, from a theoretical pov. Python > prides itself on the idea of "first-class functions" and such, but > unlike the world of lambda calculus, this selling point is a bit > invalid. Because for Python (and any C-based language), it is roots > squarely in the Turing machine and its real-word implementation. I'm having a hard time following what you're trying to say here. Lambda calculus and Turing machines are theoretical models of computation, not languages. You can model Lisp programs with Turing machine, and you can model C programs with lambda expressions. Practically speaking you would probably have an easier time doing it the other way around, due to the procedural nature of the Turing machine versus the functional nature of the lambda calculus. By the usual definition of "first-class function" [1], Python functions are first-class; this has nothing to do with functional vs. procedural programming (although it is more commonly found in the former) or to do with Turing machines (which don't even include functions as a concept). > (Note this contrasts starkly with Java(script), which doesn't seem > to be based on anything -- can anyone clarify where Java actually > comes from?) I don't understand why you would consider Python to be "C-based" or "Turing machine-based" but not Java or Javascript. [1] http://en.wikipedia.org/wiki/First-class_citizen From torriem at gmail.com Thu Apr 18 12:37:17 2013 From: torriem at gmail.com (Michael Torrie) Date: Thu, 18 Apr 2013 10:37:17 -0600 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> Message-ID: <5170213D.2080207@gmail.com> On 04/16/2013 04:38 PM, Mark Janssen wrote: > (Note this contrasts starkly with Java(script), which doesn't seem > to be based on anything -- can anyone clarify where Java actually > comes from?) Java is not equal in any way with JavaScript. The only thing they share are semicolons and braces. Naming EMCAScript JavaScript was a very unfortunate thing indeed. For the record, JavaScript is what they call a "prototype-based language." http://en.wikipedia.org/wiki/Prototype-based_programming. You can emulate an OOP system with a prototype-based language. I highly recommend you read a book on formal programming language theory and concepts. From neilc at norwich.edu Thu Apr 18 13:57:13 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 18 Apr 2013 17:57:13 GMT Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> Message-ID: On 2013-04-18, Michael Torrie wrote: > On 04/16/2013 04:38 PM, Mark Janssen wrote: >> (Note this contrasts starkly with Java(script), which doesn't seem >> to be based on anything -- can anyone clarify where Java >> actually comes from?) > > Java is not equal in any way with JavaScript. The only thing > they share are semicolons and braces. Naming EMCAScript > JavaScript was a very unfortunate thing indeed. > > For the record, JavaScript is what they call a "prototype-based > language." http://en.wikipedia.org/wiki/Prototype-based_programming. > You can emulate an OOP system with a prototype-based language. > > I highly recommend you read a book on formal programming > language theory and concepts. Let me recommend Concepts, Techniques and Models of Computer Programming, Van Roy and Haridi. http://www.info.ucl.ac.be/~pvr/book.html -- Neil Cerutti From steve+comp.lang.python at pearwood.info Thu Apr 18 21:00:48 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Apr 2013 01:00:48 GMT Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> Message-ID: <51709740$0$29977$c3e8da3$5496439d@news.astraweb.com> On Thu, 18 Apr 2013 10:37:17 -0600, Michael Torrie wrote: > For the record, JavaScript is what they call a "prototype-based > language." http://en.wikipedia.org/wiki/Prototype-based_programming. > You can emulate an OOP system with a prototype-based language. Prototype languages *are* OOP. Note that it is called OBJECT oriented programming, not class oriented, and prototype-based languages are based on objects just as much as class-based languages. They are merely two distinct models for OOP. -- Steven From roy at panix.com Thu Apr 18 21:08:22 2013 From: roy at panix.com (Roy Smith) Date: Thu, 18 Apr 2013 21:08:22 -0400 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> <51709740$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <51709740$0$29977$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > On Thu, 18 Apr 2013 10:37:17 -0600, Michael Torrie wrote: > > > For the record, JavaScript is what they call a "prototype-based > > language." http://en.wikipedia.org/wiki/Prototype-based_programming. > > You can emulate an OOP system with a prototype-based language. > > Prototype languages *are* OOP. Note that it is called OBJECT oriented > programming, not class oriented, and prototype-based languages are based > on objects just as much as class-based languages. They are merely two > distinct models for OOP. One of the nice things about OOP is it means so many different things to different people. All of whom believe with religious fervor that they know the true answer. From dreamingforward at gmail.com Thu Apr 18 21:24:50 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Thu, 18 Apr 2013 18:24:50 -0700 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> <51709740$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: > One of the nice things about OOP is it means so many different things to > different people. All of whom believe with religious fervor that they > know the true answer. Here's a simple rule to resolve the ambiguity. Whoever publishes first, gets to claim origin of a word and its usage, kind of like a BDFL. The rest can adapt around that, make up their own word, or be corrected as the community requires. -- MarkJ Tacoma, Washington From ned at nedbatchelder.com Thu Apr 18 22:10:07 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 18 Apr 2013 22:10:07 -0400 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> <51709740$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5170A77F.7040002@nedbatchelder.com> On 4/18/2013 9:24 PM, Mark Janssen wrote: >> One of the nice things about OOP is it means so many different things to >> different people. All of whom believe with religious fervor that they >> know the true answer. > Here's a simple rule to resolve the ambiguity. Whoever publishes > first, gets to claim origin of a word and its usage, kind of like a > BDFL. The rest can adapt around that, make up their own word, or be > corrected as the community requires. > You won't solve the problem of confusing, ambiguous, or conflicting terminology by making up a rule. "Object-oriented" means subtly different things to different people. It turns out that computing is a complex field with subtle concepts that don't always fit neatly into a categorization. Python, Java, Javascript, Ruby, Smalltalk, Self, PHP, C#, Objective-C, and C++ are all "object-oriented", but they also all have differences between them. That's OK. We aren't going to make up a dozen words as alternatives to "object-oriented", one for each language. You seem to want to squeeze all of computer science and programming into a tidy hierarchy. It won't work, it's not tidy. I strongly suggest you read more about computer science before forming more opinions. You have a lot to learn ahead of you. --Ned. From dreamingforward at gmail.com Thu Apr 18 22:30:39 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Thu, 18 Apr 2013 19:30:39 -0700 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: <5170A77F.7040002@nedbatchelder.com> References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> <51709740$0$29977$c3e8da3$5496439d@news.astraweb.com> <5170A77F.7040002@nedbatchelder.com> Message-ID: On Thu, Apr 18, 2013 at 7:10 PM, Ned Batchelder wrote: > You won't solve the problem of confusing, ambiguous, or conflicting > terminology by making up a rule. "Object-oriented" means subtly different > things to different people. That's a problem, not a solution. > It turns out that computing is a complex field > with subtle concepts that don't always fit neatly into a categorization. But that is the point of having a *field*. > Python, Java, Javascript, Ruby, Smalltalk, Self, PHP, C#, Objective-C, and > C++ are all "object-oriented", but they also all have differences between > them. That's OK. We aren't going to make up a dozen words as alternatives > to "object-oriented", one for each language. Well, you won't, but other people *in the field* already have, fortunately. They have names like dynamically-typed, statically-typed, etc. > You seem to want to squeeze all of computer science and programming into a > tidy hierarchy. No on "squeeze" and "tidy". Maybe on "hierarchy". > It won't work, it's not tidy. I strongly suggest you read > more about computer science before forming more opinions. You have a lot to > learn ahead of you. Okay, professor is it, master? What is your provenance anyway? > --Ned. -- :) -- MarkJ Tacoma, Washington From ned at nedbatchelder.com Thu Apr 18 22:39:42 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 18 Apr 2013 22:39:42 -0400 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> <51709740$0$29977$c3e8da3$5496439d@news.astraweb.com> <5170A77F.7040002@nedbatchelder.com> Message-ID: <5170AE6E.8030806@nedbatchelder.com> On 4/18/2013 10:30 PM, Mark Janssen wrote: > Okay, professor is it, master? What is your provenance anyway? I'm not a professor, I'm a software engineer. I'm just trying to help. You've made statements that strike me as half-informed. You're trying to unify concepts that perhaps can't or shouldn't be unified. You've posted now to three different mailing lists about your thoughts on the nature of programming languages and object-orientation, and have apparently had little success in interesting people in them. A number of people have suggested that you study more about the topics you're interested in, and I agree with them. --Ned. From steve+comp.lang.python at pearwood.info Thu Apr 18 23:38:34 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Apr 2013 03:38:34 GMT Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> <51709740$0$29977$c3e8da3$5496439d@news.astraweb.com> <5170A77F.7040002@nedbatchelder.com> Message-ID: <5170bc3a$0$29977$c3e8da3$5496439d@news.astraweb.com> On Thu, 18 Apr 2013 19:30:39 -0700, Mark Janssen wrote: > On Thu, Apr 18, 2013 at 7:10 PM, Ned Batchelder > wrote: >> You won't solve the problem of confusing, ambiguous, or conflicting >> terminology by making up a rule. "Object-oriented" means subtly >> different things to different people. > > That's a problem, not a solution. It's a fact, not necessarily a problem. "Sandwich" means subtly different things to different people in different places, but human beings manage to cope, and very few people accidentally eat a sandwich of differently doped silicon crystals (i.e. a transistor) when they intended to eat a sandwich of bread and cheese. So long as people recognise the existence and nature of these subtle differences, it's all good. Java's OOP model is different from Python's, which is different from Lua's, which is different from Smalltalk's. That's all grand, they all have their strengths and weaknesses, and if all programming languages were the same, there would only be one. (And it would probably be PHP.) >> It turns out that computing is a complex field >> with subtle concepts that don't always fit neatly into a >> categorization. > > But that is the point of having a *field*. Reality is the way it is. However we would like fields of knowledge to neatly fit inside pigeonholes, they don't. >> Python, Java, Javascript, Ruby, Smalltalk, Self, PHP, C#, Objective-C, >> and C++ are all "object-oriented", but they also all have differences >> between them. That's OK. We aren't going to make up a dozen words as >> alternatives to "object-oriented", one for each language. > > Well, you won't, but other people *in the field* already have, > fortunately. They have names like dynamically-typed, statically-typed, > etc. They are not names for variations of OOP. They are independent of whether a language is OOP or not. For example: Java is statically typed AND object oriented. Haskell is statically typed but NOT object oriented. Python is dynamically typed AND object oriented. Scheme is dynamically typed but NOT object oriented. -- Steven From steve+comp.lang.python at pearwood.info Wed Apr 17 02:40:42 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Apr 2013 06:40:42 GMT Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> Message-ID: <516e43ea$0$29872$c3e8da3$5496439d@news.astraweb.com> On Tue, 16 Apr 2013 15:38:29 -0700, Mark Janssen wrote: > On Mon, Apr 15, 2013 at 3:32 PM, Chris Angelico > wrote: >> On Tue, Apr 16, 2013 at 8:12 AM, Rotwang wrote: >>> Traceback (most recent call last): >>> File "", line 1, in >>> class C(type(lambda: None)): >>> TypeError: type 'function' is not an acceptable base type >>> >>> >>> and I don't think that FunctionType would be considered an "internal >>> detail", would it? Not that I'd cite the fact that not all types can >>> be inherited from as evidence that types and classes are not synonyms, >>> mind. >> >> Actually, I'm not sure how you'd go about inheriting from a function. >> Why not just create a bare class, then assign its __call__ to be the >> function you're inheriting from? > > I think his point remains valid, from a theoretical pov. Python prides > itself on the idea of "first-class functions" and such, but unlike the > world of lambda calculus, this selling point is a bit invalid. Python functions are first-class functions, which is short-hand for saying "functions which are also capable of being treated as values, which means they can be created at run-time, returned from functions, passed around as arguments, and assigned to variables". Python's function type is not a first-class object-type, because it cannot be subclassed in at least three of the main implementations. But this has nothing to do with whether or not functions are first-class functions, which is an unrelated meaning. One can conceive of a language where FunctionType is a first-class type capable of being subclasses, but functions are *not* first-class values capable of being passed around as arguments. > Because for Python (and any C-based language), Python-the-language is not C-based, or at least, very little of Python is C-based. It's main influences are, according to GvR, Lisp and ABC, with Pascal, Haskell and of course C also having some influence. Syntax-wise, it is much more of an Algol-inspired language than a C-inspired language. > it is roots squarely in the > Turing machine and its real-word implementation. Python is certainly not inspired by Turing machines. Since a Turing machine is a simple device with an infinitely long paper tape which can have marks added and deleted from it, very few real programming languages are based on Turing machines. It is, however, Turing-complete. Just like every programming language worthy of the name, whether it has syntax like Python, C, Lisp, Forth, INTERCAL, Oook, Applescript, Inform-7, Java, PHP, or x86 assembler. > (Note this contrasts starkly with Java(script), which doesn't seem > to be based on anything -- can anyone clarify where Java actually comes > from?) C. -- Steven From rosuav at gmail.com Wed Apr 17 02:56:45 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Apr 2013 16:56:45 +1000 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: <516e43ea$0$29872$c3e8da3$5496439d@news.astraweb.com> References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> <516e43ea$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 17, 2013 at 4:40 PM, Steven D'Aprano wrote: > On Tue, 16 Apr 2013 15:38:29 -0700, Mark Janssen wrote: >> (Note this contrasts starkly with Java(script), which doesn't seem >> to be based on anything -- can anyone clarify where Java actually comes >> from?) > > C. offee. ChrisA From clp2 at rebertia.com Wed Apr 17 03:16:21 2013 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 17 Apr 2013 00:16:21 -0700 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: <516e43ea$0$29872$c3e8da3$5496439d@news.astraweb.com> References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> <516e43ea$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Apr 16, 2013 at 11:40 PM, Steven D'Aprano wrote: > On Tue, 16 Apr 2013 15:38:29 -0700, Mark Janssen wrote: > > (Note this contrasts starkly with Java(script), which doesn't seem > > to be based on anything -- can anyone clarify where Java actually comes > > from?) > > C. "Influenced by: Ada 83, C++, C#, Eiffel, Generic Java, Mesa, Modula-3, Oberon, Objective-C, UCSD Pascal, Smalltalk" "Categories: C programming language family | [...]" ? http://en.wikipedia.org/wiki/Java_(programming_language) Sincerely, Chris -- Read Wikipedia's infoboxes! People work hard on them! From sg552 at hotmail.co.uk Mon Apr 15 18:54:21 2013 From: sg552 at hotmail.co.uk (Rotwang) Date: Mon, 15 Apr 2013 23:54:21 +0100 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> Message-ID: On 15/04/2013 23:32, Chris Angelico wrote: > On Tue, Apr 16, 2013 at 8:12 AM, Rotwang wrote: >> Traceback (most recent call last): >> File "", line 1, in >> class C(type(lambda: None)): >> TypeError: type 'function' is not an acceptable base type >> >> >> and I don't think that FunctionType would be considered an "internal >> detail", would it? Not that I'd cite the fact that not all types can be >> inherited from as evidence that types and classes are not synonyms, mind. > > Actually, I'm not sure how you'd go about inheriting from a function. > Why not just create a bare class, then assign its __call__ to be the > function you're inheriting from? No idea. I wasn't suggesting that trying to inherit from FunctionType was a sensible thing to do; I was merely pointing out that slice's status as an internal feature was not IMO relevant to the point that Antoon was making. From tjreedy at udel.edu Mon Apr 15 20:52:58 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Mon, 15 Apr 2013 20:52:58 -0400 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: <516C3C44.6010706@rece.vub.ac.be> References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> Message-ID: On 4/15/2013 1:43 PM, Antoon Pardon wrote: > $ python3 > Python 3.2.3 (default, Feb 20 2013, 17:02:41) > [GCC 4.7.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> class vslice (slice): > ... pass > ... > Traceback (most recent call last): > File "", line 1, in > TypeError: type 'slice' is not an acceptable base type > > > It seems types and classes are still not mere synonyms. Some builtin classes cannot be subclassed. There is an issue to document which better. That does not mean that it is not a class. From steve+comp.lang.python at pearwood.info Mon Apr 15 22:32:59 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Apr 2013 02:32:59 GMT Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> Message-ID: <516cb85b$0$29977$c3e8da3$5496439d@news.astraweb.com> On Mon, 15 Apr 2013 20:52:58 -0400, Terry Jan Reedy wrote: > On 4/15/2013 1:43 PM, Antoon Pardon wrote: > >> $ python3 >> Python 3.2.3 (default, Feb 20 2013, 17:02:41) [GCC 4.7.2] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> class vslice (slice): >> ... pass >> ... >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: type 'slice' is not an acceptable base type >> >> >> It seems types and classes are still not mere synonyms. > > Some builtin classes cannot be subclassed. There is an issue to document > which better. That does not mean that it is not a class. I think it is also important to document whether that is a language feature, or a mere restriction of the implementation. There is an important distinction to be made between: "In CPython, you cannot subclass slice or FunctionType. Other Pythons may have more, or fewer, restrictions." and: "No language that calls itself Python is permitted to allow slice and FunctionType to be subclassable." If I had a say in this, I would vote for the first case, with the possible exception of documented singleton types like NoneType and bool. -- Steven From tjreedy at udel.edu Mon Apr 15 23:17:36 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Mon, 15 Apr 2013 23:17:36 -0400 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: <516cb85b$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> <516cb85b$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/15/2013 10:32 PM, Steven D'Aprano wrote: > On Mon, 15 Apr 2013 20:52:58 -0400, Terry Jan Reedy wrote: >> Some builtin classes cannot be subclassed. There is an issue to document >> which better. That does not mean that it is not a class. > > > I think it is also important to document whether that is a language > feature, or a mere restriction of the implementation. There is an > important distinction to be made between: > > "In CPython, you cannot subclass slice or FunctionType. Other Pythons may > have more, or fewer, restrictions." > > and: > > "No language that calls itself Python is permitted to allow slice and > FunctionType to be subclassable." > > > If I had a say in this, I would vote for the first case, with the > possible exception of documented singleton types like NoneType and bool. I will keep the above in mind if I write or review a patch. here are 4 non-subclassable builtin classes. Two are already documented. Bool in one, forget which other. I believe it was recently decided to leave the other two as is given the absence of any practical use case. From ian.g.kelly at gmail.com Tue Apr 16 00:46:49 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 15 Apr 2013 22:46:49 -0600 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> <516cb85b$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Apr 15, 2013 at 9:17 PM, Terry Jan Reedy wrote: > I will keep the above in mind if I write or review a patch. here are 4 > non-subclassable builtin classes. Two are already documented. Bool in one, > forget which other. I believe it was recently decided to leave the other two > as is given the absence of any practical use case. The four are bool, NoneType, slice and ellipsis, I believe. From storchaka at gmail.com Tue Apr 16 04:25:53 2013 From: storchaka at gmail.com (Serhiy Storchaka) Date: Tue, 16 Apr 2013 11:25:53 +0300 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> <516cb85b$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 16.04.13 07:46, Ian Kelly wrote: > On Mon, Apr 15, 2013 at 9:17 PM, Terry Jan Reedy wrote: >> I will keep the above in mind if I write or review a patch. here are 4 >> non-subclassable builtin classes. Two are already documented. Bool in one, >> forget which other. I believe it was recently decided to leave the other two >> as is given the absence of any practical use case. > > The four are bool, NoneType, slice and ellipsis, I believe. >>> import builtins >>> for n in dir(builtins): ... if type(getattr(builtins, n)) is type: ... try: ... t = type(n, (getattr(builtins, n),), {}) ... except TypeError as e: ... print(e) ... type 'bool' is not an acceptable base type type 'memoryview' is not an acceptable base type type 'range' is not an acceptable base type type 'slice' is not an acceptable base type From ethan at stoneleaf.us Tue Apr 16 13:29:18 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 16 Apr 2013 10:29:18 -0700 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> <516cb85b$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <516D8A6E.6020002@stoneleaf.us> On 04/16/2013 01:25 AM, Serhiy Storchaka wrote: > On 16.04.13 07:46, Ian Kelly wrote: >> On Mon, Apr 15, 2013 at 9:17 PM, Terry Jan Reedy wrote: >>> I will keep the above in mind if I write or review a patch. here are 4 >>> non-subclassable builtin classes. Two are already documented. Bool in one, >>> forget which other. I believe it was recently decided to leave the other two >>> as is given the absence of any practical use case. >> >> The four are bool, NoneType, slice and ellipsis, I believe. > > --> import builtins > --> for n in dir(builtins): > ... if type(getattr(builtins, n)) is type: > ... try: > ... t = type(n, (getattr(builtins, n),), {}) > ... except TypeError as e: > ... print(e) > ... > type 'bool' is not an acceptable base type > type 'memoryview' is not an acceptable base type > type 'range' is not an acceptable base type > type 'slice' is not an acceptable base type Well that bumps our count to five then: --> NoneType = type(None) --> NoneType --> class MoreNone(NoneType): ... pass ... Traceback (most recent call last): File "", line 1, in TypeError: type 'NoneType' is not an acceptable base type -- ~Ethan~ From tjreedy at udel.edu Tue Apr 16 14:29:40 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Tue, 16 Apr 2013 14:29:40 -0400 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: <516D8A6E.6020002@stoneleaf.us> References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> <516cb85b$0$29977$c3e8da3$5496439d@news.astraweb.com> <516D8A6E.6020002@stoneleaf.us> Message-ID: On 4/16/2013 1:29 PM, Ethan Furman wrote: > On 04/16/2013 01:25 AM, Serhiy Storchaka wrote: >> On 16.04.13 07:46, Ian Kelly wrote: >>> On Mon, Apr 15, 2013 at 9:17 PM, Terry Jan Reedy >>> wrote: >>>> I will keep the above in mind if I write or review a patch. here are 4 >>>> non-subclassable builtin classes. Two are already documented. Bool >>>> in one, >>>> forget which other. I believe it was recently decided to leave the >>>> other two >>>> as is given the absence of any practical use case. >>> >>> The four are bool, NoneType, slice and ellipsis, I believe. >> >> --> import builtins >> --> for n in dir(builtins): >> ... if type(getattr(builtins, n)) is type: >> ... try: >> ... t = type(n, (getattr(builtins, n),), {}) >> ... except TypeError as e: >> ... print(e) >> ... >> type 'bool' is not an acceptable base type >> type 'memoryview' is not an acceptable base type >> type 'range' is not an acceptable base type >> type 'slice' is not an acceptable base type > > Well that bumps our count to five then: > > --> NoneType = type(None) > --> NoneType > > --> class MoreNone(NoneType): > ... pass > ... > Traceback (most recent call last): > File "", line 1, in > TypeError: type 'NoneType' is not an acceptable base type 'NoneType' is not a builtin name in builtins, which is precisely why you accessed it the way you did ;-). From issue 17279 (for 3.3): "Attached subclassable.py produces these lists: Among named builtin classes, these cannot be subclassed: bool, memoryview, range, slice, Among types classes, these can be subclassed: ModuleType, SimpleNamespace," From ian.g.kelly at gmail.com Tue Apr 16 14:22:42 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 16 Apr 2013 12:22:42 -0600 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: <516D8A6E.6020002@stoneleaf.us> References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> <516cb85b$0$29977$c3e8da3$5496439d@news.astraweb.com> <516D8A6E.6020002@stoneleaf.us> Message-ID: On Tue, Apr 16, 2013 at 11:29 AM, Ethan Furman wrote: >>> The four are bool, NoneType, slice and ellipsis, I believe. >> >> >> --> import builtins >> --> for n in dir(builtins): >> >> ... if type(getattr(builtins, n)) is type: >> ... try: >> ... t = type(n, (getattr(builtins, n),), {}) >> ... except TypeError as e: >> ... print(e) >> ... >> type 'bool' is not an acceptable base type >> type 'memoryview' is not an acceptable base type >> type 'range' is not an acceptable base type >> type 'slice' is not an acceptable base type > > > Well that bumps our count to five then: Six. >>> class test(type(...)): pass ... Traceback (most recent call last): File "", line 1, in TypeError: type 'ellipsis' is not an acceptable base type From antoon.pardon at rece.vub.ac.be Tue Apr 16 05:07:38 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 16 Apr 2013 11:07:38 +0200 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> <516cb85b$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <516D14DA.5090406@rece.vub.ac.be> Op 16-04-13 05:17, Terry Jan Reedy schreef: > On 4/15/2013 10:32 PM, Steven D'Aprano wrote: >> On Mon, 15 Apr 2013 20:52:58 -0400, Terry Jan Reedy wrote: > >>> Some builtin classes cannot be subclassed. There is an issue to >>> document >>> which better. That does not mean that it is not a class. >> >> >> I think it is also important to document whether that is a language >> feature, or a mere restriction of the implementation. There is an >> important distinction to be made between: >> >> "In CPython, you cannot subclass slice or FunctionType. Other Pythons >> may >> have more, or fewer, restrictions." >> >> and: >> >> "No language that calls itself Python is permitted to allow slice and >> FunctionType to be subclassable." >> >> >> If I had a say in this, I would vote for the first case, with the >> possible exception of documented singleton types like NoneType and bool. > > I will keep the above in mind if I write or review a patch. here are 4 > non-subclassable builtin classes. Two are already documented. Bool in > one, forget which other. I believe it was recently decided to leave > the other two as is given the absence of any practical use case. Why should there be a practical use case here? Since classes are in general subclassable, shouldn't you have a reason to not make them so instead of people needing to give you a practical use case before you treat them as you do most of them? I once had an idea of a slice-like class that I would have liked to experiment with. As things were I didn't get far because slice not being subclassable was a major hurdle in getting it practical. Would the end result have been a practical use case? I don't know, I didn't get the chance to find out because making a class that looked like a slice didn't work either. Python wanted, maybe still wants, a real slice in a number of circumstances and not a ducktyped slice-like object. Now maybe there are good reasons for slice not being subclassable but there not being a practical use case doesn't seem to be one in this case. From tjreedy at udel.edu Tue Apr 16 12:49:01 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Tue, 16 Apr 2013 12:49:01 -0400 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: <516D14DA.5090406@rece.vub.ac.be> References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> <516cb85b$0$29977$c3e8da3$5496439d@news.astraweb.com> <516D14DA.5090406@rece.vub.ac.be> Message-ID: On 4/16/2013 5:07 AM, Antoon Pardon wrote: > Op 16-04-13 05:17, Terry Jan Reedy schreef: >> On 4/15/2013 10:32 PM, Steven D'Aprano wrote: >>> On Mon, 15 Apr 2013 20:52:58 -0400, Terry Jan Reedy wrote: >> >> I will keep the above in mind if I write or review a patch. here are 4 >> non-subclassable builtin classes. Two are already documented. Bool in >> one, forget which other. I believe it was recently decided to leave >> the other two as is given the absence of any practical use case. > > Why should there be a practical use case here? As a practical matter, the change is non-trivial. Someone has to be motivated to write the patch to enable subclassing, write tests, and consider the effect on internal C uses of slice and stdlib Python used of slice (type() versus isinstance). > Since classes are in general subclassable, if written in Python, but not if written in C. > I once had an idea of a slice-like class that I would have liked to > experiment with. Did the idea actually require that instances *be* a slice rather than *wrap* a slice? -- Terry Jan Reedy From antoon.pardon at rece.vub.ac.be Wed Apr 17 08:04:48 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 17 Apr 2013 14:04:48 +0200 Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> <516cb85b$0$29977$c3e8da3$5496439d@news.astraweb.com> <516D14DA.5090406@rece.vub.ac.be> Message-ID: <516E8FE0.5040005@rece.vub.ac.be> Op 16-04-13 18:49, Terry Jan Reedy schreef: > On 4/16/2013 5:07 AM, Antoon Pardon wrote: >> Op 16-04-13 05:17, Terry Jan Reedy schreef: >> >>> I will keep the above in mind if I write or review a patch. here are 4 >>> non-subclassable builtin classes. Two are already documented. Bool in >>> one, forget which other. I believe it was recently decided to leave >>> the other two as is given the absence of any practical use case. >> >> Why should there be a practical use case here? > > As a practical matter, the change is non-trivial. Someone has to be > motivated to write the patch to enable subclassing, write tests, and > consider the effect on internal C uses of slice and stdlib Python used > of slice (type() versus isinstance). I see. It seems I have underestimated the work involved. >> I once had an idea of a slice-like class that I would have liked to >> experiment with. > > Did the idea actually require that instances *be* a slice rather than > *wrap* a slice? As far as I remember I wanted my slice object usable to slice lists with. But python doesn't allow duck typing when you use your object to "index" a list. No matter how much your object resembles a slice, when you actualy try to use it to get a slice of a list, python throw a TypeError with the message "object cannot be interpreted as an index". This in combination with slice not being subclassable effectively killed the idea. As I already said I don't know if the idea would have turned up something usefull. The following years I never had the feeling how great it would have been should I have been able to pursue this idea. I just thought it was a pity I was so thoroughly stopped at the time. -- Antoon Pardon From rustompmody at gmail.com Tue Apr 16 00:56:12 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 15 Apr 2013 21:56:12 -0700 (PDT) Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> <516cb85b$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9eaff713-2376-4173-8325-a599e393ff20@gh3g2000pbd.googlegroups.com> On Apr 16, 7:32?am, Steven D'Aprano wrote: > > If I had a say in this, I would vote for the first case, with the > possible exception of documented singleton types like NoneType and bool. How is bool a singleton type? From steve+comp.lang.python at pearwood.info Tue Apr 16 01:59:23 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Apr 2013 05:59:23 GMT Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> <516C3C44.6010706@rece.vub.ac.be> <516cb85b$0$29977$c3e8da3$5496439d@news.astraweb.com> <9eaff713-2376-4173-8325-a599e393ff20@gh3g2000pbd.googlegroups.com> Message-ID: <516ce8ba$0$29872$c3e8da3$5496439d@news.astraweb.com> On Mon, 15 Apr 2013 21:56:12 -0700, rusi wrote: > On Apr 16, 7:32?am, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> >> If I had a say in this, I would vote for the first case, with the >> possible exception of documented singleton types like NoneType and >> bool. > > How is bool a singleton type? A doubleton, then. The point being, GvR declared that bool should guarantee the invariant that True and False are the only instances of bool, and if you can subclass it, either that invariant is violated, or you can't instantiate the subclass. -- Steven From steve+comp.lang.python at pearwood.info Mon Apr 15 22:15:00 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Apr 2013 02:15:00 GMT Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages References: <516bd241$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: <516cb424$0$29977$c3e8da3$5496439d@news.astraweb.com> On Mon, 15 Apr 2013 19:43:32 +0200, Antoon Pardon wrote: > Op 15-04-13 12:11, Steven D'Aprano schreef: > > >> Python's data model has always been 100% object oriented. Prior to the >> "class/type" unification, it simply had *two distinct* implementations >> of objects: types, which were written in C, and classes, which were >> written in Python. >> >> After unification, the two kinds of object were no longer entirely >> distinct -- you could then subclass types in Python code, using the >> same "class" keyword as you would use for a pure-Python class. >> >> And starting with Python 3, the last vestiges of the distinction have >> disappeared. Now, "class" and "type" are mere synonyms. Both built-in >> types and custom classes use the same mechanism. > > I had gotten my hopes up after reading this but then I tried: > > > $ python3 > Python 3.2.3 (default, Feb 20 2013, 17:02:41) [GCC 4.7.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> class vslice (slice): > ... pass > ... > Traceback (most recent call last): > File "", line 1, in > TypeError: type 'slice' is not an acceptable base type > > > It seems types and classes are still not mere synonyms. You are misinterpreting what you are reading. The mere fact that something cannot be subclassed doesn't mean anything. That's just a restriction put on the class by the implementation. It's not even clear that it is a guaranteed language restriction or a mere accident of implementation. With a bit of metaclass trickery, I could equally create a pure-Python class that cannot be easily subclassed. The proof that types and classes are the same in Python 3 is simple: py> class C: ... pass ... py> type(C) is type(int) is type(type) is type True The type of the pure-Python class is type itself. However, even this can be bypassed, using a metaclass! py> class D(metaclass=Meta): ... pass ... py> type(D) is type False py> issubclass(type(D), type) True So when using a metaclass, the type of the class is not necessarily type itself, but it will be a subclass of type. This does not hold in Python 2.x, not for old-style "classic" classes. Classic classes are in a world of their own, distinct from types: # Python 2 py> class C: ... pass ... py> type(C) py> issubclass(type(C), type) False In Python 3, we can expect these two conditions to always hold: * all instances are instances of object; * all classes are instances of type. Notice that this implies that type and object are circularly defined: object, being a class, is an instance of type, but type, being an object, is an instance of object: py> isinstance(type, object) True py> isinstance(object, type) True These two conditions even apply to unsubclassable objects like slice: py> isinstance(slice(1, 5, 2), object) True py> isinstance(slice, type) True -- Steven From dihedral88888 at googlemail.com Tue Apr 16 02:54:59 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Mon, 15 Apr 2013 23:54:59 -0700 (PDT) Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: Message-ID: <27d2da01-e732-4e72-b3ba-0c2f34c2cb2d@googlegroups.com> zipher? 2013?4?15????UTC+8??11?48?05???? > Hello, > > > > I'm new to the list and hoping this might be the right place to > > introduce something that has provoked a bit of an argument in my > > programming community. I'll state about my opinions about the imperative and non-imperative part. If the finite stack depth is used instead of the infinite one, then the auto local variables of the imperative part can be implemented quite safe and cheap or at least self-recoverable from a stack overflow event. This can save a lot burdens in the GC part in an imperative language. From dihedral88888 at googlemail.com Tue Apr 16 02:54:59 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Mon, 15 Apr 2013 23:54:59 -0700 (PDT) Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: Message-ID: <27d2da01-e732-4e72-b3ba-0c2f34c2cb2d@googlegroups.com> zipher? 2013?4?15????UTC+8??11?48?05???? > Hello, > > > > I'm new to the list and hoping this might be the right place to > > introduce something that has provoked a bit of an argument in my > > programming community. I'll state about my opinions about the imperative and non-imperative part. If the finite stack depth is used instead of the infinite one, then the auto local variables of the imperative part can be implemented quite safe and cheap or at least self-recoverable from a stack overflow event. This can save a lot burdens in the GC part in an imperative language. From rustompmody at gmail.com Sun Apr 21 11:44:32 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 21 Apr 2013 08:44:32 -0700 (PDT) Subject: The type/object distinction and possible synthesis of OOP and imperative programming languages References: Message-ID: On Apr 15, 8:48?am, Mark Janssen wrote: > That all being said, the thrust of this whole effort is to possibly > advance Computer Science and language design, because in-between the > purely concrete "object" architecture of the imperative programming > languages and the purely abstract object architecture of > object-oriented programming languages is a possible middle ground that > could unite them all. Just been poking around with eclipse. And saw this: http://softwaresimplexity.blogspot.in/2013/02/where-java-fails.html For context, the guy seems to be big in the java/eclipse community [Or at least is well hyped -- he's finalist for eclipse' best developer award] This context is needed to underscore something he says in one of the comments on that page: "OO just sucks?" From matthias at ccs.neu.edu Mon Apr 15 09:50:38 2013 From: matthias at ccs.neu.edu (Matthias Felleisen) Date: Mon, 15 Apr 2013 09:50:38 -0400 Subject: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages In-Reply-To: References: Message-ID: <1AD3C7F6-96F4-4E90-8849-84D6E53308E2@ccs.neu.edu> On Apr 14, 2013, at 11:48 PM, Mark Janssen wrote: > After the 2001 "type/class unification" , it went towards Alan Kay's ideal Are you sure? Remember Kay's two motivations [*], which he so elegantly describes with "[the] large scale one was to find a better module scheme for complex systems involving hiding of details, and the small scale one was to find a more flexible version of assignment, and then to try to eliminate it altogether." At least for me, this quote sends a signal to language designers that is still looking for a receiver -- Matthias [*] http://gagne.homedns.org/~tgagne/contrib/EarlyHistoryST.html From moraa.lovetakes2 at gmail.com Mon Apr 15 06:50:35 2013 From: moraa.lovetakes2 at gmail.com (Ombongi Moraa Fe) Date: Mon, 15 Apr 2013 13:50:35 +0300 Subject: Iterating dictionary items + if statement results in problems Message-ID: hello Team, I have this fairly simple script to iterate the dictionary items and check if the items match certain values; dictionary={'1234567890':001, '0987654321':002} for k, v in dictionary.iteritems(): ..... ..... #suds client statements; if (k == '1234567890' and v == 001): criteria='Test' elif (k == '0987654321' and v == 002): criteria='Running' client.service.methodcall(value1,value2,criteria) During the first run of the dictionary items, the client.service.methodcall is called only once as expected; and a success initiation response is received from server. However, during the second run, the client.service.methodcall is called twice - when i check the log files, i see the client send request is done twice. Duplicate send requests of the same parameters results in a error in inititating a connection. Someone please show me why my second run results in the client.service.methodcall() running twice. I can't seem to get a hang on it. Saludos Ombongi Moraa Faith -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Mon Apr 15 07:25:36 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 15 Apr 2013 12:25:36 +0100 Subject: Iterating dictionary items + if statement results in problems In-Reply-To: References: Message-ID: On 15/04/2013 11:50, Ombongi Moraa Fe wrote: > hello Team, > > I have this fairly simple script to iterate the dictionary items and > check if the items match certain values; > > dictionary={'1234567890':001, '0987654321':002} > for k, v in dictionary.iteritems(): > ..... > ..... #suds client statements; > > if (k == '1234567890' and v == 001): > criteria='Test' > elif (k == '0987654321' and v == 002): > criteria='Running' > client.service.methodcall(value1,value2,criteria) > > During the first run of the dictionary items, the > client.service.methodcall is called only once as expected; and a success > initiation response is received from server. However, during the second > run, the client.service.methodcall is called twice - when i check the > log files, i see the client send request is done twice. Duplicate send > requests of the same parameters results in a error in inititating a > connection. What makes you think there should be one call given the code above? client.service.methodcall must be called for every loop iteration, so there's one call with criteria 'test' and one with 'Running'. Note there's no guarantee that the calls will always take place in the same order. Slight aside there's no need for the round brackets in the if and elif above. > > Someone please show me why my second run results in the > client.service.methodcall() running twice. I can't seem to get a hang on > it. > > Saludos > > Ombongi Moraa Faith > > -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From __peter__ at web.de Mon Apr 15 07:31:03 2013 From: __peter__ at web.de (Peter Otten) Date: Mon, 15 Apr 2013 13:31:03 +0200 Subject: Iterating dictionary items + if statement results in problems References: Message-ID: Ombongi Moraa Fe wrote: > hello Team, > > I have this fairly simple script to iterate the dictionary items and check > if the items match certain values; > > dictionary={'1234567890':001, '0987654321':002} > for k, v in dictionary.iteritems(): > ..... > ..... #suds client statements; > > if (k == '1234567890' and v == 001): > criteria='Test' > elif (k == '0987654321' and v == 002): > criteria='Running' > client.service.methodcall(value1,value2,criteria) > > > > During the first run of the dictionary items, the > client.service.methodcall is called only once as expected; and a success > initiation response is received from server. However, during the second > run, the client.service.methodcall is called twice - when i check the log > files, i see the client send request is done twice. Duplicate send > requests of the same parameters results in a error in inititating a > connection. > > Someone please show me why my second run results in the > client.service.methodcall() running twice. I can't seem to get a hang on > it. methodcall() is inside the for-loop and will be repeated on every iteration. In your example code the dictionary has two entries -- therefore methodcall() will be invoked twice. If the length of the dictionary changes from 1 to 2 while your programm is running you will see the behaviour you described. One way to avoid the problem is to omit the loop: criteria = None if dictionary.get("1234567890") == 1: criteria = "Test" elif dictionary.get("0987654321") == 2: criteria = "Running else: raise Exception("undefined criteria") # for example client.service.methodcall(value1, value2, criteria) Note that leading zeros are usually not a good idea as they mark integer constants as octal: >>> 001 1 >>> 010 8 >>> 008 File "", line 1 008 ^ SyntaxError: invalid token From davea at davea.name Mon Apr 15 08:09:16 2013 From: davea at davea.name (Dave Angel) Date: Mon, 15 Apr 2013 08:09:16 -0400 Subject: Iterating dictionary items + if statement results in problems In-Reply-To: References: Message-ID: <516BEDEC.1090303@davea.name> On 04/15/2013 06:50 AM, Ombongi Moraa Fe wrote: > hello Team, > > I have this fairly simple script to iterate the dictionary items and check > if the items match certain values; > > dictionary={'1234567890':001, '0987654321':002} > for k, v in dictionary.iteritems(): > ..... > ..... #suds client statements; > > if (k == '1234567890' and v == 001): > criteria='Test' > elif (k == '0987654321' and v == 002): > criteria='Running' > client.service.methodcall(value1,value2,criteria) > > That's not the whole script, since at the least, you need some code to import or create client, value1 and value2. > > During the first run of the dictionary items, What do you mean by that, exactly? Do you mean the first time around the loop? Or the first time the script is run? Or what? > the client.service.methodcall > is called only once as expected; and a success initiation response is > received from server. However, during the second run, the > client.service.methodcall is called twice - when i check the log files, i > see the client send request is done twice. Duplicate send requests of the > same parameters results in a error in inititating a connection. > > Someone please show me why my second run results in the > client.service.methodcall() running twice. I can't seem to get a hang on > it. > > Why not take out the middleman, and just add some prints in the loop? I don't see any point in the loop; if you're sure there are exactly two items in the dict, just process those two items. If you're not sure, what do you want to happen when you encounter something that doesn't match either the if or the elif. Currently, you'll just repeat the last methodcall. One final thing, a dict's order is not promised. So you may process these items in either as "Test" and "Running", or in the reverse order. My guess is that this is not your actual code at all, and you're trying to "simplify" it for us. You probably have more than two items in the dict, and one of them is NOT matching any of the if/elif tests. Possibly it's not matching because of your mistaken use of octal. Octal won't hurt for ints below 8, but you probably don't restrict it in the real code. For example, v = 030 will not match equal in the following: elif v == 30: -- DaveA From moraa.lovetakes2 at gmail.com Mon Apr 15 09:37:27 2013 From: moraa.lovetakes2 at gmail.com (Ombongi Moraa Fe) Date: Mon, 15 Apr 2013 16:37:27 +0300 Subject: Iterating dictionary items + if statement results in problems Message-ID: Hello Team, Thanks for your input. |Possibly it's not matching because of your mistaken use of octal. Octal won't hurt for ints below 8, but you probably don't restrict it in the real code. For example, v = 030 will not match equal in the following: I've changed the key,value pairs in the dictionary because of privacy commitment with my provider; |My guess is that this is not your actual code at all, and you're trying to "simplify" it for us. You probably have more than |two items in the dict, and one of them is NOT matching any of the if/elif tests. Currently, I only have 2 items in the dictionary. However, this is a test environment and in the product environ, my items will be as many as the number of services created on server for my connection. Currently, the production has 10 services (key,value pairs) I will only have a set number of key,value pairs and I cannot use other items outside this range. The connection to providerr wouldn't be establish for anything out of the allowed item ranges; |That's not the whole script, since at the least, you need some code to import or create client, value1 and value2. The other portion of script to import the client and get values of parameters value1 and value2 works well. I have tested the script without using dictionaries by manually changing the items within the dictionary, inside the code and it works successfully, establishing a connection for both items; Now I need to iterate this for the sake of numerous items in the production environment. And that's where I thought to bring in the if statement. |What makes you think there should be one call given the code above? client.service.methodcall must be called for every |loop iteration, so there's one call with criteria 'test' and one with 'Running'. Note there's no guarantee that the calls will |always take place in the same order. Yes, I do understand that the items in the dictionary are not ordered. And what I expect is "one call with criteria 'Test' and one with 'Running'. From my logs file, the duplicate call always occurs at the last iteration of the dictionary items. In short, my problem arises after I include the if statement inside the loop. I am new to python but I am pretty sure my program syntax is correct here. If I run a print statement instead of the client.service.methodcall(value1, value2), my output is just Test Running 2 of the services in the production environment will require the criteria value. For the rest of the services, the method call will simply be client.service.methodcall(value1, value2) I need this criteria value in order to establish a service specific connection for these 2 matching key,value pairs; instead of a generalised connection as will be the case for any additional keys.this is where the else default statement will come in later on. Right now I need to be able to resolve the problem with my script as-it-is (with 2 dictionary items) Thanks in advance. Saludos Ombongi Moraa Faith -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Mon Apr 15 13:29:20 2013 From: davea at davea.name (Dave Angel) Date: Mon, 15 Apr 2013 13:29:20 -0400 Subject: Iterating dictionary items + if statement results in problems In-Reply-To: References: Message-ID: <516C38F0.5020005@davea.name> On 04/15/2013 09:37 AM, Ombongi Moraa Fe wrote: > Hello Team, > > Thanks for your input. > > |Possibly it's not matching because of your mistaken use of octal. Octal > won't hurt for ints below 8, but you probably don't restrict it in the real > code. For example, v = 030 will not match equal in the following: > > I've changed the key,value pairs in the dictionary because of privacy > commitment with my provider; > > |My guess is that this is not your actual code at all, and you're trying to > "simplify" it for us. You probably have more than |two items in the dict, > and one of them is NOT matching any of the if/elif tests. > > Currently, I only have 2 items in the dictionary. However, this > is a test environment and in the product environ, my items will be as many > as the number of services created on server for my connection. Currently, > the production has 10 services (key,value pairs) > > I will only have a set number of key,value pairs and I cannot use other > items outside this range. The connection to providerr wouldn't be establish > for anything out of the allowed item ranges; > > |That's not the whole script, since at the least, you need some code to > import or create client, value1 and value2. > > The other portion of script to import the client and get values of > parameters value1 and value2 works well. I have tested the script without > using dictionaries by manually changing the items within the dictionary, > inside the code and it works successfully, establishing a connection for > both items; Now I need to iterate this for the sake of numerous items in > the production environment. And that's where I thought to bring in the if > statement. > > |What makes you think there should be one call given the code above? > client.service.methodcall must be called for every |loop iteration, so > there's one call with criteria 'test' and one with 'Running'. Note there's > no guarantee that the calls will |always take place in the same order. > > Yes, I do understand that the items in the dictionary are not ordered. And > what I expect is "one call with criteria 'Test' and one with 'Running'. From > my logs file, the duplicate call always occurs at the last iteration of the > dictionary items. Do you mean there are 3 calls to that method, with only two items in the dictionary?? More likely, there's some logic inside the method that's faking an extra log entry. > > In short, my problem arises after I include the if statement inside the > loop. I am new to python but I am pretty sure my program syntax is correct > here. If I run a print statement instead of the > client.service.methodcall(value1, > value2), my output is just > > Test > Running > > 2 of the services in the production environment will require the criteria > value. For the rest of the services, the method call will simply be > > client.service.methodcall(value1, value2) > > I need this criteria value in order to establish a service specific > connection for these 2 matching key,value pairs; instead of a generalised > connection as will be the case for any additional keys.this is where the > else default statement will come in later on. Right now I need to be able > to resolve the problem with my script as-it-is (with 2 dictionary items) > As far as I can see, there's no problem with the script, as far as it goes. If you replace the method call with a print statement, and it suddenly starts working, then by definition, there's something wrong with the method. We cannot help there. Many times, we can play detective, and guess what's going on without running a program. Since we've told you what we each have found, and you haven't posted any new version of the code, that's about all we can do. Perhaps someone else who hasn't chimed in can help. But if I were you, I'd post a self-contained program that demonstrates the problem. Or maybe it's because you're posting in html, rather than the expected text, and you have some indent problem that doesn't show up after converting round trip. Please tell your email program to use text message format when posting here. -- DaveA From steeve.hetu at gmail.com Mon Apr 15 08:27:10 2013 From: steeve.hetu at gmail.com (Steeve) Date: Mon, 15 Apr 2013 05:27:10 -0700 (PDT) Subject: Making ETL from Access 97 to Access 2003 Message-ID: <7f77cfaf-7a22-43a8-880d-6556bfbad315@googlegroups.com> Hi, I need to take data from 5 differents (but similar) database in MS Access 97 and merge them into one MS Access 2003 database. Is some packages exist to do this task? Thank From rustompmody at gmail.com Mon Apr 15 09:33:26 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 15 Apr 2013 06:33:26 -0700 (PDT) Subject: Making ETL from Access 97 to Access 2003 References: <7f77cfaf-7a22-43a8-880d-6556bfbad315@googlegroups.com> Message-ID: On Apr 15, 5:27?pm, Steeve wrote: > Hi, > > I need to take data from 5 differents (but similar) database in MS Access 97 and merge them into one MS Access 2003 database. Not sure what this had to do with python. However? You could write out the five as csvs and then read in those csvs. This is assuming that access 2003 cannot read in access 97. [Seems a bit surprising though] > > Is some packages exist to do this task? Dunno? Have you seen http://allenbrowne.com/ser-48.html ? From psimon at sonic.net Mon Apr 15 12:01:28 2013 From: psimon at sonic.net (Paul Simon) Date: Mon, 15 Apr 2013 09:01:28 -0700 Subject: Making ETL from Access 97 to Access 2003 References: <7f77cfaf-7a22-43a8-880d-6556bfbad315@googlegroups.com> Message-ID: <516c255c$0$52774$742ec2ed@news.sonic.net> "rusi" wrote in message news:ff550c58-58b0-4bf2-bf12-08986ab2b695 at ka6g2000pbb.googlegroups.com... On Apr 15, 5:27 pm, Steeve wrote: > Hi, > > I need to take data from 5 differents (but similar) database in MS Access > 97 and merge them into one MS Access 2003 database. Not sure what this had to do with python. However? You could write out the five as csvs and then read in those csvs. This is assuming that access 2003 cannot read in access 97. [Seems a bit surprising though] > > Is some packages exist to do this task? Dunno? Have you seen http://allenbrowne.com/ser-48.html ? If there are indices and especially linked primary and foreign keys its much more complicated than that. One has to delve into Access container structures etc. As far as I know it has to be done from Access. Paul Simon From rustompmody at gmail.com Mon Apr 15 12:20:11 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 15 Apr 2013 09:20:11 -0700 (PDT) Subject: Making ETL from Access 97 to Access 2003 References: <7f77cfaf-7a22-43a8-880d-6556bfbad315@googlegroups.com> <516c255c$0$52774$742ec2ed@news.sonic.net> Message-ID: <92551c63-1347-4f1a-9dca-d1bbd5e4d112@ys5g2000pbc.googlegroups.com> Its hard to distinguish what you are saying from what I said because you've lost the quotes. On Apr 15, 9:01?pm, "Paul Simon" wrote: > "rusi" wrote in message > > news:ff550c58-58b0-4bf2-bf12-08986ab2b695 at ka6g2000pbb.googlegroups.com... > On Apr 15, 5:27 pm, Steeve wrote: > > > Hi, > > > I need to take data from 5 differents (but similar) database in MS Access > > 97 and merge them into one MS Access 2003 database. > > Not sure what this had to do with python. > However? > You could write out the five as csvs and then read in those csvs. > This is assuming that access 2003 cannot read in access 97. [Seems a > bit surprising though] > > > > > Is some packages exist to do this task? > > Dunno? > Have you seenhttp://allenbrowne.com/ser-48.html? > > If ?there are indices and especially linked primary and foreign keys its > much more complicated than that. ?One has to delve into Access container > structures etc. ?As far as I know it has to be done from Access. I assume you are saying this for my csv suggestion? Yes of course. I gave this as the last resort if direct import and other such attempts dont work out. From psimon at sonic.net Mon Apr 15 15:02:10 2013 From: psimon at sonic.net (Paul Simon) Date: Mon, 15 Apr 2013 12:02:10 -0700 Subject: Making ETL from Access 97 to Access 2003 References: <7f77cfaf-7a22-43a8-880d-6556bfbad315@googlegroups.com> <516c255c$0$52774$742ec2ed@news.sonic.net> <92551c63-1347-4f1a-9dca-d1bbd5e4d112@ys5g2000pbc.googlegroups.com> Message-ID: <516c4fd1$0$52752$742ec2ed@news.sonic.net> "rusi" wrote in message news:92551c63-1347-4f1a-9dca-d1bbd5e4d112 at ys5g2000pbc.googlegroups.com... Its hard to distinguish what you are saying from what I said because you've lost the quotes. On Apr 15, 9:01 pm, "Paul Simon" wrote: > "rusi" wrote in message > > news:ff550c58-58b0-4bf2-bf12-08986ab2b695 at ka6g2000pbb.googlegroups.com... > On Apr 15, 5:27 pm, Steeve wrote: > > > Hi, > > > I need to take data from 5 differents (but similar) database in MS > > Access > > 97 and merge them into one MS Access 2003 database. > > Not sure what this had to do with python. > However? > You could write out the five as csvs and then read in those csvs. > This is assuming that access 2003 cannot read in access 97. [Seems a > bit surprising though] > > > > > Is some packages exist to do this task? > > Dunno? > Have you seenhttp://allenbrowne.com/ser-48.html? > > If there are indices and especially linked primary and foreign keys its > much more complicated than that. One has to delve into Access container > structures etc. As far as I know it has to be done from Access. I assume you are saying this for my csv suggestion? Yes of course. I gave this as the last resort if direct import and other such attempts dont work out. >>>Could you please append your comments instead of splitting them? >>>Let me try to be clearer. If one only wants to merge tables, csv will >>>work fine, exporting them from Access. >>>Reconstucting keys and relationships can be done with some difficulty >>>using Access' container model. See the Developer's Handbook by Getz, >>>Litwin and Gilbert. >>>Paul Simon From nospam at nospam.com Mon Apr 15 11:20:50 2013 From: nospam at nospam.com (Gilles) Date: Mon, 15 Apr 2013 17:20:50 +0200 Subject: Cross-compiling Python for ARM? Message-ID: <7d6om8tigsjg0eqcpig5fl75dbth6qpflc@4ax.com> Hello I tried running uWSGI on an ARM-based appliance, but it fails. Apparently, it could be due to the official Python 2.6.6 interpreter in the depot not being compiled the way uWSGI expects it to be: ./configure --enable-shared; make; make install; www.raspberrypi.org/phpBB3/viewtopic.php?f=32&t=15370 I see Python mentioned in /usr/lib and /usr/share, and was wondering if all it'd take to solve this issue, is just to cross-compile the interpreter and the rest is just CPU-agnostic Python scripts. Just in case, here's the output: www.pastebin.com/wJHjBrfn Thank you. From tjreedy at udel.edu Mon Apr 15 20:50:09 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Mon, 15 Apr 2013 20:50:09 -0400 Subject: Cross-compiling Python for ARM? In-Reply-To: <7d6om8tigsjg0eqcpig5fl75dbth6qpflc@4ax.com> References: <7d6om8tigsjg0eqcpig5fl75dbth6qpflc@4ax.com> Message-ID: On 4/15/2013 11:20 AM, Gilles wrote: > Hello > > I tried running uWSGI on an ARM-based appliance, but it fails. > > Apparently, it could be due to the official Python 2.6.6 interpreter > in the depot not being compiled the way uWSGI expects it to be: > > ./configure --enable-shared; make; make install; > www.raspberrypi.org/phpBB3/viewtopic.php?f=32&t=15370 > > I see Python mentioned in /usr/lib and /usr/share, and was wondering > if all it'd take to solve this issue, is just to cross-compile the > interpreter and the rest is just CPU-agnostic Python scripts. > > Just in case, here's the output: > www.pastebin.com/wJHjBrfn I believe some cross-compile support was added to 2.7.4 but I do not know the exact nature. From as at sci.fi Tue Apr 16 10:22:55 2013 From: as at sci.fi (Anssi Saari) Date: Tue, 16 Apr 2013 17:22:55 +0300 Subject: Cross-compiling Python for ARM? References: <7d6om8tigsjg0eqcpig5fl75dbth6qpflc@4ax.com> Message-ID: Gilles writes: > I see Python mentioned in /usr/lib and /usr/share, and was wondering > if all it'd take to solve this issue, is just to cross-compile the > interpreter and the rest is just CPU-agnostic Python scripts. I suppose. In any case, cross compiling Python shouldn't be that hard. I just recently built 2.7.3 for my OpenWRT router since the packaged Python didn't have readline support (some long standing linking issue with readline and ncurses and uClibc). From nospam at nospam.com Sat Apr 20 18:41:10 2013 From: nospam at nospam.com (Gilles) Date: Sun, 21 Apr 2013 00:41:10 +0200 Subject: Cross-compiling Python for ARM? References: <7d6om8tigsjg0eqcpig5fl75dbth6qpflc@4ax.com> Message-ID: On Tue, 16 Apr 2013 17:22:55 +0300, Anssi Saari wrote: >In any case, cross compiling Python shouldn't be that hard. I >just recently built 2.7.3 for my OpenWRT router since the packaged >Python didn't have readline support (some long standing linking issue >with readline and ncurses and uClibc). Thanks guys. Turns out the error was not due to Python, so the ARM version available in the Debian depot is fine. From gnarlodious at gmail.com Mon Apr 15 14:25:44 2013 From: gnarlodious at gmail.com (Gnarlodious) Date: Mon, 15 Apr 2013 11:25:44 -0700 (PDT) Subject: Process tuple contents on the fly Message-ID: Say I have a tuple I want to expand assigning to variables: tup = *func() var = tup[0] lst.append(tup[1]) Or could I do it in one line? var, lst.append() = *func() So I want to append one variable to a list on the fly, is it possible? -- Gnarlie http://gnarlodious.com From python.list at tim.thechases.com Mon Apr 15 14:50:13 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 15 Apr 2013 13:50:13 -0500 Subject: Process tuple contents on the fly In-Reply-To: References: Message-ID: <20130415135013.58430065@bigbox.christie.dr> On 2013-04-15 11:25, Gnarlodious wrote: > Say I have a tuple I want to expand assigning to variables: > > tup = *func() > var = tup[0] > lst.append(tup[1]) > > Or could I do it in one line? > > var, lst.append() = *func() > > So I want to append one variable to a list on the fly, is it > possible? I stumbled across this atrocity[*], which if you chose to use it, you'd deserve a kick in the pants: lst.append("Value I don't care about and will overwrite") var, lst[-1] = *func() It's not quite one step, but at least the *assignment* is one step :-) -tkc [*] my original discovery was d = {} for key, d[key] in (("this",18), ("that",17), ("other",38)): print key do_something(d) but the same applies to a plain ol' assignment statement as to an assignment in a "for" loop. From musikal.fusion at gmail.com Mon Apr 15 15:05:04 2013 From: musikal.fusion at gmail.com (Barrett Lewis) Date: Mon, 15 Apr 2013 12:05:04 -0700 Subject: Process tuple contents on the fly In-Reply-To: <20130415135013.58430065@bigbox.christie.dr> References: <20130415135013.58430065@bigbox.christie.dr> Message-ID: > d = {} > for key, d[key] in (("this",18), ("that",17), ("other",38)): > print key > do_something(d) > Why not use a dict comprehension? d = {k:v for k,v in (("this",18), ("that",17), ("other",38))} I feel this is more straightforward and easier to read. the results are the same however. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Mon Apr 15 15:10:42 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 15 Apr 2013 14:10:42 -0500 Subject: Process tuple contents on the fly In-Reply-To: References: <20130415135013.58430065@bigbox.christie.dr> Message-ID: <20130415141042.2b046c3c@bigbox.christie.dr> On 2013-04-15 12:05, Barrett Lewis wrote: > > d = {} > > for key, d[key] in (("this",18), ("that",17), ("other",38)): > > print key > > do_something(d) > > Why not use a dict comprehension? > d = {k:v for k,v in (("this",18), ("that",17), ("other",38))} > > I feel this is more straightforward and easier to read. the results > are the same however. In the particular case I did it in, I needed the incremental results passed to a function, not just the final result. I don't think this made it into the final code, rather it was expanded to be more readable. But the discovery made me feel a disturbance in the Pythonic force of the universe. :*) -tkc From musikal.fusion at gmail.com Mon Apr 15 15:16:48 2013 From: musikal.fusion at gmail.com (Barrett Lewis) Date: Mon, 15 Apr 2013 12:16:48 -0700 Subject: Process tuple contents on the fly In-Reply-To: <20130415141042.2b046c3c@bigbox.christie.dr> References: <20130415135013.58430065@bigbox.christie.dr> <20130415141042.2b046c3c@bigbox.christie.dr> Message-ID: > In the particular case I did it in, I needed the incremental results > passed to a function, not just the final result. I don't think this > made it into the final code, rather it was expanded to be more > readable. But the discovery made me feel a disturbance in the > Pythonic force of the universe. :*) > > -tkc > I see what you are saying, but I agree that is a disturbance I didn't even know you could do for key, d[key], that just feels like bad news. however for what you are saying it makes sense. TIL that you can use an unpacked value during unpacking! -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Mon Apr 15 15:29:47 2013 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 15 Apr 2013 20:29:47 +0100 Subject: Process tuple contents on the fly In-Reply-To: References: <20130415135013.58430065@bigbox.christie.dr> Message-ID: <516C552B.7010903@mrabarnett.plus.com> On 15/04/2013 20:05, Barrett Lewis wrote: > > > > d = {} > for key, d[key] in (("this",18), ("that",17), ("other",38)): > print key > do_something(d) > > > Why not use a dict comprehension? > d = {k:v for k,v in (("this",18), ("that",17), ("other",38))} > > I feel this is more straightforward and easier to read. the results are > the same however. > Why use a dict comprehension? :-) d = dict((("this",18), ("that",17), ("other",38))} From __peter__ at web.de Mon Apr 15 15:07:32 2013 From: __peter__ at web.de (Peter Otten) Date: Mon, 15 Apr 2013 21:07:32 +0200 Subject: Process tuple contents on the fly References: <20130415135013.58430065@bigbox.christie.dr> Message-ID: Tim Chase wrote: > On 2013-04-15 11:25, Gnarlodious wrote: >> Say I have a tuple I want to expand assigning to variables: >> >> tup = *func() >> var = tup[0] >> lst.append(tup[1]) >> >> Or could I do it in one line? >> >> var, lst.append() = *func() >> >> So I want to append one variable to a list on the fly, is it >> possible? > > I stumbled across this atrocity[*], which if you chose to use it, > you'd deserve a kick in the pants: > > lst.append("Value I don't care about and will overwrite") > var, lst[-1] = *func() > > It's not quite one step, but at least the *assignment* is one step :-) I think the star is on the wrong side. So: >>> items = ["a", "b", "c"] >>> def f(result=(4, 5, 6)): return result ... >>> var, *items[len(items):] = f() >>> var 4 >>> items ['a', 'b', 'c', 5, 6] From toby at tobiah.org Mon Apr 15 16:35:10 2013 From: toby at tobiah.org (Tobiah) Date: Mon, 15 Apr 2013 13:35:10 -0700 Subject: Process tuple contents on the fly In-Reply-To: References: Message-ID: On 04/15/2013 11:25 AM, Gnarlodious wrote: > Say I have a tuple I want to expand assigning to variables: > > tup = *func() What is the asterisk for? I assume it's a python 3 thing, because I get a syntax error, but I'm having trouble Googling it. Thanks, Tobiah From torriem at gmail.com Mon Apr 15 17:16:29 2013 From: torriem at gmail.com (Michael Torrie) Date: Mon, 15 Apr 2013 15:16:29 -0600 Subject: Process tuple contents on the fly In-Reply-To: References: Message-ID: <516C6E2D.3090309@gmail.com> On 04/15/2013 02:35 PM, Tobiah wrote: > On 04/15/2013 11:25 AM, Gnarlodious wrote: >> Say I have a tuple I want to expand assigning to variables: >> >> tup = *func() > > What is the asterisk for? I assume it's a python 3 > thing, because I get a syntax error, but I'm having > trouble Googling it. No it's not. It's a tuple unpack operator. It's commonly used in this context: def func1(*args, **kwargs): #func1 can take variable args # do stuff func2( *args ) #unpack the variable args and pass them to func2 func3( *args ) func4( *args, **kwargs) def func2( a, b, c): d = a + b + c def func3 ( *args ): pass def func4 ( *args, **kwargs): pass func1(1,2,3) From gnarlodious at gmail.com Mon Apr 15 19:46:03 2013 From: gnarlodious at gmail.com (Gnarlodious) Date: Mon, 15 Apr 2013 16:46:03 -0700 (PDT) Subject: Process tuple contents on the fly In-Reply-To: References: Message-ID: On Monday, April 15, 2013 2:35:10 PM UTC-6, Tobiah wrote: > > tup = *func() > What is the asterisk for? I assume it's a python 3 Not Python 3, pseudocode. I should have said as such, sorry. Supposed to indicate an expanded tuple. -- Gnarlie From brian.costlow at gmail.com Mon Apr 15 20:36:15 2013 From: brian.costlow at gmail.com (Brian Costlow) Date: Mon, 15 Apr 2013 20:36:15 -0400 Subject: PyOhio 2013 Call For Proposals Message-ID: PyOhio 2013, the annual Python programming conference for Ohio and the surrounding region, is now accepting proposals for scheduled talks, tutorials, and panels. This year's PyOhio will will take place Saturday, July 27th, and Sunday, July 28th, 2013 at the Ohio Union, on the campus of The Ohio State University in Columbus, Ohio. Deadline for submitting a proposal is June, 1st 2013 Details about submitting a proposed talk are here: http://pyohio.org/call-for-proposals/ The 2013 PyOhio Organizing Committee -------------- next part -------------- An HTML attachment was scrubbed... URL: From renato.barbosa.pim.pereira at gmail.com Mon Apr 15 22:02:10 2013 From: renato.barbosa.pim.pereira at gmail.com (Renato Barbosa Pim Pereira) Date: Mon, 15 Apr 2013 23:02:10 -0300 Subject: Python with Apache Message-ID: I am trying to execute cgi101.py: #!/usr/bin/python import cgi form = cgi.FieldStorage() # parse form data print('Content-type: text/html\n') # hdr plus blank line print('Reply Page') # html reply page if not 'user' in form: print('

Who are you?

') else: print('

Hello %s!

' % cgi.escape(form['user'].value)) I have installed mod_python do apache2 and created one entry in /etc/apache2/sites-available/default: DocumentRoot /var/www AddHandler mod_python .py PythonHandler cgi101 PythonDebug On What. happen is: when i call this file on browser I have the following error: Can someone help? MOD_PYTHON ERROR ProcessId: 2742 Interpreter: '127.0.1.1' ServerName: '127.0.1.1' DocumentRoot: '/var/www' URI: '/py/cgi101.py' Location: None Directory: '/var/www/py/' Filename: '/var/www/py/cgi101.py' PathInfo: '' Phase: 'PythonHandler' Handler: 'cgi101' Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 1537, in HandlerDispatch default=default_handler, arg=req, silent=hlist.silent) File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 1206, in _process_target object = apache.resolve_object(module, object_str, arg, silent=silent) File "/usr/lib/python2.7/dist-packages/mod_python/apache.py", line 696, in resolve_object raise AttributeError, s AttributeError: module '/var/www/py/cgi101.py' contains no 'handler' MODULE CACHE DETAILS Accessed: Mon Apr 15 22:02:42 2013 Generation: 0 _mp_63ea7b6576c7d3a5f48ef8741e8048b0 { FileName: '/var/www/py/cgi101.py' Instance: 1 [IMPORT] Generation: 1 Modified: Mon Apr 15 21:52:27 2013 Imported: Mon Apr 15 22:02:42 2013 } -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Mon Apr 15 22:38:21 2013 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Apr 2013 03:38:21 +0100 Subject: Python with Apache In-Reply-To: References: Message-ID: <516CB99D.206@mrabarnett.plus.com> On 16/04/2013 03:02, Renato Barbosa Pim Pereira wrote: > I am trying to execute cgi101.py: > > #!/usr/bin/python > > import cgi > > form = cgi.FieldStorage() # parse form data > print('Content-type: text/html\n') # hdr plus blank line > print('Reply Page') # html reply page > if not 'user' in form: > print('

Who are you?

') > else: > print('

Hello %s!

' % cgi.escape(form['user'].value)) > > I have installed mod_python do apache2 and created one entry in > /etc/apache2/sites-available/default: > > DocumentRoot /var/www > > AddHandler mod_python .py > PythonHandler cgi101 > PythonDebug On > > > What. happen is: when i call this file on browser I have the following > error: > Can someone help? > > MOD_PYTHON ERROR > > ProcessId: 2742 > Interpreter: '127.0.1.1' > > ServerName: '127.0.1.1' > DocumentRoot: '/var/www' > > URI: '/py/cgi101.py' > Location: None > Directory: '/var/www/py/' > Filename: '/var/www/py/cgi101.py' > PathInfo: '' > > Phase: 'PythonHandler' > Handler: 'cgi101' > > Traceback (most recent call last): > > File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 1537, in HandlerDispatch > default=default_handler, arg=req, silent=hlist.silent) > > File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 1206, in _process_target > object = apache.resolve_object(module, object_str, arg, silent=silent) > > File "/usr/lib/python2.7/dist-packages/mod_python/apache.py", line 696, in resolve_object > raise AttributeError, s > > AttributeError: module '/var/www/py/cgi101.py' contains no 'handler' > > > MODULE CACHE DETAILS > > Accessed: Mon Apr 15 22:02:42 2013 > Generation: 0 > > _mp_63ea7b6576c7d3a5f48ef8741e8048b0 { > FileName: '/var/www/py/cgi101.py' > Instance: 1 [IMPORT] > Generation: 1 > Modified: Mon Apr 15 21:52:27 2013 > Imported: Mon Apr 15 22:02:42 2013 > } > I think it's looking for a function called 'handler' in the module 'cgi101.py'. This might help you: http://www.modpython.org/live/mod_python-2.7.8/doc-html/tut-overview.html From andrea.crotti.0 at gmail.com Tue Apr 16 06:21:26 2013 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Tue, 16 Apr 2013 11:21:26 +0100 Subject: dynamic forms generation Message-ID: We are re-designing a part of our codebase, which should in short be able to generate forms with custom fields. We use django for the frontend and bottle for the backend (using CouchDB as database), and at the moment we simply plug extra fields on normal django forms. This is not really scalable, and we want to make the whole thing more generic. So ideally there could be a DSL (YAML or something else) that we could define to then generate the forms, but the problem is that I'm quite sure that this DSL would soon become too complex and inadeguate, so I'm not sure if it's worth since noone should write forms by hands anyway. Between the things that we should be able to do there are: - dependent fields - validation (both server and client side, better if client-side auto-generated) - following DRY as much as possible Any suggestions of possible designs or things I can look at? -------------- next part -------------- An HTML attachment was scrubbed... URL: From wayne at waynewerner.com Thu Apr 18 08:53:54 2013 From: wayne at waynewerner.com (Wayne Werner) Date: Thu, 18 Apr 2013 07:53:54 -0500 (CDT) Subject: dynamic forms generation In-Reply-To: References: Message-ID: On Tue, 16 Apr 2013, andrea crotti wrote: > This is not really scalable, and we want to make the whole thing more > generic. > > So ideally there could be a DSL (YAML or something else) that we could > define to then generate the forms, but the problem is that I'm quite > sure that this DSL would soon become too complex and inadeguate, so I'm > not sure if it's worth since noone should write forms by hands anyway. > > Between the things that we should be able to do there are: > - dependent fields > - validation (both server and client side, better if client-side > ? auto-generated) > - following DRY as much as possible > > Any suggestions of possible designs or things I can look at? I would highly recommend a look at Flask, and Flask-WTF in particular. It's fairly easy to write forms, and with only a bit of setup you can end out with some fairly generic systems. I don't think that by default it does any client-side validation generation, but as the HTML for the forms are completely generated, extending the form and adding validation logic to the output wouldn't be too difficult. Example: # form.py from flask.ext.wtf import Form, TextField, Required class MyBasicForm(Form): some_text = TextField("Put some text here:", validators=[Required()]) # View/HTML {% extends 'base.html' %} {{ form.some_text.label() }}{{ form.some_text(size=40) }} # Server code @app.route("/basic_form", methods=['GET', 'POST']) def basic(): form = MyBasicForm() if form.validate_on_submit(): do_the_needful(form.some_text.data) return redirect(url_for('main')) return render_template('basic_form.html', form=form) Obviously a really basic example. Check out Flask here: http://flask.pocoo.org/ And Flask WTF here: http://pythonhosted.org/Flask-WTF/ HTH, Wayne From andrea.crotti.0 at gmail.com Fri Apr 19 09:09:55 2013 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Fri, 19 Apr 2013 14:09:55 +0100 Subject: dynamic forms generation In-Reply-To: References: Message-ID: Well I think since we are using django anyway (and bottle on the API side) I'm not sure why we would use flask forms for this.. Anyway the main question is probably, is it worth to try to define a DSL or not? The problem I see is that we have a lot and very complex requirements, trying to define a DSL that is able to represent everything might be a massive pain. I prefer to do something smart with metaclasses and just use Python as the configuration language itself, using metaclasses and similar nice things to define the language used.. The only annoying part is the persistance, I don't like too much the idea to store Python code in the db for example, but maybe it's fine, many projects configure things with Python anyway.. -------------- next part -------------- An HTML attachment was scrubbed... URL: From prquinn at gmail.com Tue Apr 16 10:14:09 2013 From: prquinn at gmail.com (PEnergy) Date: Tue, 16 Apr 2013 07:14:09 -0700 (PDT) Subject: Calling python script in dos and passing arguments Message-ID: <88b87ac0-1fce-4383-9841-d99a49f50556@googlegroups.com> Greetings, I am trying to write a python script that, when called from the DOS prompt, will call another python script and pass it input variables. My current code will open the other python script but doesn't seem to pass it any values: import os,sys,subprocess subprocess.Popen(['python.exe','C:\NDEX\GRE2\uip\uip_20.py','t3c*']) Am I missing something or is this type of call not possible through DOS? Thanks, PEnergy From clp2 at rebertia.com Tue Apr 16 15:10:09 2013 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 16 Apr 2013 12:10:09 -0700 Subject: Calling python script in dos and passing arguments In-Reply-To: <88b87ac0-1fce-4383-9841-d99a49f50556@googlegroups.com> References: <88b87ac0-1fce-4383-9841-d99a49f50556@googlegroups.com> Message-ID: On Tue, Apr 16, 2013 at 7:14 AM, PEnergy wrote: > Greetings, > > I am trying to write a python script that, when called from the DOS prompt, will call another python script and pass it input variables. My current code will open the other python script but doesn't seem to pass it any values: > > import os,sys,subprocess > subprocess.Popen(['python.exe','C:\NDEX\GRE2\uip\uip_20.py','t3c*']) > > Am I missing something or is this type of call not possible through DOS? 1. Backslash is an escape character in Python strings (e.g. "\n" = newline). You should therefore double-up on your backslashes. (Your exact string just so happens to work due to a misfeature regarding how invalid backslash escapes are handled.) 2. Glob/wildcard ("*") expansion is done by the shell, but subprocess.Popen does not use the shell by default (for good reason!). Use the `glob` library to do the expansion yourself, in Python: http://docs.python.org/2/library/glob.html Cheers, Chris From alister.ware at ntlworld.com Tue Apr 16 15:19:20 2013 From: alister.ware at ntlworld.com (Alister) Date: Tue, 16 Apr 2013 19:19:20 GMT Subject: Calling python script in dos and passing arguments References: <88b87ac0-1fce-4383-9841-d99a49f50556@googlegroups.com> Message-ID: On Tue, 16 Apr 2013 12:10:09 -0700, Chris Rebert wrote: > On Tue, Apr 16, 2013 at 7:14 AM, PEnergy wrote: >> Greetings, >> >> I am trying to write a python script that, when called from the DOS >> prompt, will call another python script and pass it input variables. >> My current code will open the other python script but doesn't seem to >> pass it any values: >> >> import os,sys,subprocess >> subprocess.Popen(['python.exe','C:\NDEX\GRE2\uip\uip_20.py','t3c*']) >> >> Am I missing something or is this type of call not possible through >> DOS? > > 1. Backslash is an escape character in Python strings (e.g. "\n" = > newline). You should therefore double-up on your backslashes. (Your > exact string just so happens to work due to a misfeature regarding how > invalid backslash escapes are handled.) > 2. Glob/wildcard ("*") expansion is done by the shell, but > subprocess.Popen does not use the shell by default (for good reason!). > Use the `glob` library to do the expansion yourself, in Python: > http://docs.python.org/2/library/glob.html > > Cheers, > Chris why cant you just import the 2nd python program & then call its main function (or any other) with the required parameters? -- You are wise, witty, and wonderful, but you spend too much time reading this sort of trash. From timr at probo.com Wed Apr 17 01:32:01 2013 From: timr at probo.com (Tim Roberts) Date: Tue, 16 Apr 2013 22:32:01 -0700 Subject: Calling python script in dos and passing arguments References: <88b87ac0-1fce-4383-9841-d99a49f50556@googlegroups.com> Message-ID: Chris Rebert wrote: > >2. Glob/wildcard ("*") expansion is done by the shell, but >subprocess.Popen does not use the shell by default (for good reason!). This is only true in Linux. In Windows, the wildcard characters are passed to the program, so each app must do its own glob expansion. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From torriem at gmail.com Tue Apr 16 15:25:22 2013 From: torriem at gmail.com (Michael Torrie) Date: Tue, 16 Apr 2013 13:25:22 -0600 Subject: Calling python script in dos and passing arguments In-Reply-To: <88b87ac0-1fce-4383-9841-d99a49f50556@googlegroups.com> References: <88b87ac0-1fce-4383-9841-d99a49f50556@googlegroups.com> Message-ID: <516DA5A2.7010109@gmail.com> On 04/16/2013 08:14 AM, PEnergy wrote: > Greetings, > > I am trying to write a python script that, when called from the DOS > prompt, will call another python script and pass it input variables. > My current code will open the other python script but doesn't seem to > pass it any values: > > import os,sys,subprocess > subprocess.Popen(['python.exe','C:\NDEX\GRE2\uip\uip_20.py','t3c*']) I find it easier just to write my python programs such that they can be imported into other python scripts. Usually I use this form: def func(*whatever): pass if __name__ == "__main__": # parse command-line arguments # call functions in this module with those args func(1,2,3,etc) This way a script can be run standalone, or I can import it and access its attributes direction. I recommend you consider this approach. From ribonucleico at gmail.com Tue Apr 16 10:30:14 2013 From: ribonucleico at gmail.com (rosoloum) Date: Tue, 16 Apr 2013 07:30:14 -0700 (PDT) Subject: Preparing sqlite, dl and tkinter for Python installation (no admin rights) Message-ID: <1366122614066-5014440.post@n6.nabble.com> I do not have admin rights on my machine and I am trying to build Python directly from source code. After running: ./configure --prefix=/some/path --enable-shared and then make I get the following: > Python build finished, but the necessary bits to build these modules > were not found: > > _tkinter bsddb185 dl imageop > sunaudiodev > > To find the necessary bits, look in setup.py in > detect_modules() for the module's name. > > Failed to build these modules: > _sqlite3 I read that `imageop` was deprecated in recent versions of Python and that `sunaudiodev` is for Sun audio hardware, which I don't need/have. ##sqlite3: To fix the above, for `sqlite3` I downloaded this file: http://www.sqlite.org/2013/sqlite-autoconf-3071602.tar.gz and then run `./configure --prefix=/path/to/sqlite`, `make` and finally `make install`, and added `/path/to/sqlite/lib` to `LD_LIBRARY_PATH`. Still this was not enough (I get the same error) Why? ##tkinter and dl: What about `_tkinter` and `dl`? How can I have them ready for the Python installer? Note: I left a copy of this thread on StackOverflow:. -- View this message in context: http://python.6.x6.nabble.com/Preparing-sqlite-dl-and-tkinter-for-Python-installation-no-admin-rights-tp5014440.html Sent from the Python - python-list mailing list archive at Nabble.com. From tjreedy at udel.edu Tue Apr 16 12:55:56 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Tue, 16 Apr 2013 12:55:56 -0400 Subject: Preparing sqlite, dl and tkinter for Python installation (no admin rights) In-Reply-To: <1366122614066-5014440.post@n6.nabble.com> References: <1366122614066-5014440.post@n6.nabble.com> Message-ID: On 4/16/2013 10:30 AM, rosoloum wrote: > I do not have admin rights on my machine The answer to your question may depend on the OS (linux), distribution (many), and version. > What about `_tkinter` and `dl`? How can I have them ready for the Python > installer? Building _tkinter (a Python C-coded module) requires tcl/tk and header files. Some distros have a separate python sdk kit with the headers not included with tcl/tk. From ribonucleico at gmail.com Tue Apr 16 13:28:46 2013 From: ribonucleico at gmail.com (James Jong) Date: Tue, 16 Apr 2013 13:28:46 -0400 Subject: Preparing sqlite, dl and tkinter for Python installation (no admin rights) In-Reply-To: References: <1366122614066-5014440.post@n6.nabble.com> Message-ID: Thank you Terry, I am working with: > cat /proc/version Linux version 2.6.18-274.el5xen (brewbuilder at norob.fnal.gov) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-50)) #1 SMP Thu Jul 21 > cat /etc/redhat-release Scientific Linux SL release 5.1 (Boron) I did not find distribution-specific tar balls for tck/tk, sqlite or dl on the Scientific Linux website, but maybe I am not looking in the right place. Do you know how I can find which tarballs I need? James On Tue, Apr 16, 2013 at 12:55 PM, Terry Jan Reedy wrote: > On 4/16/2013 10:30 AM, rosoloum wrote: > >> I do not have admin rights on my machine >> > > The answer to your question may depend on the OS (linux), distribution > (many), and version. > > > What about `_tkinter` and `dl`? How can I have them ready for the Python >> installer? >> > > Building _tkinter (a Python C-coded module) requires tcl/tk and header > files. Some distros have a separate python sdk kit with the headers not > included with tcl/tk. > > > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ribonucleico at gmail.com Wed Apr 17 18:39:15 2013 From: ribonucleico at gmail.com (James Jong) Date: Wed, 17 Apr 2013 18:39:15 -0400 Subject: Preparing sqlite, dl and tkinter for Python installation (no admin rights) In-Reply-To: References: <1366122614066-5014440.post@n6.nabble.com> Message-ID: I managed to compile sqlite with: CPPFLAGS='-I/path_to_sqlite-3.7.16.2/include -I/path_to_tk8.6.0/include' DFLAGS='-L/path_to_sqlite-3.7.16.2/lib -L/path_to_tk8.6.0/lib/' ./configure --prefix=/path_to_python-2.7.4 --enable-shared However, _tkinter is still failing. I don't know what else to try. Any thoughts? Thanks, James On Tue, Apr 16, 2013 at 1:28 PM, James Jong wrote: > Thank you Terry, I am working with: > > cat /proc/version > Linux version 2.6.18-274.el5xen (brewbuilder at norob.fnal.gov) (gcc version > 4.1.2 20080704 (Red Hat 4.1.2-50)) #1 SMP Thu Jul 21 > > > cat /etc/redhat-release > Scientific Linux SL release 5.1 (Boron) > > I did not find distribution-specific tar balls for tck/tk, sqlite or dl on > the Scientific Linux website, but maybe I am not looking in the right > place. Do you know how I can find which tarballs I need? > > James > > > > > > > > > On Tue, Apr 16, 2013 at 12:55 PM, Terry Jan Reedy wrote: > >> On 4/16/2013 10:30 AM, rosoloum wrote: >> >>> I do not have admin rights on my machine >>> >> >> The answer to your question may depend on the OS (linux), distribution >> (many), and version. >> >> >> What about `_tkinter` and `dl`? How can I have them ready for the Python >>> installer? >>> >> >> Building _tkinter (a Python C-coded module) requires tcl/tk and header >> files. Some distros have a separate python sdk kit with the headers not >> included with tcl/tk. >> >> >> -- >> http://mail.python.org/**mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Apr 17 21:59:29 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 18 Apr 2013 11:59:29 +1000 Subject: Preparing sqlite, dl and tkinter for Python installation (no admin rights) In-Reply-To: References: <1366122614066-5014440.post@n6.nabble.com> Message-ID: On Thu, Apr 18, 2013 at 8:39 AM, James Jong wrote: > I managed to compile sqlite with: > > CPPFLAGS='-I/path_to_sqlite-3.7.16.2/include -I/path_to_tk8.6.0/include' > > DFLAGS='-L/path_to_sqlite-3.7.16.2/lib -L/path_to_tk8.6.0/lib/' > > ./configure --prefix=/path_to_python-2.7.4 --enable-shared > > However, _tkinter is still failing. I don't know what else to try. Any > thoughts? Can you build Python on a different system (to which you have admin rights), then deploy the binary to the one where you don't? Then you could do a much more standard compilation process. As long as the two systems are broadly similar, it should work. ChrisA From ribonucleico at gmail.com Thu Apr 18 10:37:14 2013 From: ribonucleico at gmail.com (James Jong) Date: Thu, 18 Apr 2013 10:37:14 -0400 Subject: Preparing sqlite, dl and tkinter for Python installation (no admin rights) In-Reply-To: References: <1366122614066-5014440.post@n6.nabble.com> Message-ID: Thanks so much Chris. This is part of a super computer and I am afraid I don't have access to a machine with sudo permissions and similar architecture & OS. Is there any way to active higher level of verbosity during the build process to identify what is failing? Or anything specifically I should watch for? James, On Wed, Apr 17, 2013 at 9:59 PM, Chris Angelico wrote: > On Thu, Apr 18, 2013 at 8:39 AM, James Jong > wrote: > > I managed to compile sqlite with: > > > > CPPFLAGS='-I/path_to_sqlite-3.7.16.2/include -I/path_to_tk8.6.0/include' > > > > DFLAGS='-L/path_to_sqlite-3.7.16.2/lib -L/path_to_tk8.6.0/lib/' > > > > ./configure --prefix=/path_to_python-2.7.4 --enable-shared > > > > However, _tkinter is still failing. I don't know what else to try. Any > > thoughts? > > Can you build Python on a different system (to which you have admin > rights), then deploy the binary to the one where you don't? Then you > could do a much more standard compilation process. As long as the two > systems are broadly similar, it should work. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Apr 18 10:41:30 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 19 Apr 2013 00:41:30 +1000 Subject: Preparing sqlite, dl and tkinter for Python installation (no admin rights) In-Reply-To: References: <1366122614066-5014440.post@n6.nabble.com> Message-ID: On Fri, Apr 19, 2013 at 12:37 AM, James Jong wrote: > Thanks so much Chris. This is part of a super computer and I am afraid I > don't have access to a machine with sudo permissions and similar > architecture & OS. Do you know what the OS is, at least? Can you, for instance, create a virtual machine on your home system that matches the OS? As long as it's broadly the same CPU architecture, chances are it'll run (maybe it won't be completely optimal, but it'd be a start); in any case, it's another possibility to try. (Is the supercomputer doing something with DNA, and that's why you picked your email address?) ChrisA From jason.swails at gmail.com Thu Apr 18 11:05:29 2013 From: jason.swails at gmail.com (Jason Swails) Date: Thu, 18 Apr 2013 11:05:29 -0400 Subject: Preparing sqlite, dl and tkinter for Python installation (no admin rights) In-Reply-To: References: <1366122614066-5014440.post@n6.nabble.com> Message-ID: On Thu, Apr 18, 2013 at 10:37 AM, James Jong wrote: > Thanks so much Chris. This is part of a super computer and I am afraid I > don't have access to a machine with sudo permissions and similar > architecture & OS. > > Is there any way to active higher level of verbosity during the build > process to identify what is failing? Or anything specifically I should > watch for? > Most supercomputers I'm familiar with have some variant of Linux running (e.g., SUSE or Red Hat are quite common). Some of these machines only have barebone kernels on the compute nodes, though, and have a fully-fledged Linux OS only on the login nodes... This info is typically on the website for that supercomputer (if it has one), or any other available documentation. That said, there are other options available that are probably less of a hassle for you: 1) Skip tkinter unless you _know_ you really need it. Do you plan on doing X-forwarding when you log in? Can you run the GUI app on your local machine before uploading the files you need for computation? Running GUIs locally rather than over the network is typically much faster, anyway. 2) Submit a ticket to the supercomputer staff requesting that they install the software you need. There may be other 'gotchas' associated with installing certain software on supercomputers that the staff would know best. Good luck, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From ribonucleico at gmail.com Thu Apr 18 12:24:42 2013 From: ribonucleico at gmail.com (James Jong) Date: Thu, 18 Apr 2013 12:24:42 -0400 Subject: Preparing sqlite, dl and tkinter for Python installation (no admin rights) In-Reply-To: References: <1366122614066-5014440.post@n6.nabble.com> Message-ID: Thanks Jason. I have pinpointed the location of the error to a very specific gcc line. I am reproducing the error below (very easy to read): I run: ================================================================== export CPPFLAGS='-I/opt/sqlite-3.7.16.2/include -I/opt/tk8.6.0/include -I/opt/tcl8.6.0/include/' export LDFLAGS='-L/opt/sqlite-3.7.16.2/lib -L/opt/tk8.6.0/lib/ -L/opt/tcl8.6.0/lib/ ./configure --prefix=/path_to_python-2.7.4 --enable-shared ================================================================== and then I run make and I got the following: ================================================================== .... building '_tkinter' extension gcc -pthread -fPIC -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DWITH_APPINIT=1 -I/usr/X11/include -I. -IInclude -I./Include -I/opt/sqlite/sqlite-3.7.16.2/include -I/opt/tk8.6.0/include -I/opt/tcl8.6.0/include -I/usr/local/include -I/opt/python/src/Python-2.7.4/Include -I/opt/python/src/Python-2.7.4 -c /opt/python/src/Python-2.7.4/Modules/_tkinter.c -o build/temp.linux-x86_64-2.7/opt/python/src/Python-2.7.4/Modules/_tkinter.o gcc -pthread -fPIC -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DWITH_APPINIT=1 -I/usr/X11/include -I. -IInclude -I./Include -I/opt/sqlite/sqlite-3.7.16.2/include -I/opt/tk8.6.0/include -I/opt/tcl8.6.0/include -I/usr/local/include -I/opt/python/src/Python-2.7.4/Include -I/opt/python/src/Python-2.7.4 -c /opt/python/src/Python-2.7.4/Modules/tkappinit.c -o build/temp.linux-x86_64-2.7/opt/python/src/Python-2.7.4/Modules/tkappinit.o gcc -pthread -shared -L/opt/sqlite/sqlite-3.7.16.2/lib -L/opt/tk8.6.0/lib/ -L/opt/tcl8.6.0/lib/ -L/opt/sqlite/sqlite-3.7.16.2/lib -L/opt/tk8.6.0/lib/ -L/opt/tcl8.6.0/lib/ -I. -IInclude -I./Include -I/opt/sqlite/sqlite-3.7.16.2/include -I/opt/tk8.6.0/include -I/opt/tcl8.6.0/include build/temp.linux-x86_64-2.7/opt/python/src/Python-2.7.4/Modules/_tkinter.o build/temp.linux-x86_64-2.7/opt/python/src/Python-2.7.4/Modules/tkappinit.o -L/usr/X11/lib -L/opt/sqlite/sqlite-3.7.16.2/lib -L/opt/tk8.6.0/lib/ -L/opt/tcl8.6.0/lib/ -L/usr/local/lib -L. -ltk8.6 -ltcl8.6 -lX11 -lpython2.7 -o build/lib.linux-x86_64-2.7/_tkinter.so *** WARNING: renaming "_tkinter" since importing it failed: libtk8.6.so: cannot open shared object file: No such file or directory ... ================================================================== The odd thing is that I can see `libtk8.6.so` under /opt/tcl8.6.0/lib, as I specified with `LDFLAGS`: ================================================================== cd /opt/tcl8.6.0/lib ls . ../ pkgconfig tk8.6 libtkstub8.6.a tkConfig.sh libtk8.6.so ================================================================== The file libtk8.6.so has 1.5M and is definitely there. So why did that compilation fail? James On Thu, Apr 18, 2013 at 11:05 AM, Jason Swails wrote: > > > > On Thu, Apr 18, 2013 at 10:37 AM, James Jong wrote: > >> Thanks so much Chris. This is part of a super computer and I am afraid I >> don't have access to a machine with sudo permissions and similar >> architecture & OS. >> >> Is there any way to active higher level of verbosity during the build >> process to identify what is failing? Or anything specifically I should >> watch for? >> > > Most supercomputers I'm familiar with have some variant of Linux running > (e.g., SUSE or Red Hat are quite common). Some of these machines only have > barebone kernels on the compute nodes, though, and have a fully-fledged > Linux OS only on the login nodes... This info is typically on the website > for that supercomputer (if it has one), or any other available > documentation. > > That said, there are other options available that are probably less of a > hassle for you: > > 1) Skip tkinter unless you _know_ you really need it. Do you plan on > doing X-forwarding when you log in? Can you run the GUI app on your local > machine before uploading the files you need for computation? Running GUIs > locally rather than over the network is typically much faster, anyway. > > 2) Submit a ticket to the supercomputer staff requesting that they install > the software you need. There may be other 'gotchas' associated with > installing certain software on supercomputers that the staff would know > best. > > Good luck, > Jason > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ribonucleico at gmail.com Thu Apr 18 14:09:36 2013 From: ribonucleico at gmail.com (James Jong) Date: Thu, 18 Apr 2013 14:09:36 -0400 Subject: Preparing sqlite, dl and tkinter for Python installation (no admin rights) In-Reply-To: References: <1366122614066-5014440.post@n6.nabble.com> Message-ID: All I finally solved the problem. The problem was that setup.py tests loading the dynamic library libtk (this I don't understand, since I though Python would statically link against TCL, TK and SQLITE. Either way, I have updated the thread at StackOverflow with the answer: http://stackoverflow.com/questions/16026348/preparing-tkinter-and-sqlite3-for-python-installation-no-admin-rights/16090051#16090051 but basically the answer was: Add the following include paths through `CPPFLAGS` * /path_to/sqlite3/include * /path_to/tcl/include * /path_to/tk/include the following lib paths through `LDFLAGS` * /path_to/sqlite3/lib * /path_to/tcl/lib * /path_to/tk/lib and the following lib paths through `LD_LIBRARY_PATH`: * /path_to/sqlite/lib * /path_to/tcl/lib * /path_to/tk/lib Thanks, James On Thu, Apr 18, 2013 at 12:24 PM, James Jong wrote: > Thanks Jason. I have pinpointed the location of the error to a very > specific gcc line. I am reproducing the error below (very easy to read): > > I run: > > ================================================================== > export CPPFLAGS='-I/opt/sqlite-3.7.16.2/include -I/opt/tk8.6.0/include > -I/opt/tcl8.6.0/include/' > > export LDFLAGS='-L/opt/sqlite-3.7.16.2/lib -L/opt/tk8.6.0/lib/ > -L/opt/tcl8.6.0/lib/ ./configure --prefix=/path_to_python-2.7.4 > --enable-shared > ================================================================== > > and then I run make and I got the following: > > ================================================================== > .... > building '_tkinter' extension > > gcc -pthread -fPIC -fno-strict-aliasing > -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DWITH_APPINIT=1 > -I/usr/X11/include -I. -IInclude -I./Include > -I/opt/sqlite/sqlite-3.7.16.2/include -I/opt/tk8.6.0/include > -I/opt/tcl8.6.0/include -I/usr/local/include > -I/opt/python/src/Python-2.7.4/Include -I/opt/python/src/Python-2.7.4 -c > /opt/python/src/Python-2.7.4/Modules/_tkinter.c -o > build/temp.linux-x86_64-2.7/opt/python/src/Python-2.7.4/Modules/_tkinter.o > > gcc -pthread -fPIC -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 > -Wall -Wstrict-prototypes -DWITH_APPINIT=1 -I/usr/X11/include -I. > -IInclude -I./Include -I/opt/sqlite/sqlite-3.7.16.2/include > -I/opt/tk8.6.0/include -I/opt/tcl8.6.0/include -I/usr/local/include > -I/opt/python/src/Python-2.7.4/Include -I/opt/python/src/Python-2.7.4 -c > /opt/python/src/Python-2.7.4/Modules/tkappinit.c -o > build/temp.linux-x86_64-2.7/opt/python/src/Python-2.7.4/Modules/tkappinit.o > > gcc -pthread -shared -L/opt/sqlite/sqlite-3.7.16.2/lib > -L/opt/tk8.6.0/lib/ -L/opt/tcl8.6.0/lib/ -L/opt/sqlite/sqlite-3.7.16.2/lib > -L/opt/tk8.6.0/lib/ -L/opt/tcl8.6.0/lib/ -I. -IInclude -I./Include > -I/opt/sqlite/sqlite-3.7.16.2/include -I/opt/tk8.6.0/include > -I/opt/tcl8.6.0/include > build/temp.linux-x86_64-2.7/opt/python/src/Python-2.7.4/Modules/_tkinter.o > build/temp.linux-x86_64-2.7/opt/python/src/Python-2.7.4/Modules/tkappinit.o > -L/usr/X11/lib -L/opt/sqlite/sqlite-3.7.16.2/lib -L/opt/tk8.6.0/lib/ > -L/opt/tcl8.6.0/lib/ -L/usr/local/lib -L. -ltk8.6 -ltcl8.6 -lX11 > -lpython2.7 -o build/lib.linux-x86_64-2.7/_tkinter.so > > *** WARNING: renaming "_tkinter" since importing it failed: libtk8.6.so: > cannot open shared object file: No such file or directory > ... > ================================================================== > > The odd thing is that I can see `libtk8.6.so` under /opt/tcl8.6.0/lib, > as I specified with `LDFLAGS`: > > ================================================================== > cd /opt/tcl8.6.0/lib > ls > . > ../ > pkgconfig > tk8.6 > libtkstub8.6.a > tkConfig.sh > libtk8.6.so > ================================================================== > > The file libtk8.6.so has 1.5M and is definitely there. > > So why did that compilation fail? > > James > > > > On Thu, Apr 18, 2013 at 11:05 AM, Jason Swails wrote: > >> >> >> >> On Thu, Apr 18, 2013 at 10:37 AM, James Jong wrote: >> >>> Thanks so much Chris. This is part of a super computer and I am afraid I >>> don't have access to a machine with sudo permissions and similar >>> architecture & OS. >>> >>> Is there any way to active higher level of verbosity during the build >>> process to identify what is failing? Or anything specifically I should >>> watch for? >>> >> >> Most supercomputers I'm familiar with have some variant of Linux running >> (e.g., SUSE or Red Hat are quite common). Some of these machines only have >> barebone kernels on the compute nodes, though, and have a fully-fledged >> Linux OS only on the login nodes... This info is typically on the website >> for that supercomputer (if it has one), or any other available >> documentation. >> >> That said, there are other options available that are probably less of a >> hassle for you: >> >> 1) Skip tkinter unless you _know_ you really need it. Do you plan on >> doing X-forwarding when you log in? Can you run the GUI app on your local >> machine before uploading the files you need for computation? Running GUIs >> locally rather than over the network is typically much faster, anyway. >> >> 2) Submit a ticket to the supercomputer staff requesting that they >> install the software you need. There may be other 'gotchas' associated >> with installing certain software on supercomputers that the staff would >> know best. >> >> Good luck, >> Jason >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Thu Apr 18 15:10:24 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Thu, 18 Apr 2013 15:10:24 -0400 Subject: Preparing sqlite, dl and tkinter for Python installation (no admin rights) In-Reply-To: References: <1366122614066-5014440.post@n6.nabble.com> Message-ID: On 4/18/2013 12:24 PM, James Jong wrote: After compiling, you might want to run the test suite. > libtk8.6.so I do not know that Python/_tkinter/tkinter has been very well tested, certainly not on all systems, with the newish tcl/tk 8.6, as opposed to 8.5.z used for several years. There are 4 test/test_xxx files to be concerned about: something like test_tcl, test_tkinter, test_ttkxxx. From ribonucleico at gmail.com Thu Apr 18 15:21:51 2013 From: ribonucleico at gmail.com (James Jong) Date: Thu, 18 Apr 2013 15:21:51 -0400 Subject: Preparing sqlite, dl and tkinter for Python installation (no admin rights) In-Reply-To: References: <1366122614066-5014440.post@n6.nabble.com> Message-ID: Thanks Terry. I run the tcl tests and passed them all. There was only one tk test that I think I didn't pass. One thing I don't understand is that I thought that Python would statically link against sqlite and tcl/tk (I presume that this is the reason why you said I could build it in a similar system and copy it to the supercomputer). But this thread shows that, at least, setup.py tries to load libtk.so (a dynamic shared library). Does Python then load dynamic libraries from sqlite, tcl, tk when using the respective modules? James On Thu, Apr 18, 2013 at 3:10 PM, Terry Jan Reedy wrote: > On 4/18/2013 12:24 PM, James Jong wrote: > > After compiling, you might want to run the test suite. > > libtk8.6.so >> > > I do not know that Python/_tkinter/tkinter has been very well tested, > certainly not on all systems, with the newish tcl/tk 8.6, as opposed to > 8.5.z used for several years. There are 4 test/test_xxx files to be > concerned about: something like test_tcl, test_tkinter, test_ttkxxx. > > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Thu Apr 18 16:34:41 2013 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Apr 2013 16:34:41 -0400 Subject: Preparing sqlite, dl and tkinter for Python installation (no admin rights) In-Reply-To: References: <1366122614066-5014440.post@n6.nabble.com> Message-ID: <517058E1.6090506@udel.edu> On 4/18/2013 3:21 PM, James Jong wrote: > Thanks Terry. I run the tcl tests and passed them all. There was only > one tk test that I think I didn't pass. > > One thing I don't understand is that I thought that Python would > statically link against sqlite and tcl/tk (I presume that this is the > reason why you said I could build it in a similar system and copy it > to the supercomputer). I am not the one who said that. i presume whoever did meant to copy the necessary .sos, but I am not using *nix. From rosuav at gmail.com Thu Apr 18 17:49:52 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 19 Apr 2013 07:49:52 +1000 Subject: Preparing sqlite, dl and tkinter for Python installation (no admin rights) In-Reply-To: <517058E1.6090506@udel.edu> References: <1366122614066-5014440.post@n6.nabble.com> <517058E1.6090506@udel.edu> Message-ID: On Fri, Apr 19, 2013 at 6:34 AM, Terry Reedy wrote: > On 4/18/2013 3:21 PM, James Jong wrote: >> >> Thanks Terry. I run the tcl tests and passed them all. There was only one >> tk test that I think I didn't pass. >> >> One thing I don't understand is that I thought that Python would >> statically link against sqlite and tcl/tk (I presume that this is the reason >> why you said I could build it in a similar system and copy it to the >> supercomputer). > > > I am not the one who said that. i presume whoever did meant to copy the > necessary .sos, but I am not using *nix. I'm the one who was talking about the build/copy. You could manually copy a bunch of .so, but there's a reasonable chance you wouldn't need to - in many Linux systems, you have the binary packages for heaps of things that you don't have the dev libraries (headers, .a files, whatever) for. At work, we have just one computer on which we build from C source (which happens to be my personal dev unit as well); all the other computers - other devs' laptops, staging servers, production servers - just get binaries deployed directly. There aren't very many libraries to install on them, as they're fully-functional Linux boxes already (we use Debian). It may, of course, be different on your setup, but I figured it was worth a try. ChrisA From storchaka at gmail.com Fri Apr 19 12:27:34 2013 From: storchaka at gmail.com (Serhiy Storchaka) Date: Fri, 19 Apr 2013 19:27:34 +0300 Subject: Preparing sqlite, dl and tkinter for Python installation (no admin rights) In-Reply-To: References: <1366122614066-5014440.post@n6.nabble.com> Message-ID: 18.04.13 19:24, James Jong ???????(??): > The file libtk8.6.so has 1.5M and is definitely there. > > So why did that compilation fail? LD_LIBRARY_PATH=/path_to_libtk However be careful. For now Python doesn't support Tk 8.6 (results of some functions changed in 8.6), this is a known bug (issue16809). You can build Python with Tk 8.6 and even run, but any real tkinter application likely will failed. Use Tk 8.5 instead. From ribonucleico at gmail.com Sun Apr 21 16:31:33 2013 From: ribonucleico at gmail.com (James Jong) Date: Sun, 21 Apr 2013 16:31:33 -0400 Subject: Preparing sqlite, dl and tkinter for Python installation (no admin rights) In-Reply-To: References: <1366122614066-5014440.post@n6.nabble.com> Message-ID: I see, just to be clear, do you mean that Python 2.7.4 (stable) is incompatible with Tk 8.6 (stable)? James On Fri, Apr 19, 2013 at 12:27 PM, Serhiy Storchaka wrote: > 18.04.13 19:24, James Jong ???????(??): > >> The file libtk8.6.so has 1.5M and is definitely >> there. >> >> >> So why did that compilation fail? >> > > LD_LIBRARY_PATH=/path_to_libtk > > However be careful. For now Python doesn't support Tk 8.6 (results of some > functions changed in 8.6), this is a known bug (issue16809). You can build > Python with Tk 8.6 and even run, but any real tkinter application likely > will failed. Use Tk 8.5 instead. > > > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From storchaka at gmail.com Mon Apr 22 10:24:09 2013 From: storchaka at gmail.com (Serhiy Storchaka) Date: Mon, 22 Apr 2013 17:24:09 +0300 Subject: Preparing sqlite, dl and tkinter for Python installation (no admin rights) In-Reply-To: References: <1366122614066-5014440.post@n6.nabble.com> Message-ID: On 21.04.13 23:31, James Jong wrote: > I see, just to be clear, do you mean that Python 2.7.4 (stable) is > incompatible with Tk 8.6 (stable)? Yes. From idkfaidkfaidkfa at gmail.com Tue Apr 16 11:20:44 2013 From: idkfaidkfaidkfa at gmail.com (idkfaidkfaidkfa at gmail.com) Date: Tue, 16 Apr 2013 08:20:44 -0700 (PDT) Subject: Newbie questions on Python Message-ID: Hi all, i'm programming in python for the first time (usually i use C as programming language). I don't understand these results: >>> a=[1,2,3,4,5] >>> a[:-1] [1, 2, 3, 4] >>> a[::-1] [5, 4, 3, 2, 1] >>> a[2::-1] [3, 2, 1] what does a[2::-1] means? Thanks From rosuav at gmail.com Tue Apr 16 11:30:03 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Apr 2013 01:30:03 +1000 Subject: Newbie questions on Python In-Reply-To: References: Message-ID: On Wed, Apr 17, 2013 at 1:20 AM, wrote: > Hi all, > i'm programming in python for the first time (usually i use C as programming language). I don't understand these results: > >>>> a=[1,2,3,4,5] >>>> a[:-1] > [1, 2, 3, 4] >>>> a[::-1] > [5, 4, 3, 2, 1] >>>> a[2::-1] > [3, 2, 1] > > what does a[2::-1] means? That's taking a slice. This page has something to say on the subject: http://docs.python.org/3.3/tutorial/introduction.html By the way, regarding your email address: there are no cheat codes in Python... either that, or Python *is* a cheat code. :) ChrisA [[ VERY HAPPY CODING ADDED ]] From matt.walker.jones at gmail.com Tue Apr 16 11:33:51 2013 From: matt.walker.jones at gmail.com (Matt Jones) Date: Tue, 16 Apr 2013 10:33:51 -0500 Subject: Newbie questions on Python In-Reply-To: References: Message-ID: When slicing: l[start:end:step] In your example of "a[2::-1]" you are reversing the list by using a step of -1, then you are slicing at index 2 (third element). *Matt Jones* On Tue, Apr 16, 2013 at 10:30 AM, Chris Angelico wrote: > On Wed, Apr 17, 2013 at 1:20 AM, wrote: > > Hi all, > > i'm programming in python for the first time (usually i use C as > programming language). I don't understand these results: > > > >>>> a=[1,2,3,4,5] > >>>> a[:-1] > > [1, 2, 3, 4] > >>>> a[::-1] > > [5, 4, 3, 2, 1] > >>>> a[2::-1] > > [3, 2, 1] > > > > what does a[2::-1] means? > > That's taking a slice. This page has something to say on the subject: > > http://docs.python.org/3.3/tutorial/introduction.html > > By the way, regarding your email address: there are no cheat codes in > Python... either that, or Python *is* a cheat code. :) > > ChrisA > [[ VERY HAPPY CODING ADDED ]] > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From neilc at norwich.edu Tue Apr 16 11:41:13 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 16 Apr 2013 15:41:13 GMT Subject: Newbie questions on Python References: Message-ID: On 2013-04-16, idkfaidkfaidkfa at gmail.com wrote: > Hi all, > i'm programming in python for the first time (usually i use C as programming language). I don't understand these results: > >>>> a=[1,2,3,4,5] >>>> a[:-1] > [1, 2, 3, 4] >>>> a[::-1] > [5, 4, 3, 2, 1] >>>> a[2::-1] > [3, 2, 1] The third item is the "step". The default value is 1. If you provide a negative step, your slice will be in reverse. So you are getting item 2 through 0 in reverse order in your result slice. Imagine something like the following for loop taking place somewhere: for (int i = 2; i <= 0; --i) { fprintf(a[i]); } -- Neil Cerutti From lele at metapensiero.it Tue Apr 16 12:06:41 2013 From: lele at metapensiero.it (Lele Gaifax) Date: Tue, 16 Apr 2013 18:06:41 +0200 Subject: Newbie questions on Python References: Message-ID: <87li8i5ujy.fsf@nautilus.nautilus> Neil Cerutti writes: > Imagine something like the following for loop taking place > somewhere: > > for (int i = 2; i <= 0; --i) { > fprintf(a[i]); > } Neil most probably meant for (int i = 2; i >= 0; --i) { fprintf(a[i]); } where "fprintf" is actually a fictitious "do_something" function. 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 neilc at norwich.edu Tue Apr 16 13:16:17 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 16 Apr 2013 17:16:17 GMT Subject: Newbie questions on Python References: Message-ID: On 2013-04-16, Lele Gaifax wrote: > Neil Cerutti writes: > >> Imagine something like the following for loop taking place >> somewhere: >> >> for (int i = 2; i <= 0; --i) { >> fprintf(a[i]); >> } > > Neil most probably meant > > for (int i = 2; i >= 0; --i) { > fprintf(a[i]); > } > > where "fprintf" is actually a fictitious "do_something" function. > > ciao, lele. Thanks for the correction. -- Neil Cerutti From walterhurry at lavabit.com Tue Apr 16 17:40:42 2013 From: walterhurry at lavabit.com (Walter Hurry) Date: Tue, 16 Apr 2013 21:40:42 +0000 (UTC) Subject: Newbie questions on Python References: Message-ID: On Wed, 17 Apr 2013 01:30:03 +1000, Chris Angelico wrote: > By the way, regarding your email address: there are no cheat codes in > Python ROFLMAO. Incidentally, my son used to use IDDQD rather than IDKFA. I of course spurned all such, since I preferred to do it the hard way. Thus I was Doomed. From rosuav at gmail.com Tue Apr 16 17:53:29 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Apr 2013 07:53:29 +1000 Subject: Newbie questions on Python In-Reply-To: References: Message-ID: On Wed, Apr 17, 2013 at 7:40 AM, Walter Hurry wrote: > On Wed, 17 Apr 2013 01:30:03 +1000, Chris Angelico wrote: > >> By the way, regarding your email address: there are no cheat codes in >> Python > > ROFLMAO. Incidentally, my son used to use IDDQD rather than IDKFA. > > I of course spurned all such, since I preferred to do it the hard way. > Thus I was Doomed. I'd sometimes use IDDQD/IDFA (no K) and then see how quickly I could blitz the levels, with proper navigation. There's something inherently fun about blasting through everything with the rocket launcher. Mind you, I was really cheap, so I never bought Doom... and was just playing through the demo over and over. ChrisA From mecagonoisician at gmail.com Tue Apr 16 11:37:01 2013 From: mecagonoisician at gmail.com (aaB) Date: Tue, 16 Apr 2013 17:37:01 +0200 Subject: a couple of things I don't understand wrt lists Message-ID: <20130416153701.GA18377@gmail.com> hello, I am a beginner programmer. I started learning programming about a year and a half ago, using C. I picked up python a few months ago, but only wrote very few scripts. I am currently trying to learn more about the python way of doing things by writing a script that generates png images using a 1D cellular automaton. While writing preliminary code for that project, I ran into a behaviour that I don't understand. I am using python 2.7 on a linux system. I represent the CA's rule with a list of integers, of value 1 or 0. Here is the function I use to generate the list: def get_rule(rulenum): rule = [] while rulenum > 0: rule.append(rulenume % 2) rulenum /= 2 while len(rule) < 8: rule.append(0) rule.reverse() return rule if i call it by writing: rule = getrule(int(8)) and then call: print rule the output is good: [0, 0, 0, 0, 1, 0, 0, 0] I then tried to print each item of the list using a for loop: for i in range(rule): print rule[i] the output is, as expected: 0 0 0 0 1 0 0 0 but when I do: for i in rule: print rule[i] I get the "complement": 1 1 1 1 0 1 1 1 There must be something I didn't understand correctly in the for statement, but I really can't think of a reason why the output is what it is. I tried this using the interactive console, and the results are the same, whatever the length of the list, i always get the complement of my bit pattern. Any pointers to help me understand this would be appreciated. I am also running into an other issue with this script, but I'd rather understand this before asking further questions. Thanks, and sorry for the rather long post. From rosuav at gmail.com Tue Apr 16 11:43:06 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Apr 2013 01:43:06 +1000 Subject: a couple of things I don't understand wrt lists In-Reply-To: <20130416153701.GA18377@gmail.com> References: <20130416153701.GA18377@gmail.com> Message-ID: On Wed, Apr 17, 2013 at 1:37 AM, aaB wrote: > but when I do: > > for i in rule: > print rule[i] When you iterate over rule, you don't iterate over the indices, but over the values themselves. Try this: for i in rule: print i Incidentally, "for i in range(rule)" isn't actually going to work; what you would have used is "for i in range(len(rule))". Be careful with that sort of thing; it's usually safest to actually copy and paste from an interactive session, rather than reconstruct manually. Sometimes it's not obvious whether it was a copy/paste problem or the cause of your underlying confusion. ChrisA From mecagonoisician at gmail.com Wed Apr 17 06:25:37 2013 From: mecagonoisician at gmail.com (aaB) Date: Wed, 17 Apr 2013 12:25:37 +0200 Subject: a couple of things I don't understand wrt lists In-Reply-To: References: <20130416153701.GA18377@gmail.com> Message-ID: <20130417102537.GA19967@gmail.com> Hello, Thanks for all your replies, things are getting clearer. - copy/paste vs retyping: Several people have remarked that I had retyped instead of copy/pasting. This is exactly what happened, the fact is I haven't figured out yet how to enable copy/pasting from urxvt to vim. I'll try to get this done before posting output from an interactive session. - iterating a list: If I understand what you've told me, bitpattern = [1, 0, 0, 1, 1, 0, 1] for bit in bitpattern: print bit and bitpattern = [1, 0, 0, 1, 1, 0, 1] for i in range(len(bitpattern)): print bitpattern[i] are equivalent, the former being more "python" and the latter being something like C written using python syntax. - the "complement" thing: I haven't yet tried to reproduce this, but I will, and I will post back if I see this happening again, this time with a real log of python's interactive console, or a complete script which people can use. - list comprehension: I wasn't at all aware of this, thanks a lot for pointing it out. I had an other function that generated a list of cells for the CA, each cell being randomly alive or dead. I have rewritten it using list comprehension, def populate(n): random.seed() return [random.randint(0,1) for i in range(n)] which works the same as my previous, C-like, version but feels much better. I might come back to you all but you've already given me a good push forward, so I guess I'll be trying to use it as much as I can before asking for an other. From lele at metapensiero.it Wed Apr 17 07:13:24 2013 From: lele at metapensiero.it (Lele Gaifax) Date: Wed, 17 Apr 2013 13:13:24 +0200 Subject: a couple of things I don't understand wrt lists References: <20130416153701.GA18377@gmail.com> <20130417102537.GA19967@gmail.com> Message-ID: <87txn5l8a3.fsf@nautilus.nautilus> aaB writes: > - copy/paste vs retyping: > Several people have remarked that I had retyped instead of copy/pasting. > This is exactly what happened, the fact is I haven't figured out yet how to > enable copy/pasting from urxvt to vim. I used to use rxvt, but since a while I switched to roxterm for exactly that annoying problem: I may be wrong, but urxvt uses only the "ancient" X cut&paste way of selecting a region with the mouse and then using the middle mouse button to paste it back. 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 mecagonoisician at gmail.com Thu Apr 18 09:01:01 2013 From: mecagonoisician at gmail.com (aaB) Date: Thu, 18 Apr 2013 15:01:01 +0200 Subject: a couple of things I don't understand wrt lists In-Reply-To: <20130417102537.GA19967@gmail.com> References: <20130416153701.GA18377@gmail.com> <20130417102537.GA19967@gmail.com> Message-ID: <20130418130101.GA22185@gmail.com> Hello, I am still in the process of writing preliminary code for my CA project. I am now running into a behavior that I can't explain. Here is a script which, at least on my system, shows the issue (python2.7 on a linux system). The final project will be wrapping these functions (and others) into a class which will be in a module which can be imported into a script. #!/usr/bin/python2 import sys import random def get_rule(rulenum): bitpattern = bin(rulenum)[2:] return [0]*(8-len(bitpattern)) + [int(bit) for bit in bitpattern] def populate(n): random.seed() return [random.randint(0,1) for i in range(n)] def get_index(thisgen, i): n = len(thisgen)-1 cell = thisgen[i] if i is 0: print "i==0" prev, next = thisgen[n], thisgen[i+1] elif i is n: print "i==%d" % n prev, next = thisgen[i-1], thisgen[0] else: prev, next = thisgen[i-1], thisgen[i+1] return prev*4 + cell*2 + next def get_nextgen(thisgen, rule): return [rule[get_index(thisgen, i)] for i in range(len(thisgen))] if len(sys.argv) == 2: n = int(sys.argv[1]) else: n = 257 rule = get_rule(145) thisgen = populate(n) nextgen = get_nextgen(thisgen, rule) print "done for n == 257" n = 258 thisgen = populate(n) nextgen = get_nextgen(thisgen, rule) My issue is that when n == 257, the script runs as expected, but if n >= 258, I get an "IndexError: list index out of range". The script is also attached to the email in case someone would like to try it on their machine. The print statements in the get_index() function's branching show me that, when I get the "out of range" error, the program doesn't enter the "elif i is n" condition, although it does for lower values of n. I'm sorry, but I still haven't found a way to copy/paste from the terminal to vim. This behaviour occurred previously and had stopped when I used an other version of the get_index() function. At that time, get_index() wasn't a function and was just conditional branching inside get_nextgen, I wanted to use the list comprehension syntax to build nextgen, and this got me into seperating the get_index() routine. -------------- next part -------------- A non-text attachment was scrubbed... Name: testca.py Type: text/x-python Size: 896 bytes Desc: not available URL: From davea at davea.name Thu Apr 18 09:23:22 2013 From: davea at davea.name (Dave Angel) Date: Thu, 18 Apr 2013 09:23:22 -0400 Subject: a couple of things I don't understand wrt lists In-Reply-To: <20130418130101.GA22185@gmail.com> References: <20130416153701.GA18377@gmail.com> <20130417102537.GA19967@gmail.com> <20130418130101.GA22185@gmail.com> Message-ID: <516FF3CA.7030407@davea.name> On 04/18/2013 09:01 AM, aaB wrote: > Hello, > > I am still in the process of writing preliminary code for my CA project. > I am now running into a behavior that I can't explain. > > Here is a script which, at least on my system, shows the issue (python2.7 on a > linux system). > The final project will be wrapping these functions (and others) into a class > which will be in a module which can be imported into a script. > > #!/usr/bin/python2 > > import sys > import random > > def get_rule(rulenum): > bitpattern = bin(rulenum)[2:] > return [0]*(8-len(bitpattern)) + [int(bit) for bit in bitpattern] > > def populate(n): > random.seed() > return [random.randint(0,1) for i in range(n)] > > def get_index(thisgen, i): > n = len(thisgen)-1 > cell = thisgen[i] > if i is 0: > print "i==0" > prev, next = thisgen[n], thisgen[i+1] > elif i is n: Don't use 'is' here and above. You're not looking for a matching object, you're looking for the same value. > print "i==%d" % n > prev, next = thisgen[i-1], thisgen[0] > else: > prev, next = thisgen[i-1], thisgen[i+1] > return prev*4 + cell*2 + next > > def get_nextgen(thisgen, rule): > return [rule[get_index(thisgen, i)] for i in range(len(thisgen))] > > > if len(sys.argv) == 2: > n = int(sys.argv[1]) > else: > n = 257 > > rule = get_rule(145) > thisgen = populate(n) > nextgen = get_nextgen(thisgen, rule) > print "done for n == 257" > > n = 258 > thisgen = populate(n) > nextgen = get_nextgen(thisgen, rule) > > > My issue is that when n == 257, the script runs as expected, but if n >= 258, I > get an "IndexError: list index out of range". No, you get an exception traceback. Please paste in the whole traceback instead of making everyone guess where in the code it might be getting the exception. My *guess* is that somewhere you're assuming that 8 bits is enough to encode 258 possibilities. I'd have expected that to fail at 256 and larger, but it's a place to look. The second guess, more likely, is that you're using "is" to compare numbers, and that's never a safe idea. It might happen to work for small numbers, but you should be using ==. if i == 0: elf i == n: > The script is also attached to the email Attachments aren't necessarily visible to everyone reading the mailing list. Just make sure you post in text mode (which you did), and that should take care of spurious indentation bugs. -- DaveA From mecagonoisician at gmail.com Thu Apr 18 09:50:44 2013 From: mecagonoisician at gmail.com (aaB) Date: Thu, 18 Apr 2013 15:50:44 +0200 Subject: a couple of things I don't understand wrt lists In-Reply-To: <516FF3CA.7030407@davea.name> References: <20130416153701.GA18377@gmail.com> <20130417102537.GA19967@gmail.com> <20130418130101.GA22185@gmail.com> <516FF3CA.7030407@davea.name> Message-ID: <20130418135044.GB22185@gmail.com> > The second guess, more likely, is that you're using "is" to compare > numbers, and that's never a safe idea. It might happen to work for > small numbers, but you should be using ==. The second guess was right, changing "is" for "==" solved it, thanks. I still have a lot to learn about python semantics. The 8 bit pattern is used to store the rule, not the cells. To compute the next cell, I index the rule list, based on the values of that cell and it's two immediate neighbours in the previous generation. This probably isn't the simplest way. Since I am using only 3 cells to compute 1 cell, the biggest index would be 2**3 - 1, hence the 8bit pattern for the rule. From rosuav at gmail.com Thu Apr 18 10:27:14 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 19 Apr 2013 00:27:14 +1000 Subject: a couple of things I don't understand wrt lists In-Reply-To: <20130418130101.GA22185@gmail.com> References: <20130416153701.GA18377@gmail.com> <20130417102537.GA19967@gmail.com> <20130418130101.GA22185@gmail.com> Message-ID: On Thu, Apr 18, 2013 at 11:01 PM, aaB wrote: > def get_index(thisgen, i): > n = len(thisgen)-1 > cell = thisgen[i] > if i is 0: > print "i==0" > prev, next = thisgen[n], thisgen[i+1] > elif i is n: > print "i==%d" % n > prev, next = thisgen[i-1], thisgen[0] > else: > prev, next = thisgen[i-1], thisgen[i+1] > return prev*4 + cell*2 + next Without seeing the exception traceback I can't be sure, but here's what I think might be happening: When n == 258, your "i is n" check never happens. Since your protective check for the end of the list doesn't fire, you therefore go into the 'else' clause, and attempt to index thisgen[i+1], which doesn't work. CPython precreates and caches a certain subset of integers, for performance. The exact set depends on the CPython version, but it's low integers only. Within that set, equality is always matched by identity: i = 3 j = i+1 k = j-1 print(i is k) This will most likely print "True" on CPython. But change i to, say, 10000000, and you may find the opposite result. So you can sometimes get away with the dangerous option of testing integers for identity, but the right thing to do is to test for equality. (You even get that right in your debugging messages, using "==" there.) A couple of other tips: > n = len(thisgen)-1 > if i is 0: > prev, next = thisgen[n], thisgen[i+1] You can reference thisgen[-1] instead of thisgen[n] - so you can fold this one into the default case. So all you need to do is deal with the one possibility that i==len(thisgen)-1 and everything else is in the else. > def populate(n): > random.seed() > return [random.randint(0,1) for i in range(n)] Don't reseed your RNG every call; just seed it once and let it run. Seeding the RNG (without using a specific value, which you're not doing here) is done in one of two ways: either from an OS-supplied source of randomness (eg /dev/random), or from the time of day. Reseeding repeatedly from /dev/random is unnecessary and might impact other processes (forcing them to block for lack of available entropy); reseeding from the time of day could mean that every call to populate() returns the exact same sequence of numbers. Have fun! ChrisA From darnold992000 at yahoo.com Wed Apr 17 09:43:42 2013 From: darnold992000 at yahoo.com (darnold) Date: Wed, 17 Apr 2013 06:43:42 -0700 (PDT) Subject: a couple of things I don't understand wrt lists References: <20130416153701.GA18377@gmail.com> Message-ID: <6c644737-28c2-4437-b584-449c55df262d@i5g2000yqh.googlegroups.com> On Apr 17, 5:25 am, aaB wrote: > > - the "complement" thing: > I haven't yet tried to reproduce this, but I will, and I will post back if I see > this happening again, this time with a real log of python's interactive console, > or a complete script which people can use. > That was happening when you incorrectly used bit as an index back into bitpattern. When you do that, the behavior actually changes depending on the value of bitpattern: a bitpattern that starts with [1, 0, ...] will yield its complement: >>> bitpattern = [1, 0, 0, 1, 1, 0, 1] >>> for bit in bitpattern: print 'bitpattern[%s] : %s' % (bit, bitpattern[bit]) bitpattern[1] : 0 bitpattern[0] : 1 bitpattern[0] : 1 bitpattern[1] : 0 bitpattern[1] : 0 bitpattern[0] : 1 bitpattern[1] : 0 >>> while a bitpattern that starts with [0, 1, ...] will yield the expected results: >>> bitpattern = [0, 1, 0, 1, 1, 0, 1] >>> for bit in bitpattern: print 'bitpattern[%s] : %s' % (bit, bitpattern[bit]) bitpattern[0] : 0 bitpattern[1] : 1 bitpattern[0] : 0 bitpattern[1] : 1 bitpattern[1] : 1 bitpattern[0] : 0 bitpattern[1] : 1 >>> HTH, Don From gordon at panix.com Tue Apr 16 12:43:23 2013 From: gordon at panix.com (John Gordon) Date: Tue, 16 Apr 2013 16:43:23 +0000 (UTC) Subject: a couple of things I don't understand wrt lists References: Message-ID: In aaB writes: > but when I do: > for i in rule: > print rule[i] > I get the "complement": > 1 > 1 > 1 > 1 > 0 > 1 > 1 > 1 When you iterate over a list with this statement: for i in rule: i contains each successive list item. However, your code: print rule[i] acts as though i is the list item's *subscript*, which is incorrect. In effect, your code is doing this: print rule[0] print rule[0] print rule[0] print rule[0] print rule[1] print rule[0] print rule[0] print rule[0] Although in your example both rule[0] and rule[1] are zero, so I don't know why '1' ever got printed. Also, as far as I can tell, this code should not have worked at all: for i in range(rule): print rule[i] The range() function expects an integer, not a list. -- 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 orgnut at yahoo.com Wed Apr 17 00:57:06 2013 From: orgnut at yahoo.com (Larry Hudson) Date: Tue, 16 Apr 2013 21:57:06 -0700 Subject: a couple of things I don't understand wrt lists In-Reply-To: References: Message-ID: <2rGdndNcINM-tvPMnZ2dnUVZ_jqdnZ2d@giganews.com> On 04/16/2013 08:37 AM, aaB wrote: > hello, > > > I represent the CA's rule with a list of integers, of value 1 or 0. > Here is the function I use to generate the list: > > def get_rule(rulenum): > rule = [] > while rulenum > 0: > rule.append(rulenume % 2) > rulenum /= 2 > while len(rule) < 8: > rule.append(0) > rule.reverse() > return rule > It appears what you are trying to do is create an eight-element list corresponding to the binary value of rulenum. Here is a different approach, using some other functions and features of Python... First you can use the bin() function to get the binary value of an integer as a string. But this string has a leading '0b', which can be cut off with slicing. eg. (using your example value of 8 and bs as the variable name for the binary string) bin(8) gives the string '0b1000', so slicing off the two leading characters: bs = bin(8)[2:] bs becomes the string '1000' Now, the number of leading zeros needed is (8 - len(bs)). You can create the initial list of leading zeros with the statement: rule = [0] * (8 - len(bs)). This gives rule as the list [0, 0, 0, 0]. Finally use a for loop to append the rest if the binary string as integers for i in bs: rule.append(int(i)) So your function becomes (with a few changed variable names): def get_rule(num): bs = bin(num)[2:] rule = [0] * (8 - len(bs)) for i in bs: rule.append(int(i)) return rule This can be shortened even more with a list comprehension. You can think of a list comprehension essentially as a terse variation of a for loop specifically to create a list. So using a list comprehension you can do it in two lines: def get_rule(num): bs = bin(num)[2:] return [0] * (8 - len(bs)) + [int(i) for i in bs] Again, I'm assuming you specifically want an 8-element list. But this could easily be generalized for any length by adding a second function parameter, say size, and change the 8 in the last statement to size. > Any pointers to help me understand this would be appreciated. > I am also running into an other issue with this script, but I'd rather > understand this before asking further questions. > > Thanks, and sorry for the rather long post. > Don't worry about the length -- my reply is plenty wordy as well. I'm hoping I went into enough detail that you can understand it without it being too advanced. Mainly I was just trying to show you a different approach using other features of Python. There's nothing wrong with your approach, it is quite straight-forward. In fact I used the same basic approach when I was writing a C function to commify the display of integers -- that is, to add commas every third digit.(*) Just about anything in programming can be approached in several different ways. I'm not saying mine is better, and certainly not the best, just different. I'm not a newbie but FAR from an expert. Keep learning Python, I think you'll like it. (*)A special function for this isn't necessary in Python, it's already built in the the new-style string formatting. Try this statement: '{:,}'.format(1000000) (That's a colon and comma inside the curly braces.) -=- Larry -=- From storchaka at gmail.com Wed Apr 17 05:35:07 2013 From: storchaka at gmail.com (Serhiy Storchaka) Date: Wed, 17 Apr 2013 12:35:07 +0300 Subject: a couple of things I don't understand wrt lists In-Reply-To: <2rGdndNcINM-tvPMnZ2dnUVZ_jqdnZ2d@giganews.com> References: <2rGdndNcINM-tvPMnZ2dnUVZ_jqdnZ2d@giganews.com> Message-ID: 17.04.13 07:57, Larry Hudson ???????(??): > So using a list comprehension you can do it in two lines: > > def get_rule(num): > bs = bin(num)[2:] > return [0] * (8 - len(bs)) + [int(i) for i in bs] You can do it in one line! def get_rule(num): return list(map(int, '{:08b}'.format(num))) From dihedral88888 at googlemail.com Wed Apr 17 12:10:37 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Wed, 17 Apr 2013 09:10:37 -0700 (PDT) Subject: a couple of things I don't understand wrt lists In-Reply-To: References: <2rGdndNcINM-tvPMnZ2dnUVZ_jqdnZ2d@giganews.com> Message-ID: <2f8ccb0c-3fb5-4675-993a-4cd3d30dc3a1@googlegroups.com> Serhiy Storchaka? 2013?4?17????UTC+8??5?35?07???? > 17.04.13 07:57, Larry Hudson ???????(??): > > > So using a list comprehension you can do it in two lines: > > > > > > def get_rule(num): > > > bs = bin(num)[2:] > > > return [0] * (8 - len(bs)) + [int(i) for i in bs] > > > > You can do it in one line! > > > > def get_rule(num): > > return list(map(int, '{:08b}'.format(num))) Well, a new object is returned and can be used. Then who is going to clean up the object when required? From dihedral88888 at googlemail.com Wed Apr 17 12:10:37 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Wed, 17 Apr 2013 09:10:37 -0700 (PDT) Subject: a couple of things I don't understand wrt lists In-Reply-To: References: <2rGdndNcINM-tvPMnZ2dnUVZ_jqdnZ2d@giganews.com> Message-ID: <2f8ccb0c-3fb5-4675-993a-4cd3d30dc3a1@googlegroups.com> Serhiy Storchaka? 2013?4?17????UTC+8??5?35?07???? > 17.04.13 07:57, Larry Hudson ???????(??): > > > So using a list comprehension you can do it in two lines: > > > > > > def get_rule(num): > > > bs = bin(num)[2:] > > > return [0] * (8 - len(bs)) + [int(i) for i in bs] > > > > You can do it in one line! > > > > def get_rule(num): > > return list(map(int, '{:08b}'.format(num))) Well, a new object is returned and can be used. Then who is going to clean up the object when required? From ned at nedbatchelder.com Wed Apr 17 14:36:34 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 17 Apr 2013 14:36:34 -0400 Subject: a couple of things I don't understand wrt lists In-Reply-To: <2f8ccb0c-3fb5-4675-993a-4cd3d30dc3a1@googlegroups.com> References: <2rGdndNcINM-tvPMnZ2dnUVZ_jqdnZ2d@giganews.com> <2f8ccb0c-3fb5-4675-993a-4cd3d30dc3a1@googlegroups.com> Message-ID: <516EEBB2.1000503@nedbatchelder.com> On 4/17/2013 12:10 PM, 88888 Dihedral wrote: > Serhiy Storchaka? 2013?4?17????UTC+8??5?35?07???? >> 17.04.13 07:57, Larry Hudson ???????(??): >> >>> So using a list comprehension you can do it in two lines: >>> def get_rule(num): >>> bs = bin(num)[2:] >>> return [0] * (8 - len(bs)) + [int(i) for i in bs] >> >> >> You can do it in one line! >> >> >> >> def get_rule(num): >> >> return list(map(int, '{:08b}'.format(num))) > Well, a new object is returned and can be used. > Then who is going to clean up the object when required? This is a key thing to understand about Python: memory is managed automatically, no one has to clean up the object. Once there are no names referring to the object, it will be cleaned up automatically. --Ned. From rosuav at gmail.com Wed Apr 17 14:42:23 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 18 Apr 2013 04:42:23 +1000 Subject: a couple of things I don't understand wrt lists In-Reply-To: <516EEBB2.1000503@nedbatchelder.com> References: <2rGdndNcINM-tvPMnZ2dnUVZ_jqdnZ2d@giganews.com> <2f8ccb0c-3fb5-4675-993a-4cd3d30dc3a1@googlegroups.com> <516EEBB2.1000503@nedbatchelder.com> Message-ID: On Thu, Apr 18, 2013 at 4:36 AM, Ned Batchelder wrote: > > On 4/17/2013 12:10 PM, 88888 Dihedral wrote: >> Well, a new object is returned and can be used. >> Then who is going to clean up the object when required? > > > This is a key thing to understand about Python: memory is managed > automatically, no one has to clean up the object. Once there are no names > referring to the object, it will be cleaned up automatically. Dihedral is a bot. An amusing one, at times, but not someone you need overly concern yourself with. :) ChrisA From steve+comp.lang.python at pearwood.info Wed Apr 17 14:46:19 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 18 Apr 2013 04:46:19 +1000 Subject: a couple of things I don't understand wrt lists References: <2rGdndNcINM-tvPMnZ2dnUVZ_jqdnZ2d@giganews.com> <2f8ccb0c-3fb5-4675-993a-4cd3d30dc3a1@googlegroups.com> Message-ID: <516eeddf$0$29971$c3e8da3$5496439d@news.astraweb.com> Ned Batchelder wrote: > On 4/17/2013 12:10 PM, 88888 Dihedral wrote: >> Well, a new object is returned and can be used. >> Then who is going to clean up the object when required? > > This is a key thing to understand about Python: memory is managed > automatically, no one has to clean up the object. Once there are no > names referring to the object, it will be cleaned up automatically. The key to understand about 88888 Dihedral is that it is a bot. :-) But seriously, it's a bot. -- Steven From tjreedy at udel.edu Tue Apr 16 13:19:55 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Tue, 16 Apr 2013 13:19:55 -0400 Subject: a couple of things I don't understand wrt lists In-Reply-To: <20130416153701.GA18377@gmail.com> References: <20130416153701.GA18377@gmail.com> Message-ID: On 4/16/2013 11:37 AM, aaB wrote: > I represent the CA's rule with a list of integers, of value 1 or 0. > Here is the function I use to generate the list: > > def get_rule(rulenum): > rule = [] > while rulenum > 0: > rule.append(rulenume % 2) > rulenum /= 2 divmod(rulenum) will return both the quotient and remainder at one time > while len(rule) < 8: > rule.append(0) > rule.reverse() > return rule In versions of Python with builtin bin(), you could write def get_rule(rulenum): b = bin(rulenum)[2:] # return [0]*(8-len(b)) + [int(i) for i in b] To know Python decently well, you should understand all of that syntax. > rule = getrule(int(8)) > print rule > [0, 0, 0, 0, 1, 0, 0, 0] From davea at davea.name Tue Apr 16 16:48:20 2013 From: davea at davea.name (Dave Angel) Date: Tue, 16 Apr 2013 16:48:20 -0400 Subject: a couple of things I don't understand wrt lists In-Reply-To: <20130416153701.GA18377@gmail.com> References: <20130416153701.GA18377@gmail.com> Message-ID: <516DB914.6040805@davea.name> On 04/16/2013 11:37 AM, aaB wrote: > hello, > > I am a beginner programmer. I started learning programming about a year and a > half ago, using C. I picked up python a few months ago, but only wrote very few > scripts. > > I am currently trying to learn more about the python way of doing things by > writing a script that generates png images using a 1D cellular automaton. > > While writing preliminary code for that project, I ran into a behaviour that I > don't understand. > I am using python 2.7 on a linux system. > > I represent the CA's rule with a list of integers, of value 1 or 0. > Here is the function I use to generate the list: > > def get_rule(rulenum): > rule = [] > while rulenum > 0: > rule.append(rulenume % 2) > rulenum /= 2 > while len(rule) < 8: > rule.append(0) > rule.reverse() > return rule > > if i call it by writing: > > rule = getrule(int(8)) > > and then call: > > print rule > > the output is good: > > [0, 0, 0, 0, 1, 0, 0, 0] > > > I then tried to print each item of the list using a for loop: > There are copy/paste errors in your following pieces. Did you retype them instead of using the clipboard? > for i in range(rule): > print rule[i] > > the output is, as expected: > 0 > 0 > 0 > 0 > 1 > 0 > 0 > 0 > Here's what I get, and how I fix it: >>> rule = [0,0,0,0,1,0,0,0] >>> for i in range(rule): ... print i ... Traceback (most recent call last): File "", line 1, in TypeError: range() integer end argument expected, got list. >>> for i in range(len(rule)): ... print rule[i] ... 0 0 0 0 1 0 0 0 > but when I do: > > for i in rule: > print rule[i] You should be printing i here, not rule[i] > > I get the "complement": > 1 > 1 > 1 > 1 > 0 > 1 > 1 > 1 I don't. And don't expect to. It's nothing like the complement. >>> for i in rule: ... print rule[i] ... 0 0 0 0 0 0 0 0 Anyway, to fix it, just print the value, don't try to use it as a subscript. >>> for value in rule: ... print value ... 0 0 0 0 1 0 0 0 > > There must be something I didn't understand correctly in the for statement, but > I really can't think of a reason why the output is what it is. > I tried this using the interactive console, and the results are the same, > whatever the length of the list, i always get the complement of my bit pattern. You should never get the complement of the bit pattern with any code you've shown above. > Hope that helps. -- DaveA From ethan at stoneleaf.us Tue Apr 16 18:37:17 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 16 Apr 2013 15:37:17 -0700 Subject: a couple of things I don't understand wrt lists In-Reply-To: <20130416153701.GA18377@gmail.com> References: <20130416153701.GA18377@gmail.com> Message-ID: <516DD29D.6050803@stoneleaf.us> On 04/16/2013 08:37 AM, aaB wrote: > rule = getrule(int(8)) just rule = getrule(8) is sufficient -- you don't need to cast the integer 8 to an integer. ;) > Thanks, and sorry for the rather long post. Not too long at all: it had lots of detail of what you were trying to do, what you were expecting, and what you got; it was darn near perfect. -- ~Ethan~ From rodrick.brown at gmail.com Tue Apr 16 12:02:01 2013 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Tue, 16 Apr 2013 12:02:01 -0400 Subject: The node.js Community is Quietly Changing the Face of Open Source Message-ID: I came across this article which sums up some of the issues I have with modern programming languages. I've never really looked at Javascript for anything serious or Node itself but I found this article really informational. "The ?Batteries included? philosophy of Python was definitely the right approach during the mid 90?s and one of the reasons that I loved Python so much; this was a time before modern package management, and before it was easy to find and install community-created libraries. Nowadays though I think it?s counter-productive. Developers in the community rarely want to bother trying to compete with the standard library, so people are less likely to try to write libraries that improve upon it." http://caines.ca/blog/programming/the-node-js-community-is-quietly-changing-the-face-of-open-source/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From ned at nedbatchelder.com Tue Apr 16 12:25:25 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 16 Apr 2013 12:25:25 -0400 Subject: The node.js Community is Quietly Changing the Face of Open Source In-Reply-To: References: Message-ID: <516D7B75.1070002@nedbatchelder.com> On 4/16/2013 12:02 PM, Rodrick Brown wrote: > I came across this article which sums up some of the issues I have > with modern programming languages. I've never really looked at > Javascript for anything serious or Node itself but I found this > article really informational. > > "The "Batteries included" philosophy of Python was definitely the > right approach during the mid 90's and one of the reasons that I loved > Python so much; this was a time before modern package management, and > before it was easy to find and install community-created libraries. > Nowadays though I think it's counter-productive. Developers in the > community rarely want to bother trying to compete with the standard > library, so people are less likely to try to write libraries that > improve upon it." > > > http://caines.ca/blog/programming/the-node-js-community-is-quietly-changing-the-face-of-open-source/ > > I don't want to get into a package pissing match, but this math is just silly: *python*: 29,720 packages / 22 years =*1351 packages per year* *ruby*: 54,385 packages / 18 years = *3022 packages per year* *node.js* 26,966 packages / 4 years = *6742 packages per year * If you want to know how fast something is growing, you don't measure 22 years and divide by 22. You look at the number of packages added in the last year (or month). Also the assertion that people don't want to compete with the stdlib seems like pure supposition. There are plenty of well-loved packages that "compete" with the stdlib. Lxml, Requests, Twisted, etc, and plenty of packages in the stdlib that started as outside "competition". --Ned. -------------- next part -------------- An HTML attachment was scrubbed... URL: From svenito at gmail.com Tue Apr 16 12:41:25 2013 From: svenito at gmail.com (Sven) Date: Tue, 16 Apr 2013 17:41:25 +0100 Subject: The node.js Community is Quietly Changing the Face of Open Source In-Reply-To: <516D7B75.1070002@nedbatchelder.com> References: <516D7B75.1070002@nedbatchelder.com> Message-ID: On 16 April 2013 17:25, Ned Batchelder wrote: > On 4/16/2013 12:02 PM, Rodrick Brown wrote: > > I came across this article which sums up some of the issues I have with > modern programming languages. I've never really looked at Javascript for > anything serious or Node itself but I found this article really > informational. > > "The ?Batteries included? philosophy of Python was definitely the right > approach during the mid 90?s and one of the reasons that I loved Python so > much; this was a time before modern package management, and before it was > easy to find and install community-created libraries. Nowadays though I > think it?s counter-productive. Developers in the community rarely want to > bother trying to compete with the standard library, so people are less > likely to try to write libraries that improve upon it." > > > > http://caines.ca/blog/programming/the-node-js-community-is-quietly-changing-the-face-of-open-source/ > > > > I don't want to get into a package pissing match, but this math is just > silly: > > *python*: 29,720 packages / 22 years =* 1351 packages per year* > > *ruby*: 54,385 packages / 18 years = *3022 packages per year* > > *node.js* 26,966 packages / 4 years = *6742 packages per year > * > If you want to know how fast something is growing, you don't measure 22 > years and divide by 22. You look at the number of packages added in the > last year (or month). Also the assertion that people don't want to compete > with the stdlib seems like pure supposition. There are plenty of > well-loved packages that "compete" with the stdlib. Lxml, Requests, > Twisted, etc, and plenty of packages in the stdlib that started as outside > "competition". > Even looking at the last year/month might be give skewed results. If a technology is new, there's a lot more packages that need writing than if it's been around for 22 years, thus I'd expect to see the first year or second year as a good comparison point. -- ./Sven -------------- next part -------------- An HTML attachment was scrubbed... URL: From bahamutzero8825 at gmail.com Tue Apr 16 12:50:36 2013 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Tue, 16 Apr 2013 11:50:36 -0500 Subject: The node.js Community is Quietly Changing the Face of Open Source In-Reply-To: References: Message-ID: <516D815C.6080903@gmail.com> On 2013.04.16 11:02, Rodrick Brown wrote: > I came across this article which sums up some of the issues I have with modern programming languages. I've never really looked at Javascript > for anything serious or Node itself but I found this article really informational. I don't think the author really knows Python. I am not familiar with node.js, but I do know that it is not Python. Python's package management is suboptimal (though it is being worked on), but the main reason to have "no dependencies" is that Python changes. Guess how many people are using Python 3 (which was released over 4 years ago) and how many people are still using Python 2. The standard library just works on the latest version, no matter how much changes - it /has/ to. I find it somewhat amusing that he says that the standard library discourages better tools to compete with the standard library right after mentioning requests, which is... a better tool to compete with the standard library. The idea that developers will rarely ever compete against the standard library is absurd - we have not only requests to compete with the HTTP libraries, but also Twisted and greenlet and Stackless to compete with the async libraries. It's also just plain dumb to have a bunch of libraries doing the same thing. If the standard library isn't doing a good job, something will compete with it. If it is doing a good job, there is no reason to write a library to do the same thing. With third-party libraries everywhere, there can easily be duplicate functionality where there doesn't need to be (there could be silly bikeshed issues or perhaps one developer simply doesn't know about the other project). While the process can be slow, the standard library will change. In fact, 3.4 is going to have a new async I/O library because asyncore and asynchat are just not good enough - after all, that's why projects like Twisted started. Perhaps having a minimal core works well for node.js, but Python is much, much better off having its batteries included. -- CPython 3.3.0 | Windows NT 6.2.9200 / FreeBSD 9.1 From rosuav at gmail.com Tue Apr 16 18:26:24 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Apr 2013 08:26:24 +1000 Subject: The node.js Community is Quietly Changing the Face of Open Source In-Reply-To: <516D815C.6080903@gmail.com> References: <516D815C.6080903@gmail.com> Message-ID: On Wed, Apr 17, 2013 at 2:50 AM, Andrew Berg wrote: > On 2013.04.16 11:02, Rodrick Brown wrote: >> I came across this article which sums up some of the issues I have with modern programming languages. I've never really looked at Javascript >> for anything serious or Node itself but I found this article really informational. > > With third-party libraries everywhere, there can easily be duplicate functionality where there doesn't need to be (there could > be silly bikeshed issues or perhaps one developer simply doesn't know about the other project). Or, since developers don't know about everything that's available, they hand-roll equivalent functionality directly into the application, instead of using a library/module. One of the problems I had installing a Ruby app was that some of the dependencies weren't as tidily packaged as could be hoped. I had to fidget with them to make them build on my system (from C source), which is something that doesn't particularly bother me (I install stuff from source all the time), but it did make it rather harder to deploy the app. Having a larger standard library guarantees that they'll all work on all formally-supported platforms. Are third-party extension builders going to guarantee that their code compiles on platforms they can't test on? I doubt it. Now maybe that's not an issue with node.js (if everything's written in the high-level language, platform support is easier, even trivial), but it certainly would be for Python. ChrisA From rustompmody at gmail.com Tue Apr 16 13:14:46 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 16 Apr 2013 10:14:46 -0700 (PDT) Subject: The node.js Community is Quietly Changing the Face of Open Source References: Message-ID: <77c77567-a97b-474c-8a92-975fe88947f5@mq5g2000pbb.googlegroups.com> For javascript *the language* this is a good watch: http://www.youtube.com/watch?v=kXEgk1Hdze0 However I believe that the language view is a bit dated. On Apr 16, 9:50?pm, Andrew Berg wrote: > Perhaps having a minimal core works well for node.js, but Python is much, much better off having its > batteries included. Standalone this statement is hardly arguable. However combine it with your other statement > Python's package management is suboptimal (though it is being worked on), and a different picture emerges, viz that *the ecosystem around the language matters more than the language* Ive talked about this in my blog http://blog.languager.org/2011/02/cs-education-is-fat-and-weak-1.html and following (Warning: CS teacher's bias) From bahamutzero8825 at gmail.com Tue Apr 16 13:36:11 2013 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Tue, 16 Apr 2013 12:36:11 -0500 Subject: The node.js Community is Quietly Changing the Face of Open Source In-Reply-To: <77c77567-a97b-474c-8a92-975fe88947f5@mq5g2000pbb.googlegroups.com> References: <77c77567-a97b-474c-8a92-975fe88947f5@mq5g2000pbb.googlegroups.com> Message-ID: <516D8C0B.1080400@gmail.com> On 2013.04.16 12:14, rusi wrote: > However combine it with your other statement > >> Python's package management is suboptimal (though it is being worked on), > > and a different picture emerges, viz that *the ecosystem around the > language matters more than the language* It was a minor point, and while I think the ecosystem is important, I am not arguing that it is more important than the language itself. This discussion has much to do with ecosystems and little to do with languages, so I'm not sure what your point is here. -- CPython 3.3.0 | Windows NT 6.2.9200 / FreeBSD 9.1 From rustompmody at gmail.com Tue Apr 16 22:14:40 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 16 Apr 2013 19:14:40 -0700 (PDT) Subject: The node.js Community is Quietly Changing the Face of Open Source References: <77c77567-a97b-474c-8a92-975fe88947f5@mq5g2000pbb.googlegroups.com> Message-ID: <08b4455c-0971-4c35-9e96-b6d5cddf9a71@g5g2000pbp.googlegroups.com> On Apr 16, 10:36?pm, Andrew Berg wrote: > On 2013.04.16 12:14, rusi wrote:> However combine it with your other statement > > >> Python's package ?management is suboptimal (though it is being worked on), > > > and a different picture emerges, viz that *the ecosystem around the > > language matters more than the language* > > It was a minor point, and while I think the ecosystem is important, I am not arguing that it is more important than the language itself. > This discussion has much to do with ecosystems and little to do with languages, so I'm not sure what your point is here. Just what I said: ecosystem matters. We may or may not argue about "more than language", but it surely matters. Some examples: 1. In the link that Roderick originally posted there is a long comment that adds perl to the languages the author discussed. As a language perl is? um well? its perl. Yet when perl wins its because CPAN wins. 2. Haskell as a language is very well designed. However its package system -- cabal+hackage -- is completely broken. Unfortunately more mindshare is taken in haskell to -- fancy type sorcery -- new syntax (eg holes) -- compiling to more and more efficient code -- etc than setting right the package-mess. To be very correct here, its not so much that cabal+hackage is a mess as that the haskell community does not devote enough mindshare to it. 3. Linux: Steven was talking of the fact that firefox code is a mess. I would wager that much of the code in heavy use in linux is a mess. Yet linux works. Why? Apt. Long before cloud-computng became a buzzword, I could sit on my debian box and utter the incantation: $ aptitude update; aptitude upgrade and things would (mostly) keep working. 4. There was a recent question here: "How to install/uninstall manpages with distutils/setuptools?" It seems to be a very basic question. It's received no answer. In case I am chided for fault- finding without answering, let me say, I looked to see if I could help. Found nothing conclusive. Gave up. If it makes me culpable, ok I am contrite. Shouldn't the python community share some of the contrition? Terry wrote: > The irony is that the author goes on to say that the node.js community > 'works' because they all use the same infrastructure battery: git and > git-hub ;-). Its called the paradox of creativity: Constraints cultivate creativity: http://www.keepwriting.com/tsc/paradox.htm From solipsis at pitrou.net Wed Apr 17 05:09:10 2013 From: solipsis at pitrou.net (Antoine Pitrou) Date: Wed, 17 Apr 2013 09:09:10 +0000 (UTC) Subject: The node.js Community is Quietly Changing the Face of Open Source References: <77c77567-a97b-474c-8a92-975fe88947f5@mq5g2000pbb.googlegroups.com> <08b4455c-0971-4c35-9e96-b6d5cddf9a71@g5g2000pbp.googlegroups.com> Message-ID: rusi gmail.com> writes: > > Just what I said: ecosystem matters. We may or may not argue about > "more than language", but it surely matters. Some examples: > > 1. In the link that Roderick originally posted there is a long comment > that adds perl to the languages the author discussed. As a language > perl is? um well? its perl. Yet when perl wins its because CPAN > wins. > > 2. Haskell as a language is very well designed. However its package > system -- cabal+hackage -- is completely broken. I think you are deluded. Haskell may very well designed from a language theoretist's point of view, but I suspect most average programmers would find it a hell to code in. Regards Antoine. From tjreedy at udel.edu Tue Apr 16 13:42:02 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Tue, 16 Apr 2013 13:42:02 -0400 Subject: The node.js Community is Quietly Changing the Face of Open Source In-Reply-To: References: Message-ID: On 4/16/2013 12:02 PM, Rodrick Brown wrote: > I came across this article which sums up some of the issues I have with > modern programming languages. I've never really looked at Javascript for > anything serious or Node itself but I found this article really > informational. > > "The ?Batteries included? philosophy of Python was definitely the right > approach during the mid 90?s and one of the reasons that I loved Python > so much; this was a time before modern package management, and before it > was easy to find and install community-created libraries. Nowadays Python gets used in places like corporations and schools where one cannot simply install stuff off the net, but must fill out a form asking permission, or maybe not ask at all. > though I think it?s counter-productive. Developers in the community > rarely want to bother trying to compete with the standard library, so > people are less likely to try to write libraries that improve upon it." Except that there is competition for many modules. That said, there are old modules that probably would not be added today, and some the dev would like to remove. (Some were for 3.0.) > http://caines.ca/blog/programming/the-node-js-community-is-quietly-changing-the-face-of-open-source/ The irony is that the author goes on to say that the node.js community 'works' because they all use the same infrastructure battery: git and git-hub ;-). -- Terry Jan Reedy From rustompmody at gmail.com Wed Apr 17 00:22:52 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 16 Apr 2013 21:22:52 -0700 (PDT) Subject: The node.js Community is Quietly Changing the Face of Open Source References: Message-ID: <3d2b446e-d904-4a9c-adc8-e5d7338bcdc1@ph9g2000pbb.googlegroups.com> On Apr 16, 10:42?pm, Terry Jan Reedy wrote: > > "The ?Batteries included? philosophy of Python was definitely the right > > approach during the mid 90?s and one of the reasons that I loved Python > > so much; this was a time before modern package management, and before it > > was easy to find and install community-created libraries. ?Nowadays > > Python gets used in places like corporations and schools where one > cannot simply install stuff off the net, but must fill out a form asking > permission, or maybe not ask at all. Yes I agree. Different healthy organisms are healthy based on different logic/laws. Python has no reason to follow node. [And the Roderick link is obviously a bit of a rant and a polemic] In particular one of the strongest (for me) features of python is the standard library. Recently I have been working with erlang and every so often when scratching my head against some impenetrable documentation, I would find myself saying: "God bless Guido for the python-docs" So, no, I am not critical of the std-lib. My wish is for a slightly larger perspective. Think of 3 concentric circles: 1. Python the language 2. Python std lib 3. Python 3rd party packages (that use 1 and 2) 1 and 2 are fine. And for any one person or small group to be fully conversant of the whole of 3 is unreasonable. However the surrounding infrastructure needed to populate/explore/use 3 could do with some love: - the distutils/distutils2/distribute/setuptools situation combined with pip and pypi - executable building (py2exe) - handling multiple pythons and packages eg virtualenv - tox and the various alternatives to testing From steve+comp.lang.python at pearwood.info Wed Apr 17 05:16:10 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Apr 2013 09:16:10 GMT Subject: The node.js Community is Quietly Changing the Face of Open Source References: Message-ID: <516e685a$0$29872$c3e8da3$5496439d@news.astraweb.com> On Tue, 16 Apr 2013 12:02:01 -0400, Rodrick Brown wrote: > I came across this article which sums up some of the issues I have with > modern programming languages. I've never really looked at Javascript for > anything serious or Node itself but I found this article really > informational. > > "The ?Batteries included? philosophy of Python was definitely the right > approach during the mid 90?s and one of the reasons that I loved Python > so much; this was a time before modern package management, and before it > was easy to find and install community-created libraries. Nowadays > though I think it?s counter-productive. Developers in the community > rarely want to bother trying to compete with the standard library, so > people are less likely to try to write libraries that improve upon it." What of corporate users on locked-down boxes where installing software is either a firing offence, or simply cannot be done at all? Or they have to fill out long and tiresome forms requesting permission. Or students using shared machines, where even if you install something, it will be gone the next time you come in? What of people who don't want the hassle of trolling through 7 different maths libraries looking for the "best" one to use, or who might not trust random packages found on the Internet by authors you know nothing about. Or those who don't want to spend their time reading licences? With the Python standard library, you know you can use anything in that library without worrying about the licence. With third party libraries, you have to decide whether or not you are legally allowed to distribute that library, and if not, how do you install it for your customers? There are all sorts of reasons why people might not want to *hunt and install* their own packages, starting with laziness and ending with "I like my job very much thank you, and I'd rather not get the sack". I think it shows astonishing privilege of the author to just assume that because he finds it easy to install third-party software, everybody must. > http://caines.ca/blog/programming/the-node-js-community-is-quietly- changing-the-face-of-open-source/ Just three sentences after telling us how the right URL library to use for Python is the third-party "requests" module, the author tells us that developers "rarely want to bother trying to compete with the standard library, so people are less likely to try to write libraries that improve upon it." Like requests, huh? He then compares node.js packages with Twitter: "Just like the 140 character limit on twitter makes people ?blog? more, the node.js community has a culture of publishing tiny modules that makes people more comfortable with publishing smaller packages, and so it happens vastly more often." Yeah, because the vast bulk of 140-character tweets are something to aspire to. What matters is not how often people publish tiny packages that nobody uses. That's not a good measure of the health of a developer's culture. How many of those tiny packages are published, only to then languish in obscurity, lost and forgotten? How many are ever used by anyone other than their author? ActiveState includes almost 4000 Python recipes: http://code.activestate.com/recipes/langs/python/new/ and I would say that the great bulk of them are rubbish, or so specialised as to be of interest to very few people, or both. Or suffering from "NIH" syndrome. I see about 100 different recipes for implementing enums:" http://code.activestate.com/search/recipes/#q=enums I don't think that 100 different recipes for enums is a good measure of Python's health, and I don't think that hundreds of little tiny packages are a good measure of the health of node.js either. If you look at the node.js site, the first thing that jumps out at me is that the culture encourages churning out packages rather than encouraging quality packages. The front page offers author recognition for being prolific, but not for writing good code. Good (or at least *popular*, which is not the same thing) packages get their name on the front page, but *authors* get their name on the front page by writing loads of packages regardless of quality. The current most prolific author is Sindre Sorhus, and if you look at his list of packages, you will see a certain amount of replication. This is what happens when you reward people for quantity: # generator-jasmine Yeoman generator for Jasmine # generator-webapp Default Yeoman generator for scaffolding out a front- end web app # generator-testacular Yeoman generator for Testacular # generator-chromeapp Yeoman generator for Chrome App # generator-angular Yeoman generator for AngularJS # generator-mocha Yeoman generator for Mocha # generator-bbb Yeoman generator for Backbone Boilerplate # generator-backbone Yeoman generator for Backbone.js https://npmjs.org/~sindresorhus I wonder, how much copy-and-pasting between packages does he do? -- Steven From stefan_ml at behnel.de Wed Apr 17 12:47:40 2013 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 17 Apr 2013 18:47:40 +0200 Subject: The node.js Community is Quietly Changing the Face of Open Source In-Reply-To: <516e685a$0$29872$c3e8da3$5496439d@news.astraweb.com> References: <516e685a$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano, 17.04.2013 11:16: > If you look at the node.js site, the first thing that jumps out at me is > that the culture encourages churning out packages rather than encouraging > quality packages. The front page offers author recognition for being > prolific, but not for writing good code. Good (or at least *popular*, > which is not the same thing) packages get their name on the front page, > but *authors* get their name on the front page by writing loads of > packages regardless of quality. > > The current most prolific author is Sindre Sorhus, and if you look at his > list of packages, you will see a certain amount of replication. This is > what happens when you reward people for quantity: > > > # generator-jasmine Yeoman generator for Jasmine > # generator-webapp Default Yeoman generator for scaffolding out a front- > end web app > # generator-testacular Yeoman generator for Testacular > # generator-chromeapp Yeoman generator for Chrome App > # generator-angular Yeoman generator for AngularJS > # generator-mocha Yeoman generator for Mocha > # generator-bbb Yeoman generator for Backbone Boilerplate > # generator-backbone Yeoman generator for Backbone.js > > > https://npmjs.org/~sindresorhus > > I wonder, how much copy-and-pasting between packages does he do? It's possible that the answer is "none", and that you actually need to install all of his packages in order to make use of one. Stefan From thomas.calmant at gmail.com Tue Apr 16 13:03:47 2013 From: thomas.calmant at gmail.com (Thomas Calmant) Date: Tue, 16 Apr 2013 19:03:47 +0200 Subject: Module import hook Message-ID: Hi, For the context, I'm working on Pelix (https://github.com/tcalmant/ipopo), a service-oriented architecture framework (in GPLv3), inspired by OSGi (from the Java world). It runs on Python >= 2.6 (with the backport of importlib) and Python 3.1 (not tested upon this version). It considers Python modules as "bundles", i.e. artifacts having a life-cycle, that can be installed, started, updated, stopped and uninstalled. The current implementation allows to install each module individually according to their full name, using the importlib standard module. I'm not yet updating the sys.modules dictionary, so any import made in module will use a different instance than the one created by an installation using the framework (if any). I've made some tests the code is available here: https://dl.dropboxusercontent.com/u/59622687/ModuleLoaderTest.tar.gz 1/ I'd like have the equivalent of a distinct sys.modules dictionary per framework instance, in order to solve the problem of the different versions of an imported and installed module, in the same framework. In my tries, I used a DictView class that replaces sys.modules during the import process, which allows to write in a given dictionary, but allows to read from other ones too. This way, the import process can write in a framework dictionary and can see the rest of the original sys.modules too (which is left untouched). To hook the imports: - I've tried overriding __import__, but I'm not comfortable with it. The replacement of sys.modules doesn't seem to be enough in Python 2 in this case. - I've tried with the Finder/Loader mechanism, but I didn't succeed in having the exact same behavior than without hooks: I get recursive loops in some cases in Python 2, or can't find some sub-modules in Python 3. Also, my finder/loader are based on the imp.find/load_module method, which will be deprecated in Python 3.4. a) Which mechanism would you use to implement such a behavior ? b) Is the deprecation of imp methods a big problem ? c) Is there any clean Finder/Loader implementation that acts like the standard import process ? All those I've found on the Internet had the same problems than me. Also, I'd like to keep track of the imports from a module installed in the framework, to store them inside the framework modules dictionary (which is an extension of point 1, I suppose), even if they are late imports, e.g. from inside a method. I'm nearly OK with that using the Finder/Loader mechanism. As all I want is being called before and after every import (to set up sys.modules and the framework, then clean it up), without re-implementing the searching and loading of modules, is there a way to be only notified of those events ? 2/ I'd like to have a method to install modules by file path, and to install the modules present in a package folder (using the visitor pattern). Once again, I think using the imp.find/load_module method to handle a module file path. For the package loading, the implementation in loader.py is based on pkgutil.iter_modules. This part seems to work, but I'm facing the bugs described in the first point. Once again, which mechanisms would you use to do that ? Thanks for your answers :) Regards, Thomas -------------- next part -------------- An HTML attachment was scrubbed... URL: From hmjeltevik at gmail.com Tue Apr 16 14:02:01 2013 From: hmjeltevik at gmail.com (hmjeltevik at gmail.com) Date: Tue, 16 Apr 2013 11:02:01 -0700 (PDT) Subject: Missing decimals in the code - some suggestions? Message-ID: <8e158cbe-4b81-476a-ac48-a0d967956277@googlegroups.com> Hi! I am using ystockquote with the following code: def get_historical_prices(symbol, start_date, end_date): """ Get historical prices for the given ticker symbol. Date format is 'YYYYMMDD' Returns a nested list. """ url = 'http://ichart.yahoo.com/table.csv?s=%s&' % symbol + \ 'd=%s&' % str(int(end_date[4:6]) - 1) + \ 'e=%s&' % str(int(end_date[6:8])) + \ 'f=%s&' % str(int(end_date[0:4])) + \ 'g=d&' + \ 'a=%s&' % str(int(start_date[4:6]) - 1) + \ 'b=%s&' % str(int(start_date[6:8])) + \ 'c=%s&' % str(int(start_date[0:4])) + \ 'ignore=.csv' days = urllib.urlopen(url).readlines() data = [day[:-2].split(',') for day in days] return data This code prints the data, but only 2 decimals. I need to print out 4 decimals. print ystockquote.get_historical_prices('EURUSD=X','20120101','20120301') Some suggestions? From ian.g.kelly at gmail.com Tue Apr 16 14:20:18 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 16 Apr 2013 12:20:18 -0600 Subject: Missing decimals in the code - some suggestions? In-Reply-To: <8e158cbe-4b81-476a-ac48-a0d967956277@googlegroups.com> References: <8e158cbe-4b81-476a-ac48-a0d967956277@googlegroups.com> Message-ID: On Tue, Apr 16, 2013 at 12:02 PM, wrote: > Hi! > > I am using ystockquote with the following code: > > def get_historical_prices(symbol, start_date, end_date): > """ > Get historical prices for the given ticker symbol. > Date format is 'YYYYMMDD' > > Returns a nested list. > """ > url = 'http://ichart.yahoo.com/table.csv?s=%s&' % symbol + \ > 'd=%s&' % str(int(end_date[4:6]) - 1) + \ > 'e=%s&' % str(int(end_date[6:8])) + \ > 'f=%s&' % str(int(end_date[0:4])) + \ > 'g=d&' + \ > 'a=%s&' % str(int(start_date[4:6]) - 1) + \ > 'b=%s&' % str(int(start_date[6:8])) + \ > 'c=%s&' % str(int(start_date[0:4])) + \ > 'ignore=.csv' > days = urllib.urlopen(url).readlines() > data = [day[:-2].split(',') for day in days] > return data > > This code prints the data, but only 2 decimals. I need to print out 4 decimals. > > print ystockquote.get_historical_prices('EURUSD=X','20120101','20120301') > > Some suggestions? This isn't a Python question. If you take a look at the csv file that you download from Yahoo, you will see that it only contains 2 digits of precision. There's no way to make Python print out 4 digits of precision when it is only provided with 2. You will need to find out if there is a way to ask for more precision in the Yahoo API. From python at mrabarnett.plus.com Tue Apr 16 14:35:10 2013 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Apr 2013 19:35:10 +0100 Subject: Missing decimals in the code - some suggestions? In-Reply-To: <8e158cbe-4b81-476a-ac48-a0d967956277@googlegroups.com> References: <8e158cbe-4b81-476a-ac48-a0d967956277@googlegroups.com> Message-ID: <516D99DE.1010504@mrabarnett.plus.com> On 16/04/2013 19:02, hmjeltevik at gmail.com wrote: > Hi! > > I am using ystockquote with the following code: > > def get_historical_prices(symbol, start_date, end_date): > """ > Get historical prices for the given ticker symbol. > Date format is 'YYYYMMDD' > > Returns a nested list. > """ > url = 'http://ichart.yahoo.com/table.csv?s=%s&' % symbol + \ > 'd=%s&' % str(int(end_date[4:6]) - 1) + \ > 'e=%s&' % str(int(end_date[6:8])) + \ > 'f=%s&' % str(int(end_date[0:4])) + \ > 'g=d&' + \ > 'a=%s&' % str(int(start_date[4:6]) - 1) + \ > 'b=%s&' % str(int(start_date[6:8])) + \ > 'c=%s&' % str(int(start_date[0:4])) + \ > 'ignore=.csv' > days = urllib.urlopen(url).readlines() > data = [day[:-2].split(',') for day in days] > return data > > This code prints the data, but only 2 decimals. I need to print out 4 decimals. > > print ystockquote.get_historical_prices('EURUSD=X','20120101','20120301') > > Some suggestions? > The code prints what it receives; the data it receives has only 2 decimal places. This question: http://stackoverflow.com/questions/11496418/yql-forex-historical-prices-queries-how-to-change-default-precision says that it's Yahoo doing the rounding to 2 decimal places. It looks like you'll have to find another way to get what you want. From tjreedy at udel.edu Tue Apr 16 14:37:40 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Tue, 16 Apr 2013 14:37:40 -0400 Subject: Missing decimals in the code - some suggestions? In-Reply-To: <8e158cbe-4b81-476a-ac48-a0d967956277@googlegroups.com> References: <8e158cbe-4b81-476a-ac48-a0d967956277@googlegroups.com> Message-ID: On 4/16/2013 2:02 PM, hmjeltevik at gmail.com wrote: > Hi! > > I am using ystockquote with the following code: > > def get_historical_prices(symbol, start_date, end_date): > """ > Get historical prices for the given ticker symbol. > Date format is 'YYYYMMDD' > > Returns a nested list. > """ > url = 'http://ichart.yahoo.com/table.csv?s=%s&' % symbol + \ > 'd=%s&' % str(int(end_date[4:6]) - 1) + \ > 'e=%s&' % str(int(end_date[6:8])) + \ > 'f=%s&' % str(int(end_date[0:4])) + \ > 'g=d&' + \ > 'a=%s&' % str(int(start_date[4:6]) - 1) + \ > 'b=%s&' % str(int(start_date[6:8])) + \ > 'c=%s&' % str(int(start_date[0:4])) + \ > 'ignore=.csv' > days = urllib.urlopen(url).readlines() > data = [day[:-2].split(',') for day in days] > return data > > This code prints the data, but only 2 decimals. I need to print out 4 decimals. As far as I know, prices are only defined to the nearest penny* (2 decimals) so I don't know what more you expect. *Not too long ago, prices were in 1/8ths of a dollar. Market makers complained about decimalization because it would squeeze the spread that they profited from -- which it did. > print ystockquote.get_historical_prices('EURUSD=X','20120101','20120301') > > Some suggestions? From steve+comp.lang.python at pearwood.info Wed Apr 17 02:23:41 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Apr 2013 06:23:41 GMT Subject: Missing decimals in the code - some suggestions? References: <8e158cbe-4b81-476a-ac48-a0d967956277@googlegroups.com> Message-ID: <516e3fed$0$29872$c3e8da3$5496439d@news.astraweb.com> On Tue, 16 Apr 2013 12:20:18 -0600, Ian Kelly wrote: > This isn't a Python question. If you take a look at the csv file that > you download from Yahoo, you will see that it only contains 2 digits of > precision. There's no way to make Python print out 4 digits of > precision when it is only provided with 2. Pish posh! It's easy to add extra precision. py> value = "2.57" py> import random py> n = random.randrange(0, 100) py> value += "%2d" % n py> print value 2.5791 On average, your numbers will only be off by five parts in a thousand. If the values represent dollars, that's half a cent. Who care about half a cent? Adding-spurious-precision-for-fun-and-profit-ly y'rs, -- Steven From ian.g.kelly at gmail.com Wed Apr 17 02:56:14 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 17 Apr 2013 00:56:14 -0600 Subject: Missing decimals in the code - some suggestions? In-Reply-To: <516e3fed$0$29872$c3e8da3$5496439d@news.astraweb.com> References: <8e158cbe-4b81-476a-ac48-a0d967956277@googlegroups.com> <516e3fed$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 17, 2013 at 12:23 AM, Steven D'Aprano wrote: > On Tue, 16 Apr 2013 12:20:18 -0600, Ian Kelly wrote: > >> This isn't a Python question. If you take a look at the csv file that >> you download from Yahoo, you will see that it only contains 2 digits of >> precision. There's no way to make Python print out 4 digits of >> precision when it is only provided with 2. > > Pish posh! It's easy to add extra precision. It's easy to add extra /digits/. Adding extra precision is much harder. ;-) From halagamal2009 at gmail.com Tue Apr 16 14:32:06 2013 From: halagamal2009 at gmail.com (Hala Gamal) Date: Tue, 16 Apr 2013 11:32:06 -0700 (PDT) Subject: Tutrtle File parsing in python2.7 Message-ID: <80c3cc6b-0ce6-41be-a87b-c5315441d759@googlegroups.com> I need a package for parsing a big .ttl file in pyhton2.7 in windows7 I have used rdflib but it returns out of memory Error. Any suggestion? From drewx at live.co.za Tue Apr 16 17:02:36 2013 From: drewx at live.co.za (Andrew Ndhlovu) Date: Tue, 16 Apr 2013 23:02:36 +0200 Subject: No subject Message-ID: -- Using Opera's mail client: http://www.opera.com/mail/ From bruce.mcgoveran at gmail.com Tue Apr 16 18:19:25 2013 From: bruce.mcgoveran at gmail.com (Bruce McGoveran) Date: Tue, 16 Apr 2013 15:19:25 -0700 (PDT) Subject: Understanding Boolean Expressions Message-ID: Hello. I am new to this group. I've done a search for the topic about which I'm posting, and while I have found some threads that are relevant, I haven't found anything exactly on point that I can understand. So, I'm taking the liberty of asking about something that may be obvious to many readers of this group. The relevant Python documentation reference is: http://docs.python.org/2/reference/expressions.html#boolean-operations. I'm trying to make sense of the rules of or_test, and_test, and not_test that appear in this section. While I understand the substance of the text in this section, it is the grammar definitions themselves that confuse me. For example, I am not clear how an or_test can be an and_test. Moreover, if I follow the chain of non-terminal references, I move from or_test, to and_test, to not_test, to comparison. And when I look at the definition for comparison, I seem to be into bitwise comparisons. I cannot explain this. Perhaps an example will help put my confusion into more concrete terms. Suppose I write the expression if x or y in my code. I presume this is an example of an or_test. Beyond that, though, I'm not sure whether this maps to an and_test (the first option on the right-hand side of the rule) or to the or_test "or" and_test option (the second on the right-hand side of the rule). If people can offer some thoughts to put me in the right direction (or out of my misery), I would appreciate it. Thank you in advance. From walterhurry at lavabit.com Tue Apr 16 18:32:44 2013 From: walterhurry at lavabit.com (Walter Hurry) Date: Tue, 16 Apr 2013 22:32:44 +0000 (UTC) Subject: Understanding Boolean Expressions References: Message-ID: On Tue, 16 Apr 2013 15:19:25 -0700, Bruce McGoveran wrote: > Hello. I am new to this group. I've done a search for the topic about > which I'm posting, and while I have found some threads that are > relevant, I haven't found anything exactly on point that I can > understand. So, I'm taking the liberty of asking about something that > may be obvious to many readers of this group. > > The relevant Python documentation reference is: > http://docs.python.org/2/reference/expressions.html#boolean-operations. > > I'm trying to make sense of the rules of or_test, and_test, and not_test > that appear in this section. While I understand the substance of the > text in this section, it is the grammar definitions themselves that > confuse me. For example, I am not clear how an or_test can be an > and_test. Moreover, if I follow the chain of non-terminal references, I > move from or_test, to and_test, to not_test, to comparison. And when I > look at the definition for comparison, I seem to be into bitwise > comparisons. I cannot explain this. > > Perhaps an example will help put my confusion into more concrete terms. > Suppose I write the expression if x or y in my code. I presume this is > an example of an or_test. Beyond that, though, I'm not sure whether > this maps to an and_test (the first option on the right-hand side of the > rule) or to the or_test "or" and_test option (the second on the > right-hand side of the rule). > > If people can offer some thoughts to put me in the right direction (or > out of my misery), I would appreciate it. $ python Python 2.7.3 (default, Jan 15 2013, 02:26:36) [GCC 4.2.1 20070831 patched [FreeBSD]] on freebsd9 Type "help", "copyright", "credits" or "license" for more information. >>> not True False >>> not False True >>> True or False True >>> True and False False >>> x = 2 >>> not (x == 2) False >>> not (x == 3) True >>> x == 2 True >>> x == 3 False >>> From davea at davea.name Tue Apr 16 18:57:00 2013 From: davea at davea.name (Dave Angel) Date: Tue, 16 Apr 2013 18:57:00 -0400 Subject: Understanding Boolean Expressions In-Reply-To: References: Message-ID: <516DD73C.5020203@davea.name> On 04/16/2013 06:19 PM, Bruce McGoveran wrote: > Hello. I am new to this group. I've done a search for the topic about which I'm posting, and while I have found some threads that are relevant, I haven't found anything exactly on point that I can understand. So, I'm taking the liberty of asking about something that may be obvious to many readers of this group. > > The relevant Python documentation reference is: http://docs.python.org/2/reference/expressions.html#boolean-operations. > > I'm trying to make sense of the rules of or_test, and_test, and not_test that appear in this section. While I understand the substance of the text in this section, it is the grammar definitions themselves that confuse me. For example, I am not clear how an or_test can be an and_test. Moreover, if I follow the chain of non-terminal references, I move from or_test, to and_test, to not_test, to comparison. And when I look at the definition for comparison, I seem to be into bitwise comparisons. I cannot explain this. > > Perhaps an example will help put my confusion into more concrete terms. Suppose I write the expression if x or y in my code. I presume this is an example of an or_test. Beyond that, though, I'm not sure whether this maps to an and_test (the first option on the right-hand side of the rule) or to the or_test "or" and_test option (the second on the right-hand side of the rule). > > If people can offer some thoughts to put me in the right direction (or out of my misery), I would appreciate it. > It's been decades since I really had to understand a complete grammar. But in some ways, a fragment like you're referencing is even harder. The trick is to take those names "and_test" as rather arbitrary. There's no token meaning "an expression containing 4 or's, 2 and's, and 1 not" So sometimes the terms used are rather silly looking. The point is you can combine 'not', 'and', 'or', and comparison operators like ==, >= etc. in some complex ways. The grammar just says which of these is legal, and doesn't help you figure out the semantics, which is usually much more important to you and me. First, nearly all objects have a 'truth' value, for which I use the terms 'true' and 'false'. For numbers, nonzero values are true, and zero values are false. For collections, nonempty collections are true and empty ones are false. And so on. So if x is an int, and if you say: if x: You're checking the 'truth' of x, and it'll execute the if clause for nonzero integers, for example. If you have an arbitrary object 'x', it is not necessarily of type bool. But if you compare it to another one, x==y the result is a bool, either True or False. Likewise if you apply the unary 'not' to an object; the result will be either True or False. But if you combine two expressions with 'or' the result is NOT necessarily of type bool. If the first expression is true, then the second expression isn't even examined. If the first expression is false, the second expression is the result. 'and' has the reverse meaning. And more complex expressions can be understood by breaking them into steps, according to operator precedence and parentheses. -- DaveA From rhodri at wildebst.demon.co.uk Tue Apr 16 19:28:58 2013 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 17 Apr 2013 00:28:58 +0100 Subject: Understanding Boolean Expressions References: Message-ID: On Tue, 16 Apr 2013 23:19:25 +0100, Bruce McGoveran wrote: > Hello. I am new to this group. I've done a search for the topic about > which I'm posting, and while I have found some threads that are > relevant, I haven't found anything exactly on point that I can > understand. So, I'm taking the liberty of asking about something that > may be obvious to many readers of this group. > > The relevant Python documentation reference is: > http://docs.python.org/2/reference/expressions.html#boolean-operations. > > I'm trying to make sense of the rules of or_test, and_test, and not_test > that appear in this section. While I understand the substance of the > text in this section, it is the grammar definitions themselves that > confuse me. For example, I am not clear how an or_test can be an > and_test. Moreover, if I follow the chain of non-terminal references, I > move from or_test, to and_test, to not_test, to comparison. And when I > look at the definition for comparison, I seem to be into bitwise > comparisons. I cannot explain this. > > Perhaps an example will help put my confusion into more concrete terms. > Suppose I write the expression if x or y in my code. I presume this is > an example of an or_test. Beyond that, though, I'm not sure whether > this maps to an and_test (the first option on the right-hand side of the > rule) or to the or_test "or" and_test option (the second on the > right-hand side of the rule). > > If people can offer some thoughts to put me in the right direction (or > out of my misery), I would appreciate it. What the grammar rules are giving you is operator precedence -- "not" has higher precedence than "and", which is higher than "or". As you follow the non-terminals back you go further through precedence chain: comparisons, then bitwise operators (*not* bitwise comparisons!), then shifts, then arithmetic operators, the unary operators, the power operator, and finally primaries. -- Rhodri James *-* Wildebeest Herder to the Masses From tjreedy at udel.edu Tue Apr 16 21:23:11 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Tue, 16 Apr 2013 21:23:11 -0400 Subject: Understanding Boolean Expressions In-Reply-To: References: Message-ID: [2nd try, quotation a bit messed up] On 4/16/2013 6:19 PM, Bruce McGoveran wrote: > Hello. I am new to this group. I've done a search for the topic > about which I'm posting, and while I have found some threads that are > relevant, I haven't found anything exactly on point that I can > understand. So, I'm taking the liberty of asking about something > that may be obvious to many readers of this group. > The relevant Python documentation reference is: > http://docs.python.org/2/reference/expressions.html#boolean-operations. > I'm trying to make sense of the rules of or_test, and_test, and > not_test that appear in this section. While I understand the > substance of the text in this section, The substance is that 1) 'not' binds tighter than 'and' binds tigher than 'or' and 2) 'and' and 'or' both associate left to right in the normal manner so that 'a op b op c' == '(a op b) op c'. > it is the grammar definitions themselves that confuse me. The techinical details reflect the fact that Python's grammar is ll(1) (top-down, parsed by recursive descent) rather than lr(1) (bottom-up). The latter (in lalr(1) form) is what yacc, etc use and might be more familiar to you. > For example, I am not clear how an or_test can be an and_test. or_test ::= and_test | or_test "or" and_test The second option expresses the associativity rule, but more is needed to get out of infinite regress. Substituting the second rule into second rule gives or_test = (or_test 'or' and_test) 'or' and_test and so on. At some point, one must replace or_test with and_test to get an 'or' of ands. Similarly, an and_test must resolve to an 'and' of nots. > Moreover, if I follow the chain of non-terminal references, I move > from or_test, to and_test, to nt_test, to comparison. And when I > look at the definition for comparison, I seem to be into bitwise > comparisons. I cannot explain this. Eventually the chain takes one to primaries, which include things like literals and identifiers. > Perhaps an example will help put my confusion into more concrete terms. Suppose I write the expression if x or y in my code. I presume this is an example of an or_test. Yes. > Beyond that, though, I'm not sure whether this maps to an and_test (the first option on the right-hand side of the rule) or to the or_test "or" and_test option (the second on the right-hand side of the rule). The second. Then the or_test on the left also maps to an and_test. Each and_test eventually resolves to 'identifier', specifically 'x' and 'y'. -- Terry Jan Reedy From bruce.mcgoveran at gmail.com Tue Apr 16 22:29:09 2013 From: bruce.mcgoveran at gmail.com (Bruce McGoveran) Date: Tue, 16 Apr 2013 19:29:09 -0700 (PDT) Subject: Understanding Boolean Expressions In-Reply-To: References: Message-ID: Thank you all for thoughts. I'm just about to post another question about atoms and primaries. If you have a moment to look it over, I would appreciate your thoughts. Many thanks in advance. On Tuesday, April 16, 2013 6:19:25 PM UTC-4, Bruce McGoveran wrote: > Hello. I am new to this group. I've done a search for the topic about which I'm posting, and while I have found some threads that are relevant, I haven't found anything exactly on point that I can understand. So, I'm taking the liberty of asking about something that may be obvious to many readers of this group. > > > > The relevant Python documentation reference is: http://docs.python.org/2/reference/expressions.html#boolean-operations. > > > > I'm trying to make sense of the rules of or_test, and_test, and not_test that appear in this section. While I understand the substance of the text in this section, it is the grammar definitions themselves that confuse me. For example, I am not clear how an or_test can be an and_test. Moreover, if I follow the chain of non-terminal references, I move from or_test, to and_test, to not_test, to comparison. And when I look at the definition for comparison, I seem to be into bitwise comparisons. I cannot explain this. > > > > Perhaps an example will help put my confusion into more concrete terms. Suppose I write the expression if x or y in my code. I presume this is an example of an or_test. Beyond that, though, I'm not sure whether this maps to an and_test (the first option on the right-hand side of the rule) or to the or_test "or" and_test option (the second on the right-hand side of the rule). > > > > If people can offer some thoughts to put me in the right direction (or out of my misery), I would appreciate it. > > > > Thank you in advance. From steve+comp.lang.python at pearwood.info Wed Apr 17 04:14:39 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Apr 2013 08:14:39 GMT Subject: Understanding Boolean Expressions References: Message-ID: <516e59ee$0$29872$c3e8da3$5496439d@news.astraweb.com> On Tue, 16 Apr 2013 15:19:25 -0700, Bruce McGoveran wrote: > Hello. I am new to this group. I've done a search for the topic about > which I'm posting, and while I have found some threads that are > relevant, I haven't found anything exactly on point that I can > understand. So, I'm taking the liberty of asking about something that > may be obvious to many readers of this group. > > The relevant Python documentation reference is: > http://docs.python.org/2/reference/expressions.html#boolean-operations. > > I'm trying to make sense of the rules of or_test, and_test, and not_test > that appear in this section. While I understand the substance of the > text in this section, it is the grammar definitions themselves that > confuse me. For example, I am not clear how an or_test can be an > and_test. In this case, you could have saved us some time by copying and pasting the relevant three lines: or_test ::= and_test | or_test "or" and_test and_test ::= not_test | and_test "and" not_test not_test ::= comparison | "not" not_test I agree that this is not entirely the most obvious wording, but it makes a sort of sense if you follow it through carefully. Unfortunately, to really understand the grammar, you have to follow through the entire thing. But translated into English, the above three rules might read like this: An expression which we call an or_test can be either: 1) an and_test; or 2) another or_test, followed by the literal string "or", followed by an and_test. An expression which we call an and_test can be either: 3) a not_test; or 4) another and_test, followed by the literal string "and", followed by another not_test. An expression which we call a not_test can be either: 5) a comparison; or 6) the literal string "not", followed by another not_test. An expression which we call a comparison can be: ... a bunch more different alternatives, going through bitwise comparisons, then arithmetic operators, then other expressions, and so on, until finally you reach the simplest expressions possible, names and constant literals. So in a sense, an "or_test" does not JUST mean it's a test with an "or" in it. The thing called an or_test is an and_test *or* a test with an "or" in it; an and_test is a not_test *or* a test with an "and" in it; a not_test is a comparison *or* a test with a "not" in it; a comparison is ... and so forth, until you run out of expressions and end up with a simple atom like a name or a constant. So paradoxically, that means that "x or y" counts as an and_test (obviously!) but also as an or_test, since every and_test also counts as an or_test. Here's some crappy ASCII art of a Venn diagram with a couple of examples shown: (best viewed in a fixed-width font): +---------------------------------+ | or_tests | | "x or y" | | +----------------------+ | | | and_tests | | | | "x and y" | | | | +-------------+ | | | | | not_tests | | | | | | | | | | | | "not x" | | | | | +-------------+ | | | +----------------------+ | +---------------------------------+ Inside the "not_test" box, not shown, are other boxes relating to other expressions, and ending deep down with boxes labelled "names" and "literals". (Or so I expect, since I haven't followed the maze of twisty grammar rules, all alike, to the very end.) Of course, in practice we wouldn't normally call an expression such as "x and y" as an or_test, even though strictly speaking the grammar says it is. We would call it by the smallest box it is contained within, namely "and_test". An analogy: normally, we would refer to Python's creator Guido van Rossum as a "man", not a "mammal", but since all men are mammals, it wouldn't be wrong to call him such. But not all mammals are men, and not all or_tests are and_tests. "x or y" is an or_test, obviously, but not an and_test. Does this help explain it? > Perhaps an example will help put my confusion into more concrete terms. > Suppose I write the expression if x or y in my code. I presume this is > an example of an or_test. Beyond that, though, I'm not sure whether > this maps to an and_test (the first option on the right-hand side of the > rule) or to the or_test "or" and_test option (the second on the > right-hand side of the rule). "x or y" maps to the second option. The "x" matches and_test, which then matches not_test, which then matches comparison, which ... blah blah blah ... which finally matches a plain name. The "or" matches the literal string "or" in the grammar rule. Then the "y" matches and_test, which ... finally matches a plain name. Of course, this is NOT necessarily what Python does every time it parses a piece of code! It's just a description of the grammar. -- Steven From jpiitula at ling.helsinki.fi Wed Apr 17 04:47:49 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 17 Apr 2013 11:47:49 +0300 Subject: Understanding Boolean Expressions References: <516e59ee$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano writes: > So paradoxically, that means that "x or y" counts as an and_test > (obviously!) but also as an or_test, since every and_test also > counts as an or_test. Here's some crappy ASCII art of a Venn diagram I think you mean to say that "x and y" counts as an and_test and also as an or_test. From steve+comp.lang.python at pearwood.info Wed Apr 17 05:20:11 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Apr 2013 09:20:11 GMT Subject: Understanding Boolean Expressions References: <516e59ee$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: <516e694b$0$29872$c3e8da3$5496439d@news.astraweb.com> On Wed, 17 Apr 2013 11:47:49 +0300, Jussi Piitulainen wrote: > Steven D'Aprano writes: > >> So paradoxically, that means that "x or y" counts as an and_test >> (obviously!) but also as an or_test, since every and_test also counts >> as an or_test. Here's some crappy ASCII art of a Venn diagram > > I think you mean to say that "x and y" counts as an and_test and also as > an or_test. You may very well be right, but I'll be damned if I go back and read through my post trying to work out what I intended to say instead of what I actually said! :-) And-or-or-and-or-or-or-and-and-or-ly y'rs, -- Steven From jpiitula at ling.helsinki.fi Wed Apr 17 05:32:21 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 17 Apr 2013 12:32:21 +0300 Subject: Understanding Boolean Expressions References: <516e59ee$0$29872$c3e8da3$5496439d@news.astraweb.com> <516e694b$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano writes: > On Wed, 17 Apr 2013 11:47:49 +0300, Jussi Piitulainen wrote: > > > Steven D'Aprano writes: > > > >> So paradoxically, that means that "x or y" counts as an and_test > >> (obviously!) but also as an or_test, since every and_test also counts > >> as an or_test. Here's some crappy ASCII art of a Venn diagram > > > > I think you mean to say that "x and y" counts as an and_test and also as > > an or_test. > > You may very well be right, but I'll be damned if I go back and read > through my post trying to work out what I intended to say instead of what > I actually said! > > :-) The quote above is sufficient context for one who knows that "x or y" is not an and_test. I'm hoping that pointing this little thing out will help some potentially confused reader of your otherwise excellent explanation see more quickly that this is really just a harmless typo. (Unless it's me who's confused :) The quote appeared just before your ASCII art. From victorhooi at gmail.com Tue Apr 16 19:45:20 2013 From: victorhooi at gmail.com (Victor Hooi) Date: Tue, 16 Apr 2013 16:45:20 -0700 (PDT) Subject: Using re.VERBOSE, and re-using components of regex? Message-ID: <8f57c6bb-5e13-4507-b93b-08e725ad6385@googlegroups.com> Hi, I'm trying to compile a regex Python with the re.VERBOSE flag (so that I can add some friendly comments). However, the issue is, I normally use constants to define re-usable bits of the regex - however, these doesn't get interpreted inside the triple quotes. For example: import re TIMESTAMP = r'(?P\d{2}:\d{2}:\d{2}.\d{9})' SPACE = r' ' FOO = r'some_regex' BAR = r'some_regex' regexes = { 'data_sent': re.compile(""" TIMESTAMP # Timestamp of our log message SPACE FOO # Some comment SPACE """, re.VERBOSE), 'data_received': re.compile(""" TIMESTAMP # Timestamp of our log message SPACE BAR # Some comment SPACE """, re.VERBOSE), } Is there a way to use CONSTANTS (or at least re-use fragments of my regex), and also use re.VERBOSE so I can comment my regex? Cheers, Victor From python at mrabarnett.plus.com Tue Apr 16 20:16:14 2013 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 17 Apr 2013 01:16:14 +0100 Subject: Using re.VERBOSE, and re-using components of regex? In-Reply-To: <8f57c6bb-5e13-4507-b93b-08e725ad6385@googlegroups.com> References: <8f57c6bb-5e13-4507-b93b-08e725ad6385@googlegroups.com> Message-ID: <516DE9CE.3090907@mrabarnett.plus.com> On 17/04/2013 00:45, Victor Hooi wrote: > Hi, > > I'm trying to compile a regex Python with the re.VERBOSE flag (so that I can add some friendly comments). > > However, the issue is, I normally use constants to define re-usable bits of the regex - however, these doesn't get interpreted inside the triple quotes. > > For example: > > import re > > TIMESTAMP = r'(?P\d{2}:\d{2}:\d{2}.\d{9})' > SPACE = r' ' > FOO = r'some_regex' > BAR = r'some_regex' > > regexes = { > 'data_sent': re.compile(""" > TIMESTAMP # Timestamp of our log message > SPACE > FOO # Some comment > SPACE > """, re.VERBOSE), > 'data_received': re.compile(""" > TIMESTAMP # Timestamp of our log message > SPACE > BAR # Some comment > SPACE > """, re.VERBOSE), > } > > Is there a way to use CONSTANTS (or at least re-use fragments of my regex), and also use re.VERBOSE so I can comment my regex? > You could do it like this: import re constants = {} constants['TIMESTAMP'] = r'(?P\d{2}:\d{2}:\d{2}.\d{9})' constants['SPACE'] = r'\ ' # Escape the space because it'll be in a VERBOSE regex. constants['FOO'] = r'some_regex' constants['BAR'] = r'some_regex' regexes = { 'data_sent': re.compile(""" {TIMESTAMP} # Timestamp of our log message {SPACE} {FOO} # Some comment {SPACE} """.format(**constants), re.VERBOSE), 'data_received': re.compile(""" {TIMESTAMP} # Timestamp of our log message {SPACE} {BAR} # Some comment {SPACE} """.format(**constants), re.VERBOSE), } From miki.tebeka at gmail.com Tue Apr 16 20:21:37 2013 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Tue, 16 Apr 2013 17:21:37 -0700 (PDT) Subject: Encoding NaN in JSON Message-ID: Greetings, I'm trying to find a way to have json emit float('NaN') as 'N/A'. I can't seem to find a way since NaN is a float, which means overriding "default" won't help. Any simple way to do this? Thanks, -- Miki From timr at probo.com Wed Apr 17 01:38:52 2013 From: timr at probo.com (Tim Roberts) Date: Tue, 16 Apr 2013 22:38:52 -0700 Subject: Encoding NaN in JSON References: Message-ID: Miki Tebeka wrote: > >I'm trying to find a way to have json emit float('NaN') as 'N/A'. >I can't seem to find a way since NaN is a float, which means overriding "default" won't help. > >Any simple way to do this? No. There is no way to represent NaN in JSON. It's simply not part of the specification. From RFC 4627 section 2.4: Numeric values that cannot be represented as sequences of digits (such as Infinity and NaN) are not permitted. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From miki.tebeka at gmail.com Wed Apr 17 10:33:26 2013 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 17 Apr 2013 07:33:26 -0700 (PDT) Subject: Encoding NaN in JSON In-Reply-To: References: Message-ID: >> I'm trying to find a way to have json emit float('NaN') as 'N/A'. > No. There is no way to represent NaN in JSON. It's simply not part of the > specification. I know that. I'm trying to emit the *string* 'N/A' for every NaN. From gordon at panix.com Wed Apr 17 10:47:27 2013 From: gordon at panix.com (John Gordon) Date: Wed, 17 Apr 2013 14:47:27 +0000 (UTC) Subject: Encoding NaN in JSON References: Message-ID: In Miki Tebeka writes: > >> I'm trying to find a way to have json emit float('NaN') as 'N/A'. > > No. There is no way to represent NaN in JSON. It's simply not part of the > > specification. > I know that. I'm trying to emit the *string* 'N/A' for every NaN. import math x = possibly_NaN() if math.isnan(x): x = 'N/A' -- 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 jhibschman at gmail.com Wed Apr 17 15:05:30 2013 From: jhibschman at gmail.com (Johann Hibschman) Date: Wed, 17 Apr 2013 14:05:30 -0500 Subject: Encoding NaN in JSON References: Message-ID: Miki Tebeka writes: >>> I'm trying to find a way to have json emit float('NaN') as 'N/A'. >> No. There is no way to represent NaN in JSON. It's simply not part of the >> specification. > I know that. I'm trying to emit the *string* 'N/A' for every NaN. Easiest way is probably to transform your object before you try to write it, e.g. def transform(x): if isinstance(x, dict): return dict((k, transform(v)) for k, v in x.items()) elif isinstance(x, list) or isinstance(x, tuple): return [transform(v) for v in x] elif isinstance(x, float) and x != x: return 'N/A' else: return x Then just use json.dumps(transform(x)) rather than just json.dumps(x) From miki.tebeka at gmail.com Wed Apr 17 17:21:27 2013 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 17 Apr 2013 14:21:27 -0700 (PDT) Subject: Encoding NaN in JSON In-Reply-To: References: Message-ID: > >>> I'm trying to find a way to have json emit float('NaN') as 'N/A'. > Easiest way is probably to transform your object before you try to write Yeah, that's what I ended up doing. Wondered if there's a better way ... Thanks, -- Miki From r.koebler at yahoo.de Wed Apr 17 18:40:30 2013 From: r.koebler at yahoo.de (Roland Koebler) Date: Thu, 18 Apr 2013 00:40:30 +0200 Subject: Encoding NaN in JSON In-Reply-To: References: Message-ID: <20130417224030.GA28906@localhost> Hi, > > Easiest way is probably to transform your object before you try to write > Yeah, that's what I ended up doing. Wondered if there's a better way ... yes, there is: subclass+extend the JSON-encoder, see pydoc json. e.g.: class JsonNanEncoder(json.JSONEncoder): def default(self, obj): if some-check-if-obj-is-NaN: return 'NaN' return json.JSONEncoder.default(self, obj) Roland From miki.tebeka at gmail.com Wed Apr 17 21:01:55 2013 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 17 Apr 2013 18:01:55 -0700 (PDT) Subject: Encoding NaN in JSON In-Reply-To: References: Message-ID: <1040891b-d350-4304-8112-de4a383562dc@googlegroups.com> [Roland] > yes, there is: subclass+extend the JSON-encoder, see pydoc json. Please read the original post before answering. What you suggested does not work since NaN is of float type. From r.koebler at yahoo.de Wed Apr 17 21:39:38 2013 From: r.koebler at yahoo.de (Roland Koebler) Date: Thu, 18 Apr 2013 03:39:38 +0200 Subject: Encoding NaN in JSON In-Reply-To: <1040891b-d350-4304-8112-de4a383562dc@googlegroups.com> References: <20130417224030.GA28906@localhost> <1040891b-d350-4304-8112-de4a383562dc@googlegroups.com> Message-ID: <20130418013938.GB28906@localhost> Hi, > > yes, there is: subclass+extend the JSON-encoder, see pydoc json. > Please read the original post before answering. What you suggested does not work since NaN is of float type. ok, right, default does not work this way. But I would still suggest to extend the JSON-encoder, since that is quite simple (see sourcecode of JSON module); as a quickhack, you could even monkey patch json.encoder.floatstr with a wrapper which returns "N/A" for NaN. (I've tested it: It works.) But: If you only need NaN and inf, and are ok with 'NaN' instead of 'N/A', you can simply use the json module. See pydoc json: If allow_nan is True, then NaN, Infinity, and -Infinity will be encoded as such. This behavior is not JSON specification compliant, but is consistent with most JavaScript based encoders and decoders. Otherwise, it will be a ValueError to encode such floats. >>> import json >>> json.dumps(float('NaN')) 'NaN' >>> json.dumps(float('inf')) 'Infinity' Roland From rosuav at gmail.com Wed Apr 17 21:46:37 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 18 Apr 2013 11:46:37 +1000 Subject: Encoding NaN in JSON In-Reply-To: <20130418013938.GB28906@localhost> References: <20130417224030.GA28906@localhost> <1040891b-d350-4304-8112-de4a383562dc@googlegroups.com> <20130418013938.GB28906@localhost> Message-ID: On Thu, Apr 18, 2013 at 11:39 AM, Roland Koebler wrote: > as a quickhack, you > could even monkey patch json.encoder.floatstr with a wrapper which > returns "N/A" for NaN. (I've tested it: It works.) Wait... you can do that? It's internal to iterencode, at least in Python 3.3 and 2.7 that I'm looking at here. Can you share your code please? I'd like to try that! When I first looked at the docstring, I was thinking "Ah, can I override the bit that emits NaN to return \"N/A\" instead?", but the code made me think that's not possible. ChrisA From r.koebler at yahoo.de Thu Apr 18 04:11:48 2013 From: r.koebler at yahoo.de (Roland Koebler) Date: Thu, 18 Apr 2013 10:11:48 +0200 Subject: Encoding NaN in JSON In-Reply-To: References: <20130417224030.GA28906@localhost> <1040891b-d350-4304-8112-de4a383562dc@googlegroups.com> <20130418013938.GB28906@localhost> Message-ID: <20130418081148.GC28906@localhost> On Thu, Apr 18, 2013 at 11:46:37AM +1000, Chris Angelico wrote: > Wait... you can do that? It's internal to iterencode, at least in > Python 3.3 and 2.7 that I'm looking at here. In Python 2.6 it wasn't internal to iterencode; in Python 2.7 and 3.x you probably would have to monkey-patch iterencode. (In addition, patching floatstr alone wouldn't be enough in 3.x and probably 2.7, since you also have to make sure that the C-extension is not used here.) BUT: Keep in mind that monkey-patches are problematic, and should be avoided (or used very carefully) in production code. So, better replace the complete encoder.py or use your own patched version of the complete json-module. Roland From rosuav at gmail.com Wed Apr 17 21:41:47 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 18 Apr 2013 11:41:47 +1000 Subject: Encoding NaN in JSON In-Reply-To: <1040891b-d350-4304-8112-de4a383562dc@googlegroups.com> References: <1040891b-d350-4304-8112-de4a383562dc@googlegroups.com> Message-ID: On Thu, Apr 18, 2013 at 11:01 AM, Miki Tebeka wrote: > [Roland] >> yes, there is: subclass+extend the JSON-encoder, see pydoc json. > Please read the original post before answering. What you suggested does not work since NaN is of float type. You may be able to override a bit more of the code, though. Check out Lib/json/encoder.py for the implementation, and have a look at the floatstr() internal function; unfortunately you can't simply subclass and override that, but perhaps overriding iterencode (which is where floatstr is defined) would do the job. ChrisA From d at davea.name Wed Apr 17 17:37:40 2013 From: d at davea.name (Dave Angel) Date: Wed, 17 Apr 2013 17:37:40 -0400 Subject: Encoding NaN in JSON In-Reply-To: References: Message-ID: <516F1624.9080604@davea.name> On 04/17/2013 03:05 PM, Johann Hibschman wrote: > Miki Tebeka writes: > >>>> I'm trying to find a way to have json emit float('NaN') as 'N/A'. >>> No. There is no way to represent NaN in JSON. It's simply not part of the >>> specification. >> I know that. I'm trying to emit the *string* 'N/A' for every NaN. > > Easiest way is probably to transform your object before you try to write > it, e.g. > > def transform(x): > if isinstance(x, dict): > return dict((k, transform(v)) for k, v in x.items()) > elif isinstance(x, list) or isinstance(x, tuple): > return [transform(v) for v in x] > elif isinstance(x, float) and x != x: > return 'N/A' > else: > return x > Note that for a self-referencing object, this function might run "forever," or until it runs out of stack. The programmer is likely to know about the possibility, but just in case ... > Then just use > > json.dumps(transform(x)) > > rather than just > > json.dumps(x) > -- DaveA From wayne at waynewerner.com Thu Apr 18 09:53:54 2013 From: wayne at waynewerner.com (Wayne Werner) Date: Thu, 18 Apr 2013 08:53:54 -0500 (CDT) Subject: Encoding NaN in JSON In-Reply-To: References: Message-ID: On Wed, 17 Apr 2013, Miki Tebeka wrote: >>> I'm trying to find a way to have json emit float('NaN') as 'N/A'. >> No. There is no way to represent NaN in JSON. It's simply not part of the >> specification. > I know that. I'm trying to emit the *string* 'N/A' for every NaN. Why not use `null` instead? It seems to be semantically more similar... -W From timr at probo.com Fri Apr 19 01:04:56 2013 From: timr at probo.com (Tim Roberts) Date: Thu, 18 Apr 2013 22:04:56 -0700 Subject: Encoding NaN in JSON References: Message-ID: Miki Tebeka wrote: > >>> I'm trying to find a way to have json emit float('NaN') as 'N/A'. >> No. There is no way to represent NaN in JSON. It's simply not part of the >> specification. > >I know that. I'm trying to emit the *string* 'N/A' for every NaN. You understand that this will result in a chunk of text that is not JSON? Other JSON readers won't be able to read it. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From robert.kern at gmail.com Fri Apr 19 02:13:26 2013 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 19 Apr 2013 11:43:26 +0530 Subject: Encoding NaN in JSON In-Reply-To: References: Message-ID: On 2013-04-19 10:34, Tim Roberts wrote: > Miki Tebeka wrote: >> >>>> I'm trying to find a way to have json emit float('NaN') as 'N/A'. >>> No. There is no way to represent NaN in JSON. It's simply not part of the >>> specification. >> >> I know that. I'm trying to emit the *string* 'N/A' for every NaN. > > You understand that this will result in a chunk of text that is not JSON? > Other JSON readers won't be able to read it. I think he means something like this: >>> json.dumps([float('nan')]) '["N/A"]' Not '[N/A]' -- 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 miki.tebeka at gmail.com Fri Apr 19 15:52:39 2013 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Fri, 19 Apr 2013 12:52:39 -0700 (PDT) Subject: Encoding NaN in JSON In-Reply-To: References: Message-ID: > > You understand that this will result in a chunk of text that is not JSON? > I think he means something like this: > >>> json.dumps([float('nan')]) > '["N/A"]' That's exactly what I mean :) From invalid at invalid.invalid Fri Apr 19 10:54:28 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 19 Apr 2013 14:54:28 +0000 (UTC) Subject: Encoding NaN in JSON References: Message-ID: On 2013-04-18, Wayne Werner wrote: > On Wed, 17 Apr 2013, Miki Tebeka wrote: > >>>> I'm trying to find a way to have json emit float('NaN') as 'N/A'. >>> No. There is no way to represent NaN in JSON. It's simply not part of the >>> specification. >> I know that. I'm trying to emit the *string* 'N/A' for every NaN. > > Why not use `null` instead? It seems to be semantically more similar... Why not use 'NaN' instead? It seems to be even more semantically similar... -- Grant Edwards grant.b.edwards Yow! I want a VEGETARIAN at BURRITO to go ... with gmail.com EXTRA MSG!! From kwpolska at gmail.com Fri Apr 19 14:21:49 2013 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Fri, 19 Apr 2013 20:21:49 +0200 Subject: Encoding NaN in JSON In-Reply-To: References: Message-ID: On Fri, Apr 19, 2013 at 4:54 PM, Grant Edwards wrote: > On 2013-04-18, Wayne Werner wrote: >> On Wed, 17 Apr 2013, Miki Tebeka wrote: >> >>>>> I'm trying to find a way to have json emit float('NaN') as 'N/A'. >>>> No. There is no way to represent NaN in JSON. It's simply not part of the >>>> specification. >>> I know that. I'm trying to emit the *string* 'N/A' for every NaN. >> >> Why not use `null` instead? It seems to be semantically more similar... > > Why not use 'NaN' instead? It seems to be even more semantically > similar... Because there is no NaN in JSON? Unless you mean a string, which makes no semantical sense and is human-oriented and not machine-oriented. -- Kwpolska | GPG KEY: 5EAAEA16 stop html mail | always bottom-post http://asciiribbon.org | http://caliburn.nl/topposting.html From invalid at invalid.invalid Fri Apr 19 15:42:49 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 19 Apr 2013 19:42:49 +0000 (UTC) Subject: Encoding NaN in JSON References: Message-ID: On 2013-04-19, Chris ???Kwpolska??? Warrick wrote: > On Fri, Apr 19, 2013 at 4:54 PM, Grant Edwards wrote: >> On 2013-04-18, Wayne Werner wrote: >>> On Wed, 17 Apr 2013, Miki Tebeka wrote: >>> >>>>>> I'm trying to find a way to have json emit float('NaN') as 'N/A'. >>>>> No. There is no way to represent NaN in JSON. It's simply not part of the >>>>> specification. >>>> I know that. I'm trying to emit the *string* 'N/A' for every NaN. >>> >>> Why not use `null` instead? It seems to be semantically more similar... >> >> Why not use 'NaN' instead? It seems to be even more semantically >> similar... > > Because there is no NaN in JSON? Unless you mean a string, which > makes no semantical sense and is human-oriented and not > machine-oriented. The OP asked for a string, and I thought you were proposing the string 'null'. If one is to use a string, then 'NaN' makes the most sense, since it can be converted back into a floating point NaN object. I infer that you were proposing a JSON null value and not the string 'null'? -- Grant Edwards grant.b.edwards Yow! I'm receiving a coded at message from EUBIE BLAKE!! gmail.com From kwpolska at gmail.com Sat Apr 20 04:00:22 2013 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Sat, 20 Apr 2013 10:00:22 +0200 Subject: Encoding NaN in JSON In-Reply-To: References: Message-ID: On Fri, Apr 19, 2013 at 9:42 PM, Grant Edwards wrote: > The OP asked for a string, and I thought you were proposing the string > 'null'. If one is to use a string, then 'NaN' makes the most sense, > since it can be converted back into a floating point NaN object. > > I infer that you were proposing a JSON null value and not the string > 'null'? Not me, Wayne Werner proposed to use the JSON null value. I parsed the backticks (`) used by him as a way to delimit it from text and not as a string. PS. > On 2013-04-19, Chris ???Kwpolska??? Warrick wrote: Is Unicode support so hard, especially in the 21st century? -- Kwpolska | GPG KEY: 5EAAEA16 stop html mail | always bottom-post http://asciiribbon.org | http://caliburn.nl/topposting.html From wayne at waynewerner.com Mon Apr 22 14:53:13 2013 From: wayne at waynewerner.com (Wayne Werner) Date: Mon, 22 Apr 2013 13:53:13 -0500 (CDT) Subject: Encoding NaN in JSON In-Reply-To: References: Message-ID: On Sat, 20 Apr 2013, Chris ?Kwpolska? Warrick wrote: > On Fri, Apr 19, 2013 at 9:42 PM, Grant Edwards wrote: >> The OP asked for a string, and I thought you were proposing the string >> 'null'. If one is to use a string, then 'NaN' makes the most sense, >> since it can be converted back into a floating point NaN object. >> >> I infer that you were proposing a JSON null value and not the string >> 'null'? > > Not me, Wayne Werner proposed to use the JSON null value. I parsed > the backticks (`) used by him as a way to delimit it from text and not > as a string. That was, in fact, my intention. Though it seems to me that you'll have to suffer between some sort of ambiguity - in Chrome, at least, `Number(null)` evaluates to `0` instead of NaN. But `Number('Whatever')` evaluates to NaN. However, a JSON parser obviously wouldn't be able to make the semantic distinction, so I think you'll be left with whichever API makes the most sense to you: NaN maps to null or NaN maps to "NaN" (or any other string, really) Obviously you're not limited to these particular choices, but they're probably the easiest to implement and communicate. HTH, -W From bruce.mcgoveran at gmail.com Tue Apr 16 22:57:25 2013 From: bruce.mcgoveran at gmail.com (Bruce McGoveran) Date: Tue, 16 Apr 2013 19:57:25 -0700 (PDT) Subject: Atoms, Identifiers, and Primaries Message-ID: <66e78281-542b-41b3-a56d-04bf736d1e0a@googlegroups.com> These are terms that appear in section 5 (Expressions) of the Python online documentation. I'm having some trouble understanding what, precisely, these terms mean. I'd appreciate the forum's thoughts on these questions: 1. Section 5.2.1 indicates that an identifier occurring as an atom is a name. However, Section 2.3 indicates that identifiers are names. My question: can an identifier be anything other than a name? 2. Section 5.3 defines primaries as the most tightly bound operations of Python. What does this mean? In particular, if an atom is a primary, what operation is the atom performing that leads to the label "most tightly bound"? To put it a different way, I think of atoms as things (i.e. identifiers). The documentation makes me think atoms actually do something, as opposed to being things (I think I have in my mind the difference between a noun and a verb as I write this). Perhaps the doing in this case (or binding, if you like) is linking (binding) the identifier to the underlying object? I think it might help if I had a better working notion of what a primary is. 3. Section 5.3.1 offers this definition of an attributeref: attributeref ::= primary "." identifier Now, I was at first a little concerned to see the non-terminal primary on the right hand side of the definition, since primary is defined to include attributeref in section 5.3 (so this struck me as circular). Am I correct in thinking attributeref is defined this way to allow for situations in which the primary, whether an atom, attributeref (example: an object on which a method is called that returns another object), subscription, slicing, or call, returns an object with property identifier? These are, I know, long-winded questions. I appreciate in advance any thoughts the group can offer. The relevant documentation link is: http://docs.python.org/2/reference/expressions.html#expressions Thanks, Bruce From rustompmody at gmail.com Tue Apr 16 23:55:49 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 16 Apr 2013 20:55:49 -0700 (PDT) Subject: Atoms, Identifiers, and Primaries References: <66e78281-542b-41b3-a56d-04bf736d1e0a@googlegroups.com> Message-ID: <14a9ca59-218d-4dec-9e03-b7ac6b92d378@af5g2000pbd.googlegroups.com> On Apr 17, 7:57?am, Bruce McGoveran wrote: > These are terms that appear in section 5 (Expressions) of the Python online documentation. ?I'm having some trouble understanding what, precisely, these terms mean. ?I'd appreciate the forum's thoughts on these questions: > > 1. ?Section 5.2.1 indicates that an identifier occurring as an atom is a name. ?However, Section 2.3 indicates that identifiers are names. ?My question: ?can an identifier be anything other than a name? > > 2. ?Section 5.3 defines primaries as the most tightly bound operations of Python. ?What does this mean? ?In particular, if an atom is a primary, what operation is the atom performing that leads to the label "most tightly bound"? ?To put it a different way, I think of atoms as things (i.e. identifiers). ?The documentation makes me think atoms actually do something, as opposed to being things (I think I have in my mind the difference between a noun and a verb as I write this). ?Perhaps the doing in this case (or binding, if you like) is linking (binding) the identifier to the underlying object? ?I think it might help if I had a better working notion of what a primary is. > > 3. ?Section 5.3.1 offers this definition of an attributeref: > ? ? attributeref ::= primary "." identifier > > Now, I was at first a little concerned to see the non-terminal primary on the right hand side of the definition, since primary is defined to include attributeref in section 5.3 (so this struck me as circular). ?Am I correct in thinking attributeref is defined this way to allow for situations in which the primary, whether an atom, attributeref (example: ?an object on which a method is called that returns another object), subscription, slicing, or call, returns an object with property identifier? > > These are, I know, long-winded questions. ?I appreciate in advance any thoughts the group can offer. > > The relevant documentation link is: ?http://docs.python.org/2/reference/expressions.html#expressions > > Thanks, > Bruce The specific details of python grammar I am not deeply familiar with, so I'll leave others to comment. One general comment I will make is regarding your distress at what you call 'circular' Circular just means recursive and recursion is the bedrock for language-design. You cannot hope to define an infinite object such as the python language (there are an infinite number of python programs) with a finite specification -- a useful language definition must start and end and preferably fit in one's pocket! The trick is to find ways of making an inifinite object finitely generated. So much of language design is a generalization of Peano's method of defining (designing?) natural numbers: a. 0 is a natural number b. If x is a natural number then the successor of x (informally x+1) is a natural number Note 1. that if we take the above as a definition of natural no. then its a recursive definition, in particular b. You can call it circular if you like. Just drop the pejorative color. Note 2. We need to add the 'informally' because + needs to be defined in terms of the above definition and not the other way round, else we get a bad case of recursion. Such a definition would run as 0 + y = y Sx + y = S(x+y) (read Sx as successor of x) Coming closer to your question, consider the 3 expressions: A: 2*x + 3*y B: (2*x) + 3*y C: 2*(x+3)*y Informally we may say that A and B are the same whereas C is different. Formally all three are different. Not only are they different as strings, their parse-trees are different. Their evaluations as defined by the python interpreter may give the same value to A and B... thats a separate question from yours which is really a syntax question. A is an a_expr because 2*x is an m_expr and 3*y is an m-expr Since an m-expr is (a trivial instance of an) a_expr therefore 2*x is an a_expr Since one way of making an a_expr is by doing a_expr + m_expr (note the recursion) therefore 2*x + 3*y is an a_expr In short Ive described the derivation: a_expr -> a_expr + m_expr -> a_expr + 3*y -> m_expr + 3*y -> 2*x + 3*y The derivation of B would be longer involving fact that (2*x) is a parent-form therefore atom atom -> enclosure -> enclosure -> parenth_form -> (expr_list) -> (expression) -> (conditional-e) -> (or_test) -> (and_test) -> (or-exp) -> (xor-> exp) -> (and-exp) -> (shift-e) -> (a_expr) [And now I got fedup of following the grammar but hopefully you get the idea!] From dreamingforward at gmail.com Wed Apr 17 19:40:13 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Wed, 17 Apr 2013 16:40:13 -0700 Subject: Atoms, Identifiers, and Primaries In-Reply-To: <14a9ca59-218d-4dec-9e03-b7ac6b92d378@af5g2000pbd.googlegroups.com> References: <66e78281-542b-41b3-a56d-04bf736d1e0a@googlegroups.com> <14a9ca59-218d-4dec-9e03-b7ac6b92d378@af5g2000pbd.googlegroups.com> Message-ID: On Tue, Apr 16, 2013 at 8:55 PM, rusi wrote: > On Apr 17, 7:57 am, Bruce McGoveran wrote: >> 3. Section 5.3.1 offers this definition of an attributeref: >> attributeref ::= primary "." identifier >> > > One general comment I will make is regarding your distress at what you > call 'circular' > Circular just means recursive and recursion is the bedrock for > language-design. Rercursion the "bedrock" of language-design. I don't think so. From what I know, a well-defined language ends at its symbols. It makes no use of "infinities". > You cannot hope to define an infinite object such as the python > language (there are an infinite number of python programs) with a > finite specification You've committed two grave sins in C.S.: Conflating a programming language ("an infinite object such as python language") with a program written in that language ("there are an infinite number of python programs"). These two are entirely separate (at least anything implemented on a real computer). Further, you've made a silly description of python "an infinite object such as the python language". A programming language that is well defined has complete, finite, specification. The fact that there are an endless number of programs that can be made from such is irrelevant to the language itself. > -- a useful language definition must start and > end and preferably fit in one's pocket! Likewise, a language specification must end in its symbols. > The trick is to find ways of making an inifinite object finitely > generated. There is no trick involved. > So much of language design is a generalization of Peano's > method of defining (designing?) natural numbers: > a. 0 is a natural number > b. If x is a natural number then the successor of x (informally x+1) > is a natural number Well now you're getting to the root of the confusion and what I'm arguing within the C.S. community: there must be clear distinction between lambda calculii and programming languages rooted in actual hardware implementations. While, traditionally, the field has not made much of a distinction, in practice the computational architecture is different. One of these has a connection to reality and the other not as much ;^). In any case, talking about the mathematical realm *as a realm of Platonic thought* is irrelevant to the discussion of program spaces where *things actually get done*. This is what this list (python) has not figured out yet, because they look up to the theoretical C.S. field and it hasn't yet been published. -- MarkJ Tacoma, Washington From ian.g.kelly at gmail.com Wed Apr 17 20:33:09 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 17 Apr 2013 18:33:09 -0600 Subject: Atoms, Identifiers, and Primaries In-Reply-To: References: <66e78281-542b-41b3-a56d-04bf736d1e0a@googlegroups.com> <14a9ca59-218d-4dec-9e03-b7ac6b92d378@af5g2000pbd.googlegroups.com> Message-ID: On Wed, Apr 17, 2013 at 5:40 PM, Mark Janssen wrote: > Rercursion the "bedrock" of language-design. I don't think so. From > what I know, a well-defined language ends at its symbols. It makes no > use of "infinities". >From what I know, you can't have a Turing-complete language without some form of recursion. So yeah, it's pretty damn important in language design. >> You cannot hope to define an infinite object such as the python >> language (there are an infinite number of python programs) with a >> finite specification > > You've committed two grave sins in C.S.: You've just committed the grave sin of being needlessly hyperbolic. > Conflating a programming > language ("an infinite object such as python language") with a program > written in that language ("there are an infinite number of python > programs"). These two are entirely separate (at least anything > implemented on a real computer). Mathematically, a language (e.g. a programming language) is a set of well-formed strings (i.e. programs) constructed from the symbols of an alphabet (i.e. tokens). For most languages, this set is infinite; saying "the Python language is infinite" is equivalent to saying "there are an infinite number of Python programs". > Further, you've made a silly > description of python "an infinite object such as the python > language". A programming language that is well defined has complete, > finite, specification. The fact that there are an endless number of > programs that can be made from such is irrelevant to the language > itself. A finite, non-recursive grammar can only hope to accept a finite number of strings. To have an infinite language, the defining grammar must then be either infinite (not practical) or recursive. > Well now you're getting to the root of the confusion and what I'm > arguing within the C.S. community: there must be clear distinction > between lambda calculii and programming languages rooted in actual > hardware implementations. While, traditionally, the field has not > made much of a distinction, in practice the computational architecture > is different. One of these has a connection to reality and the other > not as much ;^). > In any case, talking about the mathematical realm *as a realm of > Platonic thought* is irrelevant to the discussion of program spaces > where *things actually get done*. Of course it's relevant. Without theory we would not have big-Oh notation or efficient data structures or regular expressions or context-free grammars; languages like Python would be harder to invent. I'm sure one could come up with a myriad other examples, but that's enough for me. From dreamingforward at gmail.com Wed Apr 17 21:04:10 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Wed, 17 Apr 2013 18:04:10 -0700 Subject: Atoms, Identifiers, and Primaries In-Reply-To: References: <66e78281-542b-41b3-a56d-04bf736d1e0a@googlegroups.com> <14a9ca59-218d-4dec-9e03-b7ac6b92d378@af5g2000pbd.googlegroups.com> Message-ID: On Wed, Apr 17, 2013 at 5:33 PM, Ian Kelly wrote: > On Wed, Apr 17, 2013 at 5:40 PM, Mark Janssen wrote: >> Rercursion the "bedrock" of language-design. I don't think so. From >> what I know, a well-defined language ends at its symbols. It makes no >> use of "infinities". > > From what I know, you can't have a Turing-complete language without > some form of recursion. So yeah, it's pretty damn important in > language design. A Turing-complete language generally has items that are defined in terms of other, simpler items, but this is not called recursion in any C.S. paper I know. In C.S. of my world, recursion is a specific term that is related to functional calculii. This type of recursion is sometimes often found in imperative/iterative languages, but is rooted in the fomer. >> Conflating a programming >> language ("an infinite object such as python language") with a program >> written in that language ("there are an infinite number of python >> programs"). These two are entirely separate (at least anything >> implemented on a real computer). > > Mathematically, a language (e.g. a programming language) is a set of > well-formed strings (i.e. programs) constructed from the symbols of an > alphabet (i.e. tokens). Mathematically, perhaps, but from C.S. theory, a language is a fully-specified set of expressions and tokens which are considered valid -- it's grammar. > For most languages, this set is infinite; This set is always finite, as you can see on the specification for Python's language. > saying "the Python language is infinite" is equivalent to saying > "there are an infinite number of Python programs". I don't think Guido would agree that "the Python language is infinite", but then perhaps he doesn't care either. > A finite, non-recursive grammar can only hope to accept a finite > number of strings. Is the language we're speaking in now one with a finite, non-recursive grammar? -- MarkJ Tacoma, Washington From breamoreboy at yahoo.co.uk Wed Apr 17 21:08:51 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 18 Apr 2013 02:08:51 +0100 Subject: Atoms, Identifiers, and Primaries In-Reply-To: References: <66e78281-542b-41b3-a56d-04bf736d1e0a@googlegroups.com> <14a9ca59-218d-4dec-9e03-b7ac6b92d378@af5g2000pbd.googlegroups.com> Message-ID: On 18/04/2013 02:04, Mark Janssen wrote: > On Wed, Apr 17, 2013 at 5:33 PM, Ian Kelly wrote: >> On Wed, Apr 17, 2013 at 5:40 PM, Mark Janssen wrote: >>> Rercursion the "bedrock" of language-design. I don't think so. From >>> what I know, a well-defined language ends at its symbols. It makes no >>> use of "infinities". >> >> From what I know, you can't have a Turing-complete language without >> some form of recursion. So yeah, it's pretty damn important in >> language design. > > A Turing-complete language generally has items that are defined in > terms of other, simpler items, but this is not called recursion in any > C.S. paper I know. > In C.S. of my world, recursion is a specific term that is related to > functional calculii. This type of recursion is sometimes often found > in imperative/iterative languages, but is rooted in the fomer. > >>> Conflating a programming >>> language ("an infinite object such as python language") with a program >>> written in that language ("there are an infinite number of python >>> programs"). These two are entirely separate (at least anything >>> implemented on a real computer). >> >> Mathematically, a language (e.g. a programming language) is a set of >> well-formed strings (i.e. programs) constructed from the symbols of an >> alphabet (i.e. tokens). > > Mathematically, perhaps, but from C.S. theory, a language is a > fully-specified set of expressions and tokens which are considered > valid -- it's grammar. > >> For most languages, this set is infinite; > > This set is always finite, as you can see on the specification for > Python's language. > >> saying "the Python language is infinite" is equivalent to saying >> "there are an infinite number of Python programs". > > I don't think Guido would agree that "the Python language is > infinite", but then perhaps he doesn't care either. > >> A finite, non-recursive grammar can only hope to accept a finite >> number of strings. > > Is the language we're speaking in now one with a finite, non-recursive grammar? > Thanks for reminding me that I must add food for the trolls to the bottom of my shopping list. -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From ian.g.kelly at gmail.com Wed Apr 17 23:10:21 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 17 Apr 2013 21:10:21 -0600 Subject: Atoms, Identifiers, and Primaries In-Reply-To: References: <66e78281-542b-41b3-a56d-04bf736d1e0a@googlegroups.com> <14a9ca59-218d-4dec-9e03-b7ac6b92d378@af5g2000pbd.googlegroups.com> Message-ID: On Wed, Apr 17, 2013 at 7:04 PM, Mark Janssen wrote: > On Wed, Apr 17, 2013 at 5:33 PM, Ian Kelly wrote: >> On Wed, Apr 17, 2013 at 5:40 PM, Mark Janssen wrote: >>> Rercursion the "bedrock" of language-design. I don't think so. From >>> what I know, a well-defined language ends at its symbols. It makes no >>> use of "infinities". >> >> From what I know, you can't have a Turing-complete language without >> some form of recursion. So yeah, it's pretty damn important in >> language design. > > A Turing-complete language generally has items that are defined in > terms of other, simpler items, but this is not called recursion in any > C.S. paper I know. > In C.S. of my world, recursion is a specific term that is related to > functional calculii. This type of recursion is sometimes often found > in imperative/iterative languages, but is rooted in the fomer. You are thinking of recursive procedures. Recursion is the more general concept of self-repetition. In a programming language, it can be implemented by recursive procedures, or it can equivalently be implemented by looping constructs. Incidentally, in computability theory (also known as "recursion theory"), "recursive" is basically a synonym for "computable", which relates back to my point that recursion is necessary for Turing-completeness; a Turing-complete language is one that can compute any computable (i.e. recursive) function. >>> Conflating a programming >>> language ("an infinite object such as python language") with a program >>> written in that language ("there are an infinite number of python >>> programs"). These two are entirely separate (at least anything >>> implemented on a real computer). >> >> Mathematically, a language (e.g. a programming language) is a set of >> well-formed strings (i.e. programs) constructed from the symbols of an >> alphabet (i.e. tokens). > > Mathematically, perhaps, but from C.S. theory, a language is a > fully-specified set of expressions and tokens which are considered > valid -- it's grammar. Sorry, but as computer science *is* math, the computer science definition is the same as the mathematical one. See for example this CS paper which formally defines "language" as I described: http://www.cs.ucr.edu/~jiang/cs215/tao-new.pdf >> For most languages, this set is infinite; > > This set is always finite, as you can see on the specification for > Python's language. No, the set of valid Python programs is not finite. >> saying "the Python language is infinite" is equivalent to saying >> "there are an infinite number of Python programs". > > I don't think Guido would agree that "the Python language is > infinite", but then perhaps he doesn't care either. > >> A finite, non-recursive grammar can only hope to accept a finite >> number of strings. > > Is the language we're speaking in now one with a finite, non-recursive grammar? No, English is also recursive. From rosuav at gmail.com Wed Apr 17 21:56:50 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 18 Apr 2013 11:56:50 +1000 Subject: Atoms, Identifiers, and Primaries In-Reply-To: References: <66e78281-542b-41b3-a56d-04bf736d1e0a@googlegroups.com> <14a9ca59-218d-4dec-9e03-b7ac6b92d378@af5g2000pbd.googlegroups.com> Message-ID: On Thu, Apr 18, 2013 at 9:40 AM, Mark Janssen wrote: > On Tue, Apr 16, 2013 at 8:55 PM, rusi wrote: >> On Apr 17, 7:57 am, Bruce McGoveran wrote: >>> 3. Section 5.3.1 offers this definition of an attributeref: >>> attributeref ::= primary "." identifier >>> >> >> One general comment I will make is regarding your distress at what you >> call 'circular' >> Circular just means recursive and recursion is the bedrock for >> language-design. > > Rercursion the "bedrock" of language-design. I don't think so. From > what I know, a well-defined language ends at its symbols. It makes no > use of "infinities". There's a difference between infinite and recursive, though. I was defining a function (it converted from JSON to an internal format) and wanted to explain that not all of JSON would reliably round-trip (ie be able to be translated to the internal format and then back again). To describe what _would_ round-trip correctly, I used this simple yet technically illegal description: typedef valid string|array(valid)|object(string:valid) In other words, a string is valid, and a list/array of valid elements is valid, and a dictionary/mapping/object with string keys and valid elements is valid. It's a recursive definition, but it can't go infinite (self-references aren't valid - though this isn't stated by the typedef); however, it can go arbitrarily deep. ChrisA From steve+comp.lang.python at pearwood.info Wed Apr 17 22:14:26 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 18 Apr 2013 02:14:26 GMT Subject: Atoms, Identifiers, and Primaries References: <66e78281-542b-41b3-a56d-04bf736d1e0a@googlegroups.com> <14a9ca59-218d-4dec-9e03-b7ac6b92d378@af5g2000pbd.googlegroups.com> Message-ID: <516f5701$0$29977$c3e8da3$5496439d@news.astraweb.com> On Wed, 17 Apr 2013 18:33:09 -0600, Ian Kelly wrote: > On Wed, Apr 17, 2013 at 5:40 PM, Mark Janssen > wrote: >> Rercursion the "bedrock" of language-design. I don't think so. From >> what I know, a well-defined language ends at its symbols. It makes no >> use of "infinities". > > From what I know, you can't have a Turing-complete language without > some form of recursion. So yeah, it's pretty damn important in language > design. Incorrect. Early Fortran, which was definitely Turing complete, was incapable of using recursion. But that doesn't matter, since any recursive algorithm can be re-written as iteration. So long as a language can iterate an indefinite number of times, it may be Turing complete. (Languages which can only iterate a fixed number of times cannot be Turing complete.) Hell, Turing machines themselves are not recursive. Since they don't have a concept of functions, they don't have a concept of functions that call themselves. A Turing machine only has a couple of trivial operations: * read a cell * write a cell * advance the tape * change direction and so it's grammar is correspondingly trivial. Actually, talking about the grammar of a Turing machine is probably wrong. In practice, Turing machines are specified as a finite (and usually small) table of states and cells. See here for examples: http://en.wikipedia.org/wiki/Turing_machine_examples So it isn't even correct to say that recursion is necessary for a language's *grammar*. However, for any real-world practical language (there's a reason that no practical language is based on Turing machines) recursive grammars are extraordinarily useful. > A finite, non-recursive grammar can only hope to accept a finite number > of strings. To have an infinite language, the defining grammar must > then be either infinite (not practical) or recursive. I don't believe that is true, so long as the grammar has a concept of "zero or more" of some syntactic element. For example, suppose your grammar has a concept of integers, defined recursively as either a digit, or a digit followed by an integer: INTEGER ::= DIGIT | DIGIT INTEGER This can be defined more naturally as a digit followed by zero or more digits: INTEGER ::= DIGIT (DIGIT)* -- Steven From ian.g.kelly at gmail.com Wed Apr 17 23:12:15 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 17 Apr 2013 21:12:15 -0600 Subject: Atoms, Identifiers, and Primaries In-Reply-To: <516f5701$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <66e78281-542b-41b3-a56d-04bf736d1e0a@googlegroups.com> <14a9ca59-218d-4dec-9e03-b7ac6b92d378@af5g2000pbd.googlegroups.com> <516f5701$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 17, 2013 at 8:14 PM, Steven D'Aprano wrote: > Incorrect. Early Fortran, which was definitely Turing complete, was > incapable of using recursion. But that doesn't matter, since any > recursive algorithm can be re-written as iteration. So long as a language > can iterate an indefinite number of times, it may be Turing complete. You're also confusing "recursion" with "recursive programming". See the response I just gave to Mark. From wuwei23 at gmail.com Wed Apr 17 20:29:45 2013 From: wuwei23 at gmail.com (alex23) Date: Wed, 17 Apr 2013 17:29:45 -0700 (PDT) Subject: Atoms, Identifiers, and Primaries References: <66e78281-542b-41b3-a56d-04bf736d1e0a@googlegroups.com> <14a9ca59-218d-4dec-9e03-b7ac6b92d378@af5g2000pbd.googlegroups.com> Message-ID: <9275196c-96fc-4183-9f1c-63f9c58e4f18@id10g2000pbc.googlegroups.com> On Apr 18, 9:40?am, Mark Janssen wrote: > This is what this list (python) has not figured out yet, because they > look up to the theoretical C.S. field and it hasn't yet been > published. No one here idolises "the theoretical C.S. field". They *use* Python to *get things done*, not to engage in pointless masturbation. Please keep your computer pseudo-science nonsense to your own threads, don't use it to derail others. From dreamingforward at gmail.com Wed Apr 17 20:41:04 2013 From: dreamingforward at gmail.com (Mark Janssen) Date: Wed, 17 Apr 2013 17:41:04 -0700 Subject: Atoms, Identifiers, and Primaries In-Reply-To: <9275196c-96fc-4183-9f1c-63f9c58e4f18@id10g2000pbc.googlegroups.com> References: <66e78281-542b-41b3-a56d-04bf736d1e0a@googlegroups.com> <14a9ca59-218d-4dec-9e03-b7ac6b92d378@af5g2000pbd.googlegroups.com> <9275196c-96fc-4183-9f1c-63f9c58e4f18@id10g2000pbc.googlegroups.com> Message-ID: On Wed, Apr 17, 2013 at 5:29 PM, alex23 wrote: > On Apr 18, 9:40 am, Mark Janssen wrote: >> This is what this list (python) has not figured out yet, because they >> look up to the theoretical C.S. field and it hasn't yet been >> published. > > No one here idolises "the theoretical C.S. field". They *use* Python > to *get things done*, not to engage in pointless masturbation. Woah! "no one" you say.... Interesting... Mark From breamoreboy at yahoo.co.uk Wed Apr 17 21:04:48 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 18 Apr 2013 02:04:48 +0100 Subject: Atoms, Identifiers, and Primaries In-Reply-To: References: <66e78281-542b-41b3-a56d-04bf736d1e0a@googlegroups.com> <14a9ca59-218d-4dec-9e03-b7ac6b92d378@af5g2000pbd.googlegroups.com> <9275196c-96fc-4183-9f1c-63f9c58e4f18@id10g2000pbc.googlegroups.com> Message-ID: On 18/04/2013 01:41, Mark Janssen wrote: > On Wed, Apr 17, 2013 at 5:29 PM, alex23 wrote: >> On Apr 18, 9:40 am, Mark Janssen wrote: >>> This is what this list (python) has not figured out yet, because they >>> look up to the theoretical C.S. field and it hasn't yet been >>> published. >> >> No one here idolises "the theoretical C.S. field". They *use* Python >> to *get things done*, not to engage in pointless masturbation. > > Woah! "no one" you say.... Interesting... > > Mark > IMHO very few cos we all know that practically beats purity. -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From rustompmody at gmail.com Thu Apr 18 03:40:28 2013 From: rustompmody at gmail.com (rusi) Date: Thu, 18 Apr 2013 00:40:28 -0700 (PDT) Subject: Atoms, Identifiers, and Primaries References: <66e78281-542b-41b3-a56d-04bf736d1e0a@googlegroups.com> <14a9ca59-218d-4dec-9e03-b7ac6b92d378@af5g2000pbd.googlegroups.com> Message-ID: <6431de9b-1771-40e3-a55b-6ac422ddd9c8@i20g2000pbq.googlegroups.com> On Apr 18, 4:40?am, Mark Janssen wrote: > On Tue, Apr 16, 2013 at 8:55 PM, rusi wrote: > > Circular just means recursive and recursion is the bedrock for > > language-design. > > Rercursion the "bedrock" of language-design. ?I don't think so. Imperative programmers may be forgiven for not understanding how pervasive the idea of recursion is in CS. For example most C programmers dont understand that the standard definition of linked list is not just recursive, its mutually recursive: pointer struct struct pointer I have a collection of some of the variety of the uses of recursion in CS here: http://blog.languager.org/2012/05/recursion-pervasive-in-cs.html Or see the first line of http://en.wikipedia.org/wiki/Recursion_theory recursion theory is by definition the same subject as computation theory From ian.g.kelly at gmail.com Wed Apr 17 03:21:00 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 17 Apr 2013 01:21:00 -0600 Subject: Atoms, Identifiers, and Primaries In-Reply-To: <66e78281-542b-41b3-a56d-04bf736d1e0a@googlegroups.com> References: <66e78281-542b-41b3-a56d-04bf736d1e0a@googlegroups.com> Message-ID: On Tue, Apr 16, 2013 at 8:57 PM, Bruce McGoveran wrote: > These are terms that appear in section 5 (Expressions) of the Python online documentation. I'm having some trouble understanding what, precisely, these terms mean. I'd appreciate the forum's thoughts on these questions: > > 1. Section 5.2.1 indicates that an identifier occurring as an atom is a name. However, Section 2.3 indicates that identifiers are names. My question: can an identifier be anything other than a name? Yes. For example: from a import b Here "a" is an identifier but not a name, as it does not carry object-binding semantics. > 2. Section 5.3 defines primaries as the most tightly bound operations of Python. What does this mean? "Tightly bound" here refers to operator precedence. For example, we say that the multiplication operator binds more tightly [to the surrounding operands] than the arithmetic operator, because the multiplication takes precedence. This section defines that the most tightly bound operations in Python are attribute references, subscriptions, slices and calls; these always take precedence over other neighboring operations. > In particular, if an atom is a primary, what operation is the atom performing that leads to the label "most tightly bound"? An atom doesn't perform an operation. The grammar defines that a primary can be just an atom, so that anywhere in the grammar that expects a primary, a simple atom with no primary operation performed on it can equally be used. From davea at davea.name Wed Apr 17 07:07:45 2013 From: davea at davea.name (Dave Angel) Date: Wed, 17 Apr 2013 07:07:45 -0400 Subject: Atoms, Identifiers, and Primaries In-Reply-To: <66e78281-542b-41b3-a56d-04bf736d1e0a@googlegroups.com> References: <66e78281-542b-41b3-a56d-04bf736d1e0a@googlegroups.com> Message-ID: <516E8281.9070907@davea.name> On 04/16/2013 10:57 PM, Bruce McGoveran wrote: > These are terms that appear in section 5 (Expressions) of the Python online documentation. I'm having some trouble understanding what, precisely, these terms mean. I'd appreciate the forum's thoughts on these questions: > > > 3. Section 5.3.1 offers this definition of an attributeref: > attributeref ::= primary "." identifier > > Now, I was at first a little concerned to see the non-terminal primary on the right hand side of the definition, since primary is defined to include attributeref in section 5.3 (so this struck me as circular). Am I correct in thinking attributeref is defined this way to allow for situations in which the primary, whether an atom, attributeref (example: an object on which a method is called that returns another object), subscription, slicing, or call, returns an object with property identifier? > It is circular. Nothing wrong with that. It means that not only can you use a.b but also a.b.c and a.b.c.d.e.f.g without any explicit limit. if a non-circular definition were to be attempted, you might need a few dozen rules, just to cover what someone *might* happen to use in an expression. Of course normally, one doesn't go much beyond a.b.c in a single expression. -- DaveA From steve+comp.lang.python at pearwood.info Wed Apr 17 07:43:18 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Apr 2013 11:43:18 GMT Subject: Atoms, Identifiers, and Primaries References: <66e78281-542b-41b3-a56d-04bf736d1e0a@googlegroups.com> Message-ID: <516e8ad5$0$29977$c3e8da3$5496439d@news.astraweb.com> On Tue, 16 Apr 2013 19:57:25 -0700, Bruce McGoveran wrote: > These are terms that appear in section 5 (Expressions) of the Python > online documentation. I'm having some trouble understanding what, > precisely, these terms mean. I'd appreciate the forum's thoughts on > these questions: > > 1. Section 5.2.1 indicates that an identifier occurring as an atom is a > name. However, Section 2.3 indicates that identifiers are names. My > question: can an identifier be anything other than a name? Yes and no. According to the Python grammar as documented, no, identifiers are just another name for, er, name. But according to common practice, yes, we call many things identifiers: x # a bare name, or "identifier" according to the grammar x.attr # name with an attribute, or "attributeref" x[key] # name with a subscript, or "subscription" x[5] # name with an indexed subscript, or "slicing" x[start:stop:step] # name with a slice subscript > 2. Section 5.3 defines primaries as the most tightly bound operations > of Python. What does this mean? It means that primaries are evaluated at the highest priority. For example, given: x.a+b that is evaluated as: (x.a) + b rather than: x . (a+b) In particular, if you have a variable: name = "Fred" then x.name will look for an attribute "name", *not* x.Fred. > In particular, if an atom is a > primary, what operation is the atom performing that leads to the label > "most tightly bound"? To put it a different way, I think of atoms as > things (i.e. identifiers). Correct. > The documentation makes me think atoms > actually do something, as opposed to being things (I think I have in my > mind the difference between a noun and a verb as I write this). The only thing they do is be evaluated. > 3. Section 5.3.1 offers this definition of an attributeref: > attributeref ::= primary "." identifier > > Now, I was at first a little concerned to see the non-terminal primary > on the right hand side of the definition, since primary is defined to > include attributeref in section 5.3 (so this struck me as circular). Am > I correct in thinking attributeref is defined this way to allow for > situations in which the primary, whether an atom, attributeref (example: > an object on which a method is called that returns another object), > subscription, slicing, or call, returns an object with property > identifier? Yes. It means you can write things like this: module.Class.method()[0](arg).attr.name[2]['spam'].aardvark() and have it evaluated from left to right. With respect, I think you may be confusing yourself unnecessarily with an excessive concern for the formal grammar of Python. You may find it makes a lot more sense in practice than it makes in theory. I strongly recommend you open up an interactive interpreter and just play around with the syntax and see what happens. -- Steven From bruce.mcgoveran at gmail.com Wed Apr 17 13:15:02 2013 From: bruce.mcgoveran at gmail.com (Bruce McGoveran) Date: Wed, 17 Apr 2013 10:15:02 -0700 (PDT) Subject: Atoms, Identifiers, and Primaries In-Reply-To: <66e78281-542b-41b3-a56d-04bf736d1e0a@googlegroups.com> References: <66e78281-542b-41b3-a56d-04bf736d1e0a@googlegroups.com> Message-ID: Thank you all for your thoughtful replies. I appreciate your collective insight. I didn't mean to cast the concept of recursion in a negative light - I'm actually comfortable with the concept, at least to some extent, and I appreciate the need for its use in this documentation. I also appreciate the need to play with expressions at the command line, to gain a feel for how expressions are evaluated. My interest in the language's formal description arises merely out of a desire to understand as precisely as possible what happens when I hit enter at the command line, or when I run a module. Your answers to my initial questions in this thread and the ones I posed in another thread ("Understanding Boolean Expressions") have lead me to some follow-up questions. Suppose I'm working at the command line, and I bind x to the value 1 and y to the value 0. Suppose I next type x and y and hit enter. Python returns 0 (zero). I'm glad I checked this before sending in this post because I thought it would return a value of False based on the presence of the and operand. My question: what did the interpreter have to do to evaluate the expression x and y and return a value of zero? I know the lexical analyzer has to parse the stream of characters into tokens. I presume this parsing generates the toxens x, y, and, and a NEWLINE. Beyond that, things get a little fuzzy, and it occurs to me that this fuzziness is the result of my looking at the expression x and y knowing full well what each token means and what I want done with them, whereas the interpreter won't know these things until it can parse the character stream and sort the tokens into some recognizable (and syntactically correct) order. As I look at it, the expression x and y has two atoms, namely x and y. x and y are also primaries, and they represent the most tightly bound parts of this expression (meaning they bind more tightly to their underlying objects than to the and operator). Incidentally, how does Python figure out that the x and y in this expression refer to the x and y I previously bound to integer values? I know there's a symbol table in each execution frame. How does Python know to go to that table and check for x and y? The and token represents an operator, a boolean operator to be specific. As I look at the grammar for and_test in section 5.10 of the documentation, it would appear that the and_test resolves via not_test's definition to two comparisons, which in turn resolve to or_expr, and then via a series of binary bitwise definitions to shift_expr, then to a_expr, then to m_expr, then to u_expr, to power, and then primary, and then to atom, which lands us finally at non-terminal identifiers (i.e. x and y themselves). Questions: In working through these steps, what I have actually demonstrated? Is this how Python deconstructs an and statement with two operands? Do I take from the fact that the progression from and_test to identifier involved reference to bitwise operators that the boolean testing of x and y involves a bitwise comparison of x and y? I have to admit these questions are a little confusing; this may reflect the fact I am not exactly sure what it is I am trying to ask. In general terms, I am trying to understand how Python evalutes the expression x and y in this context. For my sanity's sake (and, perhaps, for yours) I will stop there. I send thanks in advance for any thoughts you have on my questions. On Tuesday, April 16, 2013 10:57:25 PM UTC-4, Bruce McGoveran wrote: > These are terms that appear in section 5 (Expressions) of the Python online documentation. I'm having some trouble understanding what, precisely, these terms mean. I'd appreciate the forum's thoughts on these questions: > > > > 1. Section 5.2.1 indicates that an identifier occurring as an atom is a name. However, Section 2.3 indicates that identifiers are names. My question: can an identifier be anything other than a name? > > > > 2. Section 5.3 defines primaries as the most tightly bound operations of Python. What does this mean? In particular, if an atom is a primary, what operation is the atom performing that leads to the label "most tightly bound"? To put it a different way, I think of atoms as things (i.e. identifiers). The documentation makes me think atoms actually do something, as opposed to being things (I think I have in my mind the difference between a noun and a verb as I write this). Perhaps the doing in this case (or binding, if you like) is linking (binding) the identifier to the underlying object? I think it might help if I had a better working notion of what a primary is. > > > > 3. Section 5.3.1 offers this definition of an attributeref: > > attributeref ::= primary "." identifier > > > > Now, I was at first a little concerned to see the non-terminal primary on the right hand side of the definition, since primary is defined to include attributeref in section 5.3 (so this struck me as circular). Am I correct in thinking attributeref is defined this way to allow for situations in which the primary, whether an atom, attributeref (example: an object on which a method is called that returns another object), subscription, slicing, or call, returns an object with property identifier? > > > > These are, I know, long-winded questions. I appreciate in advance any thoughts the group can offer. > > > > The relevant documentation link is: http://docs.python.org/2/reference/expressions.html#expressions > > > > Thanks, > > Bruce From steve+comp.lang.python at pearwood.info Wed Apr 17 14:43:43 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 18 Apr 2013 04:43:43 +1000 Subject: Atoms, Identifiers, and Primaries References: <66e78281-542b-41b3-a56d-04bf736d1e0a@googlegroups.com> Message-ID: <516eed60$0$29971$c3e8da3$5496439d@news.astraweb.com> Wow, that's some impressive wall of text! Splitting your comments up into a few paragraphs would make it much easier to read :-) My comments below... On Wed, 17 Apr 2013 10:15:02 -0700, Bruce McGoveran wrote: > Thank you all for your thoughtful replies. I appreciate your collective > insight. I didn't mean to cast the concept of recursion in a negative > light - I'm actually comfortable with the concept, at least to some > extent, and I appreciate the need for its use in this documentation. I > also appreciate the need to play with expressions at the command line, > to gain a feel for how expressions are evaluated. My interest in the > language's formal description arises merely out of a desire to > understand as precisely as possible what happens when I hit enter at the > command line, or when I run a module. You won't gain that from the *grammar* of the language. Grammar is only part of the story, and in some ways, the least important part. If I tell you that the grammar of English includes: ADJECTIVE NOUN that alone is not going to help you understand the differences between a "wise man" and a "wise guy", or "peanut oil" and "baby oil". I'm not saying that syntax and grammar is unimportant, but it is independent of the *semantics* of the program, and really its the semantics (the meaning) of code that is important. One can easily imagine four languages where the identical operation was written as: name.attribute name->attribute name(attribute) attribute of name Contrariwise, just because two languages have ostensibly the same syntax for something, doesn't mean they are doing the same thing. E.g. there are subtle differences between attribute lookup name.attribute in Java and Python. > Your answers to my initial > questions in this thread and the ones I posed in another thread > ("Understanding Boolean Expressions") have lead me to some follow-up > questions. Suppose I'm working at the command line, and I bind x to the > value 1 and y to the value 0. Suppose I next type x and y and hit > enter. Python returns 0 (zero). I'm glad I checked this before sending > in this post because I thought it would return a value of False based on > the presence of the and operand. The command line is actually irrelevant here. With one or two minor exceptions, Python will do the same thing whether you are working interactively or not. The main differences are that at the interactive prompt, Python will automatically print the result of any expression which is not otherwise bound to a value, and also bind it to the variable name "_". (A single underscore.) Other interactive command prompts may do more, or less. > My question: what did the interpreter > have to do to evaluate the expression x and y and return a value of > zero? I know the lexical analyzer has to parse the stream of characters > into tokens. I presume this parsing generates the toxens x, y, and, and > a NEWLINE. Well, yes, but you're being awfully reductionist here. I'm the first to be in favour of curiosity for curiosity's sake, but I'm not sure that getting bogged down at such a low level this early in your Python learning experience is a good idea. *shrug* No skin off my nose though. The answer is going to depend on the implementation. There are at least four major implementations of Python these days, and another dozen or two obsolete, experimental or minor implementations. (Oh, and let me apologise in advance to anyone whose implementation I haven't listed as "major".) CPython is the implementation you are probably using; Jython runs on top of the Java virtual machine, IronPython runs on top of the Dot Net virtual machine, and PyPy runs on the deepest, darkest voodoo known to Mankind. But essentially, any implementation will have to perform all or most of these steps: * Parse the source code into tokens. CPython generates an AST, Abstract Syntax Tree. What that means in practice, I have no idea. This is relatively new: some versions back, the syntax was essentially identical, but there was no AST involved. * From the tokens, or the AST, generate byte code. Or machine code, if your compiler is clever enough. * Execute the byte code in some virtual machine, or the machine code directly on your CPU, as the case may be. You can view the byte code using the dis module, e.g.: py> import dis py> code = compile('x = 1; y = 0; print x and y', '', 'exec') py> dis.dis(code) 1 0 LOAD_CONST 0 (1) 3 STORE_NAME 0 (x) 6 LOAD_CONST 1 (0) 9 STORE_NAME 1 (y) 12 LOAD_NAME 0 (x) 15 JUMP_IF_FALSE_OR_POP 21 18 LOAD_NAME 1 (y) >> 21 PRINT_ITEM 22 PRINT_NEWLINE 23 LOAD_CONST 2 (None) 26 RETURN_VALUE If you run this under another implementation of Python, such as WPython, or even a different version of CPython, you may get completely different byte code. But the *semantics* of what it does must be identical, otherwise it isn't Python. > Beyond that, things get a little fuzzy, and it occurs to me > that this fuzziness is the result of my looking at the expression x and > y knowing full well what each token means and what I want done with > them, whereas the interpreter won't know these things until it can parse > the character stream and sort the tokens into some recognizable (and > syntactically correct) order. No. Python will not sort the tokens into syntactically correct order. It will only take them in the order you provide them. If you write code in the wrong syntax: x y <= # I prefer to write reverse Polish notation you will get a syntax error, Python won't rearrange the tokens into the correct order x <= y. > As I look at it, the expression x and y > has two atoms, namely x and y. x and y are also primaries, and they > represent the most tightly bound parts of this expression (meaning they > bind more tightly to their underlying objects than to the and operator). > Incidentally, how does Python figure out that the x and y in this > expression refer to the x and y I previously bound to integer values? Ah, now you're finally asking the right questions! This is the important part: Python's execution model. All that stuff about parsing source code and generating ASTs and byte-code is just the mechanics that are needed to make it work. In principle, you could simulate a Python interpreter in your head, or build a CPU that executed Python code directly, and avoid everything except the most simple parser. The behaviour of the interpreter will be the same, regardless of how much work it does. In this case, Python does a runtime lookup in the current namespace for names "x" and "y", retrieve the appropriate values, or raise a NameError if they don't exist. In pseudo-code: get the current namespace if 'x' is not in the namespace: raise NameError if 'y' is not in the namespace: raise NameError get the value of x in the current namespace get the value of y in the current namespace perform the "and" operator on those two values (more or less). Python's actual execution model is based on a stack, like Forth, but really, unless you're trying to read byte code, you will never need to know this. It's irrelevant to the day-to-day understanding of Python code. > I know there's a symbol table in each execution frame. How does Python > know to go to that table and check for x and y? Because some person, many years ago, programmed the Python compiler to do that. > The and token represents > an operator, a boolean operator to be specific. As I look at the > grammar for and_test in section 5.10 of the documentation, it would > appear that the and_test resolves via not_test's definition to two > comparisons, which in turn resolve to or_expr, and then via a series of > binary bitwise definitions to shift_expr, then to a_expr, then to > m_expr, then to u_expr, to power, and then primary, and then to atom, > which lands us finally at non-terminal identifiers (i.e. x and y > themselves). Questions: In working through these steps, what I have > actually demonstrated? Is this how Python deconstructs an and statement > with two operands? Absolutely not. All you're doing is focusing on the formal grammar, instead of either the Python virtual machine, or it's execution model. > Do I take from the fact that the progression from > and_test to identifier involved reference to bitwise operators that the > boolean testing of x and y involves a bitwise comparison of x and y? Absolutely not. What you actually need to know is much more high-level than this. When Python evaluates "x and y", it runs pseudo-code something like this: * if x is not a true-like value, return x * return y This is short-cut semantics of boolean "and", with truthy/falsey values instead of just a pair of True/False values. You won't learn this from the grammar, because it isn't part of the grammar. It is part of the execution model of the language. How does Python determine whether x is "true-like"? It asks x, "are you true?". If x has a __bool__ method, it calls x.__bool__(). Otherwise, if x has a __len__ method, it calls x.__len__() and compares the result to zero. Otherwise, it (somewhat arbitrarily, but reasonably) declares that since x is an object, it is something rather than nothing and therefore it must be true-ish. I hope this helps, and expect it will raise as many questions as it answers! -- Steven From rustompmody at gmail.com Thu Apr 18 13:04:43 2013 From: rustompmody at gmail.com (rusi) Date: Thu, 18 Apr 2013 10:04:43 -0700 (PDT) Subject: Atoms, Identifiers, and Primaries References: <66e78281-542b-41b3-a56d-04bf736d1e0a@googlegroups.com> <516eed60$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8d1745ff-9f10-490d-93c6-7142a8a35ad5@hc4g2000pbb.googlegroups.com> On Apr 17, 11:43?pm, Steven D'Aprano wrote: > > You won't gain that from the *grammar* of the language. Grammar is only part > of the story, and in some ways, the least important part. If I tell you > that the grammar of English includes: > > ADJECTIVE NOUN > > that alone is not going to help you understand the differences between > a "wise man" and a "wise guy", or "peanut oil" and "baby oil". Heh!! Cute example. [I'll remember it when I am teaching] > > My question: ?what did the interpreter > > have to do to evaluate the expression x and y and return a value of > > zero? I know the lexical analyzer has to parse the stream of characters > > into tokens. ?I presume this parsing generates the toxens x, y, and, and > > a NEWLINE. > > Well, yes, but you're being awfully reductionist here. I'm the first to be > in favour of curiosity for curiosity's sake, but I'm not sure that getting > bogged down at such a low level this early in your Python learning > experience is a good idea. *shrug* No skin off my nose though. > Good to be reductionist sometime (and stop being reductionist rest of the time) That is to say good to know the general lay of the land for what happens inside a language implementation. Broadly speaking it goes like this: 1. Lexical analysis -- separating into tokens/lexemes, removing comments, (special for python, making sense of the indentation structure) 2. Syntax analysis -- building the parse tree (at least in principle) for the program that accords with the grammar Convert the (concrete) parse tree into an abstract syntax tree (AST) 3. Semantic analysis (Type-checking): Not much of typechecking in python just things like checking Name error In a more usual (statically typed) language like C/java etc the AST gets 'decorated' with type information Once you are here, the undesirable cases have been weeded out and the program (if correct) has been annotated well enough (decorated AST) for? 4. Code generation/Interpretation using a straightforward recursive walk down the decorated AST 5. An optimizing compiler may do more with the output of 4 (also between 3 and 4) Languages like C put the above 1-5 into a box called 'compiler-proper' and stick a preprocessor before and assembler and linker after. So while it is good to ask about the lexer, it is also the most boring and irrelevant part of the system (to paraphrase Steven) From dihedral88888 at googlemail.com Thu Apr 18 00:29:57 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Wed, 17 Apr 2013 21:29:57 -0700 (PDT) Subject: Atoms, Identifiers, and Primaries In-Reply-To: References: <66e78281-542b-41b3-a56d-04bf736d1e0a@googlegroups.com> Message-ID: Ian? 2013?4?17????UTC+8??3?21?00???? > On Tue, Apr 16, 2013 at 8:57 PM, Bruce McGoveran > > wrote: > > > These are terms that appear in section 5 (Expressions) of the Python online documentation. I'm having some trouble understanding what, precisely, these terms mean. I'd appreciate the forum's thoughts on these questions: > > > > > > 1. Section 5.2.1 indicates that an identifier occurring as an atom is a name. However, Section 2.3 indicates that identifiers are names. My question: can an identifier be anything other than a name? > > > > Yes. For example: > > > > from a import b > > > > Here "a" is an identifier but not a name, as it does not carry > > object-binding semantics. > > > > > 2. Section 5.3 defines primaries as the most tightly bound operations of Python. What does this mean? > > > > "Tightly bound" here refers to operator precedence. For example, we > > say that the multiplication operator binds more tightly [to the > > surrounding operands] than the arithmetic operator, because the > > multiplication takes precedence. This section defines that the most > > tightly bound operations in Python are attribute references, > > subscriptions, slices and calls; these always take precedence over > > other neighboring operations. > > > > > In particular, if an atom is a primary, what operation is the atom performing that leads to the label "most tightly bound"? > > > > An atom doesn't perform an operation. The grammar defines that a > > primary can be just an atom, so that anywhere in the grammar that > > expects a primary, a simple atom with no primary operation performed > > on it can equally be used. An atom can not be divided into further details. An atom can be created and cloned or just referenced in some relations. An object is composed of atoms linked in someway. Of course, one can box those atoms of an object to make the object immutable at least in some situations to be named and used. From dihedral88888 at googlemail.com Thu Apr 18 00:29:57 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Wed, 17 Apr 2013 21:29:57 -0700 (PDT) Subject: Atoms, Identifiers, and Primaries In-Reply-To: References: <66e78281-542b-41b3-a56d-04bf736d1e0a@googlegroups.com> Message-ID: Ian? 2013?4?17????UTC+8??3?21?00???? > On Tue, Apr 16, 2013 at 8:57 PM, Bruce McGoveran > > wrote: > > > These are terms that appear in section 5 (Expressions) of the Python online documentation. I'm having some trouble understanding what, precisely, these terms mean. I'd appreciate the forum's thoughts on these questions: > > > > > > 1. Section 5.2.1 indicates that an identifier occurring as an atom is a name. However, Section 2.3 indicates that identifiers are names. My question: can an identifier be anything other than a name? > > > > Yes. For example: > > > > from a import b > > > > Here "a" is an identifier but not a name, as it does not carry > > object-binding semantics. > > > > > 2. Section 5.3 defines primaries as the most tightly bound operations of Python. What does this mean? > > > > "Tightly bound" here refers to operator precedence. For example, we > > say that the multiplication operator binds more tightly [to the > > surrounding operands] than the arithmetic operator, because the > > multiplication takes precedence. This section defines that the most > > tightly bound operations in Python are attribute references, > > subscriptions, slices and calls; these always take precedence over > > other neighboring operations. > > > > > In particular, if an atom is a primary, what operation is the atom performing that leads to the label "most tightly bound"? > > > > An atom doesn't perform an operation. The grammar defines that a > > primary can be just an atom, so that anywhere in the grammar that > > expects a primary, a simple atom with no primary operation performed > > on it can equally be used. An atom can not be divided into further details. An atom can be created and cloned or just referenced in some relations. An object is composed of atoms linked in someway. Of course, one can box those atoms of an object to make the object immutable at least in some situations to be named and used. From info at egenix.com Wed Apr 17 03:30:16 2013 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Wed, 17 Apr 2013 09:30:16 +0200 Subject: ANN: eGenix mx Base Distribution 3.2.6 (mxDateTime, mxTextTools, etc.) Message-ID: <516E4EBA.4020105@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mx Base Distribution mxDateTime, mxTextTools, mxProxy, mxURL, mxUID, mxBeeBase, mxStack, mxQueue, mxTools Version 3.2.6 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.6-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.6 release of the eGenix mx Base Distribution is the latest release of our open-source Python extensions. It includes these fixes and enhancements: Fixes ----- * mxURL: Added a work-around to resolve a segfault when exiting the Python 2.7.4 interpreter. This is a Python bug which was introduced in Python 2.7.4 and will get fixed again in Python 2.7.5 - see http://bugs.python.org/issue17703. Documentation Enhancements -------------------------- * mxURL: Added sections on URL join operations and interaction with strings to mxURL documentation. * mxDateTime: Added notice to documentation that .gmtoffset() can give wrong results during DST switching time. Compatibility Enhancements -------------------------- * Filled the tp_methods slot of all extension types to improve Python 2.7 compatibility. Distribution Enhancements ------------------------- * Added download URL registered with PyPI is now a static page and includes an MD5 hash tag to allow verification of the page. * All distribution files are GPG signed with our release key. We also provide MD5 and SHA1 hash values for all files to easily verify the downloads. eGenix mx Base Distribution 3.2.0 was release on 2012-08-28. Please see the eGenix mx Base Distribution 3.2.0 announcement for new features in the 3.2 major release: https://cms.egenix.com/company/news/eGenix-mx-Base-Distribution-3.2.0-GA.html For a full list of changes, please refer to the eGenix mx Base Distribution change log and the change logs of the various included Python packages. http://www.egenix.com/products/python/mxBase/changelog.html ________________________________________________________________________ UPGRADING We encourage all users to upgrade to this latest eGenix mx Base Distribution release. If you are upgrading from eGenix mx Base 3.1.x, please see the eGenix mx Base Distribution 3.2.0 release notes for details on what has changed since the 3.1 major release. http://www.egenix.com/company/news/eGenix-mx-Base-Distribution-3.2.0-GA.html 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. ________________________________________________________________________ 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 ________________________________________________________________________ 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/ 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 prebuilt package or the source distribution, installation is a simple "python setup.py install" command in all cases. The only difference is that the prebuilt packages do not require a compiler or the Python development packages to be installed. ________________________________________________________________________ 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. ________________________________________________________________________ MORE INFORMATION For more information on the eGenix mx Base Distribution, documentation and installation notes, please visit our web-site: http://www.egenix.com/products/python/mxBase/ About Python (http://www.python.org/): Python is an object-oriented Open Source programming language which runs on all modern platforms. By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for today's IT challenges. About eGenix (http://www.egenix.com/): eGenix is a software project, consulting and product company focusing on expert project services and professional quality products for companies, Python users and developers. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Apr 17 2013) >>> Python Projects, Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2013-04-09: Released mxODBC.Connect 2.0.3 ... http://egenix.com/go42 ::::: Try our 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 m.shemuni at gmail.com Wed Apr 17 05:08:50 2013 From: m.shemuni at gmail.com (m.shemuni at gmail.com) Date: Wed, 17 Apr 2013 02:08:50 -0700 (PDT) Subject: RGB combine Message-ID: Hi everyone. I have 3 grayscaled picture. These are Red, Green and Blue filtered. I want to colorize it. I'm a GNU/Linux user and I did it with imagemagick using this code: convert r.png g.png b.png -set colorspace RGB -combine -set colorspace sRGB rgb.gif But I want to colorize it with using color matrix. For example I want it to looks more red or blue. I remember something from fits liberator. I was able to change density of colors. How can I do it with python? Sorry for bad English. From tavares at fe.up.pt Wed Apr 17 06:56:17 2013 From: tavares at fe.up.pt (tavares at fe.up.pt) Date: Wed, 17 Apr 2013 03:56:17 -0700 (PDT) Subject: IV ECCOMAS Thematic Conference VipIMAGE 2013: SUBMISSION DEADLINE EXTENDED Message-ID: <6a8823e9-d974-4a50-b7c1-6f53aeb1fab0@googlegroups.com> Dear Colleague, We are pleased to inform you that the submission of abstracts for the International Conference VipIMAGE 2013 - IV ECCOMAS THEMATIC CONFERENCE ON COMPUTATIONAL VISION AND MEDICAL IMAGE PROCESSING (www.fe.up.pt/~vipimage) to be held October 14-16, 2013, in Melia Madeira Mare Hotel, Madeira Island, Funchal, Portugal, is going very well. Attending several requests, the organizing committee has extended the submission period to May 6th. Once again, we would like to invite you to participate and share your expertise in VipIMAGE 2013. Possible Topics (not limited to) ? Signal and Image Processing ? Computational Vision ? Medical Imaging ? Physics of Medical Imaging ? Tracking and Analysis of Movement ? Simulation and Modeling ? Image Acquisition ? Industrial Applications ? Shape Reconstruction ? Objects Segmentation, Matching, Simulation ? Data Interpolation, Registration, Acquisition and Compression ? 3D Vision ? Virtual Reality ? Visual Inspection ? Software Development for Image Processing and Analysis ? Computer Aided Diagnosis, Surgery, Therapy, and Treatment ? Computational Bioimaging and Visualization ? Telemedicine Systems and their Applications Invited Lecturers ? Daniel Rueckert - Imperial College London, UK ? Dimitris N. Metaxas - Rutgers University, USA ? Durval C. Costa - Champalimaud Foundation, Portugal ? James S Duncan - Yale School of Medicine, USA ? Milan Sonka - The University of Iowa, USA ? Richard Bowden - University of Surrey, UK Thematic Sessions Proposals to organize Thematic Session under the auspicious of VipIMAGE 2013 are welcome. The proposals should be submitted by email to the conference co-chairs (tavares at fe.up.pt, rnatal at fe.up.pt). Confirmed Thematic Sessions ? Imaging of Biological Flows: trends and challenges ? Trabecular Bone Characterization: New trends and challenges ? Computational Vision and Image Processing applied to Dental Medicine Publications ? Proceedings: The proceedings book will be published by the Taylor & Francis Group (www.balkema.nl/instructions.asp) and indexed by Thomson Reuters Conference Proceedings Citation Index, IET Inspect and Elsevier Scopus. ? Springer Book: A book with 20 invited works from the ones presented in the conference will be published by Springer under the book series ?Lecture Notes in Computational Vision and Biomechanics? (www.springer.com/series/8910). ? Journal Publication: A dedicated special issue of the Taylor & Francis International Journal ?Computer Methods in Biomechanics and Biomedical Engineering: Imaging & Visualization? (www.tandfonline.com/tciv) will be published with extended versions of the best works presented in the conference. Important dates ? Deadline for (2-4 pages) Abstracts: May 6, 2013 (POSTPONED) ? Authors Notification: June 10, 2013 (POSTPONED) ? Deadline to upload Lectures and Papers: July 1, 2013 We are looking forward to see you in Funchal next October. Kind regards, Jo?o Manuel R. S. Tavares Renato Natal Jorge (conference co-chairs) PS. For further details, please, have a look in the conference website at: www.fe.up.pt/~vipimage, or in the conference Facebook page at: www.facebook.com/pages/Vipimage/237980719665456, or join the LinkedIn conference group at: http://www.linkedin.com/groups?gid=4752820&trk=hb_side_g From moraa.lovetakes2 at gmail.com Wed Apr 17 09:50:26 2013 From: moraa.lovetakes2 at gmail.com (Ombongi Moraa Fe) Date: Wed, 17 Apr 2013 16:50:26 +0300 Subject: Parsing soap result Message-ID: My client.service.gere(ri) method call logs the below soap response in my log file.
254727
DeliveredToNetwork
If I assign the client.service.gere(ri) to a variable, i get the output on my screen: result=client.service.gere(ri) output: [(DeliveryInformation){ address = "254727" deliveryStatus = "DeliveredToNetwork" }] string functions replace() and strip don't work. how do I use xml.etree.ElementTree to print the parameters address and deliveryStatus? Or is there a better python method? Thanks in advance. Saludos Ombongi Moraa Faith -------------- next part -------------- An HTML attachment was scrubbed... URL: From darnold992000 at yahoo.com Wed Apr 17 13:55:13 2013 From: darnold992000 at yahoo.com (darnold) Date: Wed, 17 Apr 2013 10:55:13 -0700 (PDT) Subject: Parsing soap result References: Message-ID: <28fde565-f8c0-4995-b5a1-2ac2509712dc@l5g2000yqe.googlegroups.com> On Apr 17, 8:50?am, Ombongi Moraa Fe wrote: > how do I use xml.etree.ElementTree to print the parameters address and > deliveryStatus? Or is there a better python method? > I'm sure there are prettier ways to do this, but you can use XPath syntax to find all of your ns1:result nodes and loop through them: >>> import xml.etree.ElementTree as ET >>> myXML = '''\
254727
DeliveredToNetwork
''' >>> myNamespaces=dict(ns1="http://www.csapi.org/schema/parlayx/sms/send/v2_2/local",soapenv="http://schemas.xmlsoap.org/soap/envelope/") >>> root = ET.fromstring(myXML) >>> for result in root.findall('.//ns1:result',namespaces=myNamespaces): address = result.find('address').text deliveryStatus = result.find('deliveryStatus').text print "address: %s, deliveryStatus: %s" % (address,deliveryStatus) address: 254727, deliveryStatus: DeliveredToNetwork >>> HTH, Don From christian at python.org Wed Apr 17 14:05:48 2013 From: christian at python.org (Christian Heimes) Date: Wed, 17 Apr 2013 20:05:48 +0200 Subject: Parsing soap result In-Reply-To: <28fde565-f8c0-4995-b5a1-2ac2509712dc@l5g2000yqe.googlegroups.com> References: <28fde565-f8c0-4995-b5a1-2ac2509712dc@l5g2000yqe.googlegroups.com> Message-ID: Am 17.04.2013 19:55, schrieb darnold: > On Apr 17, 8:50 am, Ombongi Moraa Fe > wrote: > >> how do I use xml.etree.ElementTree to print the parameters address and >> deliveryStatus? Or is there a better python method? >> > > > I'm sure there are prettier ways to do this, but you can use XPath > syntax to find all of your ns1:result nodes and loop through them: You want all {http://www.csapi.org/schema/parlayx/sms/send/v2_2/ local}result tags. The prefix isn't fixed. From darnold992000 at yahoo.com Wed Apr 17 15:14:59 2013 From: darnold992000 at yahoo.com (darnold) Date: Wed, 17 Apr 2013 12:14:59 -0700 (PDT) Subject: Parsing soap result References: <28fde565-f8c0-4995-b5a1-2ac2509712dc@l5g2000yqe.googlegroups.com> Message-ID: On Apr 17, 1:05?pm, Christian Heimes wrote: > Am 17.04.2013 19:55, schrieb darnold: > > > On Apr 17, 8:50 am, Ombongi Moraa Fe > > wrote: > > >> how do I use xml.etree.ElementTree to print the parameters address and > >> deliveryStatus? Or is there a better python method? > > > I'm sure there are prettier ways to do this, but you can use XPath > > syntax to find all of your ns1:result nodes and loop through them: > > You want all {http://www.csapi.org/schema/parlayx/sms/send/v2_2/ > local}result tags. The prefix isn't fixed. I'm sorry, but I'm not understanding the difference. By specifying: >>> myNamespaces=dict(ns1="http://www.csapi.org/schema/parlayx/sms/send/v2_2/local") Isn't this: >>> for result in root.findall('.//ns1:result',namespaces=myNamespaces): equivalent to: >>> for result in root.findall('.//{http://www.csapi.org/schema/parlayx/sms/send/v2_2/local}result'): ? Or am I misunderstanding? Is there a namespace-agnostic way of doing this? Admittedly, I haven't used ElementTree or XPath much prior to toying with them to (attempt to) answer the OP's question. Thanks for your patience, Don From burak.arslan at arskom.com.tr Wed Apr 17 17:41:18 2013 From: burak.arslan at arskom.com.tr (Burak Arslan) Date: Thu, 18 Apr 2013 00:41:18 +0300 Subject: Parsing soap result In-Reply-To: References: Message-ID: <516F16FE.4080900@arskom.com.tr> On 04/17/13 16:50, Ombongi Moraa Fe wrote: > My > > client.service.gere(ri) > > method call logs the below soap response in my log file. > > xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> xmlns:ns1="http://www.csapi.org/schema/parlayx/sms/send/v2_2/local">
254727
DeliveredToNetwork
> > > If I assign the client.service.gere(ri) to a variable, i get the > output on my screen: > > result=client.service.gere(ri) > > output: > [(DeliveryInformation){ > address = "254727" > deliveryStatus = "DeliveredToNetwork" > }] > > string functions replace() and strip don't work. > > how do I use xml.etree.ElementTree to print the parameters address and > deliveryStatus? Or is there a better python method? hi, try: result[0].deliveryStatus or result[0].DeliveryInformation.deliveryStatus and let us know. best, burak -------------- next part -------------- An HTML attachment was scrubbed... URL: From moraa.lovetakes2 at gmail.com Thu Apr 18 06:46:32 2013 From: moraa.lovetakes2 at gmail.com (Ombongi Moraa Fe) Date: Thu, 18 Apr 2013 13:46:32 +0300 Subject: Parsing soap result In-Reply-To: <516F16FE.4080900@arskom.com.tr> References: <516F16FE.4080900@arskom.com.tr> Message-ID: Hi Burak, Team, Your solution worked perfectly thanks. Could you share the logic of this solution? Saludos Ombongi Moraa Faith On 18 April 2013 00:41, Burak Arslan wrote: > On 04/17/13 16:50, Ombongi Moraa Fe wrote: > > My > > client.service.gere(ri) > > method call logs the below soap response in my log file. > > xmlns:ns1="http://www.csapi.org/schema/parlayx/sms/send/v2_2/local > ">
254727
DeliveredToNetwork
> > > If I assign the client.service.gere(ri) to a variable, i get the output > on my screen: > > result=client.service.gere(ri) > > output: > [(DeliveryInformation){ > address = "254727" > deliveryStatus = "DeliveredToNetwork" > }] > > string functions replace() and strip don't work. > > how do I use xml.etree.ElementTree to print the parameters address and > deliveryStatus? Or is there a better python method? > > > hi, > > try: > > result[0].deliveryStatus > > or > > result[0].DeliveryInformation.deliveryStatus > > > and let us know. > > best, > burak > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From burak.arslan at arskom.com.tr Thu Apr 18 06:55:26 2013 From: burak.arslan at arskom.com.tr (Burak Arslan) Date: Thu, 18 Apr 2013 13:55:26 +0300 Subject: Parsing soap result In-Reply-To: References: <516F16FE.4080900@arskom.com.tr> Message-ID: <516FD11E.4010006@arskom.com.tr> Hi, On 04/18/13 13:46, Ombongi Moraa Fe wrote: > Hi Burak, Team, > Apparently I was too deep in answering support questions for my company :) This is python-list, so It's just me here :) > Your solution worked perfectly thanks. > > Could you share the logic of this solution? > You're using suds. Let's have a look at what you see: [(DeliveryInformation){ address = "254727" deliveryStatus = "DeliveredToNetwork" }] You have it in square brackets, so it's an array. You apparently want the first element, so it's result[0]. It's of type DeliveryInformation with two fields, they are what you see there. Depending on the which soap mode (rpc/document) your server uses, you should either use result[0].deliveryStatus or result[0].DeliveryInformation.deliveryStatus. I guess I got too much experience doing SOAP with python :) (I maintain spyne, see: http://spyne.io) I'm glad it worked. Best, Burak -------------- next part -------------- An HTML attachment was scrubbed... URL: From renato.barbosa.pim.pereira at gmail.com Wed Apr 17 10:01:02 2013 From: renato.barbosa.pim.pereira at gmail.com (Renato Barbosa Pim Pereira) Date: Wed, 17 Apr 2013 11:01:02 -0300 Subject: Tornado with cgi form Message-ID: *I installed tornado and he is functional, but when I execute the following script:* import tornado.ioloop import tornado.web import cgi class MainHandler(tornado.web. RequestHandler): form = cgi.FieldStorage() # parse form data print('Content-type: text/html\n') # hdr plus blank line print('Reply Page') # html reply page if not 'user' in form: print('

Who are you?

') else: print('

Hello %s!

' % cgi.escape(form['user'].value)) application = tornado.web.Application([ (r"/", MainHandler), ]) if __name__ == "__main__": application.listen(8888) tornado.ioloop.IOLoop.instance().start() *In the terminal have these outputs:* python test.py Content-type: text/html Reply Page

Who are you?

*When I call the browser on localhost:8888, the message is this:* 405: Method Not Allowed * **Please, can someone have a idea about why the error occurs? and what I need to do to fix this?* -------------- next part -------------- An HTML attachment was scrubbed... URL: From lele at metapensiero.it Wed Apr 17 10:43:15 2013 From: lele at metapensiero.it (Lele Gaifax) Date: Wed, 17 Apr 2013 16:43:15 +0200 Subject: Tornado with cgi form References: Message-ID: <87li8hkykc.fsf@nautilus.nautilus> Renato Barbosa Pim Pereira writes: > *I installed tornado and he is functional, but when I execute the following > script:* I think this is the wrong place to ask such a question, more appropriate would be http://groups.google.com/group/python-tornado Anyway, you defined a MainHandler class *without* any method, and you should instead implement at least a "get" or "post" method, as the "Hello, world" example on http://www.tornadoweb.org suggests. 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 newsboost at gmail.com Wed Apr 17 17:08:49 2013 From: newsboost at gmail.com (someone) Date: Wed, 17 Apr 2013 23:08:49 +0200 Subject: anyone know pandas ? Don't understand error: NotImplementedError... Message-ID: Hi, Here's my script (from http://brenda.moon.net.au/category/data-visualisation/: ============================ #!/usr/bin/python import pandas import datetime import numpy datesList = [datetime.date(2011,12,1), \ datetime.date(2011,12,2), \ datetime.date(2011,12,3), \ datetime.date(2011,12,10)] countsList = numpy.random.randn(len(datesList)) startData = datetime.datetime(2011,12,3) endData = datetime.datetime(2011,12,8) def convertListPairToTimeSeries(dList, cList): # my dateList had date objects, so convert back to datetime objects dListDT = [datetime.datetime.combine(x, datetime.time()) for x in dList] # found that NaN didn't work if the cList contained int data cListL = [float(x) for x in cList] # create the index from the datestimes list indx = pandas.Index(dListDT) # create the timeseries ts = pandas.Series(cListL, index=indx) # fill in missing days ts = ts.asfreq(pandas.datetools.DateOffset()) return ts print "\nOriginal datesList list:\n", datesList tSeries = convertListPairToTimeSeries(datesList, countsList) print "\nPandas timeseries:\n", tSeries # use slicing to change length of data tSeriesSlice = tSeries.ix[startData:endData] print "\nPandas timeseries sliced between", startData.date(), \ "and", endData.date(), ":\n", tSeriesSlice # use truncate instead of slicing to change length of data tSeriesTruncate = tSeries.truncate(before=startData, after=endData) print "\nPandas timeseries truncated between", startData.date(), \ "and", endData.date(), ":\n", tSeriesTruncate # my data had lots of gaps that were actually 0 values, not missing data # So I used this to fix the NaN outside the known outage startOutage = datetime.datetime(2011,12,7) endOutage = datetime.datetime(2011,12,8) tsFilled = tSeries.fillna(0) # set the known outage values back to NAN tsFilled.ix[startOutage:endOutage] = numpy.NAN print "\nPandas timeseries NaN reset to 0 outside known outage between", \ startOutage.date(), "and", endOutage.date(), ":\n", tsFilled print "\nPandas series.tail(1) and series.head(1) are handy for " +\ "checking ends of list:\n", tsFilled.head(1), tsFilled.tail(1) print tsFilled.plot(); # <====== NotImplementedError...!!! ============================ If I run it, I get: -------------------- ... ... .. 2011-12-09 0.000000 2011-12-10 1.431665 Freq: <1 DateOffset> Pandas series.tail(1) and series.head(1) are handy for checking ends of list: 2011-12-01 -0.969533 Freq: <1 DateOffset> 2011-12-10 1.431665 Freq: <1 DateOffset> Traceback (most recent call last): File "./pandas_example.py", line 57, in tsFilled.plot(); File "/usr/lib/pymodules/python2.7/pandas/tools/plotting.py", line 985, in plot_series plot_obj.generate() File "/usr/lib/pymodules/python2.7/pandas/tools/plotting.py", line 376, in generate self._make_plot() File "/usr/lib/pymodules/python2.7/pandas/tools/plotting.py", line 623, in _make_plot if self.use_index and self._use_dynamic_x(): File "/usr/lib/pymodules/python2.7/pandas/tools/plotting.py", line 619, in _use_dynamic_x return (freq is not None) and self._is_dynamic_freq(freq) File "/usr/lib/pymodules/python2.7/pandas/tools/plotting.py", line 602, in _is_dynamic_freq freq = freq.rule_code File "/usr/lib/pymodules/python2.7/pandas/tseries/offsets.py", line 214, in rule_code raise NotImplementedError NotImplementedError -------------------- Can anyone tell why this error appears and how to fix it? From wayne at waynewerner.com Thu Apr 18 09:44:53 2013 From: wayne at waynewerner.com (Wayne Werner) Date: Thu, 18 Apr 2013 08:44:53 -0500 (CDT) Subject: anyone know pandas ? Don't understand error: NotImplementedError... In-Reply-To: References: Message-ID: On Wed, 17 Apr 2013, someone wrote: > File "/usr/lib/pymodules/python2.7/pandas/tseries/offsets.py", line 214, in > rule_code > raise NotImplementedError > NotImplementedError > -------------------- > > Can anyone tell why this error appears and how to fix it? I don't know anything about pandas, but my recommendation? $ vim /usr/lib/pymodules/python2.7/pandas/tseries/offsets.py (or nano or emacs - whatever editor you're comfortable with). Go to line 214, and take a look-see at what you find. My guess is it will be something like: def rule_code(): raise NotImplementedError() Which is terribly unhelpful. HTH, Wayne From neilc at norwich.edu Thu Apr 18 10:07:18 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 18 Apr 2013 14:07:18 GMT Subject: anyone know pandas ? Don't understand error: NotImplementedError... References: Message-ID: On 2013-04-18, Wayne Werner wrote: > On Wed, 17 Apr 2013, someone wrote: > >> File "/usr/lib/pymodules/python2.7/pandas/tseries/offsets.py", line 214, in >> rule_code >> raise NotImplementedError >> NotImplementedError >> -------------------- >> >> Can anyone tell why this error appears and how to fix it? > > I don't know anything about pandas, but my recommendation? > > $ vim /usr/lib/pymodules/python2.7/pandas/tseries/offsets.py > > (or nano or emacs - whatever editor you're comfortable with). > > Go to line 214, and take a look-see at what you find. My guess is it will > be something like: > > def rule_code(): > raise NotImplementedError() > > Which is terribly unhelpful. It most likely means that the program is instantiating an abstract base class when it should be using one of its subclasses instead, e.g., BusinessDay, MonthEnd, MonthBegin, BusinessMonthEnd, etc. http://pandas.pydata.org/pandas-docs/dev/timeseries.html -- Neil Cerutti From newsboost at gmail.com Thu Apr 18 15:30:20 2013 From: newsboost at gmail.com (someone) Date: Thu, 18 Apr 2013 21:30:20 +0200 Subject: anyone know pandas ? Don't understand error: NotImplementedError... In-Reply-To: References: Message-ID: On 04/18/2013 04:07 PM, Neil Cerutti wrote: > On 2013-04-18, Wayne Werner wrote: >> On Wed, 17 Apr 2013, someone wrote: .... >> Go to line 214, and take a look-see at what you find. My guess is it will >> be something like: >> >> def rule_code(): >> raise NotImplementedError() >> >> Which is terribly unhelpful. > > It most likely means that the program is instantiating an > abstract base class when it should be using one of its subclasses > instead, e.g., BusinessDay, MonthEnd, MonthBegin, > BusinessMonthEnd, etc. > > http://pandas.pydata.org/pandas-docs/dev/timeseries.html Hi Neil and Wayne, Thank you very much for your suggestions... I now found out something: In the function: def convertListPairToTimeSeries(dList, cList): ... ... # create the timeseries ts = pandas.Series(cListL, index=indx) # fill in missing days #ts = ts.asfreq(pandas.datetools.DateOffset()) return ts I had to out-comment the last line before the return-statement (not sure what that line is supposed to do, in the first case)... Now the program runs, but no plot is seen. Then I found out that I had to add: import matplotlib.pyplot as plt in the top of the program and add the following in the bottom of the program: plt.show() Final program: ================== #!/usr/bin/python import pandas import datetime import numpy import ipdb import matplotlib.pyplot as plt datesList = [datetime.date(2011,12,1), \ datetime.date(2011,12,2), \ datetime.date(2011,12,3), \ datetime.date(2011,12,10)] countsList = numpy.random.randn(len(datesList)) startData = datetime.datetime(2011,12,3) endData = datetime.datetime(2011,12,8) def convertListPairToTimeSeries(dList, cList): # my dateList had date objects, so convert back to datetime objects dListDT = [datetime.datetime.combine(x, datetime.time()) for x in dList] # found that NaN didn't work if the cList contained int data cListL = [float(x) for x in cList] # create the index from the datestimes list indx = pandas.Index(dListDT) # create the timeseries ts = pandas.Series(cListL, index=indx) # fill in missing days #ts = ts.asfreq(pandas.datetools.DateOffset()) return ts print "\nOriginal datesList list:\n", datesList tSeries = convertListPairToTimeSeries(datesList, countsList) print "\nPandas timeseries:\n", tSeries # use slicing to change length of data tSeriesSlice = tSeries.ix[startData:endData] print "\nPandas timeseries sliced between", startData.date(), \ "and", endData.date(), ":\n", tSeriesSlice # use truncate instead of slicing to change length of data tSeriesTruncate = tSeries.truncate(before=startData, after=endData) print "\nPandas timeseries truncated between", startData.date(), \ "and", endData.date(), ":\n", tSeriesTruncate # my data had lots of gaps that were actually 0 values, not missing data # So I used this to fix the NaN outside the known outage startOutage = datetime.datetime(2011,12,7) endOutage = datetime.datetime(2011,12,8) tsFilled = tSeries.fillna(0) # set the known outage values back to NAN tsFilled.ix[startOutage:endOutage] = numpy.NAN print "\nPandas timeseries NaN reset to 0 outside known outage between", \ startOutage.date(), "and", endOutage.date(), ":\n", tsFilled print "\nPandas series.tail(1) and series.head(1) are handy for " +\ "checking ends of list:\n", tsFilled.head(1), tsFilled.tail(1) print tsFilled.plot() plt.show() ================== This seem to work, although I don't fully understand it, as I'm pretty new to pandas... From newsboost at gmail.com Thu Apr 18 14:28:34 2013 From: newsboost at gmail.com (someone) Date: Thu, 18 Apr 2013 20:28:34 +0200 Subject: anyone know pandas ? Don't understand error: NotImplementedError... In-Reply-To: References: Message-ID: On 04/18/2013 03:44 PM, Wayne Werner wrote: > On Wed, 17 Apr 2013, someone wrote: > >> File "/usr/lib/pymodules/python2.7/pandas/tseries/offsets.py", line >> 214, in rule_code >> raise NotImplementedError >> NotImplementedError >> -------------------- >> >> Can anyone tell why this error appears and how to fix it? > > I don't know anything about pandas, but my recommendation? > > $ vim /usr/lib/pymodules/python2.7/pandas/tseries/offsets.py > > (or nano or emacs - whatever editor you're comfortable with). > > Go to line 214, and take a look-see at what you find. My guess is it > will be something like: > > def rule_code(): > raise NotImplementedError() > > > > Which is terribly unhelpful. Oh, yes - you're completely right: # line 211 (empty line) @property # line 212 def rule_code(self): # line 213 raise NotImplementedError # line 214 # line 215 (empty line) Below and above this "rule_code" is code belonging to some other functions... hmmm... I also tried to look in: /usr/lib/pymodules/python2.7/pandas/tools/plotting.py But I'm very unfamiliar with pandas, so everything looks "correct" to me - because I don't understand the data structure, I think I cannot see what is wrong... From cbc at unc.edu Wed Apr 17 17:24:35 2013 From: cbc at unc.edu (Chris Calloway) Date: Wed, 17 Apr 2013 17:24:35 -0400 Subject: PyCamp Registration Open for Columbus, Toronto, and Oshkosh Message-ID: <516F1313.9070700@unc.edu> Registration is open for three upcoming PyCamps produced by the Triangle Python Users Group: - A five-day PyOhio PyCamp hosted by the Ohio State University Open Source Club, July 22-26, 2013 the week prior to the PyOhio regional Python conference weekend. PyCamp is a training program and sponsor of PyOhio: http://trizpug.org/boot-camp/pyohio13/ - A five-day Toronto PyCamp hosted by the University of Toronto Department of Physics, August 12-16, 2013 the week after the PyCon Canada national Python conference weekend. PyCamp is a Diversity Sponsor of PyCon CA: http://trizpug.org/boot-camp/torpy13/ - A three-day Wisconsin Mini-PyCamp hosted at the University of Wisconsin Oshkosh, June 2-4, 2013 as part of the Plone Symposium Midwest training days: http://trizpug.org/boot-camp/wiscpy13/ PyCamp is the original, ultra-low-cost Python Boot Camp created by a user group for user groups. For beginners, PyCamp makes you productive so you can get your work done quickly. PyCamp emphasizes the features which make Python a simpler and more efficient language. Following along with example Python PushUps speeds your learning process. Become a self-sufficient Python developer at PyCamp. PyCamps are conducted in state of the art high technology classrooms on university campuses. Registration will open soon also for two additional Triangle Python User Group boot camp events. An additional announcement will follow when registration opens for these events, but mark your calendars now: - A five-day Seattle PyCamp hosted by the University of Washington Department of Computer Science and Engineering and UW Marketing, September 9-13, 2013. PyCamp is a sponsor of the Seattle Plone Users Group. - A five-day special Python Web Programming boot camp hosted by the University of North Carolina Department of Marine Sciences, August 5-9, 2013. -- Sincerely, Chris Calloway http://nccoos.org/Members/cbc office: 3313 Venable Hall phone: (919) 599-3530 mail: Campus Box #3300, UNC-CH, Chapel Hill, NC 27599 From bradley.wright.biz at gmail.com Thu Apr 18 00:06:59 2013 From: bradley.wright.biz at gmail.com (Bradley Wright) Date: Wed, 17 Apr 2013 21:06:59 -0700 (PDT) Subject: Novice Issue Message-ID: <0fa050c1-3a00-4c17-9fa6-b79a22485c7a@googlegroups.com> Good Day all, currently writing a script that ask the user for three things; 1.Name 2.Number 3.Description I've gotten it to do this hurah! print "Type \"q\" or \"quit\" to quit" while raw_input != "quit" or "q": print "" name = str(raw_input("Name: ")) number = str(raw_input("Number: ")) description = str(raw_input("Description: ")) but here a few things, can anyone help me on figuring out how to at the users whim print out all of the names, numbers and descriptions. this is sort of an information logger. additionally, minor issue with getting script to stop when q or quit is typed any help would be greatly appreciated From rosuav at gmail.com Thu Apr 18 00:14:41 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 18 Apr 2013 14:14:41 +1000 Subject: Novice Issue In-Reply-To: <0fa050c1-3a00-4c17-9fa6-b79a22485c7a@googlegroups.com> References: <0fa050c1-3a00-4c17-9fa6-b79a22485c7a@googlegroups.com> Message-ID: On Thu, Apr 18, 2013 at 2:06 PM, Bradley Wright wrote: > Good Day all, currently writing a script that ask the user for three things; > 1.Name > 2.Number > 3.Description > I've gotten it to do this hurah! > > print "Type \"q\" or \"quit\" to quit" > while raw_input != "quit" or "q": You'll want to actually _call_ that function: raw_input() > > print "" > name = str(raw_input("Name: ")) > number = str(raw_input("Number: ")) > description = str(raw_input("Description: ")) raw_input already returns a string, so the str() is redundant here. > but here a few things, can anyone help me on figuring out how to at the users whim print out all of the names, numbers and descriptions. this is sort of an information logger. > > additionally, minor issue with getting script to stop when q or quit is typed > > any help would be greatly appreciated Once you have all the values, you just need to figure out what you're trying to do with them. Do you need to retain them till the end of the loop? If so, consider a list or dictionary. Or do you need to work with them right there inside the loop? What are you needing to accomplish? ChrisA From wolfgang.maier at biologie.uni-freiburg.de Thu Apr 18 04:58:56 2013 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Thu, 18 Apr 2013 08:58:56 +0000 (UTC) Subject: Novice Issue References: <0fa050c1-3a00-4c17-9fa6-b79a22485c7a@googlegroups.com> Message-ID: Bradley Wright gmail.com> writes: > > Good Day all, currently writing a script that ask the user for three things; > 1.Name > 2.Number > 3.Description > I've gotten it to do this hurah! > > print "Type \"q\" or \"quit\" to quit" > while raw_input != "quit" or "q": > > print "" > name = str(raw_input("Name: ")) > number = str(raw_input("Number: ")) > description = str(raw_input("Description: ")) > > but here a few things, can anyone help me on figuring out how to at the users whim print out all of the names, > numbers and descriptions. this is sort of an information logger. > > additionally, minor issue with getting script to stop when q or quit is typed your minor issue here is your "or" test, which is not doing what you think it does. You're testing here for either of the following to conditions: 1) raw_input != "quit" 2) "q" (Python can't know that you want raw_input != "q" here!!) Now any non-empty string in Python tests True, so your while loop never stops. There are two solutions for that: the obvious: while not (raw_input == "quit" or raw_input == "q") or the pythonic way: while raw_input not in ("quit", "q") The second form definitely is preferable over the first when you have to test for more than two conditions. For your other questions see Chris' answers. Best, Wolfgang From rosuav at gmail.com Thu Apr 18 05:06:08 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 18 Apr 2013 19:06:08 +1000 Subject: Novice Issue In-Reply-To: References: <0fa050c1-3a00-4c17-9fa6-b79a22485c7a@googlegroups.com> Message-ID: On Thu, Apr 18, 2013 at 6:58 PM, Wolfgang Maier wrote: > There are two solutions for that: > the obvious: while not (raw_input == "quit" or raw_input == "q") That has another problem: Once that's changed to raw_input() so it actually requests input, it will do so twice, compare the first line against "quit" and the second against "q", and proceed on that basis. The membership test raw_input() in ("quit","q") is going to be far better. ChrisA From breamoreboy at yahoo.co.uk Thu Apr 18 06:10:51 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 18 Apr 2013 11:10:51 +0100 Subject: Novice Issue In-Reply-To: <0fa050c1-3a00-4c17-9fa6-b79a22485c7a@googlegroups.com> References: <0fa050c1-3a00-4c17-9fa6-b79a22485c7a@googlegroups.com> Message-ID: On 18/04/2013 05:06, Bradley Wright wrote: > Good Day all, currently writing a script that ask the user for three things; > 1.Name > 2.Number > 3.Description > I've gotten it to do this hurah! > > print "Type \"q\" or \"quit\" to quit" You've had a couple of answers already so I'll just point out that the above line could be. print 'Type "q" or "quit" to quit' Looks prettier if nothing else :) > while raw_input != "quit" or "q": > > print "" > name = str(raw_input("Name: ")) > number = str(raw_input("Number: ")) > description = str(raw_input("Description: ")) > > but here a few things, can anyone help me on figuring out how to at the users whim print out all of the names, numbers and descriptions. this is sort of an information logger. > > additionally, minor issue with getting script to stop when q or quit is typed > > any help would be greatly appreciated > -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From bradley.wright.biz at gmail.com Thu Apr 18 08:18:44 2013 From: bradley.wright.biz at gmail.com (Bradley Wright) Date: Thu, 18 Apr 2013 05:18:44 -0700 (PDT) Subject: Novice Issue In-Reply-To: <0fa050c1-3a00-4c17-9fa6-b79a22485c7a@googlegroups.com> References: <0fa050c1-3a00-4c17-9fa6-b79a22485c7a@googlegroups.com> Message-ID: <36c94c5e-6ad1-4aba-b18c-61cf14cf102c@googlegroups.com> On Thursday, April 18, 2013 12:06:59 AM UTC-4, Bradley Wright wrote: > Good Day all, currently writing a script that ask the user for three things; > > 1.Name > > 2.Number > > 3.Description > > I've gotten it to do this hurah! > > > > print "Type \"q\" or \"quit\" to quit" > > while raw_input != "quit" or "q": > > > > print "" > > name = str(raw_input("Name: ")) > > number = str(raw_input("Number: ")) > > description = str(raw_input("Description: ")) > > > > but here a few things, can anyone help me on figuring out how to at the users whim print out all of the names, numbers and descriptions. this is sort of an information logger. > > > > additionally, minor issue with getting script to stop when q or quit is typed > > > > any help would be greatly appreciated Joining this group has been the smartest decision since birth Firstly, thanks Chris - str() [REMOVED] and yes i would like to retain them until the end of the loop simply for printing or viewing purposes. [I'll DO MORE RESEARCH ON LISTS] Secondly, thanks Wolfgang while raw_input not in ("quit", "q") - genius, i get your point clearly Thirdly, thanks mark went through the link you provided, insightful Cheers From davea at davea.name Thu Apr 18 08:29:37 2013 From: davea at davea.name (Dave Angel) Date: Thu, 18 Apr 2013 08:29:37 -0400 Subject: Novice Issue In-Reply-To: <36c94c5e-6ad1-4aba-b18c-61cf14cf102c@googlegroups.com> References: <0fa050c1-3a00-4c17-9fa6-b79a22485c7a@googlegroups.com> <36c94c5e-6ad1-4aba-b18c-61cf14cf102c@googlegroups.com> Message-ID: <516FE731.1060504@davea.name> On 04/18/2013 08:18 AM, Bradley Wright wrote: > > >> > Secondly, thanks Wolfgang > while raw_input not in ("quit", "q") - genius, i get your point clearly But you have to combine his point with Chris's, don't forget the parens on the call to raw_input. And if it were I, I'd also put a prompt string in the call. while raw_input("q to quit") not in ("quit", "q"): > If you've got a list, and each time through you want to add some item(s) to a list, you can use the following idiom: result = [] #empty list for whatever in something: value = another result.append(value) Then when you finish the list, you can examine the whole list. -- DaveA From bradley.wright.biz at gmail.com Thu Apr 18 08:34:24 2013 From: bradley.wright.biz at gmail.com (Bradley Wright) Date: Thu, 18 Apr 2013 05:34:24 -0700 (PDT) Subject: Novice Issue In-Reply-To: <0fa050c1-3a00-4c17-9fa6-b79a22485c7a@googlegroups.com> References: <0fa050c1-3a00-4c17-9fa6-b79a22485c7a@googlegroups.com> Message-ID: On Thursday, April 18, 2013 12:06:59 AM UTC-4, Bradley Wright wrote: > Good Day all, currently writing a script that ask the user for three things; > > 1.Name > > 2.Number > > 3.Description > > I've gotten it to do this hurah! > > > > print "Type \"q\" or \"quit\" to quit" > > while raw_input != "quit" or "q": > > > > print "" > > name = str(raw_input("Name: ")) > > number = str(raw_input("Number: ")) > > description = str(raw_input("Description: ")) > > > > but here a few things, can anyone help me on figuring out how to at the users whim print out all of the names, numbers and descriptions. this is sort of an information logger. > > > > additionally, minor issue with getting script to stop when q or quit is typed > > > > any help would be greatly appreciated Thanks Dave quite helpful as well, now i have a clear road to go on, with regards the lists portion of my script From gordon at panix.com Thu Apr 18 10:21:36 2013 From: gordon at panix.com (John Gordon) Date: Thu, 18 Apr 2013 14:21:36 +0000 (UTC) Subject: Novice Issue References: <0fa050c1-3a00-4c17-9fa6-b79a22485c7a@googlegroups.com> Message-ID: In <0fa050c1-3a00-4c17-9fa6-b79a22485c7a at googlegroups.com> Bradley Wright writes: > while raw_input != "quit" or "q": Others have pointed out flaws in this statement. However, even if you had written the loop the 'correct' way: user_input = raw_input() while user_input != "quit" or user_input != "q": There is still a logic bug. This loop will execute forever, because no matter what the user enters, it will be unequal to "q" or unequal to "quit". Use 'and' instead of 'or'. Of course in this specific situation, as others have suggested, 'in' is better still. -- 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 bhanu.ramappa at gmail.com Thu Apr 18 04:46:16 2013 From: bhanu.ramappa at gmail.com (BhanuKumarRamappa) Date: Thu, 18 Apr 2013 09:46:16 +0100 Subject: Good python testing book Message-ID: Hi All, Greetings...... can anyone please suggest me good python automation testing book ..... to develop automation tests. Thanks, -Bhanu -------------- next part -------------- An HTML attachment was scrubbed... URL: From xiaohanyu1988 at gmail.com Thu Apr 18 06:02:52 2013 From: xiaohanyu1988 at gmail.com (xiaohanyu1988 at gmail.com) Date: Thu, 18 Apr 2013 03:02:52 -0700 (PDT) Subject: Good python testing book In-Reply-To: References: Message-ID: On Thursday, April 18, 2013 4:46:16 PM UTC+8, BhanuKumarRamappa wrote: > Hi All, > > > Greetings...... > can anyone please suggest me good python automation testing book ..... to develop automation tests. > > > Thanks, > > -Bhanu Maybe you can try "Python Testing Cookbook" for a basic testing in Python From xiaohanyu1988 at gmail.com Thu Apr 18 06:02:52 2013 From: xiaohanyu1988 at gmail.com (xiaohanyu1988 at gmail.com) Date: Thu, 18 Apr 2013 03:02:52 -0700 (PDT) Subject: Good python testing book In-Reply-To: References: Message-ID: On Thursday, April 18, 2013 4:46:16 PM UTC+8, BhanuKumarRamappa wrote: > Hi All, > > > Greetings...... > can anyone please suggest me good python automation testing book ..... to develop automation tests. > > > Thanks, > > -Bhanu Maybe you can try "Python Testing Cookbook" for a basic testing in Python From insideshoes at gmail.com Thu Apr 18 09:58:16 2013 From: insideshoes at gmail.com (inshu chauhan) Date: Thu, 18 Apr 2013 19:28:16 +0530 Subject: Working with lists within Dictionaries Message-ID: Hello Everyone, I am trying to work with lists and dictionaries together. In the following code I have to access pixels in a segmented image through a dictionary. But the problem is when I am trying to update the list through dict it is giving me this error of tuple, ofcourse because list indices should be integer. THE CODE IS : import cv def access_segments(segimage, data): print segimage segments = {} for y in xrange(0, segimage.height): for x in xrange(0, segimage.width): if segimage[y,x] == (0.0, 0.0, 0.0): continue else: seg_color = segimage[y,x] blue = int(seg_color[0]) green = int(seg_color[1]) red = int(seg_color[2]) reg_num = blue + 256 * green + 65536 * red point = data[y,x] segments.setdefault(reg_num, [])[point] += point for p in sorted(segments.iterkeys()): points = (segments[p]) print len(points) print points if __name__== "__main__": data = cv.Load(r"C:\Users\inshu\Desktop\Masters Thesis\data\xyz_00000.yml") segimage = cv.LoadImageM(r"C:\Users\inshu\Desktop\Masters Thesis\Segmentation\segmentation_numbers_00000.tif", cv.CV_LOAD_IMAGE_UNCHANGED) access_segments(segimage, data) THE ERROR IS: Traceback (most recent call last): File "C:\Users\inshu\Desktop\test_reading .py", line 27, in access_segments(segimage, data) File "C:\Users\inshu\Desktop\test_reading .py", line 16, in access_segments segments.setdefault(reg_num, [])[point] += point TypeError: list indices must be integers, not tuple How can I access the data without getting this error ? the points have x, y, z co-ordinates. Thanks In Advance for your suggestions. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Apr 18 10:38:19 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 19 Apr 2013 00:38:19 +1000 Subject: Working with lists within Dictionaries In-Reply-To: References: Message-ID: On Thu, Apr 18, 2013 at 11:58 PM, inshu chauhan wrote: > segments.setdefault(reg_num, [])[point] += point Not sure what your desired structure is. This is seeking to add the point to something indexed by the point; perhaps you simply want to append to the list itself? segments.setdefault(reg_num, []).append(point) ChrisA From abelahcene at gmail.com Thu Apr 18 13:06:05 2013 From: abelahcene at gmail.com (abdelkader belahcene) Date: Thu, 18 Apr 2013 18:06:05 +0100 Subject: equivalent to C pointer Message-ID: Hi everybody, I am new to python and I am discovering it. I know C well, and want to know if python knows how to manage Pointers like pointer to function here is a C example how to write it in python Intergration with trapeze method When we write Trapeze ( at the compilation level) we don't know which functions Fonc to handle. Here for example we use sin and a user defined F1 The program is attached too #include #include double F1 (double x){ return x*x; } double Trapeze(double Fonc(double ), double left, double right, double step){ double X1, X0, Y0, Y1, Z = 0; for(X0=left; X0 < right ; X0 = X0 + step) { X1 = X0 + step; Y1 = Fonc(X1); Y0 = Fonc(X0); Z += (Y1 + Y0) * step * 0.5; } return Z; } int main(){ double y; y=Trapeze(sin, -2.5, 3.2, 0.1); printf("\n\tValue for sin is : \t %8.3lf ", y); y=Trapeze(F1, 0, 3, 0.1); printf("\n\tValue for F1 is : \t %8.3lf ", y); return 0; } /** Value for sin is : 0.197 Value for F1 is : 9.005 */ thanks a lot -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: trapeze.c Type: text/x-csrc Size: 633 bytes Desc: not available URL: From kliateni at gmail.com Thu Apr 18 13:17:42 2013 From: kliateni at gmail.com (Karim) Date: Thu, 18 Apr 2013 19:17:42 +0200 Subject: equivalent to C pointer In-Reply-To: References: Message-ID: <51702AB6.30609@gmail.com> Hello, There is no such notion in python. But the closest are iterators and generator functions. Cheers Karim On 18/04/2013 19:06, abdelkader belahcene wrote: > Hi everybody, > > I am new to python and I am discovering it. > I know C well, > and want to know if python knows how to manage Pointers > like pointer to function here is a C example how to write it in python > Intergration with trapeze method > > When we write Trapeze ( at the compilation level) we don't know > which functions > Fonc to handle. Here for example we use sin and a user defined F1 > The program is attached too > > #include > #include > > double F1 (double x){ > return x*x; > } > double Trapeze(double Fonc(double ), > double left, double right, double step){ > double X1, X0, Y0, Y1, Z = 0; > for(X0=left; X0 < right ; X0 = X0 + step) { > X1 = X0 + step; > Y1 = Fonc(X1); Y0 = Fonc(X0); > Z += (Y1 + Y0) * step * 0.5; > } > return Z; > } > int main(){ > double y; > y=Trapeze(sin, -2.5, 3.2, 0.1); > printf("\n\tValue for sin is : \t %8.3lf ", y); > y=Trapeze(F1, 0, 3, 0.1); > printf("\n\tValue for F1 is : \t %8.3lf ", y); > return 0; > } > /** > Value for sin is : 0.197 > Value for F1 is : 9.005 > */ > thanks a lot > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From abelahcene at gmail.com Thu Apr 18 13:50:00 2013 From: abelahcene at gmail.com (abdelkader belahcene) Date: Thu, 18 Apr 2013 18:50:00 +0100 Subject: equivalent to C pointer In-Reply-To: <51702AB6.30609@gmail.com> References: <51702AB6.30609@gmail.com> Message-ID: Thanks for answer, but with C we can compile the trapeze function and put it in librairy, If we try to save the trapeze alone in package to import it later, I think, I am not sure it will be refused because F1 and sin are not define !!! this is the power of the C pointers !!! the link is dynamic thanks On Thu, Apr 18, 2013 at 6:17 PM, Karim wrote: > > Hello, > > There is no such notion in python. > But the closest are iterators and generator functions. > > Cheers > Karim > > > On 18/04/2013 19:06, abdelkader belahcene wrote: > > Hi everybody, > > I am new to python and I am discovering it. > I know C well, > and want to know if python knows how to manage Pointers > like pointer to function here is a C example how to write it in python > Intergration with trapeze method > > When we write Trapeze ( at the compilation level) we don't know which > functions > Fonc to handle. Here for example we use sin and a user defined F1 > The program is attached too > > #include > #include > > double F1 (double x){ > return x*x; > } > double Trapeze(double Fonc(double ), > double left, double right, double step){ > double X1, X0, Y0, Y1, Z = 0; > for(X0=left; X0 < right ; X0 = X0 + step) { > X1 = X0 + step; > Y1 = Fonc(X1); Y0 = Fonc(X0); > Z += (Y1 + Y0) * step * 0.5; > } > return Z; > } > int main(){ > double y; > y=Trapeze(sin, -2.5, 3.2, 0.1); > printf("\n\tValue for sin is : \t %8.3lf ", y); > y=Trapeze(F1, 0, 3, 0.1); > printf("\n\tValue for F1 is : \t %8.3lf ", y); > return 0; > } > /** > Value for sin is : 0.197 > Value for F1 is : 9.005 > */ > thanks a lot > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From drobinow at gmail.com Thu Apr 18 14:14:52 2013 From: drobinow at gmail.com (David Robinow) Date: Thu, 18 Apr 2013 14:14:52 -0400 Subject: equivalent to C pointer In-Reply-To: References: <51702AB6.30609@gmail.com> Message-ID: On Thu, Apr 18, 2013 at 1:50 PM, abdelkader belahcene wrote: > Thanks for answer, > but with C we can compile the trapeze function and put it in librairy, > If we try to save the trapeze alone in package to import it later, I > think, I am not sure > it will be refused because F1 and sin are not define !!! this is the > power of the C pointers !!! > the link is dynamic > You don't need C pointers. The design below is demonstrative, not ideal. # file MyFuncs.py def F1(x): return x*x def Trapeze(f, left, right, step): X0 = left Z = 0.0 while (X0 < right): X1 = X0 + step Y1 = f(X1) Y0 = f(X0) Z += (Y1 + Y0) * step * 0.5 X0 = X1 return Z # file UseMyFuncs.py import math import MyFuncs def main(): y = MyFuncs.Trapeze(math.sin, -2.5, 3.2, 0.1) print("Value for sin is:{0} ".format(y)) y = MyFuncs.Trapeze(MyFuncs.F1, 0, 3, 0.1) print("Value for F1 is {0} ".format(y)) if __name__ == "__main__": main() ### #python3 UseMyFuncs.py ### -------------- next part -------------- An HTML attachment was scrubbed... URL: From abelahcene at gmail.com Thu Apr 18 15:54:58 2013 From: abelahcene at gmail.com (abdelkader belahcene) Date: Thu, 18 Apr 2013 20:54:58 +0100 Subject: equivalent to C pointer In-Reply-To: References: <51702AB6.30609@gmail.com> Message-ID: Thanks a lot, I think this does the task cheers On Thu, Apr 18, 2013 at 7:14 PM, David Robinow wrote: > On Thu, Apr 18, 2013 at 1:50 PM, abdelkader belahcene < > abelahcene at gmail.com> wrote: > >> Thanks for answer, >> but with C we can compile the trapeze function and put it in librairy, >> If we try to save the trapeze alone in package to import it later, I >> think, I am not sure >> it will be refused because F1 and sin are not define !!! this is the >> power of the C pointers !!! >> the link is dynamic >> > You don't need C pointers. The design below is demonstrative, not ideal. > > # file MyFuncs.py > > def F1(x): > return x*x > > def Trapeze(f, left, right, step): > X0 = left > Z = 0.0 > while (X0 < right): > X1 = X0 + step > Y1 = f(X1) > Y0 = f(X0) > > Z += (Y1 + Y0) * step * 0.5 > X0 = X1 > return Z > > > > # file UseMyFuncs.py > import math > import MyFuncs > > def main(): > y = MyFuncs.Trapeze(math.sin, -2.5, 3.2, 0.1) > > print("Value for sin is:{0} ".format(y)) > y = MyFuncs.Trapeze(MyFuncs.F1, 0, 3, 0.1) > > print("Value for F1 is {0} ".format(y)) > > if __name__ == "__main__": > main() > > ### > #python3 UseMyFuncs.py > ### > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Thu Apr 18 14:25:40 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 18 Apr 2013 12:25:40 -0600 Subject: equivalent to C pointer In-Reply-To: References: <51702AB6.30609@gmail.com> Message-ID: On Thu, Apr 18, 2013 at 11:50 AM, abdelkader belahcene wrote: > Thanks for answer, > but with C we can compile the trapeze function and put it in librairy, > If we try to save the trapeze alone in package to import it later, I > think, I am not sure > it will be refused because F1 and sin are not define !!! this is the > power of the C pointers !!! > the link is dynamic The Python equivalent of a dynamically linked library is a module. You can certainly pass functions defined in one module as arguments to functions defined in another, completely unrelated module. In fact, Python doesn't care where they were defined or even whether they are functions; they're just objects, no different in that regard from strings or ints or class instances. From neilc at norwich.edu Thu Apr 18 14:07:32 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 18 Apr 2013 18:07:32 GMT Subject: equivalent to C pointer References: <51702AB6.30609@gmail.com> Message-ID: On 2013-04-18, abdelkader belahcene wrote: > Thanks for answer, > but with C we can compile the trapeze function and put it in > librairy, If we try to save the trapeze alone in package to > import it later, I think, I am not sure it will be refused > because F1 and sin are not define !!! this is the power of > the C pointers !!! the link is dynamic There's no linking stage in Python. Everything you use must be defined before you use it. In Python you can put trapeze in a library, and it will be able to accept any old function under the sun when you call it, as long as that function is defined. in trapeze.py: def trapeze(func, left, right, step): return sum((func(x) + func(x + step)) * step * 0.5 for x in range(left, right, step)) in file1.py: import trapeze def square(x): return x*x print(trapeze.trapeze(square, 0, 3, 2.5)) if file2.py: import trapeze import math print(trapeze.trapeze(math.sin, 1.3, 2.5, 1.0)) The functions square and sin are both defined before you pass them to trapeze, so all is well. Trapeze doesn't know or care about the signature of those functions until it actually tries to call them. At that time, if either one isn't defined properly Python will raise an exception. -- Neil Cerutti From python.list at tim.thechases.com Thu Apr 18 14:48:41 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 18 Apr 2013 13:48:41 -0500 Subject: equivalent to C pointer In-Reply-To: References: <51702AB6.30609@gmail.com> Message-ID: <20130418134841.6c2a502d@bigbox.christie.dr> On 2013-04-18 18:07, Neil Cerutti wrote: > There's no linking stage in Python. Everything you use must be > defined before you use it. "must be defined", only if you don't want an error. But in python, it isn't even REQUIRED that it be defined: some_undefined_function("args go here") will bomb out your program, but Python graciously allows you to do so: >>> try: ... hello(42) ... except NameError: ... print "You had me at hello" ... You had me at hello -tkc From ckaynor at zindagigames.com Thu Apr 18 13:25:58 2013 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Thu, 18 Apr 2013 10:25:58 -0700 Subject: equivalent to C pointer In-Reply-To: References: Message-ID: While Python does not have pointers, Python functions are objects, and they may be passed like any other object: def F1(x): return x * x def Trapeze(Fonc, left, right, step): ...code... Y1 = Fonc(X1) ...code... def main(): ...code... y = Trapeze(F1, -2.5, 3.2, 0.1) ...code... Chris On Thu, Apr 18, 2013 at 10:06 AM, abdelkader belahcene wrote: > Hi everybody, > > I am new to python and I am discovering it. > I know C well, > and want to know if python knows how to manage Pointers > like pointer to function here is a C example how to write it in python > Intergration with trapeze method > > When we write Trapeze ( at the compilation level) we don't know which > functions > Fonc to handle. Here for example we use sin and a user defined F1 > The program is attached too > > #include > #include > > double F1 (double x){ > return x*x; > } > double Trapeze(double Fonc(double ), > double left, double right, double step){ > double X1, X0, Y0, Y1, Z = 0; > for(X0=left; X0 < right ; X0 = X0 + step) { > X1 = X0 + step; > Y1 = Fonc(X1); Y0 = Fonc(X0); > Z += (Y1 + Y0) * step * 0.5; > } > return Z; > } > int main(){ > double y; > y=Trapeze(sin, -2.5, 3.2, 0.1); > printf("\n\tValue for sin is : \t %8.3lf ", y); > y=Trapeze(F1, 0, 3, 0.1); > printf("\n\tValue for F1 is : \t %8.3lf ", y); > return 0; > } > /** > Value for sin is : 0.197 > Value for F1 is : 9.005 > */ > thanks a lot > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From drobinow at gmail.com Thu Apr 18 14:04:49 2013 From: drobinow at gmail.com (David Robinow) Date: Thu, 18 Apr 2013 14:04:49 -0400 Subject: equivalent to C pointer In-Reply-To: References: Message-ID: On Thu, Apr 18, 2013 at 1:06 PM, abdelkader belahcene wrote: > Hi everybody, > > I am new to python and I am discovering it. > I know C well, > and want to know if python knows how to manage Pointers > like pointer to function here is a C example how to write it in python > Intergration with trapeze method > > When we write Trapeze ( at the compilation level) we don't know which > functions > Fonc to handle. Here for example we use sin and a user defined F1 > The program is attached too > > #include > #include > > double F1 (double x){ > return x*x; > } > double Trapeze(double Fonc(double ), > double left, double right, double step){ > double X1, X0, Y0, Y1, Z = 0; > for(X0=left; X0 < right ; X0 = X0 + step) { > X1 = X0 + step; > Y1 = Fonc(X1); Y0 = Fonc(X0); > Z += (Y1 + Y0) * step * 0.5; > } > return Z; > } > int main(){ > double y; > y=Trapeze(sin, -2.5, 3.2, 0.1); > printf("\n\tValue for sin is : \t %8.3lf ", y); > y=Trapeze(F1, 0, 3, 0.1); > printf("\n\tValue for F1 is : \t %8.3lf ", y); > return 0; > } > /** > Value for sin is : 0.197 > Value for F1 is : 9.005 > */ > > Python doesn't have pointers, but don't let that bother you. A python version is actually a lot simpler. See below (I didn't bother with getting the print formats just right) -- import math def F1(x): return x*x def Trapeze(f, left, right, step): X0 = left Z = 0.0 while (X0 < right): X1 = X0 + step Y1 = f(X1) Y0 = f(X0) Z += (Y1 + Y0) * step * 0.5 X0 = X1 return Z def main(): y = Trapeze(math.sin, -2.5, 3.2, 0.1) print("Value for sin is:{0} ".format(y)) y = Trapeze(F1, 0, 3, 0.1) print("Value for F1 is {0} ".format(y)) if __name__ == "__main__": main() -------------- next part -------------- An HTML attachment was scrubbed... URL: From ruyttenhove at gmail.com Thu Apr 18 16:35:18 2013 From: ruyttenhove at gmail.com (Robrecht W. Uyttenhove) Date: Thu, 18 Apr 2013 14:35:18 -0600 Subject: Strange behavior for a 2D list Message-ID: Hello, I tried out the following code: y=[range(0,7),range(7,14),range(14,21),range(21,28),range(28,35)] >>> y [[0, 1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12, 13], [14, 15, 16, 17, 18, 19, 20], [21, 22, 23, 24, 25, 26, 27], [28, 29, 30, 31, 32, 33, 34]] >>> y[1:5:2][::3] [[7, 8, 9, 10, 11, 12, 13]] I expected the 2D list: [[ 7, 10, 13], [21, 24, 27]] Any ideas? Thanks, Rob PS: I used Python 2.7.3 -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Thu Apr 18 17:12:52 2013 From: __peter__ at web.de (Peter Otten) Date: Thu, 18 Apr 2013 23:12:52 +0200 Subject: Strange behavior for a 2D list References: Message-ID: Robrecht W. Uyttenhove wrote: > Hello, > > I tried out the following code: > y=[range(0,7),range(7,14),range(14,21),range(21,28),range(28,35)] >>>> y > [[0, 1, 2, 3, 4, 5, 6], > [7, 8, 9, 10, 11, 12, 13], > [14, 15, 16, 17, 18, 19, 20], > [21, 22, 23, 24, 25, 26, 27], > [28, 29, 30, 31, 32, 33, 34]] > >>>> y[1:5:2][::3] > [[7, 8, 9, 10, 11, 12, 13]] > > I expected the 2D list: > [[ 7, 10, 13], > [21, 24, 27]] > > Any ideas? It is not really a 2D list; rather a list of lists. You cannot see the two slices together, the slicing happens in two separate steps. y[1:5:2] is a list containing two items (that happen to be lists) >>> x = y[1:5:2] >>> x [[7, 8, 9, 10, 11, 12, 13], [21, 22, 23, 24, 25, 26, 27]] x[::3] then operates on the outer list >>> x[::3] [[7, 8, 9, 10, 11, 12, 13]] By the way, numpy offers the behaviour you expected: >>> import numpy >>> a = numpy.array(y) >>> a array([[ 0, 1, 2, 3, 4, 5, 6], [ 7, 8, 9, 10, 11, 12, 13], [14, 15, 16, 17, 18, 19, 20], [21, 22, 23, 24, 25, 26, 27], [28, 29, 30, 31, 32, 33, 34]]) >>> a[1:5:2,::3] array([[ 7, 10, 13], [21, 24, 27]]) Note that both slices are passed in the same a[...] operation. From gordon at panix.com Thu Apr 18 17:13:34 2013 From: gordon at panix.com (John Gordon) Date: Thu, 18 Apr 2013 21:13:34 +0000 (UTC) Subject: Strange behavior for a 2D list References: Message-ID: In "Robrecht W. Uyttenhove" writes: > I tried out the following code: > y=[range(0,7),range(7,14),range(14,21),range(21,28),range(28,35)] > >>> y > [[0, 1, 2, 3, 4, 5, 6], > [7, 8, 9, 10, 11, 12, 13], > [14, 15, 16, 17, 18, 19, 20], > [21, 22, 23, 24, 25, 26, 27], > [28, 29, 30, 31, 32, 33, 34]] > >>> y[1:5:2][::3] > [[7, 8, 9, 10, 11, 12, 13]] > I expected the 2D list: > [[ 7, 10, 13], > [21, 24, 27]] > Any ideas? y is just a list. It happens to be a list of lists, but that doesn't make it a "2D" list. It's an important distinction. y[1:5:2] is the contents of y, starting at the second element and selecting every second element after that: [[7, 8, 9, 10, 11, 12, 13], [21, 22, 23, 24, 25, 26, 27]] y[1:5:2][::3] is the contents of y[1:5:2], starting at the first element and selecting every third element after that (and there are only two elements, so it stops after the first one): [[7, 8, 9, 10, 11, 12, 13]] Why were you expecting the other result? -- 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 wolfgang.maier at biologie.uni-freiburg.de Thu Apr 18 17:19:00 2013 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Thu, 18 Apr 2013 21:19:00 +0000 (UTC) Subject: Strange behavior for a 2D list References: Message-ID: Robrecht W. Uyttenhove gmail.com> writes: > > Hello, > I tried out the following code:y=[range(0,7),range(7,14),range(14,21),range(21,28),range(28,35)] > >>> y[[0, 1, 2, 3, 4, 5, 6], ?[7, 8, 9, 10, 11, 12, 13], > [14, 15, 16, 17, 18, 19, 20], ?[21, 22, 23, 24, 25, 26, 27], ?[28, > 29, 30, 31, 32, 33, 34]] > >>> y[1:5:2][::3] > [[7, 8, 9, 10, 11, 12, 13]] > I expected the 2D list:[[ 7, 10, 13], > ?[21, 24, 27]] > > Any ideas? > > Thanks, > Rob > PS: I used Python 2.7.3 > The explanation is rather simple, just break up your complex slicing into its parts: y[1:5:2] => [[7, 8, 9, 10, 11, 12, 13],[21, 22, 23, 24, 25, 26, 27]] and [::3] is asking for the first,4th,7th,... element from this list. Obviously, only the first one's existing, so [7, 8, 9, 10, 11, 12, 13] What you expected is kind of vertical slicing through the rows. I don't think you can achieve this with slicing alone in standard Python, but it's possible with numpy arrays. In Python you will have to combine slicing with a comprehension, like this: [x[::3] for x in y[1:5:2]] Best, Wolfgang From wcardoen at gmail.com Thu Apr 18 17:33:10 2013 From: wcardoen at gmail.com (Wim R. Cardoen) Date: Thu, 18 Apr 2013 15:33:10 -0600 Subject: Strange behavior for a 2D list In-Reply-To: References: Message-ID: Thank you all for your replies. I had the matrix concept in mind such as explained in the numpy example. Rob On Thu, Apr 18, 2013 at 3:19 PM, Wolfgang Maier < wolfgang.maier at biologie.uni-freiburg.de> wrote: > Robrecht W. Uyttenhove gmail.com> writes: > > > > > Hello, > > I tried out the following > code:y=[range(0,7),range(7,14),range(14,21),range(21,28),range(28,35)] > > >>> y[[0, 1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12, 13], > > [14, 15, 16, 17, 18, 19, 20], [21, 22, 23, 24, 25, 26, 27], [28, > > > 29, 30, 31, 32, 33, 34]] > > >>> y[1:5:2][::3] > > [[7, 8, 9, 10, 11, 12, 13]] > > I expected the 2D list:[[ 7, 10, 13], > > [21, 24, 27]] > > > > Any ideas? > > > > Thanks, > > Rob > > PS: I used Python 2.7.3 > > > > The explanation is rather simple, just break up your complex slicing into > its parts: > y[1:5:2] => [[7, 8, 9, 10, 11, 12, 13],[21, 22, 23, 24, 25, 26, 27]] > and [::3] is asking for the first,4th,7th,... element from this list. > Obviously, only the first one's existing, so [7, 8, 9, 10, 11, 12, 13] > > What you expected is kind of vertical slicing through the rows. I don't > think you can achieve this with slicing alone in standard Python, but it's > possible with numpy arrays. > In Python you will have to combine slicing with a comprehension, like this: > [x[::3] for x in y[1:5:2]] > > Best, > Wolfgang > > -- > http://mail.python.org/mailman/listinfo/python-list > -- --------------------------------------------------------------- Wim R. Cardoen, PhD Staff Scientist, Center for High Performance Computing University of Utah (801)971-4184 *?? ??? ???? ??????? ???????! (?????????)* --------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: From affdfsdfdsfsd at b.com Thu Apr 18 17:24:29 2013 From: affdfsdfdsfsd at b.com (Tracubik) Date: Thu, 18 Apr 2013 23:24:29 +0200 Subject: How to set my gui? Message-ID: <5170648d$0$1368$4fafbaef@reader2.news.tin.it> Hi all! I'm trying to make a simple program that essentially do this: 1) open a html file (extracted epub file) 2) search for occurrences like "ita-ly" 3) put them on a simple GUI: 1 text field and two buttons: keepy it and correct it (i.e. it will become italy) now this is quite simple but how can i do it properly? i suppose i've to first generate the window and than populate it, but where i've to put the "search for occurences" code? I don't think init() is the right place.. Thanks MedeoTL From gordon at panix.com Thu Apr 18 17:27:04 2013 From: gordon at panix.com (John Gordon) Date: Thu, 18 Apr 2013 21:27:04 +0000 (UTC) Subject: How to set my gui? References: <5170648d$0$1368$4fafbaef@reader2.news.tin.it> Message-ID: In <5170648d$0$1368$4fafbaef at reader2.news.tin.it> Tracubik writes: > i suppose i've to first generate the window and than populate it, but > where i've to put the "search for occurences" code? I don't think init() > is the right place.. What GUI library are you using? -- 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 affdfsdfdsfsd at b.com Thu Apr 18 17:36:50 2013 From: affdfsdfdsfsd at b.com (Tracubik) Date: Thu, 18 Apr 2013 23:36:50 +0200 Subject: How to set my gui? In-Reply-To: References: <5170648d$0$1368$4fafbaef@reader2.news.tin.it> Message-ID: <51706772$0$1368$4fafbaef@reader2.news.tin.it> On 18/04/2013 23:27, John Gordon wrote: > In <5170648d$0$1368$4fafbaef at reader2.news.tin.it> Tracubik writes: > >> i suppose i've to first generate the window and than populate it, but >> where i've to put the "search for occurences" code? I don't think init() >> is the right place.. > > What GUI library are you using? > Gtk3 via Glade, anyway the problem is referred to all gui toolkit, isn't it? MedeoTL From rosuav at gmail.com Thu Apr 18 18:00:11 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 19 Apr 2013 08:00:11 +1000 Subject: How to set my gui? In-Reply-To: <51706772$0$1368$4fafbaef@reader2.news.tin.it> References: <5170648d$0$1368$4fafbaef@reader2.news.tin.it> <51706772$0$1368$4fafbaef@reader2.news.tin.it> Message-ID: On Fri, Apr 19, 2013 at 7:36 AM, Tracubik wrote: > On 18/04/2013 23:27, John Gordon wrote: >> >> In <5170648d$0$1368$4fafbaef at reader2.news.tin.it> Tracubik >> writes: >> >>> i suppose i've to first generate the window and than populate it, but >>> where i've to put the "search for occurences" code? I don't think init() >>> is the right place.. >> >> >> What GUI library are you using? >> > > Gtk3 via Glade, anyway the problem is referred to all gui toolkit, isn't it? You're looking here for fairly broad and general advice on GUI code layout. Unfortunately that's so broad that all I can say is "there are many ways to do it". :) Back in the 1990s, I used to (mostly) treat GUI programming as somewhat different from console programming. I'd use a window-builder, I'd structure my code in an event loop instead of top-down imperative, I'd use an IDE rather than simply coding in a text editor. But 1 Corinthians 13:11. These days, GUI programming is to me just programming and calling on certain libraries/modules. There are many ways to lay out code, and treating the GUI framework/boilerplate as the most important is only one of them. One thing you may want to consider is using your main thread for the UI, and spinning off another thread to do your search. But do that ONLY if you know you understand threads, and threading in Python. Otherwise you'll make your life unnecessarily hard. :) ChrisA From r.koebler at yahoo.de Fri Apr 19 05:47:16 2013 From: r.koebler at yahoo.de (Roland Koebler) Date: Fri, 19 Apr 2013 11:47:16 +0200 Subject: How to set my gui? In-Reply-To: References: <5170648d$0$1368$4fafbaef@reader2.news.tin.it> <51706772$0$1368$4fafbaef@reader2.news.tin.it> Message-ID: <20130419094716.GD28906@localhost> Hi, > These days, GUI programming is to me just > programming and calling on certain libraries/modules. +1 > One thing you may want to consider is using your main thread for the > UI, and spinning off another thread to do your search. But do that > ONLY if you know you understand threads, and threading in Python. > Otherwise you'll make your life unnecessarily hard. :) For simple tasks, you don't need threads, but can use the glib-functions timeout_add(), idle_add() etc. Roland From walterhurry at lavabit.com Thu Apr 18 18:57:36 2013 From: walterhurry at lavabit.com (Walter Hurry) Date: Thu, 18 Apr 2013 22:57:36 +0000 (UTC) Subject: How to set my gui? References: <5170648d$0$1368$4fafbaef@reader2.news.tin.it> <51706772$0$1368$4fafbaef@reader2.news.tin.it> Message-ID: On Fri, 19 Apr 2013 08:00:11 +1000, Chris Angelico wrote: > But 1 Corinthians 13:11 You are grown up now, I surmise. From rosuav at gmail.com Thu Apr 18 19:24:36 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 19 Apr 2013 09:24:36 +1000 Subject: How to set my gui? In-Reply-To: References: <5170648d$0$1368$4fafbaef@reader2.news.tin.it> <51706772$0$1368$4fafbaef@reader2.news.tin.it> Message-ID: On Fri, Apr 19, 2013 at 8:57 AM, Walter Hurry wrote: > On Fri, 19 Apr 2013 08:00:11 +1000, Chris Angelico wrote: > >> But 1 Corinthians 13:11 > > You are grown up now, I surmise. :) Born in 1984, so that'll give you some idea where I was in the 1990s. ChrisA From rosuav at gmail.com Fri Apr 19 22:10:48 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 20 Apr 2013 12:10:48 +1000 Subject: How to set my gui? In-Reply-To: References: <5170648d$0$1368$4fafbaef@reader2.news.tin.it> <51706772$0$1368$4fafbaef@reader2.news.tin.it> Message-ID: On Sat, Apr 20, 2013 at 9:10 AM, Dennis Lee Bieber wrote: > On Fri, 19 Apr 2013 09:24:36 +1000, Chris Angelico > declaimed the following in gmane.comp.python.general: > >> On Fri, Apr 19, 2013 at 8:57 AM, Walter Hurry wrote: >> > On Fri, 19 Apr 2013 08:00:11 +1000, Chris Angelico wrote: >> > >> >> But 1 Corinthians 13:11 >> > >> > You are grown up now, I surmise. >> >> :) Born in 1984, so that'll give you some idea where I was in the 1990s. >> > > A puppy to be taught by greymuzzles (unfortunately, /this/ > greymuzzle [1958] has reached the point of being an old dog that only > learns new tricks with extreme difficulty ) Yep, taught by my Dad, who has often told the story of how he once held a whole kilobyte of memory in his hands (something like a cubic meter in size). He introduced me to programming, to fiddling with the system configs (actually he forbade that, for ages - because he had to clean up the mess if the system wouldn't boot), and to the joys of networking. So in a large way he's why I'm a geek... and actually he started that even earlier, when I was given the name Chris at birth. That on its own probably is the biggest cause of my geekery, I think! ChrisA From gheskett at wdtv.com Fri Apr 19 22:19:09 2013 From: gheskett at wdtv.com (Gene Heskett) Date: Fri, 19 Apr 2013 22:19:09 -0400 Subject: How to set my gui? In-Reply-To: References: <5170648d$0$1368$4fafbaef@reader2.news.tin.it> Message-ID: <201304192219.34719.gheskett@wdtv.com> On Friday 19 April 2013 22:16:18 Chris Angelico did opine: > On Sat, Apr 20, 2013 at 9:10 AM, Dennis Lee Bieber > > wrote: > > On Fri, 19 Apr 2013 09:24:36 +1000, Chris Angelico > > > > declaimed the following in gmane.comp.python.general: > >> On Fri, Apr 19, 2013 at 8:57 AM, Walter Hurry wrote: > >> > On Fri, 19 Apr 2013 08:00:11 +1000, Chris Angelico wrote: > >> >> But 1 Corinthians 13:11 > >> > > >> > You are grown up now, I surmise. > >> : > >> :) Born in 1984, so that'll give you some idea where I was in the > >> :1990s. > >> : > > A puppy to be taught by greymuzzles (unfortunately, /this/ > > > > greymuzzle [1958] has reached the point of being an old dog that only > > learns new tricks with extreme difficulty ) > > Yep, taught by my Dad, who has often told the story of how he once > held a whole kilobyte of memory in his hands (something like a cubic > meter in size). He introduced me to programming, to fiddling with the > system configs (actually he forbade that, for ages - because he had to > clean up the mess if the system wouldn't boot), and to the joys of > networking. So in a large way he's why I'm a geek... and actually he > started that even earlier, when I was given the name Chris at birth. > That on its own probably is the biggest cause of my geekery, I think! > > ChrisA Buncha spring chickens, the whole lot of you. Born in '34, I was a geek before the word was invented. But like some of you claim, I am now that old dog that doesn't learn new tricks easily. 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: is up! My views Mandrell: "You know what I think?" Doctor: "Ah, ah that's a catch question. With a brain your size you don't think, right?" -- Dr. Who A pen in the hand of this president is far more dangerous than a gun in the hands of 200 million law-abiding citizens. From alister.ware at ntlworld.com Fri Apr 19 04:42:48 2013 From: alister.ware at ntlworld.com (Alister) Date: Fri, 19 Apr 2013 08:42:48 GMT Subject: How to set my gui? References: <5170648d$0$1368$4fafbaef@reader2.news.tin.it> Message-ID: On Thu, 18 Apr 2013 23:24:29 +0200, Tracubik wrote: > Hi all! > I'm trying to make a simple program that essentially do this: > > 1) open a html file (extracted epub file) > 2) search for occurrences like "ita-ly" > 3) put them on a simple GUI: 1 text field and two buttons: keepy it and > correct it (i.e. it will become italy) > > now this is quite simple but how can i do it properly? > i suppose i've to first generate the window and than populate it, but > where i've to put the "search for occurences" code? I don't think init() > is the right place.. > > Thanks MedeoTL One simple way Make a method to search for the next occorance & use that as button click event. -- "Faith: not *wanting* to know what is true." -- Friedrich Nietzsche From affdfsdfdsfsd at b.com Fri Apr 19 10:37:33 2013 From: affdfsdfdsfsd at b.com (Tracubik) Date: Fri, 19 Apr 2013 16:37:33 +0200 Subject: How to set my gui? In-Reply-To: References: <5170648d$0$1368$4fafbaef@reader2.news.tin.it> Message-ID: <517156ad$0$1365$4fafbaef@reader2.news.tin.it> On 19/04/2013 10:42, Alister wrote: > On Thu, 18 Apr 2013 23:24:29 +0200, Tracubik wrote: > >> Hi all! >> I'm trying to make a simple program that essentially do this: >> >> 1) open a html file (extracted epub file) >> 2) search for occurrences like "ita-ly" >> 3) put them on a simple GUI: 1 text field and two buttons: keepy it and >> correct it (i.e. it will become italy) >> >> now this is quite simple but how can i do it properly? >> i suppose i've to first generate the window and than populate it, but >> where i've to put the "search for occurences" code? I don't think init() >> is the right place.. >> >> Thanks MedeoTL > One simple way > Make a method to search for the next occorance & use that as button click > event. > Mmmmh, this seem good to me. But i also need to add some code in the __init__() of the GUI class to get the first occurence and put it in the text field. Thanks for your reply, you was really helpful MedeoTL From moraa.lovetakes2 at gmail.com Fri Apr 19 05:56:10 2013 From: moraa.lovetakes2 at gmail.com (Ombongi Moraa Fe) Date: Fri, 19 Apr 2013 12:56:10 +0300 Subject: subprocess.call Message-ID: Hi Team, In my python script, I have this: command="lynx -dump 'phpscript?param1=%s¶m2=%s¶m3=%s¶m4=%s¶m5=%s'"%(value1,value2,value3,value4) result=subprocess.call(command,shell=True) print 'xml message' However, the response from running the php script is also printed on output screen. I don't want this output. How can i ensure that only the last print 'xml response' is returned? Saludos Ombongi Moraa Faith -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at hotmail.com Fri Apr 19 06:32:08 2013 From: nobody at hotmail.com (Mau C) Date: Fri, 19 Apr 2013 12:32:08 +0200 Subject: subprocess.call In-Reply-To: References: Message-ID: <51711d28$0$1374$4fafbaef@reader2.news.tin.it> Il 19/04/2013 11:56, Ombongi Moraa Fe ha scritto: > Hi Team, > > In my python script, I have this: > > command="lynx -dump > 'phpscript?param1=%s¶m2=%s¶m3=%s¶m4=%s¶m5=%s'"%(value1,value2,value3,value4) http://docs.python.org/2/library/subprocess.html#module-subprocess You should set the properly values for stdou and stderr. Under UNIX, '/dev/null' worked out fine for me, when 'None' didn't. M. From jt at toerring.de Fri Apr 19 10:43:05 2013 From: jt at toerring.de (Jens Thoms Toerring) Date: 19 Apr 2013 14:43:05 GMT Subject: subprocess.call References: Message-ID: Ombongi Moraa Fe wrote: > [-- text/plain, encoding 7bit, charset: ISO-8859-1, 19 lines --] > In my python script, I have this: > command="lynx -dump > 'phpscript?param1=%s¶m2=%s¶m3=%s¶m4=%s¶m5=%s'"%(value1,value2,value3,value4) > result=subprocess.call(command,shell=True) > print 'xml message' > However, the response from running the php script is also printed on output > screen. I don't want this output. > How can i ensure that only the last print 'xml response' is returned? You mean is printed out? Use subprocess.Popen() and redirect stdout to a pipe, similar to this: p = subprocess.Popen(command, stdout=subprocess.PIPE) r = p.communicate() print r[0] # This is the output (to stdout) The return value of the Popen objects communicate() method is a tuple with two elements, first contains what got written to stdout (if redirected to a pipe, otherwise Nome), the second what went to stderr (again if redirected to a pipe). If you also redirect stdin then you can pass what you want to send to the process spawned via Popen() as an argument to commu- nicate(). BTW, according to the dicumentation you should split the command line into its componenents and pass that as a list to the call() or Popen() subprocess methods, so it would seem to reasonable to use e.g. command = [ 'lynx', '-dump', ( "'phpscript?param1={0}¶m2={1}¶m3={2}" "¶m4={3}¶m5={4}'" ) .format( value1, value2, value3, value4, value5 ) ] Note that there was one value for creating the string to be passed to lynx was mising. Regards, Jens -- \ Jens Thoms Toerring ___ jt at toerring.de \__________________________ http://toerring.de From umjoda at gmail.com Fri Apr 19 09:18:37 2013 From: umjoda at gmail.com (usman mjoda) Date: Fri, 19 Apr 2013 21:18:37 +0800 Subject: Request Message-ID: Good day, I need help on how to upgradean SAES to AES 128 bits. thank you -- *Usman M. Joda (zhoda), * * * * * *Master Student of Computer Science & Technology,* * * * * * * *Liaoning University Of Technology (LUT), * * * * * * * *+8613840619645* * * * usmanjoda1 at yahoo.com * * * * Zhinzou- China* -------------- next part -------------- An HTML attachment was scrubbed... URL: From m.gilson1 at gmail.com Fri Apr 19 10:27:09 2013 From: m.gilson1 at gmail.com (Matthew Gilson) Date: Fri, 19 Apr 2013 10:27:09 -0400 Subject: Feature Request: `operator.not_in` Message-ID: <5171543D.708@gmail.com> I believe that I read somewhere that this is the place to start discussions on feature requests, etc. Please let me know if this isn't the appropriate venue (and what the appropriate venue would be if you know). This request has 2 related parts, but I think they can be considered seperately: 1) It seems to me that the operator module should have a `not_in` or `not_contains` function. It seems asymmetric that there exists a `is_not` function which implements `x is not y` but there isn't a function to represent `x not in y`. 2) I suspect this one might be a little more controversial, but it seems to me that there should be a separate magic method bound to the `not in` operator. Currently, when inspecting the bytecode, it appears to me that `not x in y` is translated to `x not in y` (this supports item 1 slightly). However, I don't believe this should be the case. In python, `x < y` does not imply `not x >= y` because a custom object can do whatever it wants with `__ge__` and `__lt__` -- They don't have to fit the normal mathematical definitions. I don't see any reason why containment should behave differently. `x in y` shouldn't necessarily imply `not x not in y`. I'm not sure if `object` could have a default `__not_contains__` method (or whatever name seems most appropriate) implemented equivalently to: def __not_contains__(self,other): return not self.__contains__(other) If not, it could probably be provided by something like `functools.total_ordering`. Anyway, it's food for thought and I'm interested to see if anyone else feels the same way that I do. Thanks, ~Matt From tjreedy at udel.edu Fri Apr 19 14:27:49 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Fri, 19 Apr 2013 14:27:49 -0400 Subject: Feature Request: `operator.not_in` In-Reply-To: <5171543D.708@gmail.com> References: <5171543D.708@gmail.com> Message-ID: On 4/19/2013 10:27 AM, Matthew Gilson wrote: ) It seems to me that the operator module should have a `not_in` or > `not_contains` function. It seems asymmetric that there exists a > `is_not` function which implements `x is not y` but there isn't a > function to represent `x not in y`. There is also no operator.in. There is operator.contains and operator.__contains__. There is no operator.not_contains because there is no __not_contains__ special method. (Your point two, which I disagree with.) > 2) I suspect this one might be a little more controversial, but it seems > to me that there should be a separate magic method bound to the `not in` > operator. The reference manual disagrees. "The operator not in is defined to have the inverse true value of in." > Currently, when inspecting the bytecode, it appears to me > that `not x in y` is translated to `x not in y` (this supports item 1 > slightly). However, I don't believe this should be the case. In > python, `x < y` does not imply `not x >= y` because a custom object can > do whatever it wants with `__ge__` and `__lt__` -- They don't have to > fit the normal mathematical definitions. The reason for this is that the rich comparisons do not have to return boolean values, and do not for numarray arrays which, I believe, implement the operators itemwise. > I don't see any reason why containment should behave differently. 'Design by analogy' is tricky because analogies often leave out important details. __contains__ *is* expected to return true/false. " object.__contains__(self, item) Called to implement membership test operators. Should return true if item is in self, false otherwise" -- Terry Jan Reedy From m.gilson1 at gmail.com Fri Apr 19 15:23:19 2013 From: m.gilson1 at gmail.com (Matthew Gilson) Date: Fri, 19 Apr 2013 15:23:19 -0400 Subject: Feature Request: `operator.not_in` In-Reply-To: References: <5171543D.708@gmail.com> Message-ID: <517199A7.3040608@gmail.com> On 4/19/13 2:27 PM, Terry Jan Reedy wrote: > On 4/19/2013 10:27 AM, Matthew Gilson wrote: > ) It seems to me that the operator module should have a `not_in` or >> `not_contains` function. It seems asymmetric that there exists a >> `is_not` function which implements `x is not y` but there isn't a >> function to represent `x not in y`. > > There is also no operator.in. True. I'm not arguing that there should be ... > There is operator.contains and operator.__contains__. Thankfully :-) > > There is no operator.not_contains because there is no __not_contains__ > special method. (Your point two, which I disagree with.) > But there's also no special method `__is_not__`, but there's a corresponding `is_not` in the operator module so I don't really see that argument. It's a matter of functionality that I'm thinking about in the first part. itertools.starmap(operator.not_in,x,y) vs. itertools.starmap(lambda a,b: a not in b,x,y) Pretty much every other operator in python (that I can think of) has an analogous function in the operator module. >> 2) I suspect this one might be a little more controversial, but it seems >> to me that there should be a separate magic method bound to the `not in` >> operator. > > The reference manual disagrees. > "The operator not in is defined to have the inverse true value of in." I would still leave that as the default behavior. It's by far the most useful and commonly expected. And I suppose if you *can't* have default behavior like that because that is a special case in itself, then that makes this second part of the request dead in the water at the outset (and I can live with that explanation). > >> Currently, when inspecting the bytecode, it appears to me >> that `not x in y` is translated to `x not in y` (this supports item 1 >> slightly). However, I don't believe this should be the case. In >> python, `x < y` does not imply `not x >= y` because a custom object can >> do whatever it wants with `__ge__` and `__lt__` -- They don't have to >> fit the normal mathematical definitions. > > The reason for this is that the rich comparisons do not have to return > boolean values, and do not for numarray arrays which, I believe, > implement the operators itemwise. > Yes, you're correct about numpy arrays behaving that way. It can be very useful for indexing them. It would also be fine for a special method `__not_contains__` to be expected to return a boolean value as well. It could still be very useful. Consider a finite square well from quantum mechanics. I could define `in` for my particle in the square well to return `True` if there is a 70% chance that it is located in the well (It's a wave-function, so it doesn't have a well defined position -- the particle could be anyway, but 7 out of 10 measurements will tell me it's in the well). It might be nice if I could define `not in` to be `True` if there is only a 30% chance that it is in the well. Of course, this leaves us with a no-man's land around the 50% mark. Is it in the well or not? There's no telling. I'm sure you could argue that this sort of thing *could* be done with rich comparisons, but I would consider that a deflection from the point at hand. It seems it should be up to the user to design the API most suited for their task. Or what about a `Fraternity` class. Are the new pledges in the fraternity or not? Maybe they should be considered neither in, nor out until pledge season is over. > > I don't see any reason why containment should behave differently. > > 'Design by analogy' is tricky because analogies often leave out > important details. __contains__ *is* expected to return true/false. > > " object.__contains__(self, item) > Called to implement membership test operators. Should return true > if item is in self, false otherwise" > > -- > Terry Jan Reedy > > From 2281570025 at qq.com Fri Apr 19 11:54:40 2013 From: 2281570025 at qq.com (=?gb18030?B?aU1hdGg=?=) Date: Fri, 19 Apr 2013 23:54:40 +0800 Subject: python : how to Opens folder with specified items selected on Windows Message-ID: I want to Opens folder with specified items selected on Windows ,I looked up the The Windows Shell Reference found a function fit for this job SHOpenFolderAndSelectItems http://msdn.microsoft.com/en-us/library/windows/desktop/bb762232(v=vs.85).aspx but I cannot find an example on how to use it with python so anyone can give a little example ? I have another extra requirement :if that folder already open ,don?t open it again ,just activate it and selected the file -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Fri Apr 19 12:07:05 2013 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 19 Apr 2013 17:07:05 +0100 Subject: python : how to Opens folder with specified items selected on Windows In-Reply-To: References: Message-ID: <51716BA9.9060105@timgolden.me.uk> On 19/04/2013 16:54, iMath wrote: > I want to Opens folder with specified items selected on Windows ,I > looked up the The Windows Shell Reference found a function fit for this job > > SHOpenFolderAndSelectItems > > http://msdn.microsoft.com/en-us/library/windows/desktop/bb762232(v=vs.85).aspx > > but I cannot find an example on how to use it with python > > so anyone can give a little example ? > > I have another extra requirement :if that folder already open ,don?t > open it again ,just activate it and selected the file Have a look over here: http://mail.python.org/pipermail/python-win32/2012-September/012533.html TJG From stefan_ml at behnel.de Fri Apr 19 12:25:37 2013 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 19 Apr 2013 18:25:37 +0200 Subject: New release 0.19 of the Cython compiler Message-ID: I'm happy to announce that Cython 0.19 has been released. This is a feature release of the Cython compiler that adds some major usability improvements especially for code that needs to run in both Py2 and Py3, as well as better Python compatibility and optimisations. http://cython.org/ You can get it from here: http://cython.org/release/Cython-0.19.tar.gz http://cython.org/release/Cython-0.19.zip Release notes: https://github.com/cython/cython/blob/29bf3493fdc80cb3261a9dfb9f73e3ccd46fec66/CHANGES.rst Documentation: http://docs.cython.org/ Major new features in this release: =========================== * New directives ``c_string_type`` and ``c_string_encoding`` to automatically convert between C strings and the different Python string types. * Keyword arguments are supported for cdef functions, including external C/C++ library functions. * New freelist decorator for extension types. * Fast extension type instantiation using the ``Type.__new__(Type)`` idiom has gained support for passing arguments. * Slicing was optimised for several builtin types and otherwise conforms better with Python semantics for user defined types. * The mapping of dict view/item methods in Python 3 was improved. What is Cython? =============== Cython is an optimising static compiler for both the Python programming language and the extended Cython programming language (based on Pyrex). It makes writing C extensions for Python as easy as Python itself. The Cython language is a superset of the Python language that additionally supports calling C functions and declaring C types on variables and class attributes. This allows the compiler to generate very efficient C code from Cython code. The C code is generated once and then compiles with all major C/C++ compilers in CPython 2.4 and later, including Python 3.x. All of this makes Cython the ideal language for wrapping external C libraries, embedding CPython into existing applications, and for fast C modules that speed up the execution of Python code. See the project home page for further information: http://cython.org/ Have fun, Stefan From lee at piclab.com Fri Apr 19 13:17:58 2013 From: lee at piclab.com (lcrocker) Date: Fri, 19 Apr 2013 10:17:58 -0700 (PDT) Subject: Ubuntu package "python3" does not include tkinter Message-ID: Am I mistaken in my belief that tkinter is a non-optional part of the Python language? I installed the "python3" package on Ubuntu, and tkinter is not included--it's an optional package "python3-tk" that has to be installed separately. I reported this as a bug as was summarily slapped down. Can we apply some pressure to Ubuntu to fix this? Python is a trademark, is it not? Can Ubuntu legally claim that their "Python" package is an implementation of the language if it does not include the whole language? From joel.goldstick at gmail.com Fri Apr 19 13:25:41 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 19 Apr 2013 13:25:41 -0400 Subject: Ubuntu package "python3" does not include tkinter In-Reply-To: References: Message-ID: On Fri, Apr 19, 2013 at 1:17 PM, lcrocker wrote: > Am I mistaken in my belief that tkinter is a non-optional part of the > Python language? I installed the "python3" package on Ubuntu, and > tkinter is not included--it's an optional package "python3-tk" that > has to be installed separately. I reported this as a bug as was > summarily slapped down. > > Can we apply some pressure to Ubuntu to fix this? Python is a > trademark, is it not? Can Ubuntu legally claim that their "Python" > package is an implementation of the language if it does not include > the whole language? > -- > http://mail.python.org/mailman/listinfo/python-list > >From here: http://wiki.python.org/moin/TkInter Does this help? Try the correct command for your version at the Python prompt: >>> import Tkinter # no underscore, uppercase 'T' for versions prior to V3.0 >>> import tkinter # no underscore, lowercase 't' for V3.0 and later -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From leedanielcrocker at gmail.com Fri Apr 19 13:30:10 2013 From: leedanielcrocker at gmail.com (lcrocker) Date: Fri, 19 Apr 2013 10:30:10 -0700 (PDT) Subject: Ubuntu package "python3" does not include tkinter References: Message-ID: <955c1941-250e-4d89-ad13-6ba82717be1d@ys5g2000pbc.googlegroups.com> Thanks, but I'm not having any trouble running tkinter, it works just fine. I have an issue with the fact that it's optional. It reflects badly on the language and community if we allow just anyone to call something "Python" that doesn't meet some minimum standard of quality. Java has its compliance tests: if your implementation doesn't pass, you can't call it "Java". I'm asking if there's something similar for Python, because Ubuntu's Python 3 doesn't pass the test. From bahamutzero8825 at gmail.com Fri Apr 19 13:35:44 2013 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Fri, 19 Apr 2013 12:35:44 -0500 Subject: Ubuntu package "python3" does not include tkinter In-Reply-To: References: Message-ID: <51718070.6010600@gmail.com> On 2013.04.19 12:17, lcrocker wrote: > Am I mistaken in my belief that tkinter is a non-optional part of the > Python language? I installed the "python3" package on Ubuntu, and > tkinter is not included--it's an optional package "python3-tk" that > has to be installed separately. I reported this as a bug as was > summarily slapped down. Forcing Tkinter as a dependency would result in a ton of things being installed to support it. Why should a web server using Django have X installed and running because Python /can/ support a GUI in the standard library? It's trivial to install Tkinter if you need it, but it would be a huge mess to try to remove it from an installation that requires it - even if you never use Tkinter. Ubuntu is far from alone here. FreeBSD (and probably the other BSDs) and most Linux distros do something similar. There is zero reason to force Tkinter and its dependencies on all Python users. -- CPython 3.3.0 | Windows NT 6.2.9200 / FreeBSD 9.1 From leedanielcrocker at gmail.com Fri Apr 19 13:42:23 2013 From: leedanielcrocker at gmail.com (lcrocker) Date: Fri, 19 Apr 2013 10:42:23 -0700 (PDT) Subject: Ubuntu package "python3" does not include tkinter References: Message-ID: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> On Apr 19, 10:35?am, Andrew Berg wrote: > On 2013.04.19 12:17, lcrocker wrote:> Am I mistaken in my belief that tkinter is a non-optional part of the > > Python language? I installed the "python3" package on Ubuntu, and > > tkinter is not included--it's an optional package "python3-tk" that > > has to be installed separately. I reported this as a bug as was > > summarily slapped down. > > Forcing Tkinter as a dependency would result in a ton of things being installed to support it. Why should a web server using Django have X > installed and running because Python /can/ support a GUI in the standard library? It's trivial to install Tkinter if you need it, but it > would be a huge mess to try to remove it from an installation that requires it - even if you never use Tkinter. Ubuntu is far from alone > here. FreeBSD (and probably the other BSDs) and most Linux distros do something similar. There is zero reason to force Tkinter and its > dependencies on all Python users. > -- > CPython 3.3.0 | Windows NT 6.2.9200 / FreeBSD 9.1 I understand that for something like a server distribution, but Ubuntu is a user-focused desktop distribution. It has a GUI, always. The purpose of a distro like that is to give users a good experience. If I install Python on Windows, I get to use Python. On Ubuntu, I don't, and I think that will confuse some users. I recently recommended Python to a friend who wants to start learning programming. Hurdles like this don't help someone like him. From rustompmody at gmail.com Fri Apr 19 13:53:48 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 19 Apr 2013 10:53:48 -0700 (PDT) Subject: Ubuntu package "python3" does not include tkinter References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> Message-ID: On Apr 19, 10:42?pm, lcrocker wrote: > On Apr 19, 10:35?am, Andrew Berg wrote: > > > On 2013.04.19 12:17, lcrocker wrote:> Am I mistaken in my belief that tkinter is a non-optional part of the > > > Python language? I installed the "python3" package on Ubuntu, and > > > tkinter is not included--it's an optional package "python3-tk" that > > > has to be installed separately. I reported this as a bug as was > > > summarily slapped down. > > > Forcing Tkinter as a dependency would result in a ton of things being installed to support it. Why should a web server using Django have X > > installed and running because Python /can/ support a GUI in the standard library? It's trivial to install Tkinter if you need it, but it > > would be a huge mess to try to remove it from an installation that requires it - even if you never use Tkinter. Ubuntu is far from alone > > here. FreeBSD (and probably the other BSDs) and most Linux distros do something similar. There is zero reason to force Tkinter and its > > dependencies on all Python users. > > -- > > CPython 3.3.0 | Windows NT 6.2.9200 / FreeBSD 9.1 > > I understand that for something like a server distribution, but Ubuntu > is a user-focused desktop distribution. It has a GUI, always. The > purpose of a distro like that is to give users a good experience. If I > install Python on Windows, I get to use Python. On Ubuntu, I don't, > and I think that will confuse some users. I recently recommended > Python to a friend who wants to start learning programming. Hurdles > like this don't help someone like him. Well I guess you could take the example of kde. kde has a kde-standard and a kde-full. Likewise one could imagine python-standard being what is currently called python and python-full pulling in other dependencies like tkinter. If there were a number of such it may even make sense, if not it looks like overkill (to me) From bahamutzero8825 at gmail.com Fri Apr 19 14:05:50 2013 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Fri, 19 Apr 2013 13:05:50 -0500 Subject: Ubuntu package "python3" does not include tkinter In-Reply-To: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> Message-ID: <5171877E.3070202@gmail.com> On 2013.04.19 12:42, lcrocker wrote: > I understand that for something like a server distribution, but Ubuntu > is a user-focused desktop distribution. It has a GUI, always. That is incorrect. http://www.ubuntu.com/server -- CPython 3.3.0 | Windows NT 6.2.9200 / FreeBSD 9.1 From nulla.epistola at web.de Sat Apr 20 12:10:58 2013 From: nulla.epistola at web.de (Sibylle Koczian) Date: Sat, 20 Apr 2013 18:10:58 +0200 Subject: Ubuntu package "python3" does not include tkinter In-Reply-To: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> Message-ID: Am 19.04.2013 19:42, schrieb lcrocker: > I understand that for something like a server distribution, but Ubuntu > is a user-focused desktop distribution. It has a GUI, always. The > purpose of a distro like that is to give users a good experience. If I > install Python on Windows, I get to use Python. On Ubuntu, I don't, > and I think that will confuse some users. I recently recommended > Python to a friend who wants to start learning programming. Hurdles > like this don't help someone like him. It's _so_ easy to install an additional package on Ubuntu that that really shouldn't be called a 'hurdle'. Using tkinter or any other GUI toolkit is much more difficult for a beginner. From steve+comp.lang.python at pearwood.info Sun Apr 21 23:57:09 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Apr 2013 03:57:09 GMT Subject: Ubuntu package "python3" does not include tkinter References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> Message-ID: <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> On Sat, 20 Apr 2013 18:10:58 +0200, Sibylle Koczian wrote: > Am 19.04.2013 19:42, schrieb lcrocker: >> I understand that for something like a server distribution, but Ubuntu >> is a user-focused desktop distribution. It has a GUI, always. The >> purpose of a distro like that is to give users a good experience. If I >> install Python on Windows, I get to use Python. On Ubuntu, I don't, and >> I think that will confuse some users. I recently recommended Python to >> a friend who wants to start learning programming. Hurdles like this >> don't help someone like him. > > It's _so_ easy to install an additional package on Ubuntu that that > really shouldn't be called a 'hurdle'. Using tkinter or any other GUI > toolkit is much more difficult for a beginner. It's only easy to install a package on Ubuntu if you know that you have to, and can somehow work out the name of the package. -- Steven From rustompmody at gmail.com Mon Apr 22 00:10:24 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 21 Apr 2013 21:10:24 -0700 (PDT) Subject: Ubuntu package "python3" does not include tkinter References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5e225794-fa3c-4fb7-9ee4-1d0db3b4ba1f@fz1g2000pbb.googlegroups.com> On Apr 22, 8:57?am, Steven D'Aprano wrote: > On Sat, 20 Apr 2013 18:10:58 +0200, Sibylle Koczian wrote: > > Am 19.04.2013 19:42, schrieb lcrocker: > >> I understand that for something like a server distribution, but Ubuntu > >> is a user-focused desktop distribution. It has a GUI, always. The > >> purpose of a distro like that is to give users a good experience. If I > >> install Python on Windows, I get to use Python. On Ubuntu, I don't, and > >> I think that will confuse some users. I recently recommended Python to > >> a friend who wants to start learning programming. Hurdles like this > >> don't help someone like him. > > > It's _so_ easy to install an additional package on Ubuntu that that > > really shouldn't be called a 'hurdle'. Using tkinter or any other GUI > > toolkit is much more difficult for a beginner. > > It's only easy to install a package on Ubuntu if you know that you have > to, and can somehow work out the name of the package. > > -- > Steven Yes There is some infrastructure in debian/ubuntu (not sure what/where/ how) which behaves something like so: $peculiar_command peculiar_command no found but exists in package FooBar I believe that repackaged pythons (like debian's) should be able to hook into this system and give better error messages than ImportError: No module named Tkinter From bahamutzero8825 at gmail.com Mon Apr 22 00:24:04 2013 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sun, 21 Apr 2013 23:24:04 -0500 Subject: Ubuntu package "python3" does not include tkinter In-Reply-To: <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5174BB64.3050203@gmail.com> On 2013.04.21 22:57, Steven D'Aprano wrote: > It's only easy to install a package on Ubuntu if you know that you have > to, and can somehow work out the name of the package. I haven't worked with Ubuntu or apt-based packaging in ages, but isn't this kind of information in a description message or something (especially in a GUI frontend)? -- CPython 3.3.0 | Windows NT 6.2.9200 / FreeBSD 9.1 From rustompmody at gmail.com Mon Apr 22 00:34:00 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 21 Apr 2013 21:34:00 -0700 (PDT) Subject: Ubuntu package "python3" does not include tkinter References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7d7dcc2b-62e0-4f1a-b8f4-e1662437a512@ot10g2000pbb.googlegroups.com> On Apr 22, 9:24?am, Andrew Berg wrote: > On 2013.04.21 22:57, Steven D'Aprano wrote:> It's only easy to install a package on Ubuntu if you know that you have > > to, and can somehow work out the name of the package. > > I haven't worked with Ubuntu or apt-based packaging in ages, but isn't this kind of information in a description message or something > (especially in a GUI frontend)? Of course... If you know where to look. (I think that's Steven's point in the 'you know that you have to') For a noob getting the error ImportError: No module named Tkinter it may be that - he has not installed tkinter - he has misspelled tkinter - he has misspelled the import statement (yeah then he'll get syntax error or somesuch? being a noob he does not know) I personally know that one can put 'python' in the search box in synaptic and fish around. The point is that the noob to python may be a noob to linux/apt also. From bahamutzero8825 at gmail.com Mon Apr 22 01:13:15 2013 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Mon, 22 Apr 2013 00:13:15 -0500 Subject: Ubuntu package "python3" does not include tkinter In-Reply-To: <7d7dcc2b-62e0-4f1a-b8f4-e1662437a512@ot10g2000pbb.googlegroups.com> References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> <7d7dcc2b-62e0-4f1a-b8f4-e1662437a512@ot10g2000pbb.googlegroups.com> Message-ID: <5174C6EB.1090508@gmail.com> On 2013.04.21 23:34, rusi wrote: > On Apr 22, 9:24 am, Andrew Berg wrote: >> On 2013.04.21 22:57, Steven D'Aprano wrote:> It's only easy to install a package on Ubuntu if you know that you have >> > to, and can somehow work out the name of the package. >> >> I haven't worked with Ubuntu or apt-based packaging in ages, but isn't this kind of information in a description message or something >> (especially in a GUI frontend)? > > Of course... If you know where to look. (I think that's Steven's point > in the 'you know that you have to') I meant when installing it. I forgot for a moment that Ubuntu and many other Linux distros come with Python already installed. -- CPython 3.3.1 | Windows NT 6.2.9200 / FreeBSD 9.1 From rui.maciel at gmail.com Mon Apr 22 02:36:47 2013 From: rui.maciel at gmail.com (Rui Maciel) Date: Mon, 22 Apr 2013 07:36:47 +0100 Subject: Ubuntu package "python3" does not include tkinter References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > It's only easy to install a package on Ubuntu if you know that you have > to, and can somehow work out the name of the package. No one actually has to install tkinter. That's the whole point of providing it as a separate package: only those who want to use it have to install it. The rest of us don't. Rui Maciel From steve+comp.lang.python at pearwood.info Mon Apr 22 03:17:27 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Apr 2013 07:17:27 GMT Subject: Ubuntu package "python3" does not include tkinter References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5174e407$0$29872$c3e8da3$5496439d@news.astraweb.com> On Mon, 22 Apr 2013 07:36:47 +0100, Rui Maciel wrote: > Steven D'Aprano wrote: > >> It's only easy to install a package on Ubuntu if you know that you have >> to, and can somehow work out the name of the package. > > No one actually has to install tkinter. That's the whole point of > providing it as a separate package: only those who want to use it have > to install it. The rest of us don't. I think that if you are worrying about the overhead of the tkinter bindings for Python, you're guilty of premature optimization. The tkinter package in Python 3.3 is trivially small, under 2 MB. Besides, how far do we go? Do we expect people to install (say): python3-copy so that those who don't need the copy module don't have to install it? sudo apt-get python3 python3-copy python3-dis python3-doctest \ python3-csv python3-logging python3-shutil ... There are advantages to having the *standard library* actually be, you know, *standard*. In my perfect world, the tk/tcl bindings and the tkinter package would be installed with any Python installation. Naturally they won't work if you don't install Tcl, but to make them work, all you need is: sudo apt-get python3 tcl Don't want Tcl? Fine, don't install it, and "import tkinter" will fail at import time, preferably with a sensible error message like "Tcl not installed". Naturally I'm just talking about the standard CPython implementation on Linux systems where Tcl is standard. If you have an embedded system, where tkinter's 2MB is *not* trivially small, or a platform where Tcl does not exist, then that's a different story. But in a standard Linux desktop install of Python, tkinter should Just Work once you install Tcl. In my perfect world. -- Steven From bahamutzero8825 at gmail.com Mon Apr 22 04:08:24 2013 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Mon, 22 Apr 2013 03:08:24 -0500 Subject: Ubuntu package "python3" does not include tkinter In-Reply-To: <5174e407$0$29872$c3e8da3$5496439d@news.astraweb.com> References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> <5174e407$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5174EFF8.90405@gmail.com> On 2013.04.22 02:17, Steven D'Aprano wrote: > I think that if you are worrying about the overhead of the tkinter > bindings for Python, you're guilty of premature optimization. The tkinter > package in Python 3.3 is trivially small, under 2 MB. > > Besides, how far do we go? Do we expect people to install (say): > > python3-copy > > so that those who don't need the copy module don't have to install it? Much of the stdlib doesn't rely on anything but the core interpreter. tkinter by itself is not the issue. As you said, the bindings are tiny. However, in order to be usable, it requires quite a few things - most notably X. On desktop Linux, this is already installed, but on server systems, it generally is not (or at least shouldn't be in most cases). Going back to my example of a web server using a Python-based framework, I'll repeat that there is no reason such a system should have X even installed in order to serve web pages. Even on a lean, mean server machine, CPython requires only a few extra libraries. Add tkinter, and suddenly you have to install a LOT of things. If you plan to actually use tkinter, this is fine. If not, you've just added a lot of stuff that you don't need. This adds unnecessary overhead in several places (like your package system's database). -- CPython 3.3.1 | Windows NT 6.2.9200 / FreeBSD 9.1 From steve+comp.lang.python at pearwood.info Mon Apr 22 05:18:24 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Apr 2013 09:18:24 GMT Subject: Ubuntu package "python3" does not include tkinter References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> <5174e407$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5175005f$0$29872$c3e8da3$5496439d@news.astraweb.com> On Mon, 22 Apr 2013 03:08:24 -0500, Andrew Berg wrote: > Much of the stdlib doesn't rely on anything but the core interpreter. > tkinter by itself is not the issue. As you said, the bindings are tiny. > However, in order to be usable, it requires quite a few things - most > notably X. On desktop Linux, this is already installed, but on server > systems, it generally is not (or at least shouldn't be in most cases). > Going back to my example of a web server using a Python-based framework, > I'll repeat that there is no reason such a system should have X even > installed in order to serve web pages. Even on a lean, mean server > machine, CPython requires only a few extra libraries. Add tkinter, and > suddenly you have to install a LOT of things. If you plan to actually > use tkinter, this is fine. If not, you've just added a lot of stuff that > you don't need. This adds unnecessary overhead in several places (like > your package system's database). I can't disagree with any of this, except to say that none of this justifies having a separate package for Tkinter. Naturally if you don't have X, Tcl won't work, and if Tcl won't work, Tkinter won't work and should give an import error. But that doesn't imply that X must be a dependency for Python. It's a dependency for having Tkinter *work*, but not for *installing* Tkinter as part of the standard library. Hell, even if you have X installed, and Tcl, and the Tkinter packages, importing tkinter can still fail, if Python wasn't built with the right magic incantations for it to recognise that Tcl is installed. -- Steven From antoon.pardon at rece.vub.ac.be Mon Apr 22 08:52:39 2013 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 22 Apr 2013 14:52:39 +0200 Subject: Ubuntu package "python3" does not include tkinter In-Reply-To: <5175005f$0$29872$c3e8da3$5496439d@news.astraweb.com> References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> <5174e407$0$29872$c3e8da3$5496439d@news.astraweb.com> <5175005f$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51753297.6060306@rece.vub.ac.be> Op 22-04-13 11:18, Steven D'Aprano schreef: > On Mon, 22 Apr 2013 03:08:24 -0500, Andrew Berg wrote: > >> Much of the stdlib doesn't rely on anything but the core interpreter. >> tkinter by itself is not the issue. As you said, the bindings are tiny. >> However, in order to be usable, it requires quite a few things - most >> notably X. On desktop Linux, this is already installed, but on server >> systems, it generally is not (or at least shouldn't be in most cases). >> Going back to my example of a web server using a Python-based framework, >> I'll repeat that there is no reason such a system should have X even >> installed in order to serve web pages. Even on a lean, mean server >> machine, CPython requires only a few extra libraries. Add tkinter, and >> suddenly you have to install a LOT of things. If you plan to actually >> use tkinter, this is fine. If not, you've just added a lot of stuff that >> you don't need. This adds unnecessary overhead in several places (like >> your package system's database). > I can't disagree with any of this, except to say that none of this > justifies having a separate package for Tkinter. Naturally if you don't > have X, Tcl won't work, and if Tcl won't work, Tkinter won't work and > should give an import error. But that doesn't imply that X must be a > dependency for Python. It's a dependency for having Tkinter *work*, but > not for *installing* Tkinter as part of the standard library. > > Hell, even if you have X installed, and Tcl, and the Tkinter packages, > importing tkinter can still fail, if Python wasn't built with the right > magic incantations for it to recognise that Tcl is installed. Then don't use a package system. The job of a package system is, that if you install something, it install all dependencies that are needed to make it work. And if, as the OP you thinks, python working, means tkinter working, not installing tcl and not installing X, is not an option. Your solution doesn't make sense in view of your earlier response where you argue tkinster should be installed because it is part of the standard combined with the advantage of having a standard library. But IMO a part of that standard library not working, is just as harmful as part of that standard library not being installed. From a user/programmer's point of view the result is the same. It is unusable. From steve+comp.lang.python at pearwood.info Mon Apr 22 20:22:40 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Apr 2013 00:22:40 GMT Subject: Ubuntu package "python3" does not include tkinter References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> <5174e407$0$29872$c3e8da3$5496439d@news.astraweb.com> <5175005f$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5175d450$0$29977$c3e8da3$5496439d@news.astraweb.com> On Mon, 22 Apr 2013 14:52:39 +0200, Antoon Pardon wrote: > Op 22-04-13 11:18, Steven D'Aprano schreef: >> On Mon, 22 Apr 2013 03:08:24 -0500, Andrew Berg wrote: >> >>> Much of the stdlib doesn't rely on anything but the core interpreter. >>> tkinter by itself is not the issue. As you said, the bindings are >>> tiny. However, in order to be usable, it requires quite a few things - >>> most notably X. On desktop Linux, this is already installed, but on >>> server systems, it generally is not (or at least shouldn't be in most >>> cases). Going back to my example of a web server using a Python-based >>> framework, I'll repeat that there is no reason such a system should >>> have X even installed in order to serve web pages. Even on a lean, >>> mean server machine, CPython requires only a few extra libraries. Add >>> tkinter, and suddenly you have to install a LOT of things. If you plan >>> to actually use tkinter, this is fine. If not, you've just added a lot >>> of stuff that you don't need. This adds unnecessary overhead in >>> several places (like your package system's database). >> I can't disagree with any of this, except to say that none of this >> justifies having a separate package for Tkinter. Naturally if you don't >> have X, Tcl won't work, and if Tcl won't work, Tkinter won't work and >> should give an import error. But that doesn't imply that X must be a >> dependency for Python. It's a dependency for having Tkinter *work*, but >> not for *installing* Tkinter as part of the standard library. >> >> Hell, even if you have X installed, and Tcl, and the Tkinter packages, >> importing tkinter can still fail, if Python wasn't built with the right >> magic incantations for it to recognise that Tcl is installed. > Then don't use a package system. The job of a package system is, that if > you install something, it install all dependencies that are needed to > make it work. No, the job of the package system is to manage dependencies. It makes no guarantee about whether or not something will "work". $ sudo apt-get install rule_world $ rule_world --start-from Australia Error: cannot connect to US nuclear arsenal from here, you cannot rule the world A joke example, of course, but a serious point. Successful installation doesn't necessarily mean the program will run successfully, or "work" in any meaningful way. We're also glossing over what it means to be a dependency. This is not obvious, and in fact I would argue that X is NOT a dependency for tkinter, even though tkinter will not "work" without it, for some definition of work. I can quite happily import tkinter on a remote machine over ssh: py> from tkinter.messagebox import showinfo or do the same thing on a local machine from a non-X terminal. I haven't tried it, but quite possibly even on a headless machine without X installed at all. And why not? Tkinter is a big module, there are all sorts of things that I might want to access that don't actually require an X display. If nothing else, I can do this: py> help(showinfo) and read the docs. Tkinter does not actually require X to "work". It merely requires X in order to *display an X window*. It's only when I actually try to do something that requires an X display that it will fail. I won't show the entire traceback, because it is long and not particularly enlightening, but the final error message explains exactly why it isn't working: _tkinter.TclError: no display name and no $DISPLAY environment variable > Your solution doesn't make sense in view of your earlier response where > you argue tkinster should be installed because it is part of the > standard combined with the advantage of having a standard library. But > IMO a part of that standard library not working, is just as harmful as > part of that standard library not being installed. From a > user/programmer's point of view the result is the same. It is unusable. Not at all. As I said earlier, I would expect that trying to import tkinter on such a system should give a meaningful error message. Actually, it need not even fail at import time. As I show above, I can happily import tkinter without an X display. I haven't tried it, but I expect that I can probably import tkinter without Tcl either. Let me put this another way: It should not matter whether I install Tcl before Python, or after Python, the end result should be that once both are installed, tkinter will be usable (provided you have an X display). To put it in Ubuntu terms, if I do this: apt-get tcl apt-get python or this: apt-get python apt-get tcl on a machine with X, tkinter should Just Work. And if I don't install tcl, tkinter should still import, it just won't be able to, you know, interface to tcl. What we're arguing here is merely the design of the dependency graph, and that's a matter of taste. My design would be different from that of the Ubuntu folks. That's fine. If we all agreed about everything, we'd have nothing to argue about *wink* But I think we can all agree that something like this is pretty crappy: py> import Tkinter Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.5/lib-tk/Tkinter.py", line 38, in import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named _tkinter Oh great. My Python is not configured for Tk. How does that help me? What do I do now? No idea. Why oh why can't we get a better class of error messages? -- Steven From rosuav at gmail.com Mon Apr 22 20:36:38 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Apr 2013 10:36:38 +1000 Subject: Ubuntu package "python3" does not include tkinter In-Reply-To: <5175d450$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> <5174e407$0$29872$c3e8da3$5496439d@news.astraweb.com> <5175005f$0$29872$c3e8da3$5496439d@news.astraweb.com> <5175d450$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Apr 23, 2013 at 10:22 AM, Steven D'Aprano wrote: > It's only when I actually try to do something that requires an X display > that it will fail. I won't show the entire traceback, because it is long > and not particularly enlightening, but the final error message explains > exactly why it isn't working: > > _tkinter.TclError: no display name and no $DISPLAY environment variable You presumably have a system to test this on. Can you try using ssh -X to get to it, and then retry that action? It looks like you actually have everything you need, just no display... which is exactly what you'd get if you ssh to something that has a real GUI. Not a dependency problem. ChrisA From bahamutzero8825 at gmail.com Mon Apr 22 20:47:26 2013 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Mon, 22 Apr 2013 19:47:26 -0500 Subject: Ubuntu package "python3" does not include tkinter In-Reply-To: <5175d450$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> <5174e407$0$29872$c3e8da3$5496439d@news.astraweb.com> <5175005f$0$29872$c3e8da3$5496439d@news.astraweb.com> <5175d450$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5175DA1E.7010700@gmail.com> On 2013.04.22 19:22, Steven D'Aprano wrote: > It's only when I actually try to do something that requires an X display > that it will fail. I won't show the entire traceback, because it is long > and not particularly enlightening, but the final error message explains > exactly why it isn't working: > > _tkinter.TclError: no display name and no $DISPLAY environment variable So you want to go from "this won't work because it's not installed" to "this won't work, and it there could be a hundred different reasons why"? tkinter's main function is to display something on a display. To say that displaying something is an optional feature is absurd. "You can install this, but your package manager won't pull in any dependencies because a few minor things will work without them. If you want it to actually do what it was made for, you need to install them yourself." Much bigger problem than the OP's, no? -- CPython 3.3.1 | Windows NT 6.2.9200 / FreeBSD 9.1 From rustompmody at gmail.com Mon Apr 22 23:50:20 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 22 Apr 2013 20:50:20 -0700 (PDT) Subject: Ubuntu package "python3" does not include tkinter References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> <5174e407$0$29872$c3e8da3$5496439d@news.astraweb.com> <5175005f$0$29872$c3e8da3$5496439d@news.astraweb.com> <5175d450$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5f014763-5f9d-43be-95c6-20865abbd78b@k6g2000pbq.googlegroups.com> On Apr 23, 5:22?am, Steven D'Aprano wrote: > We're also glossing over what it means to be a dependency. This is not > obvious, and in fact I would argue that X is NOT a dependency for > tkinter, even though tkinter will not "work" without it, for some > definition of work. I can quite happily import tkinter on a remote > machine over ssh: Yes the crux of the matter is what it means 'to work' and therefore 'to not work' Lets say my car is 'not working' On further investigation its found that the petrol tank is empty. A case could be made for either case: 'it (the car) working' or 'its not working' To the extent that pragmatically 'not working' is attended by a mechanic, its not in that category To the extent that (even more pragmatically) I missed an important appointment, its in that category Both of which gloss over the fact that after filling the petrol it may still not work. So to conclude: "since I could not check, its vacuously working" is more problematic than the contrary "since I could not check, its vacuously not working" Package systems need to 'federate' so to speak workingness from a zillion packages to the whole system. The problem is that workingness is peculiar to each package. Therefore it seems reasonable to me to ask of a package system that - it allows a maximum number of different configurations for different requirements ('without crap') - it disallows all kinds of misconfigured/non-working systems -- therefore conservative dependencies are good - the above subject to reasonable best efforts -- so dont cater to fringe pathological cases (like I want Tkinter but not X) BTW I suggested earlier that python could have something like KDE (Kde- full and a smaller Kde-standard). Just checked that python already has python2.7 and python2.7-minimal where the description of the latter says: "it can be used in the boot process for basic tasks" From steve+comp.lang.python at pearwood.info Tue Apr 23 00:03:14 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Apr 2013 04:03:14 GMT Subject: Ubuntu package "python3" does not include tkinter References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> <5174e407$0$29872$c3e8da3$5496439d@news.astraweb.com> <5175005f$0$29872$c3e8da3$5496439d@news.astraweb.com> <5175d450$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51760802$0$29872$c3e8da3$5496439d@news.astraweb.com> On Tue, 23 Apr 2013 10:36:38 +1000, Chris Angelico wrote: > On Tue, Apr 23, 2013 at 10:22 AM, Steven D'Aprano > wrote: >> It's only when I actually try to do something that requires an X >> display that it will fail. I won't show the entire traceback, because >> it is long and not particularly enlightening, but the final error >> message explains exactly why it isn't working: >> >> _tkinter.TclError: no display name and no $DISPLAY environment variable > > You presumably have a system to test this on. Can you try using ssh -X > to get to it, and then retry that action? It looks like you actually > have everything you need, just no display... which is exactly what you'd > get if you ssh to something that has a real GUI. Not a dependency > problem. I didn't say it was a dependency problem. I'm just demonstrating that it is possible for tkinter code to fail even if all the dependencies are met; and on the other hand, it is useful to be able to import tkinter even if you cannot display any tkinter windows. -- Steven From rosuav at gmail.com Tue Apr 23 00:11:45 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Apr 2013 14:11:45 +1000 Subject: Ubuntu package "python3" does not include tkinter In-Reply-To: <51760802$0$29872$c3e8da3$5496439d@news.astraweb.com> References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> <5174e407$0$29872$c3e8da3$5496439d@news.astraweb.com> <5175005f$0$29872$c3e8da3$5496439d@news.astraweb.com> <5175d450$0$29977$c3e8da3$5496439d@news.astraweb.com> <51760802$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Apr 23, 2013 at 2:03 PM, Steven D'Aprano wrote: > On Tue, 23 Apr 2013 10:36:38 +1000, Chris Angelico wrote: > >> On Tue, Apr 23, 2013 at 10:22 AM, Steven D'Aprano >> wrote: >>> It's only when I actually try to do something that requires an X >>> display that it will fail. I won't show the entire traceback, because >>> it is long and not particularly enlightening, but the final error >>> message explains exactly why it isn't working: >>> >>> _tkinter.TclError: no display name and no $DISPLAY environment variable >> >> You presumably have a system to test this on. Can you try using ssh -X >> to get to it, and then retry that action? It looks like you actually >> have everything you need, just no display... which is exactly what you'd >> get if you ssh to something that has a real GUI. Not a dependency >> problem. > > I didn't say it was a dependency problem. I'm just demonstrating that it > is possible for tkinter code to fail even if all the dependencies are > met; and on the other hand, it is useful to be able to import tkinter > even if you cannot display any tkinter windows. Sure. But I don't know that the situation you're seeing is the same as the one you'd see if you install tkinter without tk. ChrisA From steve+comp.lang.python at pearwood.info Tue Apr 23 01:49:09 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Apr 2013 05:49:09 GMT Subject: Ubuntu package "python3" does not include tkinter References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> <5174e407$0$29872$c3e8da3$5496439d@news.astraweb.com> <5175005f$0$29872$c3e8da3$5496439d@news.astraweb.com> <5175d450$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <517620d4$0$29872$c3e8da3$5496439d@news.astraweb.com> On Mon, 22 Apr 2013 19:47:26 -0500, Andrew Berg wrote: > On 2013.04.22 19:22, Steven D'Aprano wrote: >> It's only when I actually try to do something that requires an X >> display that it will fail. I won't show the entire traceback, because >> it is long and not particularly enlightening, but the final error >> message explains exactly why it isn't working: >> >> _tkinter.TclError: no display name and no $DISPLAY environment variable > > So you want to go from "this won't work because it's not installed" to > "this won't work, and it there could be a hundred different reasons > why"? No, that's not what I said. I want to go from: "this won't work because it's not installed, and I have no idea how to install it or what dependencies are needed, and even when I meet all the dependencies and install it, it might still not work" to: "this won't work, and here are the reasons why". Splitting tkinter out into an extra package doesn't buy you much, if anything. Here is the error I get on Debian when I try importing tkinter: Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.1/tkinter/__init__.py", line 42, in raise ImportError(str(msg) + ', please install the python-tk package') ImportError: No module named _tkinter, please install the python-tk package This implies that the pure Python parts of tkinter are already installed. It's just the magic _tkinter module which isn't included. (Also, many points for actually telling me what I need to do to fix the problem.) > tkinter's main function is to display something on a display. To > say that displaying something is an optional feature is absurd. Of course it is optional. Python will run on headless systems, or before X starts up, or on systems where there is no X. Importing tkinter works before X starts up. There's *no reason why* importing tkinter ought to fail before X starts up. Obviously you cannot display an X window without X, well duh, but merely importing tkinter doesn't require an X display. > "You can > install this, but your package manager won't pull in any dependencies > because a few minor things will work without them. If you want it to > actually do what it was made for, you need to install them yourself." > Much bigger problem than the OP's, no? Not necessarily bigger, just different. I don't see why "apt-get install python-tk" is considered too trivial to worry about, but "apt-get install tcl" is considered a "much bigger problem". So long as the error tells you what to do, they're both more or less equally hard. Or easy. We agree on the conditions needed to display tkinter GUI windows: - you must have Python - and the tkinter package - and the _tkinter module - and Tk/Tcl - and X (and an OS, and a computer, and electricity, but we can take them as given). We just disagree on where to break the packages up. Debian appears to do this: (Python tkinter) (_tkinter) (Tk/Tcl) (X) Ubuntu appears to do this, I think: (Python) (tkinter _tkinter) (Tk/Tcl) (X) I'm suggesting there's no real harm in doing this: (Python tkinter _tkinter) (Tk/Tcl) (X) for standard desktop installs, and some minor advantages. -- Steven From bahamutzero8825 at gmail.com Tue Apr 23 03:33:54 2013 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Tue, 23 Apr 2013 02:33:54 -0500 Subject: Ubuntu package "python3" does not include tkinter In-Reply-To: <517620d4$0$29872$c3e8da3$5496439d@news.astraweb.com> References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> <5174e407$0$29872$c3e8da3$5496439d@news.astraweb.com> <5175005f$0$29872$c3e8da3$5496439d@news.astraweb.com> <5175d450$0$29977$c3e8da3$5496439d@news.astraweb.com> <517620d4$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51763962.5080503@gmail.com> On 2013.04.23 00:49, Steven D'Aprano wrote: > Obviously you cannot display an X window without > X, well duh, but merely importing tkinter doesn't require an X display. Importing it doesn't. Doing anything useful with it, however, does. Would you consider the engine an optional part of a car? After all, the radio would still work and you can put things in the glove compartment. > We just disagree on where to break the packages up. We disagree on what a dependency is. I say a dependency is something required in order to have any functionality that is not defined as optional or extra by the author(s). You say it's anything required in order to initialize, even if there is little to no actual functionality. Perhaps you are fond of hunting down components to make something work, but most people would expect a packaging system to automatically install whatever is required to make the software they want to use do what it is supposed to. Or perhaps you had a dummy package in mind that would automatically pull in Tcl/Tk and X and whatever else is required to make tkinter draw things on a screen as a convenience. Of course, that brings us back to the OP's problem... Since Linux distros already include whatever third-party software they see fit as part of their base (or have the OS installer install whatever the user specifies during installation), why not have desktop configurations include tkinter by default when installing? -- CPython 3.3.1 | Windows NT 6.2.9200 / FreeBSD 9.1 From rui.maciel at gmail.com Tue Apr 23 02:57:55 2013 From: rui.maciel at gmail.com (Rui Maciel) Date: Tue, 23 Apr 2013 07:57:55 +0100 Subject: Ubuntu package "python3" does not include tkinter References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> <5174e407$0$29872$c3e8da3$5496439d@news.astraweb.com> <5175005f$0$29872$c3e8da3$5496439d@news.astraweb.com> <5175d450$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > No, the job of the package system is to manage dependencies. It makes no > guarantee about whether or not something will "work". The purpose of establishing dependencies is to guarantee that once a software package is installed, all the necessary components needed for it to run properly are already present in the system or can be installed automatically. http://en.wikipedia.org/wiki/Dependency_hell Rui Maciel From rui.maciel at gmail.com Mon Apr 22 17:09:14 2013 From: rui.maciel at gmail.com (Rui Maciel) Date: Mon, 22 Apr 2013 22:09:14 +0100 Subject: Ubuntu package "python3" does not include tkinter References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> <5174e407$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I think that if you are worrying about the overhead of the tkinter > bindings for Python, you're guilty of premature optimization. I'm not worried about that. No one should be forced to install crap that they don't use or will ever need, no matter how great the average HD capacity is nowadays. Rui Maciel From steve+comp.lang.python at pearwood.info Mon Apr 22 19:30:45 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Apr 2013 23:30:45 GMT Subject: Ubuntu package "python3" does not include tkinter References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> <5174e407$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5175c825$0$29977$c3e8da3$5496439d@news.astraweb.com> On Mon, 22 Apr 2013 22:09:14 +0100, Rui Maciel wrote: > Steven D'Aprano wrote: > >> I think that if you are worrying about the overhead of the tkinter >> bindings for Python, you're guilty of premature optimization. > > I'm not worried about that. No one should be forced to install crap > that they don't use or will ever need, no matter how great the average > HD capacity is nowadays. Nobody forces you to do anything. Python is open source, and the source code is freely available. Feel free to hand-optimize your Python installation, selecting carefully each and every module, class, and function in the standard library so that only the ones you absolutely know you will need to use are installed, using your godlike powers of precognition to foresee exactly what you need in seventeen months from now and what is "crap" that you will never need. Good luck with that. I look forward to hearing about the results. -- Steven From rui.maciel at gmail.com Tue Apr 23 02:44:57 2013 From: rui.maciel at gmail.com (Rui Maciel) Date: Tue, 23 Apr 2013 07:44:57 +0100 Subject: Ubuntu package "python3" does not include tkinter References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> <5174e407$0$29872$c3e8da3$5496439d@news.astraweb.com> <5175c825$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Nobody forces you to do anything. Python is open source, and the source > code is freely available. That goes both ways, with the added benefit that python-tkinter is already available in distro's official repositories. If you want to install it, go for it. Nothing stops you. If you don't then you aren't forced to install half the packages in the repository just to have a python interpreter in your system. Rui Maciel From rustompmody at gmail.com Tue Apr 23 08:01:19 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 23 Apr 2013 05:01:19 -0700 (PDT) Subject: Ubuntu package "python3" does not include tkinter References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> <5174e407$0$29872$c3e8da3$5496439d@news.astraweb.com> <5175c825$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Apr 23, 11:44?am, Rui Maciel wrote: > Steven D'Aprano wrote: > > Nobody forces you to do anything. Python is open source, and the source > > code is freely available. > > That goes both ways, with the added benefit that python-tkinter is already > available in distro's official repositories. ?If you want to install it, go > for it. ?Nothing stops you. ?If you don't then you aren't forced to install > half the packages in the repository just to have a python interpreter in > your system. > > Rui Maciel Collecting together what are the conflicting principles --------------------------------------------- 1 Fail early Fail fast 2 Good error messages 3 No crap 4 A working system that is easily upgradable and keeps working 5 Package system permissive allows wide variation of package combinations 6 Package system strict Disallows error-prone situations/combinations 7 Easy on learners/noobs From bob.martin at excite.com Tue Apr 23 07:33:56 2013 From: bob.martin at excite.com (Bob Martin) Date: Tue, 23 Apr 2013 07:33:56 BST Subject: Ubuntu package "python3" does not include tkinter References: <5174e407$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: in 695509 20130422 081727 Steven D'Aprano wrote: >I think that if you are worrying about the overhead of the tkinter >bindings for Python, you're guilty of premature optimization. The tkinter >package in Python 3.3 is trivially small, under 2 MB. "trivially small"? 30 years ago a small mainframe only had 2MB. From rosuav at gmail.com Tue Apr 23 02:41:36 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Apr 2013 16:41:36 +1000 Subject: Ubuntu package "python3" does not include tkinter In-Reply-To: References: <5174e407$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Apr 23, 2013 at 3:33 PM, Bob Martin wrote: > in 695509 20130422 081727 Steven D'Aprano wrote: > >>I think that if you are worrying about the overhead of the tkinter >>bindings for Python, you're guilty of premature optimization. The tkinter >>package in Python 3.3 is trivially small, under 2 MB. > > "trivially small"? > 30 years ago a small mainframe only had 2MB. 30 years ago, people weren't using Tk. We've moved on beyond worrying about the odd kilobyte of space. (Also, I think you're talking RAM, and Steven was talking hard disk. Systems can easily have another SI unit of disk than memory.) ChrisA From rui.maciel at gmail.com Tue Apr 23 02:48:47 2013 From: rui.maciel at gmail.com (Rui Maciel) Date: Tue, 23 Apr 2013 07:48:47 +0100 Subject: Ubuntu package "python3" does not include tkinter References: <5174e407$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico wrote: > 30 years ago, people weren't using Tk. And after 30 years gone by, some people still don't use Tk, let alone Tkinter. There is absolutely no reason to force them to install that if they don't need to. > We've moved on beyond worrying about the odd kilobyte of space. That must be reason why you are the only one complaining about that. Rui Maciel From rosuav at gmail.com Tue Apr 23 03:34:03 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Apr 2013 17:34:03 +1000 Subject: Ubuntu package "python3" does not include tkinter In-Reply-To: References: <5174e407$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Apr 23, 2013 at 4:48 PM, Rui Maciel wrote: > Chris Angelico wrote: > >> 30 years ago, people weren't using Tk. > > And after 30 years gone by, some people still don't use Tk, let alone > Tkinter. There is absolutely no reason to force them to install that if > they don't need to. Agreed; my preference is GTK, when I do GUI work. >> We've moved on beyond worrying about the odd kilobyte of space. > > That must be reason why you are the only one complaining about that. I'm not. ChrisA From leedanielcrocker at gmail.com Mon Apr 22 07:18:59 2013 From: leedanielcrocker at gmail.com (lcrocker) Date: Mon, 22 Apr 2013 04:18:59 -0700 (PDT) Subject: Ubuntu package "python3" does not include tkinter References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: <26d6d300-9f1b-4640-bbc6-d9c653bb6ad4@ph9g2000pbb.googlegroups.com> On Apr 21, 11:36?pm, Rui Maciel wrote: > Steven D'Aprano wrote: > > It's only easy to install a package on Ubuntu if you know that you have > > to, and can somehow work out the name of the package. > > No one actually has to install tkinter. ?That's the whole point of providing > it as a separate package: only those who want to use it have to install it. > The rest of us don't. I'm a programmer, I installed Tkinter, and use it. I'd like to deploy programs written with it to others. **Those** people know nothing about it, and **shouldn't have to**. I've given them a program in Python, they have Python, but it doesn't run, and doesn't give them a helpful error. They'll probably just blame me and move on. Not every Python user is a programmer. If I write a program in Java, any user with Java installed can run it. As it stands, that's no true for Python. That's not good PR for the cause. From rustompmody at gmail.com Mon Apr 22 08:08:08 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 22 Apr 2013 05:08:08 -0700 (PDT) Subject: Ubuntu package "python3" does not include tkinter References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> <26d6d300-9f1b-4640-bbc6-d9c653bb6ad4@ph9g2000pbb.googlegroups.com> Message-ID: <8543d75e-c4d6-4683-abbf-c0ad766d6e52@mf10g2000pbb.googlegroups.com> On Apr 22, 4:18?pm, lcrocker wrote: > On Apr 21, 11:36?pm, Rui Maciel wrote: > > > Steven D'Aprano wrote: > > > It's only easy to install a package on Ubuntu if you know that you have > > > to, and can somehow work out the name of the package. > > > No one actually has to install tkinter. ?That's the whole point of providing > > it as a separate package: only those who want to use it have to install it. > > The rest of us don't. > > I'm a programmer, I installed Tkinter, and use it. I'd like to deploy > programs > written with it to others. ?**Those** people know nothing about it, > and > **shouldn't have to**. I've given them a program in Python, they have > Python, > but it doesn't run, and doesn't give them a helpful error. They'll > probably > just blame me and move on. ?Not every Python user is a programmer. ?If > I write > a program in Java, any user with Java installed can run it. ?As it > stands, > that's no true for Python. ?That's not good PR for the cause. On the whole agree -- except for the java part -- maybe you've not heard of 'jar hell'? On the whole easy-deployability without losing easy-programmability is a major research issue. See this for someone choosing C++ over Lisp http://comments.gmane.org/gmane.comp.finance.ledger.general/1955 From rosuav at gmail.com Mon Apr 22 09:07:02 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 22 Apr 2013 23:07:02 +1000 Subject: Ubuntu package "python3" does not include tkinter In-Reply-To: <26d6d300-9f1b-4640-bbc6-d9c653bb6ad4@ph9g2000pbb.googlegroups.com> References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> <26d6d300-9f1b-4640-bbc6-d9c653bb6ad4@ph9g2000pbb.googlegroups.com> Message-ID: On Mon, Apr 22, 2013 at 9:18 PM, lcrocker wrote: > On Apr 21, 11:36 pm, Rui Maciel wrote: >> Steven D'Aprano wrote: >> > It's only easy to install a package on Ubuntu if you know that you have >> > to, and can somehow work out the name of the package. >> >> No one actually has to install tkinter. That's the whole point of providing >> it as a separate package: only those who want to use it have to install it. >> The rest of us don't. > > I'm a programmer, I installed Tkinter, and use it. I'd like to deploy > programs > written with it to others. **Those** people know nothing about it, > and > **shouldn't have to**. I've given them a program in Python, they have > Python, > but it doesn't run, and doesn't give them a helpful error. They'll > probably > just blame me and move on. Not every Python user is a programmer. If > I write > a program in Java, any user with Java installed can run it. As it > stands, > that's no true for Python. That's not good PR for the cause. If you're deploying only to Debian-based Linuxes (such as the Ubuntu you mentioned originally), then it may be worth distributing your program as a .deb file and declaring all the appropriate dependencies (which would then include python3-tk). Alternatively, just put an "apt-get install python3-tk" into your install script (which is what I do for internal deployments - if you need package XYZ for program Foo, inst-foo will install XYZ), or simply tell people they need to install it. How do you make sure they even have a Python 3.x? Whatever you do to ensure that, just add python3-tk to it. ChrisA From rui.maciel at gmail.com Mon Apr 22 17:00:31 2013 From: rui.maciel at gmail.com (Rui Maciel) Date: Mon, 22 Apr 2013 22:00:31 +0100 Subject: Ubuntu package "python3" does not include tkinter References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> <5174b515$0$29872$c3e8da3$5496439d@news.astraweb.com> <26d6d300-9f1b-4640-bbc6-d9c653bb6ad4@ph9g2000pbb.googlegroups.com> Message-ID: lcrocker wrote: > I'm a programmer, I installed Tkinter, and use it. I'd like to deploy > programs written with it to others. **Those** people know nothing > about it, and **shouldn't have to**. They don't need to. The only person that needs to know what he is doing is you. You want to distribute a software package? Package it. Learn the very basics and set python-tkinter as a dependency. http://wiki.debian.org/Packaging Rui Maciel From rui.maciel at gmail.com Mon Apr 22 02:35:33 2013 From: rui.maciel at gmail.com (Rui Maciel) Date: Mon, 22 Apr 2013 07:35:33 +0100 Subject: Ubuntu package "python3" does not include tkinter References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> Message-ID: lcrocker wrote: > I understand that for something like a server distribution, but Ubuntu > is a user-focused desktop distribution. It has a GUI, always. Irrelevant. > The > purpose of a distro like that is to give users a good experience. If I > install Python on Windows, I get to use Python. On Ubuntu, I don't, > and I think that will confuse some users. Nonsense. No one is keeping anyone off tkinter. If you want it, install it. There are official packages in the repositories such as python-tk and python3-tk. If someone else doesn't want them then they aren't forced to pack their Ubuntu systems with more cruft. There's nothing worse than being forced to install piles of irrelevant and useless stuff as a dependency to a fundamental package. > I recently recommended > Python to a friend who wants to start learning programming. Hurdles > like this don't help someone like him. If your friend believes that having to do an extra pair of clicks or typing sudo apt-get install python-tk is an unbeatable hurdle then your friend's computer skills are awfully lacking and he won't have much success learning how to write programs. Rui Maciel From rustompmody at gmail.com Mon Apr 22 07:16:17 2013 From: rustompmody at gmail.com (rusi) Date: Mon, 22 Apr 2013 04:16:17 -0700 (PDT) Subject: Ubuntu package "python3" does not include tkinter References: <9ba1d90b-1a69-4e5a-8a9e-574009b0bdf3@fs2g2000pbd.googlegroups.com> Message-ID: <4c598dba-8167-4c84-b9dd-2f9a840859b8@g5g2000pbp.googlegroups.com> On Apr 22, 11:35?am, Rui Maciel wrote: > lcrocker wrote: > > > > I recently recommended > > Python to a friend who wants to start learning programming. Hurdles > > like this don't help someone like him. > > If your friend believes that having to do an extra pair of clicks or typing > sudo apt-get install python-tk is an unbeatable hurdle then your friend's > computer skills are awfully lacking and he won't have much success learning > how to write programs. There are two worldviews here and they are as far as far can be. Its good to see them before arguing. 1. python as a standalone language 2. python as part of an (OS-related) ecosystem In windows python may or may not exist. And if it exists and I go inside the python directories and start messing around -- deleting some files, modifying others etc -- what will happen? Nothing much. My python programs will stop working. Presumably if I reinstall, it will be fine thereafter. What about linux? As an experiment I just tried $ aptitude purge python #Noobs BEWARE of that command and aptitude was too confused to give me a coherent report Tried then $ aptitude purge python2.7 The list of packages that it would purge was in hundreds. Heres a small sample of what would go: Firstly there are all the python-* packages. This is obvious. Not so obvious that some like python-csound were probably installed by me. Others like python-debian are needed for the basic health and functioning of the system. And besides these there are a pile of others that have no relation to python. A sample: asciidoc, bzr, dia, eog, gcj-*, gdb(!!), gimp, gnome-* (about 20 of these) printconf? So python is completely optional in windows. It is a part of the infrastructure on linux Messing with it is almost like saying: "I dont see what that vmlinuz file is doing in /boot. So I removed it." Coming to the OP question: a. The python that PSF provides is suitable for learning python b. The python that linux distros provide is part of the wireframe on which the system rests. b may be derived from a but they are hardly the same. They may look very similar but their intents are quite different. So when you say > If your friend believes that having to do an extra pair of clicks or typing > sudo apt-get install python-tk is an unbeatable hurdle then your friend's > computer skills are awfully lacking and he won't have much success learning > how to write programs. Its all correct what you say. You wont have too many people learning from you if thats how you say it. Remember that the difference between an expert and a noob is rarely a question of intelligence or diligence. Its just some boring trivial mountain of data that the expert has picked up over time From __peter__ at web.de Fri Apr 19 13:53:39 2013 From: __peter__ at web.de (Peter Otten) Date: Fri, 19 Apr 2013 19:53:39 +0200 Subject: Ubuntu package "python3" does not include tkinter References: Message-ID: lcrocker wrote: > Am I mistaken in my belief that tkinter is a non-optional part of the > Python language? I installed the "python3" package on Ubuntu, and > tkinter is not included--it's an optional package "python3-tk" that > has to be installed separately. I reported this as a bug as was > summarily slapped down. > > Can we apply some pressure to Ubuntu to fix this? Python is a > trademark, is it not? Can Ubuntu legally claim that their "Python" > package is an implementation of the language if it does not include > the whole language? Thank you for bringing this criminal offense to our attention. Right now a PSU team is readying their black helicopters to get Mr Shuttleworth and his accompli From tjreedy at udel.edu Fri Apr 19 14:42:34 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Fri, 19 Apr 2013 14:42:34 -0400 Subject: Ubuntu package "python3" does not include tkinter In-Reply-To: References: Message-ID: On 4/19/2013 1:17 PM, lcrocker wrote: > Am I mistaken in my belief that tkinter is a non-optional part of the > Python language? Yes. The PSF CPython Windows installer makes installation of tcl/tk/tkinter optional. The build files will compile and build Python without tkinter and without other modules that depend on other c libraries (example, lzma). I believe one can build python 2 without unicode, which is much more 'core' than the Tkinter module. > I installed the "python3" package on Ubuntu, and > tkinter is not included--it's an optional package "python3-tk" that > has to be installed separately. I reported this as a bug as was > summarily slapped down. I hope it was done politely ;-). Overall, Ubuntu is relatively advanced in moving to new versions. I believe I read that they are hoping to make 3.3 the default Python as soon as possible. From steve+comp.lang.python at pearwood.info Fri Apr 19 20:05:14 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Apr 2013 00:05:14 GMT Subject: Ubuntu package "python3" does not include tkinter References: Message-ID: <5171dbba$0$29977$c3e8da3$5496439d@news.astraweb.com> On Fri, 19 Apr 2013 10:17:58 -0700, lcrocker wrote: > Am I mistaken in my belief that tkinter is a non-optional part of the > Python language? I installed the "python3" package on Ubuntu, and > tkinter is not included--it's an optional package "python3-tk" that has > to be installed separately. I reported this as a bug as was summarily > slapped down. Personally, I think that is a silly design by Ubuntu, but tkinter is optional and they're free to distribute Python with or without it. That becomes a *quality of implementation* issue: some distributions may be more complete, easier to install, more up-to-date, etc. than others, but they're still Python. There is Python the language, which is distinct from the CPython implementation (to say nothing of other implementations like Jython, IronPython, Stackless, PyPy, ...), and then there is the standard library. Much of the standard library is optional, although unfortunately the documentation doesn't really make that as clear as it should. Tkinter depends on you have Tk/Tcl installed, which on Linux and Unix systems depends on you having X installed. Personally, I think that a good packaging system should ensure that once you install Tk/Tcl, tkinter should "just work". But there may be technical reasons why this is impossible. If you ever build Python from source, you will often get warnings that it could not build certain modules. I spent a fruitless couple of hours last week trying to install Python 2.7 from scratch with sqlite, before giving up. What I got was still Python 2.7. It was just Python 2.7 without sqlite (and four or five other modules, which I don't care about and don't remember). > Can we apply some pressure to Ubuntu to fix this? Python is a trademark, > is it not? Can Ubuntu legally claim that their "Python" package is an > implementation of the language if it does not include the whole > language? Tkinter is not part of the language. The tkinter module is an interface to another language, not part of Python the language itself. There are platforms where Tk/Tcl do not exist, platforms which may not even have a GUI environment at all. Do you really intend to say that it is forbidden to have Python on such platforms? -- Steven From brian at dashley.net Fri Apr 19 13:59:26 2013 From: brian at dashley.net (b_erickson1) Date: Fri, 19 Apr 2013 17:59:26 -0000 Subject: unzipping a zipx file Message-ID: I have python 2.6.2 and I trying to get it to unzip a file made with winzip pro. The file extension is zipx. This is on a windows machine where I have to send them all that files necessary to run. I am packaging this with py2exe. I can open the file with zFile = zipfile.ZipFile(fullPathName,'r') and I can look through all the file in the archive for filename in zFile.namelist(): but when I write the file out with this code: ozFile = open(filename,'w') ozFile.write(zFile.read(filename)) ozFile.close() that file still looks encrypted. No errors are thrown. The file is just a text file not a jpeg or anything else. I can open the file with 7zip and extract the text file out just fine. What am I missing? Thanks From gordon at panix.com Fri Apr 19 14:33:54 2013 From: gordon at panix.com (John Gordon) Date: Fri, 19 Apr 2013 18:33:54 +0000 (UTC) Subject: unzipping a zipx file References: Message-ID: In "b_erickson1" writes: > ozFile = open(filename,'w') > ozFile.write(zFile.read(filename)) > ozFile.close() Perhaps you want to use zFile.extract() instead of zFile.read()? -- 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 gordon at panix.com Fri Apr 19 14:56:12 2013 From: gordon at panix.com (John Gordon) Date: Fri, 19 Apr 2013 18:56:12 +0000 (UTC) Subject: unzipping a zipx file References: Message-ID: In John Gordon writes: > In "b_erickson1" writes: > > ozFile = open(filename,'w') > > ozFile.write(zFile.read(filename)) > > ozFile.close() > Perhaps you want to use zFile.extract() instead of zFile.read()? No, that's not it. Your code should work. You said the output file 'looks encrypted'. Is the source zip file encrypted? Is the source text file something other than plain ASCII? -- 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 steve+comp.lang.python at pearwood.info Fri Apr 19 20:24:22 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Apr 2013 00:24:22 GMT Subject: unzipping a zipx file References: Message-ID: <5171e036$0$29977$c3e8da3$5496439d@news.astraweb.com> On Fri, 19 Apr 2013 17:59:26 +0000, b_erickson1 wrote: > I have python 2.6.2 and I trying to get it to unzip a file made with > winzip pro. The file extension is zipx. This is on a windows machine > where I have to send them all that files necessary to run. I am > packaging this with py2exe. I can open the file with zFile = > zipfile.ZipFile(fullPathName,'r') and I can look through all the file in > the archive for filename in zFile.namelist(): > but when I write the file out with this code: > ozFile = open(filename,'w') > ozFile.write(zFile.read(filename)) > ozFile.close() > that file still looks encrypted. No errors are thrown. The file is > just a text file not a jpeg or anything else. I can open the file with > 7zip and extract the text file out just fine. > > > What am I missing? You are missing that zipx is not the same as zip, and Python very likely does not support the zipx compression algorithm. http://kb.winzip.com/kb/entry/7/ My guess is that the zipx header is similar enough to zip that Python can retrieve the file names, but it cannot decompress the files. Unfortunately, instead of getting a nice error, it is fooled into thinking that it decompressed when in fact you just got junk. I suggest that you start with a simple example: create a plain text file with just a few words. Compress this single file to .zipx, then try to decompress it using Python. If it still fails, you will have a simple example that you could post here and see if others have more success. -- Steven From davea at davea.name Fri Apr 19 21:50:49 2013 From: davea at davea.name (Dave Angel) Date: Fri, 19 Apr 2013 21:50:49 -0400 Subject: unzipping a zipx file In-Reply-To: <5171e036$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <5171e036$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5171F479.9070809@davea.name> On 04/19/2013 08:24 PM, Steven D'Aprano wrote: > > > > You are missing that zipx is not the same as zip, and Python very likely > does not support the zipx compression algorithm. > > http://kb.winzip.com/kb/entry/7/ > > My guess is that the zipx header is similar enough to zip that Python can > retrieve the file names, but it cannot decompress the files. > Unfortunately, instead of getting a nice error, it is fooled into > thinking that it decompressed when in fact you just got junk. > The zip header includes a 32bit CRC for each file. Do you know whether the zip module checks that CRC ? > > I suggest that you start with a simple example: create a plain text file > with just a few words. Compress this single file to .zipx, then try to > decompress it using Python. If it still fails, you will have a simple > example that you could post here and see if others have more success. > > > -- DaveA From davea at davea.name Fri Apr 19 16:29:58 2013 From: davea at davea.name (Dave Angel) Date: Fri, 19 Apr 2013 16:29:58 -0400 Subject: unzipping a zipx file In-Reply-To: References: Message-ID: <5171A946.9090609@davea.name> On 04/19/2013 01:59 PM, b_erickson1 wrote: > I have python 2.6.2 and I trying to get it to unzip a file made with winzip pro. The file extension is zipx. This is on a windows machine where I have to send them all that files necessary to run. I am packaging this with py2exe. I can open the file with > zFile = zipfile.ZipFile(fullPathName,'r') > and I can look through all the file in the archive > for filename in zFile.namelist(): > but when I write the file out with this code: > ozFile = open(filename,'w') > ozFile.write(zFile.read(filename)) > ozFile.close() > that file still looks encrypted. No errors are thrown. The file is just a text file not a jpeg or anything else. I can open the file with 7zip and extract the text file out just fine. > > > What am I missing? > > Thanks > The second parameter to ZipFile() probably should be 'rb' not 'r' Likewise, I'd suggest using 'wb' on the output file, though that's not your problem here. -- DaveA From python.list at tim.thechases.com Fri Apr 19 16:45:49 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 19 Apr 2013 15:45:49 -0500 Subject: unzipping a zipx file In-Reply-To: <5171A946.9090609@davea.name> References: <5171A946.9090609@davea.name> Message-ID: <20130419154549.778004b4@bigbox.christie.dr> On 2013-04-19 16:29, Dave Angel wrote: > > zFile = zipfile.ZipFile(fullPathName,'r') > > The second parameter to ZipFile() probably should be 'rb' not 'r' Just for the record, the zipfile.ZipFile.__init__ maps "r" to open the file with "rb", so that's not the issue. Your suggestion about opening the file to write in binary mode is a good one, but I'd just suggest using ZipFile.extract(...) which is built in and takes care of writing the file for you. :-) -tkc From storchaka at gmail.com Sat Apr 20 11:45:10 2013 From: storchaka at gmail.com (Serhiy Storchaka) Date: Sat, 20 Apr 2013 18:45:10 +0300 Subject: unzipping a zipx file In-Reply-To: References: Message-ID: 19.04.13 20:59, b_erickson1 ???????(??): > I have python 2.6.2 and I trying to get it to unzip a file made with winzip pro. The file extension is zipx. This is on a windows machine where I have to send them all that files necessary to run. I am packaging this with py2exe. I can open the file with > zFile = zipfile.ZipFile(fullPathName,'r') > and I can look through all the file in the archive > for filename in zFile.namelist(): > but when I write the file out with this code: > ozFile = open(filename,'w') > ozFile.write(zFile.read(filename)) > ozFile.close() > that file still looks encrypted. AFAIK some archivers use zipx extension for zip files which contains files compressed with advanced compression methods (bzip2, lzma, etc). Python supports bzip2 and lzma compression in zip files since 3.3. > No errors are thrown. Python 2.7 and 3.2 should raise an exception (this bug was fixed several months ago). 2.6 is too old and this fix was not backported to it. > What am I missing? Use Python 3.3 or at least 2.7. From lionelgreenstreet at gmail.com Fri Apr 19 14:56:15 2013 From: lionelgreenstreet at gmail.com (lionelgreenstreet at gmail.com) Date: Fri, 19 Apr 2013 11:56:15 -0700 (PDT) Subject: Toolbar and PyQT Message-ID: <4a7de822-70df-4ae3-8243-5ce728f20d34@googlegroups.com> Hi, i'm new with python, so i need an help about this problem. I've implemented a toolbar in a QDialog box: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar ..... self.toolbar = NavigationToolbar(self.canvas, self) I've found this code on internet. I have two question: 1. How i can set that toolbar (if possible) with QtDesigner? 2. If i want to modify that toolbar, for example adding a function during axis settings, is it possible? Thanks From pydev at hotmail.com Sat Apr 20 01:37:39 2013 From: pydev at hotmail.com (Fabian PyDEV) Date: Sat, 20 Apr 2013 00:37:39 -0500 Subject: Different cache filename Message-ID: Hi, when load a module "mymodule.py" with importlib.machinery.SourceFileLoader a bytecode file is created as mymodule.cpython-33.pyc. If I load a module "mymodule.ext.py" the same way the same bytecode file is created as mymodule.cpython-33.pyc. Is there any way I could tell python to generate the bycode file as mymodule.ext.cpython-33.pyc? Regards, Fabian From davea at davea.name Sat Apr 20 07:09:18 2013 From: davea at davea.name (Dave Angel) Date: Sat, 20 Apr 2013 07:09:18 -0400 Subject: Different cache filename In-Reply-To: References: Message-ID: <5172775E.1000805@davea.name> On 04/20/2013 01:37 AM, Fabian PyDEV wrote: > Hi, > > when load a module "mymodule.py" with importlib.machinery.SourceFileLoader a bytecode file is created as mymodule.cpython-33.pyc. > > If I load a module "mymodule.ext.py" the same way the same bytecode file is created as mymodule.cpython-33.pyc. > > Is there any way I could tell python to generate the bycode file as mymodule.ext.cpython-33.pyc? > > Regards, > Fabian > Rename the source file to a legal one, such as: mymodule_ext.py and you won't have the problem. Period is not a valid character within a Python identifier. -- DaveA From asweigart at gmail.com Sat Apr 20 02:37:05 2013 From: asweigart at gmail.com (asweigart at gmail.com) Date: Fri, 19 Apr 2013 23:37:05 -0700 (PDT) Subject: Free book, "Hacking Secret Ciphers with Python" Message-ID: <4eb75135-ebaa-43ed-b7a0-7e8208a243e1@googlegroups.com> I've released my third book, "Hacking Secret Ciphers with Python" for free under a Creative Commons license. This book is aimed at people who have no experience programming or with cryptography. The book goes through writing Python programs that not only implement several ciphers but also can hack these ciphers. Each chapter presents a new program and explains how the source code works. You can download the book from http://inventwithpython.com/hacking 100% of the proceeds from the book sales will be donated to the Electronic Frontier Foundation, Creative Commons, and The Tor Project. From kliateni at gmail.com Sat Apr 20 06:12:50 2013 From: kliateni at gmail.com (Karim) Date: Sat, 20 Apr 2013 12:12:50 +0200 Subject: Free book, "Hacking Secret Ciphers with Python" In-Reply-To: <4eb75135-ebaa-43ed-b7a0-7e8208a243e1@googlegroups.com> References: <4eb75135-ebaa-43ed-b7a0-7e8208a243e1@googlegroups.com> Message-ID: <51726A22.7020508@gmail.com> On 20/04/2013 08:37, asweigart at gmail.com wrote: > I've released my third book, "Hacking Secret Ciphers with Python" for free under a Creative Commons license. This book is aimed at people who have no experience programming or with cryptography. The book goes through writing Python programs that not only implement several ciphers but also can hack these ciphers. Each chapter presents a new program and explains how the source code works. > > You can download the book from http://inventwithpython.com/hacking > > 100% of the proceeds from the book sales will be donated to the Electronic Frontier Foundation, Creative Commons, and The Tor Project. Very good book! 1000 Thanks for your unvaluable work. By the way who is Aaron? Karim France From jsf80238 at gmail.com Sat Apr 20 13:09:42 2013 From: jsf80238 at gmail.com (Jason Friedman) Date: Sat, 20 Apr 2013 11:09:42 -0600 Subject: itertools.groupby Message-ID: I have a file such as: $ cat my_data Starting a new group a b c Starting a new group 1 2 3 4 Starting a new group X Y Z Starting a new group I am wanting a list of lists: ['a', 'b', 'c'] ['1', '2', '3', '4'] ['X', 'Y', 'Z'] [] I wrote this: ------------------------------------ #!/usr/bin/python3 from itertools import groupby def get_lines_from_file(file_name): with open(file_name) as reader: for line in reader.readlines(): yield(line.strip()) counter = 0 def key_func(x): if x.startswith("Starting a new group"): global counter counter += 1 return counter for key, group in groupby(get_lines_from_file("my_data"), key_func): print(list(group)[1:]) ------------------------------------ I get the output I desire, but I'm wondering if there is a solution without the global counter. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ned at nedbatchelder.com Sat Apr 20 13:27:18 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 20 Apr 2013 13:27:18 -0400 Subject: itertools.groupby In-Reply-To: References: Message-ID: <5172CFF6.8040902@nedbatchelder.com> On 4/20/2013 1:09 PM, Jason Friedman wrote: > I have a file such as: > > $ cat my_data > Starting a new group > a > b > c > Starting a new group > 1 > 2 > 3 > 4 > Starting a new group > X > Y > Z > Starting a new group > > I am wanting a list of lists: > ['a', 'b', 'c'] > ['1', '2', '3', '4'] > ['X', 'Y', 'Z'] > [] > > I wrote this: > ------------------------------------ > #!/usr/bin/python3 > from itertools import groupby > > def get_lines_from_file(file_name): > with open(file_name) as reader: > for line in reader.readlines(): > yield(line.strip()) > > counter = 0 > def key_func(x): > if x.startswith("Starting a new group"): > global counter > counter += 1 > return counter > > for key, group in groupby(get_lines_from_file("my_data"), key_func): > print(list(group)[1:]) > ------------------------------------ > > I get the output I desire, but I'm wondering if there is a solution > without the global counter. > > > def separate_on(lines, separator): group = None for line in lines: if line.strip() == separator: if group is not None: yield group group = [] else: assert group is not None # Should have gotten a separator first group.append(line) yield group with open("my_data") as my_data: for group in separate_on(my_data, "Starting a new group"): print group The handling of the first separator line feels delicate to me, but this provides the output you want. --Ned. -------------- next part -------------- An HTML attachment was scrubbed... URL: From wolfgang.maier at biologie.uni-freiburg.de Sat Apr 20 17:14:48 2013 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Sat, 20 Apr 2013 21:14:48 +0000 (UTC) Subject: itertools.groupby References: Message-ID: Jason Friedman gmail.com> writes: > > I have a file such as: > > $ cat my_data? > Starting a new group > > a > b > c > Starting a new group > 1 > 2 > 3 > > 4 > Starting a new group > X > Y > Z > Starting a new group > > > I am wanting a list of lists: > ['a', 'b', 'c'] > > ['1', '2', '3', '4'] > ['X', 'Y', 'Z'] > [] > > I wrote this: > > ------------------------------------ > #!/usr/bin/python3 > from itertools import groupby > > def get_lines_from_file(file_name): > ? ? with open(file_name) as reader: > ? ? ? ? for line in reader.readlines(): > ? ? ? ? ? ? yield(line.strip()) > > counter = 0 > def key_func(x): > ? ? if x.startswith("Starting a new group"): > ? ? ? ? global counter > ? ? ? ? counter += 1 > ? ? return counter > > for key, group in groupby(get_lines_from_file("my_data"), key_func): > ? ? print(list(group)[1:]) > ------------------------------------ > > > > > I get the output I desire, but I'm wondering if there is a solution without the global counter. > Here's a solution that makes use of groupby (which is a good idea I think), but avoids the counter (actually this is trivial; you just return the result of startswith directly). It also provides you with the rest of the separator line (you're using startswith in your code, so I figured you expect more on these lines). I replaced the startswith() with slicing though as this is usually faster. def separate_on(iterable, separator): sep_len=len(separator) grouped_iter = (x[1] for x in groupby(iterable, lambda line: line[:sep_len] == separator)) for separator_line in grouped_iter: rest_of_separator_line = next(separator_line)[sep_len:].strip() yield (rest_of_separator_line, [s.strip() for s in next(grouped_iter)]) then for sep_tail, group in separate_on(your_input,your_separator): do_what_ever() Hope it's what you want, Wolfgang From steve+comp.lang.python at pearwood.info Sat Apr 20 20:13:27 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Apr 2013 00:13:27 GMT Subject: itertools.groupby References: Message-ID: <51732f27$0$29977$c3e8da3$5496439d@news.astraweb.com> On Sat, 20 Apr 2013 11:09:42 -0600, Jason Friedman wrote: > I have a file such as: > > $ cat my_data > Starting a new group > a > b > c > Starting a new group > 1 > 2 > 3 > 4 > Starting a new group > X > Y > Z > Starting a new group > > I am wanting a list of lists: > ['a', 'b', 'c'] > ['1', '2', '3', '4'] > ['X', 'Y', 'Z'] > [] > > I wrote this: [...] > I get the output I desire, but I'm wondering if there is a solution > without the global counter. I wouldn't use groupby. It's a hammer, not every grouping job is a nail. Instead, use a simple accumulator: def group(lines): accum = [] for line in lines: line = line.strip() if line == 'Starting a new group': if accum: # Don't bother if there are no accumulated lines. yield accum accum = [] else: accum.append(line) # Don't forget the last group of lines. if accum: yield accum -- Steven From joshua.landau.ws at gmail.com Sun Apr 21 23:09:04 2013 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Mon, 22 Apr 2013 04:09:04 +0100 Subject: itertools.groupby In-Reply-To: <51732f27$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <51732f27$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 21 April 2013 01:13, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > I wouldn't use groupby. It's a hammer, not every grouping job is a nail. > > Instead, use a simple accumulator: > > > def group(lines): > accum = [] > for line in lines: > line = line.strip() > if line == 'Starting a new group': > if accum: # Don't bother if there are no accumulated lines. > yield accum > accum = [] > else: > accum.append(line) > # Don't forget the last group of lines. > if accum: yield accum > Whilst yours is the simplest bar Dennis Lee Bieber's and nicer in that it yields, neither of yours work for empty groups properly. I recommend the simple change: def group(lines): accum = None for line in lines: line = line.strip() if line == 'Starting a new group': if accum is not None: # Don't bother if there are no accumulated lines. yield accum accum = [] else: accum.append(line) # Don't forget the last group of lines. yield accum But will recommend my own small twist (because I think it is clever): def group(lines): lines = (line.strip() for line in lines) if next(lines) != "Starting a new group": raise ValueError("First line must be 'Starting a new group'") while True: acum = [] for line in lines: if line == "Starting a new group": break acum.append(line) else: yield acum break yield acum -------------- next part -------------- An HTML attachment was scrubbed... URL: From neilc at norwich.edu Mon Apr 22 10:24:11 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 22 Apr 2013 14:24:11 GMT Subject: itertools.groupby References: Message-ID: On 2013-04-20, Jason Friedman wrote: > I have a file such as: > > $ cat my_data > Starting a new group > a > b > c > Starting a new group > 1 > 2 > 3 > 4 > Starting a new group > X > Y > Z > Starting a new group > > I am wanting a list of lists: > ['a', 'b', 'c'] > ['1', '2', '3', '4'] > ['X', 'Y', 'Z'] > [] Hrmmm, hoomm. Nobody cares for slicing any more. def headered_groups(lst, header): b = lst.index(header) + 1 while True: try: e = lst.index(header, b) except ValueError: yield lst[b:] break yield lst[b:e] b = e+1 for group in headered_groups([line.strip() for line in open('data.txt')], "Starting a new group"): print(group) -- Neil Cerutti From oscar.j.benjamin at gmail.com Mon Apr 22 10:49:49 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 22 Apr 2013 15:49:49 +0100 Subject: itertools.groupby In-Reply-To: References: Message-ID: On 22 April 2013 15:24, Neil Cerutti wrote: > > Hrmmm, hoomm. Nobody cares for slicing any more. > > def headered_groups(lst, header): > b = lst.index(header) + 1 > while True: > try: > e = lst.index(header, b) > except ValueError: > yield lst[b:] > break > yield lst[b:e] > b = e+1 This requires the whole file to be read into memory. Iterators are typically preferred over list slicing for sequential text file access since you can avoid loading the whole file at once. This means that you can process a large file while only using a constant amount of memory. > > for group in headered_groups([line.strip() for line in open('data.txt')], > "Starting a new group"): > print(group) The list comprehension above loads the entire file into memory. Assuming that .strip() is just being used to remove the newline at the end it would be better to just use the readlines() method since that loads everything into memory and removes the newlines. To remove them without reading everything you can use map (or imap in Python 2): with open('data.txt') as inputfile: for group in headered_groups(map(str.strip, inputfile)): print(group) Oscar From rosuav at gmail.com Mon Apr 22 11:14:39 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Apr 2013 01:14:39 +1000 Subject: itertools.groupby In-Reply-To: References: Message-ID: On Tue, Apr 23, 2013 at 12:49 AM, Oscar Benjamin wrote: > Iterators are > typically preferred over list slicing for sequential text file access > since you can avoid loading the whole file at once. This means that > you can process a large file while only using a constant amount of > memory. And, perhaps even more importantly, allows you to pipe text in and out. Obviously some operations (eg grep) lend themselves better to this than do others (eg sort), but with this it ought at least to output each group as it comes. ChrisA From neilc at norwich.edu Mon Apr 22 11:04:52 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 22 Apr 2013 15:04:52 GMT Subject: itertools.groupby References: Message-ID: On 2013-04-22, Oscar Benjamin wrote: > On 22 April 2013 15:24, Neil Cerutti wrote: >> >> Hrmmm, hoomm. Nobody cares for slicing any more. >> >> def headered_groups(lst, header): >> b = lst.index(header) + 1 >> while True: >> try: >> e = lst.index(header, b) >> except ValueError: >> yield lst[b:] >> break >> yield lst[b:e] >> b = e+1 > > This requires the whole file to be read into memory. Iterators > are typically preferred over list slicing for sequential text > file access since you can avoid loading the whole file at once. > This means that you can process a large file while only using a > constant amount of memory. I agree, but this application processes unknowns-sized slices, you have to build lists anyhow. I find slicing much more convenient than accumulating in this case, but it's possibly a tradeoff. > with open('data.txt') as inputfile: > for group in headered_groups(map(str.strip, inputfile)): > print(group) Thanks, that's a nice improvement. -- Neil Cerutti From __peter__ at web.de Sun Apr 21 04:28:12 2013 From: __peter__ at web.de (Peter Otten) Date: Sun, 21 Apr 2013 10:28:12 +0200 Subject: itertools.groupby References: Message-ID: Jason Friedman wrote: > I have a file such as: > > $ cat my_data > Starting a new group > a > b > c > Starting a new group > 1 > 2 > 3 > 4 > Starting a new group > X > Y > Z > Starting a new group > > I am wanting a list of lists: > ['a', 'b', 'c'] > ['1', '2', '3', '4'] > ['X', 'Y', 'Z'] > [] > > I wrote this: > ------------------------------------ > #!/usr/bin/python3 > from itertools import groupby > > def get_lines_from_file(file_name): > with open(file_name) as reader: > for line in reader.readlines(): readlines() slurps the whole file into memory! Don't do that, iterate over the file directly instead: for line in reader: > yield(line.strip()) > > counter = 0 > def key_func(x): > if x.startswith("Starting a new group"): > global counter > counter += 1 > return counter > > for key, group in groupby(get_lines_from_file("my_data"), key_func): > print(list(group)[1:]) > ------------------------------------ > > I get the output I desire, but I'm wondering if there is a solution > without the global counter. If you were to drop the empty groups you could simplify it to def is_header(line): return line.startswith("Starting a new group") with open("my_data") as lines: stripped_lines = (line.strip() for line in lines) for header, group in itertools.groupby(stripped_lines, key=is_header): if not header: print(list(group)) And here's a refactoring for your initial code. The main point is the use of nonlocal instead of global state to make the function reentrant. def split_groups(items, header): odd = True def group_key(item): nonlocal odd if header(item): odd = not odd return odd for _key, group in itertools.groupby(items, key=group_key): yield itertools.islice(group, 1, None) def is_header(line): return line.startswith("Starting a new group") with open("my_data") as lines: stripped_lines = map(str.strip, lines) for group in split_groups(stripped_lines, header=is_header): print(list(group)) One remaining problem with that code is that it will silently drop the first line of the file if it doesn't start with a header: $ cat my_data alpha beta gamma Starting a new group a b c Starting a new group Starting a new group 1 2 3 4 Starting a new group X Y Z Starting a new group $ python3 group.py ['beta', 'gamma'] # where's alpha? ['a', 'b', 'c'] [] ['1', '2', '3', '4'] ['X', 'Y', 'Z'] [] How do you want to handle that case? From jsf80238 at gmail.com Sun Apr 21 12:44:44 2013 From: jsf80238 at gmail.com (Jason Friedman) Date: Sun, 21 Apr 2013 10:44:44 -0600 Subject: itertools.groupby In-Reply-To: References: Message-ID: #!/usr/bin/python3 > from itertools import groupby > > def get_lines_from_file(file_name): > with open(file_name) as reader: > for line in reader.readlines(): > yield(line.strip()) > > counter = 0 > def key_func(x): > if x.startswith("Starting a new group"): > global counter > counter += 1 > return counter > > for key, group in groupby(get_lines_from_file("my_data"), key_func): > print(list(group)[1:]) > > Thank you for the responses! Not sure yet which one I will pick. -------------- next part -------------- An HTML attachment was scrubbed... URL: From wolfgang.maier at biologie.uni-freiburg.de Mon Apr 22 09:17:43 2013 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Mon, 22 Apr 2013 13:17:43 +0000 (UTC) Subject: itertools.groupby References: Message-ID: Jason Friedman gmail.com> writes: > > Thank you for the responses! ?Not sure yet which one I will pick. > Hi again, I was working a bit on my own solution and on the one from Steven/Joshua, and maybe that helps you deciding: def separate_on(iterable, separator): # based on groupby sep_len=len(separator) for is_header, item in groupby(iterable, lambda line: line[:sep_len] == separator): if is_header: header_tails = [h[sep_len:].strip() for h in item] for naked_header in header_tails[:-1]: yield (naked_header,[]) header_tail = header_tails[-1] else: try: yield (header_tail, [s.strip() for s in item]) except UnboundLocalError: yield (None, [s.strip() for s in item]) def group(iterable, separator): # Steven's/Joshua's rewritten sep_len = len(separator) accum = None header = None for item in iterable: item = item.strip() if item[:sep_len] == separator: if accum is not None: # Don't bother if there are no accumulated lines. yield (header, accum) header = item[sep_len:] accum = [] else: try: accum.append(item) except AttributeError: accum = [item] # Don't forget the last group of lines. yield (header, accum) Both versions behave as follows: - any line that *starts* with the separator is treated as a header line. The tail of that line is returned as the groups title in a tuple with the group's content, i.e. (header, [body]). If there's only the separator, the title is ''. I find this a more useful behaviour as it allows things like: ##Group1 elem1 elem2 elem3 ##Group2 a b c ... - if there are headers without body, they are reported as (header, []). - if the first body has no header, that's reported as (None, [body]). Advantages & Disadvantages of either form: Steven's/Joshua's: simple and fast it's more readable I'd say, and for small groups the groupby implementation is about 1.5x slower than this one. The groupby version catches up with increasing group sizes (because it uses comprehensions instead of list.append I think), but it only wins with groups of ~1000 elements. the groupby implementation: more flexible its yield statement deliberately returns a list of the elements, but before that you just have an iterator, which you could just as well turn into a tuple, set, string or anything without constructing the list in memory. So in terms of code recycling this might be preferable. Cheers, Wolfgang From wxjmfauth at gmail.com Sat Apr 20 13:12:43 2013 From: wxjmfauth at gmail.com (jmfauth) Date: Sat, 20 Apr 2013 10:12:43 -0700 (PDT) Subject: Is Unicode support so hard... Message-ID: In a previous post, http://groups.google.com/group/comp.lang.python/browse_thread/thread/6aec70817705c226# , Chris ?Kwpolska? Warrick wrote: ?Is Unicode support so hard, especially in the 21st century?? -- Unicode is not really complicate and it works very well (more than two decades of development if you take into account iso-14****). But, - I can say, "as usual" - people prefer to spend their time to make a "better Unicode than Unicode" and it usually fails. Python does not escape to this rule. ----- I'm "busy" with TeX (unicode engine variant), fonts and typography. This gives me plenty of ideas to test the "flexible string representation" (FSR). I should recognize this FSR is failing particulary very well... I can almost say, a delight. jmf Unicode lover From ned at nedbatchelder.com Sat Apr 20 13:22:44 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 20 Apr 2013 13:22:44 -0400 Subject: Is Unicode support so hard... In-Reply-To: References: Message-ID: <5172CEE4.9070403@nedbatchelder.com> On 4/20/2013 1:12 PM, jmfauth wrote: > In a previous post, > > http://groups.google.com/group/comp.lang.python/browse_thread/thread/6aec70817705c226# > , > > Chris ?Kwpolska? Warrick wrote: > > ?Is Unicode support so hard, especially in the 21st century?? > > -- > > Unicode is not really complicate and it works very well (more > than two decades of development if you take into account > iso-14****). > > But, - I can say, "as usual" - people prefer to spend their > time to make a "better Unicode than Unicode" and it usually > fails. Python does not escape to this rule. > > ----- > > I'm "busy" with TeX (unicode engine variant), fonts and typography. > This gives me plenty of ideas to test the "flexible string > representation" (FSR). I should recognize this FSR is failing > particulary very well... > > I can almost say, a delight. > > jmf > Unicode lover I'm totally confused about what you are saying. What does "make a better Unicode than Unicode" mean? Are you saying that Python is guilty of this? In what way? Can you provide specifics? Or are you saying that you like how Python has implemented it? "FSR is failing ... a delight"? I don't know what you mean. --Ned. From benjamin.kaplan at case.edu Sat Apr 20 14:02:54 2013 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 20 Apr 2013 11:02:54 -0700 Subject: Is Unicode support so hard... In-Reply-To: <5172CEE4.9070403@nedbatchelder.com> References: <5172CEE4.9070403@nedbatchelder.com> Message-ID: On Sat, Apr 20, 2013 at 10:22 AM, Ned Batchelder wrote: > On 4/20/2013 1:12 PM, jmfauth wrote: >> >> In a previous post, >> >> >> http://groups.google.com/group/comp.lang.python/browse_thread/thread/6aec70817705c226# >> , >> >> Chris ?Kwpolska? Warrick wrote: >> >> ?Is Unicode support so hard, especially in the 21st century?? >> >> -- >> >> Unicode is not really complicate and it works very well (more >> than two decades of development if you take into account >> iso-14****). >> >> But, - I can say, "as usual" - people prefer to spend their >> time to make a "better Unicode than Unicode" and it usually >> fails. Python does not escape to this rule. >> >> ----- >> >> I'm "busy" with TeX (unicode engine variant), fonts and typography. >> This gives me plenty of ideas to test the "flexible string >> representation" (FSR). I should recognize this FSR is failing >> particulary very well... >> >> I can almost say, a delight. >> >> jmf >> Unicode lover > > I'm totally confused about what you are saying. What does "make a better > Unicode than Unicode" mean? Are you saying that Python is guilty of this? > In what way? Can you provide specifics? Or are you saying that you like > how Python has implemented it? "FSR is failing ... a delight"? I don't > know what you mean. > > --Ned. Don't bother trying to figure this out. jmfauth has been hijacking every thread that mentions Unicode to complain about the flexible string representation introduced in Python 3.3. Apparently, having proper Unicode semantics (indexing is based on characters, not code points) at the expense of performance when calling .replace on the only non-ASCII or BMP character in the string is a horrible bug. From kwpolska at gmail.com Sat Apr 20 14:15:07 2013 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Sat, 20 Apr 2013 20:15:07 +0200 Subject: Is Unicode support so hard... In-Reply-To: References: <5172CEE4.9070403@nedbatchelder.com> Message-ID: On Sat, Apr 20, 2013 at 8:02 PM, Benjamin Kaplan wrote: > On Sat, Apr 20, 2013 at 10:22 AM, Ned Batchelder wrote: >> On 4/20/2013 1:12 PM, jmfauth wrote: >>> >>> In a previous post, >>> >>> >>> http://groups.google.com/group/comp.lang.python/browse_thread/thread/6aec70817705c226# >>> , >>> >>> Chris ?Kwpolska? Warrick wrote: >>> >>> ?Is Unicode support so hard, especially in the 21st century?? >>> >>> -- >>> >>> Unicode is not really complicate and it works very well (more >>> than two decades of development if you take into account >>> iso-14****). >>> >>> But, - I can say, "as usual" - people prefer to spend their >>> time to make a "better Unicode than Unicode" and it usually >>> fails. Python does not escape to this rule. >>> >>> ----- >>> >>> I'm "busy" with TeX (unicode engine variant), fonts and typography. >>> This gives me plenty of ideas to test the "flexible string >>> representation" (FSR). I should recognize this FSR is failing >>> particulary very well... >>> >>> I can almost say, a delight. >>> >>> jmf >>> Unicode lover >> >> I'm totally confused about what you are saying. What does "make a better >> Unicode than Unicode" mean? Are you saying that Python is guilty of this? >> In what way? Can you provide specifics? Or are you saying that you like >> how Python has implemented it? "FSR is failing ... a delight"? I don't >> know what you mean. >> >> --Ned. > > Don't bother trying to figure this out. jmfauth has been hijacking > every thread that mentions Unicode to complain about the flexible > string representation introduced in Python 3.3. Apparently, having > proper Unicode semantics (indexing is based on characters, not code > points) at the expense of performance when calling .replace on the > only non-ASCII or BMP character in the string is a horrible bug. > -- > http://mail.python.org/mailman/listinfo/python-list Don?t forget the original context: this was a short remark to a guy I was responding to. His newsgroups software (slrn according to the headers) mangled the encoding of U+201C and U+201D in my From field, turning them into three question marks each. And jmf started a rant, as usual? PS. There are two fancy Unicode characters around. Can you find both of them, jmf? -- Kwpolska | GPG KEY: 5EAAEA16 stop html mail | always bottom-post http://asciiribbon.org | http://caliburn.nl/topposting.html From breamoreboy at yahoo.co.uk Sat Apr 20 14:18:04 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 20 Apr 2013 19:18:04 +0100 Subject: Is Unicode support so hard... In-Reply-To: References: <5172CEE4.9070403@nedbatchelder.com> Message-ID: On 20/04/2013 19:02, Benjamin Kaplan wrote: > On Sat, Apr 20, 2013 at 10:22 AM, Ned Batchelder wrote: >> On 4/20/2013 1:12 PM, jmfauth wrote: >>> >>> In a previous post, >>> >>> >>> http://groups.google.com/group/comp.lang.python/browse_thread/thread/6aec70817705c226# >>> , >>> >>> Chris ?Kwpolska? Warrick wrote: >>> >>> ?Is Unicode support so hard, especially in the 21st century?? >>> >>> -- >>> >>> Unicode is not really complicate and it works very well (more >>> than two decades of development if you take into account >>> iso-14****). >>> >>> But, - I can say, "as usual" - people prefer to spend their >>> time to make a "better Unicode than Unicode" and it usually >>> fails. Python does not escape to this rule. >>> >>> ----- >>> >>> I'm "busy" with TeX (unicode engine variant), fonts and typography. >>> This gives me plenty of ideas to test the "flexible string >>> representation" (FSR). I should recognize this FSR is failing >>> particulary very well... >>> >>> I can almost say, a delight. >>> >>> jmf >>> Unicode lover >> >> I'm totally confused about what you are saying. What does "make a better >> Unicode than Unicode" mean? Are you saying that Python is guilty of this? >> In what way? Can you provide specifics? Or are you saying that you like >> how Python has implemented it? "FSR is failing ... a delight"? I don't >> know what you mean. >> >> --Ned. > > Don't bother trying to figure this out. jmfauth has been hijacking > every thread that mentions Unicode to complain about the flexible > string representation introduced in Python 3.3. Apparently, having > proper Unicode semantics (indexing is based on characters, not code > points) at the expense of performance when calling .replace on the > only non-ASCII or BMP character in the string is a horrible bug. > He can't complain about performance for the .replace issue any more as it's been fixed http://bugs.python.org/issue16061 Sadly he'll almost certainly have more edge cases up his sleeve while continuing to ignore minor issues like memory saving and correctness. -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From rosuav at gmail.com Sat Apr 20 14:14:50 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 21 Apr 2013 04:14:50 +1000 Subject: Is Unicode support so hard... In-Reply-To: <5172CEE4.9070403@nedbatchelder.com> References: <5172CEE4.9070403@nedbatchelder.com> Message-ID: On Sun, Apr 21, 2013 at 3:22 AM, Ned Batchelder wrote: > I'm totally confused about what you are saying. What does "make a better > Unicode than Unicode" mean? Are you saying that Python is guilty of this? > In what way? Can you provide specifics? Or are you saying that you like > how Python has implemented it? "FSR is failing ... a delight"? I don't > know what you mean. You're not familiar with jmf? He's one of our resident trolls. Allow me to summarize Python 3's Unicode support... >From 3.0 up to and including 3.2.x, Python could be built as either "narrow" or "wide". A wide build consumes four bytes per character in every string, which is rather wasteful (given that very few strings actually NEED that); a narrow build gets some things wrong. (I'm using a 2.7 here as I don't have a narrow-build 3.x handy; the same considerations apply, though.) Python 2.7.4 (default, Apr 6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> len(u"asdf\U00012345qwer") 10 >>> u"asdf\U00012345qwer"[8] u'e' In a narrow build, strings are stored in UTF-16, so astral characters count as two. This means that a program will behave unexpectedly differently on different platforms (other languages, such as ECMAScript, actually *mandate* UTF-16; at least this means you can depend on this otherwise-bizarre behaviour regardless of what platform you're on), and I have to say this is counter-intuitive. Enter Python 3.3 and PEP 393 strings. Now *EVERY* Python build is, conceptually, wide. (I'm not sure how PEP 393 applies to other Pythons - Jython, PyPy, etc - so assume that whenever I refer to Python, I'm restricting this to CPython.) The underlying representation might be more efficient, but to the script, it's exactly the same as a wide build. If a string has no characters that demand more width, it'll be stored nice and narrow. (It's the same technique that Pike has been using for a while, so it's a proven system; in any case, we know that this is going to work, it's just a question of performance - it adds a fixed overhead.) Great! We save memory in Python programs. Wonderful! Right? Enter jmf. No, it's not wonderful, because OBVIOUSLY Python is now America-centric, because now the full Unicode range is divided into "these ones get stored in 1 byte per char, these in 2, these in 4". Clearly that's making life way worse for everyone else. Also, compared to the narrow build that jmf was previously using, this uses heaps MORE space in the stupid micro-benchmarks that he keeps on trotting out, because he has just one astral character in a sea of ASCII. And that's totally what programs are doing all the time, too. Never mind that basic operations like length, slicing, etc are no longer buggy, no, Python has taken a terrible step backwards here. Oh, and check this out: >>> def munge(s): """Move characters around in a string.""" l=len(s)//4 return s[:l]+s[l*2:l*3]+s[l:l*2]+s[l*3:] >>> munge("asdfqwerzxcv1234") 'asdfzxcvqwer1234' Looks fine. >>> munge(u"asd\U00012345we\U00034567xc\U00023456bla") u'asd\U00012167xc\U00023745we\U00034456bla' Where'd those characters come from? I was just moving stuff around, right? I can't get new characters out of it... can I? Flash forward to current date, and jmf has hijacked so many threads to moan about PEP 393 that I'm actually happy about this one, simply because he gave it a new subject line and one appropriate to a discussion about Unicode. ChrisA From ethan at stoneleaf.us Sat Apr 20 21:06:50 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 20 Apr 2013 18:06:50 -0700 Subject: Is Unicode support so hard... In-Reply-To: References: <5172CEE4.9070403@nedbatchelder.com> Message-ID: <51733BAA.6010107@stoneleaf.us> On 04/20/2013 11:14 AM, Chris Angelico wrote: > Flash forward to current date, and jmf has hijacked so many threads to > moan about PEP 393 that I'm actually happy about this one, simply > because he gave it a new subject line and one appropriate to a > discussion about Unicode. +1000 From nhodgson at iinet.net.au Sat Apr 20 19:03:08 2013 From: nhodgson at iinet.net.au (Neil Hodgson) Date: Sun, 21 Apr 2013 09:03:08 +1000 Subject: Is Unicode support so hard... In-Reply-To: References: Message-ID: <0vKdnXSde-E8gu7MnZ2dnUVZ_sidnZ2d@westnet.com.au> Hi jmf, > This gives me plenty of ideas to test the "flexible string > representation" (FSR). I should recognize this FSR is failing > particulary very well... This is too vague for me. Which string representation should Python use? 1) UTF-32 2) UTF-8 3) Python 3.3 -- 1, 2, or 4 bytes per character decided at runtime 4) Python 3.2 -- 2 or 4 bytes per character decided at Python build time 5) Something else Neil From rustompmody at gmail.com Sat Apr 20 21:37:00 2013 From: rustompmody at gmail.com (rusi) Date: Sat, 20 Apr 2013 18:37:00 -0700 (PDT) Subject: Is Unicode support so hard... References: <0vKdnXSde-E8gu7MnZ2dnUVZ_sidnZ2d@westnet.com.au> Message-ID: <7be0ad7b-bc35-4ea2-aa16-b9af535b455e@ys5g2000pbc.googlegroups.com> On Apr 21, 4:03?am, Neil Hodgson wrote: > ? ? Hi jmf, > > > This gives me plenty of ideas to test the "flexible string > > representation" (FSR). I should recognize this FSR is failing > > particulary very well... > > ? ? This is too vague for me. > > ? ? Which string representation should Python use? > 1) UTF-32 > 2) UTF-8 > 3) Python 3.3 -- 1, 2, or 4 bytes per character decided at runtime > 4) Python 3.2 -- 2 or 4 bytes per character decided at Python build time > 5) Something else jmf recommends UTF-8. Apart from the fact the UTF-8 would be less (time) performant in all cases and more extremely so in cases like indexing, the fact that jmf says so makes it more ridiculous. According to jmf python sucks up to ASCII (those big bad Americans? of whom Steven is the first?) whereas unicode is the true international/ universal standard. I guess the irony is clear to all (except jmf) given that: - its unicode that sucks up to ASCII by carefully conforming in the first 127 positions including the completely useless control chars; python just implements the standard - UTF-8 is an ASCII-biased unicode-compression method viz UTF-8 is most space-efficient on ASCII at the cost of being generally time- inefficient - All jmf's beefs (as far as I remember) are variations on the theme: "time-inefficiency is equivalent to non-unicode-compliant" In short he manifests a dog-in-the-manger mindset: "Since the whole world will never speak french (grief, mope, grumble, thrash?) everyone should pay for the Chinese character set's size even if they are monolingually English" All that said? I believe that the recent correction in unicode performance followed jmf's grumbles (Mark please correct me if I am wrong) So python community can be thankful to jmf even if he insists on laboring under bizarre political hallucinations. [Written from India where a monolingual person is as rare as a palmtree on a polecap] From steve+comp.lang.python at pearwood.info Sat Apr 20 23:36:57 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Apr 2013 03:36:57 GMT Subject: Is Unicode support so hard... References: <0vKdnXSde-E8gu7MnZ2dnUVZ_sidnZ2d@westnet.com.au> <7be0ad7b-bc35-4ea2-aa16-b9af535b455e@ys5g2000pbc.googlegroups.com> Message-ID: <51735ed9$0$29977$c3e8da3$5496439d@news.astraweb.com> On Sat, 20 Apr 2013 18:37:00 -0700, rusi wrote: > According to jmf python sucks up to ASCII (those big bad Americans? of > whom Steven is the first?) Watch who you're calling an American, mate. -- Steven From rosuav at gmail.com Sat Apr 20 23:42:40 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 21 Apr 2013 13:42:40 +1000 Subject: Is Unicode support so hard... In-Reply-To: <51735ed9$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <0vKdnXSde-E8gu7MnZ2dnUVZ_sidnZ2d@westnet.com.au> <7be0ad7b-bc35-4ea2-aa16-b9af535b455e@ys5g2000pbc.googlegroups.com> <51735ed9$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Apr 21, 2013 at 1:36 PM, Steven D'Aprano wrote: > On Sat, 20 Apr 2013 18:37:00 -0700, rusi wrote: > >> According to jmf python sucks up to ASCII (those big bad Americans? of >> whom Steven is the first?) > > Watch who you're calling an American, mate. I think he knows, and that's why he said it. You and I are foremost among Americans who are destroying Python. ChrisA From tjreedy at udel.edu Sun Apr 21 05:02:32 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Sun, 21 Apr 2013 05:02:32 -0400 Subject: Is Unicode support so hard... In-Reply-To: <7be0ad7b-bc35-4ea2-aa16-b9af535b455e@ys5g2000pbc.googlegroups.com> References: <0vKdnXSde-E8gu7MnZ2dnUVZ_sidnZ2d@westnet.com.au> <7be0ad7b-bc35-4ea2-aa16-b9af535b455e@ys5g2000pbc.googlegroups.com> Message-ID: On 4/20/2013 9:37 PM, rusi wrote: > I believe that the recent correction in unicode performance followed > jmf's grumbles No, the correction followed upon his accurate report of a regression, last August, which was unfortunately mixed in with grumbles and inaccurate claims. Others separated out and verified the accurate report. I reported it to pydev and enquired as to its necessity, I believe Mark opened the tracker issue, and the two people who worked on optimizing 3.3 a year ago fairly quickly came up with two different patches. The several month delay after was a matter of testing and picking the best approach. From breamoreboy at yahoo.co.uk Sun Apr 21 08:03:48 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 21 Apr 2013 13:03:48 +0100 Subject: Is Unicode support so hard... In-Reply-To: References: <0vKdnXSde-E8gu7MnZ2dnUVZ_sidnZ2d@westnet.com.au> <7be0ad7b-bc35-4ea2-aa16-b9af535b455e@ys5g2000pbc.googlegroups.com> Message-ID: On 21/04/2013 10:02, Terry Jan Reedy wrote: > On 4/20/2013 9:37 PM, rusi wrote: > >> I believe that the recent correction in unicode performance followed >> jmf's grumbles > > No, the correction followed upon his accurate report of a regression, > last August, which was unfortunately mixed in with grumbles and > inaccurate claims. Others separated out and verified the accurate > report. I reported it to pydev and enquired as to its necessity, I > believe Mark opened the tracker issue, and the two people who worked on > optimizing 3.3 a year ago fairly quickly came up with two different > patches. The several month delay after was a matter of testing and > picking the best approach. > > I'd again like to point out that all I did was raise the issue. It was based on data provided by Steven D'Aprano and confirmed by Serhiy Storchaka. -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From dihedral88888 at googlemail.com Sun Apr 21 02:09:59 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sat, 20 Apr 2013 23:09:59 -0700 (PDT) Subject: Is Unicode support so hard... In-Reply-To: References: Message-ID: <2524ede0-5c8b-4f82-9fba-f3d6c31a7320@googlegroups.com> jmfauth? 2013?4?21????UTC+8??1?12?43???? > In a previous post, > > > > http://groups.google.com/group/comp.lang.python/browse_thread/thread/6aec70817705c226# > > , > > > > Chris ?Kwpolska? Warrick wrote: > > > > ?Is Unicode support so hard, especially in the 21st century?? > > > > -- > > > > Unicode is not really complicate and it works very well (more > > than two decades of development if you take into account > > iso-14****). > > > > But, - I can say, "as usual" - people prefer to spend their > > time to make a "better Unicode than Unicode" and it usually > > fails. Python does not escape to this rule. > > > > ----- > > > > I'm "busy" with TeX (unicode engine variant), fonts and typography. > > This gives me plenty of ideas to test the "flexible string > > representation" (FSR). I should recognize this FSR is failing > > particulary very well... > > > > I can almost say, a delight. > > > > jmf > > Unicode lover To support the unicode is easy in the language part. But to support the unicode in a platform involves the OS and the display and input hardware devices which are not suitable to be free most of the time. From bv8bv8bv8 at gmail.com Sat Apr 20 15:14:09 2013 From: bv8bv8bv8 at gmail.com (BV BV) Date: Sat, 20 Apr 2013 12:14:09 -0700 (PDT) Subject: Dear Human !!!!!!!!!!!!!! Message-ID: Dear Human! The lecturer says at the beginning of the video, "I am talking to you as a human; it does not matter whether you are Christian, Jew, Buddhist or Hindu. It does not matter whether you are a worshipper of idols, atheist, religious, secularist, a man or woman. I talk and address you as a human. Have you ever stopped and asked yourself one day the reason why you believe in what you believe in? Have you ever thought about the reason for which you chose the religion you practice?" http://youtube.googleapis.com/v/-PcxpUGSmK0?rel=0 thank you From xucaen at gmail.com Sat Apr 20 16:59:19 2013 From: xucaen at gmail.com (xucaen at gmail.com) Date: Sat, 20 Apr 2013 13:59:19 -0700 (PDT) Subject: Include and lib files for Visual Studio? Message-ID: I am looking for the Python include and lib files for windows. I have a c++ project that I am importing into Visual Studio 2010 (express) and it links python. I need the include and lib files for windows. Where can I get them? I'd like to use python 3.3.1 if possible. I found the msi on python.org but is says they don't include source. I am assuming there is a dev sdk or something similar but can't seem to find it. From bahamutzero8825 at gmail.com Sat Apr 20 17:15:14 2013 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Sat, 20 Apr 2013 16:15:14 -0500 Subject: Include and lib files for Visual Studio? In-Reply-To: References: Message-ID: <51730562.4030504@gmail.com> On 2013.04.20 15:59, xucaen at gmail.com wrote: > I am looking for the Python include and lib files for windows. I have a c++ project that I am importing into Visual Studio 2010 (express) and it links python. I need the include and lib files for windows. Where can I get them? > I'd like to use python 3.3.1 if possible. Are they not in the source tarballs or VS debug info files archives on the 3.3.1 download page? -- CPython 3.3.1 | Windows NT 6.2.9200 / FreeBSD 9.1 From drobinow at gmail.com Sat Apr 20 18:44:07 2013 From: drobinow at gmail.com (David Robinow) Date: Sat, 20 Apr 2013 18:44:07 -0400 Subject: Include and lib files for Visual Studio? In-Reply-To: References: Message-ID: On Sat, Apr 20, 2013 at 4:59 PM, wrote: > I am looking for the Python include and lib files for windows. I have a > c++ project that I am importing into Visual Studio 2010 (express) and it > links python. I need the include and lib files for windows. Where can I get > them? > I'd like to use python 3.3.1 if possible. > > I found the msi on python.org but is says they don't include source. I am > assuming there is a dev sdk or something similar but can't seem to find it. > > You are misinterpreting what you are reading. Install the msi. Look in C:\Python33\include and C:\Python33\libs -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sat Apr 20 21:04:24 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Sat, 20 Apr 2013 21:04:24 -0400 Subject: Include and lib files for Visual Studio? In-Reply-To: References: Message-ID: On 4/20/2013 4:59 PM, xucaen at gmail.com wrote: > I am looking for the Python include and lib files for windows. I have a c++ project that I am importing into Visual Studio 2010 (express) and it links python. I need the include and lib files for windows. Where can I get them? > I'd like to use python 3.3.1 if possible. > > I found the msi on python.org but is says they don't include source. I am assuming there is a dev sdk or something similar but can't seem to find it. If you want *everything*, clone hg.python.org/cpython (or something like that). PCBuild has Windows stuff, including VS .sln files. From cjw at ncf.ca Sat Apr 20 19:46:07 2013 From: cjw at ncf.ca (Colin J. Williams) Date: Sat, 20 Apr 2013 19:46:07 -0400 Subject: There must be a better way Message-ID: Below is part of a script which shows the changes made to permit the script to run on either Python 2.7 or Python 3.2. I was surprised to see that the CSV next method is no longer available. Suggestions welcome. Colin W. def main(): global inData, inFile if ver == '2': headerLine= inData.next() else: # Python version 3.3 inFile.close() inFile= open('Don Wall April 18 2013.csv', 'r', newline= '') inData= csv.reader(inFile) headerLine= inData.__next__() From clp2 at rebertia.com Sat Apr 20 19:57:05 2013 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 20 Apr 2013 16:57:05 -0700 Subject: There must be a better way In-Reply-To: References: Message-ID: On Sat, Apr 20, 2013 at 4:46 PM, Colin J. Williams wrote: > Below is part of a script which shows the changes made to permit the script > to run on either Python 2.7 or Python 3.2. > > I was surprised to see that the CSV next method is no longer available. > > Suggestions welcome. > if ver == '2': > headerLine= inData.next() > else: # Python version 3.3 > headerLine= inData.__next__() Use the built-in next() function (http://docs.python.org/2/library/functions.html#next ) instead: headerLine = next(iter(inData)) Cheers, Chris From steve+comp.lang.python at pearwood.info Sat Apr 20 20:06:25 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Apr 2013 00:06:25 GMT Subject: There must be a better way References: Message-ID: <51732d81$0$29977$c3e8da3$5496439d@news.astraweb.com> On Sat, 20 Apr 2013 19:46:07 -0400, Colin J. Williams wrote: > Below is part of a script which shows the changes made to permit the > script to run on either Python 2.7 or Python 3.2. > > I was surprised to see that the CSV next method is no longer available. This makes no sense. What's "the CSV next method"? Are you talking about the csv module? It has no "next method". py> import csv py> csv.next Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'next' Please *define your terms*, otherwise we are flailing in the dark trying to guess what your code is supposed to do. The code you provide cannot possible work -- you use variables before they are defined, use other variables that are never defined at all, reference mysterious globals. You even close a file before it is opened! Please read this: http://sscce.org/ and provide a *short, self-contained, correct example* that we can actually run. But in the meantime, I'm going to consult the entrails and try to guess what you are doing: you're complaining that iterators have a next method in Python 2, and __next__ in Python 3. Am I correct? If so, this is true, but you should not be using the plain next method in Python 2. You should be using the built-in function next(), not calling the method directly. The plain next *method* was a mistake, only left in for compatibility with older versions of Python. Starting from Python 2.6 the correct way to get the next value from an arbitrary iterator is with the built-in function next(), not by calling a method directly. (In the same way that you get the length of a sequence by calling the built-in function len(), not by calling the __len__ method directly.) So provided you are using Python 2.6 or better, you call: next(inData) to get the next value, regardless of whether it is Python 2.x or 3.x. If you need to support older versions, you can do this: try: next # Does the built-in already exist? except NameError: # No, we define our own. def next(iterator): return iterator.next() then just use next(inData) as normal. -- Steven From python.list at tim.thechases.com Sat Apr 20 20:34:22 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 20 Apr 2013 19:34:22 -0500 Subject: There must be a better way In-Reply-To: <51732d81$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <51732d81$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20130420193422.25255e98@bigbox.christie.dr> On 2013-04-21 00:06, Steven D'Aprano wrote: > On Sat, 20 Apr 2013 19:46:07 -0400, Colin J. Williams wrote: > > > Below is part of a script which shows the changes made to permit > > the script to run on either Python 2.7 or Python 3.2. > > > > I was surprised to see that the CSV next method is no longer > > available. > > This makes no sense. What's "the CSV next method"? Are you talking > about the csv module? It has no "next method". In 2.x, the csv.reader() class (and csv.DictReader() class) offered a .next() method that is absent in 3.x For those who use(d) the csv.reader object on a regular basis, this was a pretty common usage. Particularly if you had to do your own header parsing: f = open(...) r = csv.reader(f) try: headers = r.next() header_map = analyze(headers) for row in r: foo = row[header_map["FOO COLUMN"]] process(foo) finally: f.close() (I did this for a number of cases where the client couldn't consistently send column-headers in a consistent capitalization/spaces, so my header-making function had to normalize the case/spaces and then reference the normalized names) > So provided you are using Python 2.6 or better, you call: > > next(inData) > > to get the next value, regardless of whether it is Python 2.x or > 3.x. > > If you need to support older versions, you can do this: > > try: > next # Does the built-in already exist? > except NameError: > # No, we define our own. > def next(iterator): > return iterator.next() > > then just use next(inData) as normal. This is a good expansion of Chris Rebert's suggestion to use next(), as those of us that have to support pre-2.6 code lack the next() function out of the box. -tkc From tjreedy at udel.edu Sat Apr 20 21:07:23 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Sat, 20 Apr 2013 21:07:23 -0400 Subject: There must be a better way In-Reply-To: <20130420193422.25255e98@bigbox.christie.dr> References: <51732d81$0$29977$c3e8da3$5496439d@news.astraweb.com> <20130420193422.25255e98@bigbox.christie.dr> Message-ID: On 4/20/2013 8:34 PM, Tim Chase wrote: > In 2.x, the csv.reader() class (and csv.DictReader() class) offered > a .next() method that is absent in 3.x In Py 3, .next was renamed to .__next__ for *all* iterators. The intention is that one iterate with for item in iterable or use builtin functions iter() and next(). From cjw at ncf.ca Sun Apr 21 09:15:28 2013 From: cjw at ncf.ca (Colin J. Williams) Date: Sun, 21 Apr 2013 09:15:28 -0400 Subject: There must be a better way In-Reply-To: References: <51732d81$0$29977$c3e8da3$5496439d@news.astraweb.com> <20130420193422.25255e98@bigbox.christie.dr> Message-ID: On 20/04/2013 9:07 PM, Terry Jan Reedy wrote: > On 4/20/2013 8:34 PM, Tim Chase wrote: >> In 2.x, the csv.reader() class (and csv.DictReader() class) offered >> a .next() method that is absent in 3.x > > In Py 3, .next was renamed to .__next__ for *all* iterators. The > intention is that one iterate with for item in iterable or use builtin > functions iter() and next(). > > Thanks to Chris, Tim and Terry for their helpful comments. I was seeking some code that would be acceptable to both Python 2.7 and 3.3. In the end, I used: inData= csv.reader(inFile) def main(): if ver == '2': headerLine= inData.next() else: headerLine= inData.__next__() ... for item in inData: assert len(dataStore) == len(item) j= findCardinal(item[10]) ... This is acceptable to both versions. It is not usual to have a name with preceding and following udserscores,imn user code. Presumably, there is a rationale for the change from csv.reader.next to csv.reader.__next__. If next is not acceptable for the version 3 csv.reader, perhaps __next__ could be added to the version 2 csv.reader, so that the same code can be used in the two versions. This would avoid the kluge I used above. Colin W. From jpiitula at ling.helsinki.fi Sun Apr 21 09:39:07 2013 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 21 Apr 2013 16:39:07 +0300 Subject: There must be a better way References: <51732d81$0$29977$c3e8da3$5496439d@news.astraweb.com> <20130420193422.25255e98@bigbox.christie.dr> Message-ID: Colin J. Williams writes: ... > It is not usual to have a name with preceding and following > udserscores,imn user code. > > Presumably, there is a rationale for the change from csv.reader.next > to csv.reader.__next__. ... I think the user code is supposed to be next(csv.reader). For example, current documentation contains the following. # csvreader.__next__() # Return the next row of the reader?s iterable object as a list, # parsed according to the current dialect. Usually you should call # this as next(reader). From cjw at ncf.ca Sun Apr 21 11:17:04 2013 From: cjw at ncf.ca (Colin J. Williams) Date: Sun, 21 Apr 2013 11:17:04 -0400 Subject: There must be a better way In-Reply-To: References: <51732d81$0$29977$c3e8da3$5496439d@news.astraweb.com> <20130420193422.25255e98@bigbox.christie.dr> Message-ID: On 21/04/2013 9:39 AM, Jussi Piitulainen wrote: > Colin J. Williams writes: > ... >> It is not usual to have a name with preceding and following >> udserscores,imn user code. >> >> Presumably, there is a rationale for the change from csv.reader.next >> to csv.reader.__next__. > ... > > I think the user code is supposed to be next(csv.reader). For example, > current documentation contains the following. > > # csvreader.__next__() > # Return the next row of the reader?s iterable object as a list, > # parsed according to the current dialect. Usually you should call > # this as next(reader). > Thanks, This works with both 2.7 and 3.3 Colin W. From __peter__ at web.de Sun Apr 21 09:43:52 2013 From: __peter__ at web.de (Peter Otten) Date: Sun, 21 Apr 2013 15:43:52 +0200 Subject: There must be a better way References: <51732d81$0$29977$c3e8da3$5496439d@news.astraweb.com> <20130420193422.25255e98@bigbox.christie.dr> Message-ID: Colin J. Williams wrote: > I was seeking some code that would be acceptable to both Python 2.7 and > 3.3. > > In the end, I used: > > inData= csv.reader(inFile) > > def main(): > if ver == '2': > headerLine= inData.next() > else: > headerLine= inData.__next__() > ... I think it was mentioned before, but to be explicit: def main(): headerLine = next(inData) ... works in Python 2.6, 2.7, and 3.x. From cjw at ncf.ca Sun Apr 21 11:30:53 2013 From: cjw at ncf.ca (Colin J. Williams) Date: Sun, 21 Apr 2013 11:30:53 -0400 Subject: There must be a better way In-Reply-To: References: <51732d81$0$29977$c3e8da3$5496439d@news.astraweb.com> <20130420193422.25255e98@bigbox.christie.dr> Message-ID: <5174062D.2090009@ncf.ca> On 21/04/2013 9:43 AM, Peter Otten wrote: > Colin J. Williams wrote: > >> I was seeking some code that would be acceptable to both Python 2.7 and >> 3.3. >> >> In the end, I used: >> >> inData= csv.reader(inFile) >> >> def main(): >> if ver == '2': >> headerLine= inData.next() >> else: >> headerLine= inData.__next__() >> ... > > I think it was mentioned before, but to be explicit: > > def main(): > headerLine = next(inData) > ... > > works in Python 2.6, 2.7, and 3.x. > Yes, the penny dropped eventually. I've used your statement The Chris suggestion was slightly different: Use the built-in next() function (http://docs.python.org/2/library/functions.html#next ) instead: headerLine = next(iter(inData)) Colin W. From cjw at ncf.ca Sun Apr 21 11:30:53 2013 From: cjw at ncf.ca (Colin J. Williams) Date: Sun, 21 Apr 2013 11:30:53 -0400 Subject: There must be a better way In-Reply-To: References: <51732d81$0$29977$c3e8da3$5496439d@news.astraweb.com> <20130420193422.25255e98@bigbox.christie.dr> Message-ID: <5174062D.2090009@ncf.ca> On 21/04/2013 9:43 AM, Peter Otten wrote: > Colin J. Williams wrote: > >> I was seeking some code that would be acceptable to both Python 2.7 and >> 3.3. >> >> In the end, I used: >> >> inData= csv.reader(inFile) >> >> def main(): >> if ver == '2': >> headerLine= inData.next() >> else: >> headerLine= inData.__next__() >> ... > > I think it was mentioned before, but to be explicit: > > def main(): > headerLine = next(inData) > ... > > works in Python 2.6, 2.7, and 3.x. > Yes, the penny dropped eventually. I've used your statement The Chris suggestion was slightly different: Use the built-in next() function (http://docs.python.org/2/library/functions.html#next ) instead: headerLine = next(iter(inData)) Colin W. From oscar.j.benjamin at gmail.com Mon Apr 22 10:32:03 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 22 Apr 2013 15:32:03 +0100 Subject: There must be a better way In-Reply-To: References: <51732d81$0$29977$c3e8da3$5496439d@news.astraweb.com> <20130420193422.25255e98@bigbox.christie.dr> Message-ID: On 21 April 2013 14:15, Colin J. Williams wrote: > In the end, I used: > > inData= csv.reader(inFile) > > def main(): > > if ver == '2': > headerLine= inData.next() > else: > headerLine= inData.__next__() > ... > for item in inData: > assert len(dataStore) == len(item) > j= findCardinal(item[10]) > ... This may not be relevant for what you're doing but if you use csv.DictReader there's no need to retrieve the top line separately: $ cat tmp.csv a,b,c 1,2,3 4,5,6 $ python Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import csv >>> with open('tmp.csv', 'rb') as csvfile: ... for row in csv.DictReader(csvfile): ... print(row) ... {'a': '1', 'c': '3', 'b': '2'} {'a': '4', 'c': '6', 'b': '5'} Oscar From neilc at norwich.edu Mon Apr 22 10:42:10 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 22 Apr 2013 14:42:10 GMT Subject: There must be a better way References: <51732d81$0$29977$c3e8da3$5496439d@news.astraweb.com> <20130420193422.25255e98@bigbox.christie.dr> Message-ID: On 2013-04-21, Colin J. Williams wrote: > On 20/04/2013 9:07 PM, Terry Jan Reedy wrote: >> On 4/20/2013 8:34 PM, Tim Chase wrote: >>> In 2.x, the csv.reader() class (and csv.DictReader() class) offered >>> a .next() method that is absent in 3.x >> >> In Py 3, .next was renamed to .__next__ for *all* iterators. The >> intention is that one iterate with for item in iterable or use builtin >> functions iter() and next(). >> >> > Thanks to Chris, Tim and Terry for their helpful comments. > > I was seeking some code that would be acceptable to both Python 2.7 and 3.3. > > In the end, I used: > > inData= csv.reader(inFile) > > def main(): > if ver == '2': > headerLine= inData.next() > else: > headerLine= inData.__next__() > ... > for item in inData: > assert len(dataStore) == len(item) > j= findCardinal(item[10]) > ... > > This is acceptable to both versions. > > It is not usual to have a name with preceding and following > udserscores,imn user code. > > Presumably, there is a rationale for the change from csv.reader.next > to csv.reader.__next__. > > If next is not acceptable for the version 3 csv.reader, perhaps __next__ > could be added to the version 2 csv.reader, so that the same code can be > used in the two versions. > > This would avoid the kluge I used above. Would using csv.DictReader instead a csv.reader be an option? -- Neil Cerutti From cjw at ncf.ca Mon Apr 22 13:44:08 2013 From: cjw at ncf.ca (Colin J. Williams) Date: Mon, 22 Apr 2013 13:44:08 -0400 Subject: There must be a better way In-Reply-To: References: <51732d81$0$29977$c3e8da3$5496439d@news.astraweb.com> <20130420193422.25255e98@bigbox.christie.dr> Message-ID: On 22/04/2013 10:42 AM, Neil Cerutti wrote: > On 2013-04-21, Colin J. Williams wrote: >> On 20/04/2013 9:07 PM, Terry Jan Reedy wrote: >>> On 4/20/2013 8:34 PM, Tim Chase wrote: >>>> In 2.x, the csv.reader() class (and csv.DictReader() class) offered >>>> a .next() method that is absent in 3.x >>> >>> In Py 3, .next was renamed to .__next__ for *all* iterators. The >>> intention is that one iterate with for item in iterable or use builtin >>> functions iter() and next(). >>> >>> >> Thanks to Chris, Tim and Terry for their helpful comments. >> >> I was seeking some code that would be acceptable to both Python 2.7 and 3.3. >> >> In the end, I used: >> >> inData= csv.reader(inFile) >> >> def main(): >> if ver == '2': >> headerLine= inData.next() >> else: >> headerLine= inData.__next__() >> ... >> for item in inData: >> assert len(dataStore) == len(item) >> j= findCardinal(item[10]) >> ... >> >> This is acceptable to both versions. >> >> It is not usual to have a name with preceding and following >> udserscores,imn user code. >> >> Presumably, there is a rationale for the change from csv.reader.next >> to csv.reader.__next__. >> >> If next is not acceptable for the version 3 csv.reader, perhaps __next__ >> could be added to the version 2 csv.reader, so that the same code can be >> used in the two versions. >> >> This would avoid the kluge I used above. > > Would using csv.DictReader instead a csv.reader be an option? > Since I'm only interested in one or two columns, the simpler approach is probably better. Colin W. From neilc at norwich.edu Tue Apr 23 09:36:19 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 23 Apr 2013 13:36:19 GMT Subject: There must be a better way References: <51732d81$0$29977$c3e8da3$5496439d@news.astraweb.com> <20130420193422.25255e98@bigbox.christie.dr> Message-ID: On 2013-04-22, Colin J. Williams wrote: > Since I'm only interested in one or two columns, the simpler > approach is probably better. Here's a sketch of how one of my projects handles that situation. I think the index variables are invaluable documentation, and make it a bit more robust. (Python 3, so not every bit is relevant to you). with open("today.csv", encoding='UTF-8', newline='') as today_file: reader = csv.reader(today_file) header = next(reader) majr_index = header.index('MAJR') div_index = header.index('DIV') for rec in reader: major = rec[majr_index] rec[div_index] = DIVISION_TABLE[major] But a csv.DictReader might still be more efficient. I never tested. This is the only place I've used this "optimization". It's fast enough. ;) -- Neil Cerutti From oscar.j.benjamin at gmail.com Tue Apr 23 10:15:21 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 23 Apr 2013 15:15:21 +0100 Subject: There must be a better way In-Reply-To: References: <51732d81$0$29977$c3e8da3$5496439d@news.astraweb.com> <20130420193422.25255e98@bigbox.christie.dr> Message-ID: On 23 April 2013 14:36, Neil Cerutti wrote: > On 2013-04-22, Colin J. Williams wrote: >> Since I'm only interested in one or two columns, the simpler >> approach is probably better. > > Here's a sketch of how one of my projects handles that situation. > I think the index variables are invaluable documentation, and > make it a bit more robust. (Python 3, so not every bit is > relevant to you). > > with open("today.csv", encoding='UTF-8', newline='') as today_file: > reader = csv.reader(today_file) > header = next(reader) I once had a bug that took a long time to track down and was caused by using next() without an enclosing try/except StopIteration (or the optional default argument to next). This is a sketch of how you can get the bug that I had: $ cat next.py #!/usr/bin/env python def join(iterables): '''Join iterable of iterables, stripping first item''' for iterable in iterables: iterator = iter(iterable) header = next(iterator) # Here's the problem for val in iterator: yield val data = [ ['foo', 1, 2, 3], ['bar', 4, 5, 6], [], # Whoops! Who put this empty iterable here? ['baz', 7, 8, 9], ] for x in join(data): print(x) $ ./next.py 1 2 3 4 5 6 The values 7, 8 and 9 are not printed but no error message is shown. This is because calling next on the iterator over the empty list raises a StopIteration that is not caught in the join generator. The StopIteration is then "caught" by the for loop that iterates over join() causing the loop to terminate prematurely. Since the exception is caught and cleared by the for loop there's no practical way to get a debugger to hook into the event that causes it. In my case this happened somewhere in the middle of a long running process. It was difficult to pin down what was causing this as the iteration was over non-constant data and I didn't know what I was looking for. As a result of the time spent fixing this I'm always very cautious about calling next() to think about what a StopIteration would do in context. In this case a StopIteration is raised when reading from an empty csv file: >>> import csv >>> with open('test.csv', 'w'): pass ... >>> with open('test.csv') as csvfile: ... reader = csv.reader(csvfile) ... header = next(reader) ... Traceback (most recent call last): File "", line 3, in StopIteration If that code were called from a generator then it would most likely be susceptible to the problem I'm describing. The fix is to use next(reader, None) or try/except StopIteration. Oscar From python.list at tim.thechases.com Tue Apr 23 10:30:05 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 23 Apr 2013 09:30:05 -0500 Subject: There must be a better way In-Reply-To: References: <51732d81$0$29977$c3e8da3$5496439d@news.astraweb.com> <20130420193422.25255e98@bigbox.christie.dr> Message-ID: <20130423093005.41ec8199@bigbox.christie.dr> On 2013-04-23 13:36, Neil Cerutti wrote: > On 2013-04-22, Colin J. Williams wrote: > > Since I'm only interested in one or two columns, the simpler > > approach is probably better. > > Here's a sketch of how one of my projects handles that situation. > I think the index variables are invaluable documentation, and > make it a bit more robust. (Python 3, so not every bit is > relevant to you). > > with open("today.csv", encoding='UTF-8', newline='') as today_file: > reader = csv.reader(today_file) > header = next(reader) > majr_index = header.index('MAJR') > div_index = header.index('DIV') > for rec in reader: > major = rec[majr_index] > rec[div_index] = DIVISION_TABLE[major] > > But a csv.DictReader might still be more efficient. I never > tested. This is the only place I've used this "optimization". > It's fast enough. ;) I believe the csv module does all the work at c-level, rather than as pure Python, so it should be notably faster. The only times I've had to do things by hand like that are when there are header peculiarities that I can't control, such as mismatched case or added/remove punctuation (client files are notorious for this). So I often end up doing something like def normalize(header): return header.strip().upper() # other cleanup as needed reader = csv.reader(f) headers = next(reader) header_map = dict( (normalize(header), i) for i, header in enumerate(headers) ) item = lambda col: row[header_map[col]].strip() for row in reader: major = item("MAJR").upper() division = item("DIV") # ... The function calling might add overhead (in which case one could just use explicit indirect indexing for each value assignment: major = row[header_map["MAJR"]].strip().upper() but I usually find that processing CSV files leaves me I/O bound rather than CPU bound. -tkc From python.list at tim.thechases.com Tue Apr 23 11:02:55 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 23 Apr 2013 10:02:55 -0500 Subject: There must be a better way (correction) In-Reply-To: <20130423093005.41ec8199@bigbox.christie.dr> References: <51732d81$0$29977$c3e8da3$5496439d@news.astraweb.com> <20130420193422.25255e98@bigbox.christie.dr> <20130423093005.41ec8199@bigbox.christie.dr> Message-ID: <20130423100255.21e84f47@bigbox.christie.dr> On 2013-04-23 09:30, Tim Chase wrote: > > But a csv.DictReader might still be more efficient. I never > > tested. This is the only place I've used this "optimization". > > It's fast enough. ;) > > I believe the csv module does all the work at c-level, rather than > as pure Python, so it should be notably faster. A little digging shows that csv.DictReader is pure Python, using the underlying _csv.reader which is written in C for speed. -tkc From skip at pobox.com Tue Apr 23 10:36:55 2013 From: skip at pobox.com (Skip Montanaro) Date: Tue, 23 Apr 2013 09:36:55 -0500 Subject: There must be a better way In-Reply-To: References: <51732d81$0$29977$c3e8da3$5496439d@news.astraweb.com> <20130420193422.25255e98@bigbox.christie.dr> Message-ID: > But a csv.DictReader might still be more efficient. Depends on what efficiency you care about. The DictReader class is implemented in Python, and builds a dict for every row. It will never be more efficient CPU-wise than instantiating the csv.reader type directly and only doing what you need. OTOH, the DictReader class "just works" and its usage is more obvious when you come back later to modify your code. It also makes the code insensitive to column ordering (though yours seems to be as well, if I'm reading it correctly). On the programmer efficiency axis, I score the DictReader class higher than the reader type. A simple test: ########################## import csv from timeit import Timer setup = '''import csv lst = ["""a,b,c,d,e,f,g"""] lst.extend(["""05:38:24,0.6326,1,0,1.0,0.0,0.0"""] * 1000000) reader = csv.reader(lst) dreader = csv.DictReader(lst) ''' t1 = Timer("for row in reader: pass", setup) t2 = Timer("for row in dreader: pass", setup) print(min(t1.repeat(number=10))) print(min(t2.repeat(number=10))) ############################### demonstrates that the raw reader is, indeed, much faster than the DictReader: 0.972723007202 8.29047989845 but that's for the basic iteration. Whatever you need to add to the raw reader to insulate yourself from changes to the structure of the CSV file and improve readability will slow it down, while the DictReader will never be worse than the above. Skip From xintai404 at gmail.com Sat Apr 20 22:45:46 2013 From: xintai404 at gmail.com (Yuanyuan Li) Date: Sat, 20 Apr 2013 19:45:46 -0700 (PDT) Subject: clear the screen Message-ID: <7aecbd4f-192e-43f2-99fb-f55c93701841@googlegroups.com> How to clear the screen? For example, in the two player game. One player sets a number and the second player guesses the number. When the first player enters the number, it should be cleared so that the second number is not able to see it. My question is how to clear the number. Thank you! From davea at davea.name Sun Apr 21 06:21:24 2013 From: davea at davea.name (Dave Angel) Date: Sun, 21 Apr 2013 06:21:24 -0400 Subject: clear the screen In-Reply-To: <7aecbd4f-192e-43f2-99fb-f55c93701841@googlegroups.com> References: <7aecbd4f-192e-43f2-99fb-f55c93701841@googlegroups.com> Message-ID: <5173BDA4.3010408@davea.name> On 04/20/2013 10:45 PM, Yuanyuan Li wrote: > How to clear the screen? For example, in the two player game. One player sets a number and the second player guesses the number. When the first player enters the number, it should be cleared so that the second number is not able to see it. My question is how to clear the number. > Thank you! > Welcome to the python mailing list. The first thing you'd have to specify is your environment. Are you writing a gui program, and if so, with which toolkit (tk, wx, etc.). Or are you writing a console program? The simplest portable way is to issue 50 or so newlines, so things scroll beyond easy visibility. Of course, many terminal programs can easily scroll back, perhaps by using the mouse wheel. If you want something better than that, you'd have to specify your Python version and Operating System. Then somebody familiar with the quirks of that particular system can chime in. -- DaveA From steve+comp.lang.python at pearwood.info Sun Apr 21 08:49:35 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Apr 2013 12:49:35 GMT Subject: clear the screen References: <7aecbd4f-192e-43f2-99fb-f55c93701841@googlegroups.com> Message-ID: <5173e05f$0$29977$c3e8da3$5496439d@news.astraweb.com> On Sat, 20 Apr 2013 19:45:46 -0700, Yuanyuan Li wrote: > How to clear the screen? For example, in the two player game. One player > sets a number and the second player guesses the number. When the first > player enters the number, it should be cleared so that the second number > is not able to see it. My question is how to clear the number. Thank > you! What sort of screen? A GUI window, or in a terminal? If you have a GUI window, you will need to read the documentation for your GUI toolkit. If it is in a terminal, that will depend on the terminal. The best solution is to use Curses, if you can, but that is Unix only. Another solution is this: print("\x1b[H\x1b[2J") although that only works in some terminals, and it will not work in IDLE. Another solution is this: import os result = os.system("clear") # Linux, Mac, Unix or for Windows: result = os.system("cls") but again, it may not work in IDLE. Last but not least, if everything else fails, try printing a whole lot of blank lines: print("\n"*100) ought to do it on all but the tallest terminals, and amazingly, it even works in IDLE! -- Steven From alokmahor at gmail.com Sun Apr 21 02:13:20 2013 From: alokmahor at gmail.com (Alok Singh Mahor) Date: Sat, 20 Apr 2013 23:13:20 -0700 (PDT) Subject: django vs zope vs web2py Message-ID: <2dc047ad-6b38-422f-8aa6-fca662b89c64@googlegroups.com> Hi everyone, few months back I decided to adopt python for my all sort of work including web progra From alokmahor at gmail.com Sun Apr 21 02:18:46 2013 From: alokmahor at gmail.com (Alok Singh Mahor) Date: Sat, 20 Apr 2013 23:18:46 -0700 (PDT) Subject: django vs zope vs web2py In-Reply-To: <2dc047ad-6b38-422f-8aa6-fca662b89c64@googlegroups.com> References: <2dc047ad-6b38-422f-8aa6-fca662b89c64@googlegroups.com> Message-ID: <47fb29e2-3e78-4989-850b-24359d84b747@googlegroups.com> I am sorry by mistake I sent incomplete mail here is my mail. Hi everyone, few months back I decided to adopt python for my all sort of work including web programming. and I have wasted long time deciding which to adopt out of django, zope and web2py. I am from php and drupal background. which framework would be better for me. I am open to learn anything, anything new. but I want to adopt best thing full of features and lot of plugins/extensions and easy to use and have better documentation and books etc. please suggest me so without wasting more time I can start learning thanks in advance :) From rustompmody at gmail.com Sun Apr 21 03:51:34 2013 From: rustompmody at gmail.com (rusi) Date: Sun, 21 Apr 2013 00:51:34 -0700 (PDT) Subject: django vs zope vs web2py References: <2dc047ad-6b38-422f-8aa6-fca662b89c64@googlegroups.com> <47fb29e2-3e78-4989-850b-24359d84b747@googlegroups.com> Message-ID: <223be064-6477-4035-9b4d-34eda5b13418@fs2g2000pbd.googlegroups.com> On Apr 21, 11:18?am, Alok Singh Mahor wrote: > I am sorry by mistake I sent incomplete mail here is my mail. > > Hi everyone, > few months back I decided to adopt python for my all sort of work including web programming. and I have wasted long time deciding which to adopt out of django, zope and web2py. > I am from php and drupal background. which framework would be better for me. I am open to learn anything, anything new. but I want to adopt best thing full of features and lot of plugins/extensions and easy to use and have better documentation and books etc. > > please suggest me so without wasting more time I can start learning > thanks in advance :) I am not the best person to advise on this area (hopefully others with more python-for-web knowledge will speak up) I see some implicit misconceptions/contradictions in your question so just saying something? Python is a general purpose programming language. php has some (poor?) pretensions to that title. Drupal cannot even pretend I guess. Therefore when switching to something like python its important to have high on your TODO list the need to grok what 'general purpose programming language' means. Many people use mega-frameworks like RoR, Django etc without really knowing much of the underlying programming language. This has some consequences: a. You function suboptimally, basically following the cookie-cutter approach b. When you have to switch out of Django into python (say) it can be very unnerving and frustrating because you suddenly find you dont know the 'ABC' So the longer but more fruitful in the long-run approach is to identify what are the general areas that web programming needs, study these in isolation and then switch to a mega-framework like django. Something like: - templating with cheetah - ORM with sqlalchemy connecting to some proper database - web-serving with cherrypy (web.py?, bottle? flask?) [I am not claiming that this list is complete or the examples are good. Of the above Ive only used cheetah] After your hands are a little dirty with the plumbing, you can switch to a mega-framework like django. Also for someone who has mostly web experience, its good to put aside web (for a while) and try out python for something completely un-web- ish (a game? a sysadmin script?) to get a feel for 'general purpose programming language' From roy at panix.com Sun Apr 21 07:22:00 2013 From: roy at panix.com (Roy Smith) Date: Sun, 21 Apr 2013 07:22:00 -0400 Subject: django vs zope vs web2py References: <2dc047ad-6b38-422f-8aa6-fca662b89c64@googlegroups.com> <47fb29e2-3e78-4989-850b-24359d84b747@googlegroups.com> Message-ID: In article <47fb29e2-3e78-4989-850b-24359d84b747 at googlegroups.com>, Alok Singh Mahor wrote: > I am sorry by mistake I sent incomplete mail here is my mail. > > Hi everyone, > few months back I decided to adopt python for my all sort of work including > web programming. and I have wasted long time deciding which to adopt out of > django, zope and web2py. > I am from php and drupal background. which framework would be better for me. > I am open to learn anything, anything new. but I want to adopt best thing > full of features and lot of plugins/extensions and easy to use and have > better documentation and books etc. Zope is a much older framework, and much lower level than django. It's almost certainly not what you want. I'm not familiar with web2py, so I can't comment on that. Django is sort of the "killer app" these days in the python web world. That's not to say that it's necessarily the best, but at least it's well documented, and has a thriving user community of people who can help you. There's also a lot of add-on software available for it. The basic things you get from django are: 1) A built-in ORM (Object Relational Mapper) layer. This is the thing which lets you ignore all the horrible details of how your underlying database works and just deal with Python objects. 2) A structure for parsing incoming HTTP requests, and calling the right bit of your code to handle each request. 3) A template language, to simplify the generation of your HTML pages. There are others besides the three you mentioned. You might want to start at http://wiki.python.org/moin/WebFrameworks to explore the possibilities. From suryak at ieee.org Sun Apr 21 07:59:43 2013 From: suryak at ieee.org (Surya Kasturi) Date: Sun, 21 Apr 2013 17:29:43 +0530 Subject: django vs zope vs web2py In-Reply-To: <47fb29e2-3e78-4989-850b-24359d84b747@googlegroups.com> References: <2dc047ad-6b38-422f-8aa6-fca662b89c64@googlegroups.com> <47fb29e2-3e78-4989-850b-24359d84b747@googlegroups.com> Message-ID: On Sun, Apr 21, 2013 at 11:48 AM, Alok Singh Mahor wrote: > I am sorry by mistake I sent incomplete mail here is my mail. > > Hi everyone, > few months back I decided to adopt python for my all sort of work > including web programming. and I have wasted long time deciding which to > adopt out of django, zope and web2py. > I am from php and drupal background. which framework would be better for > me. I am open to learn anything, anything new. but I want to adopt best > thing full of features and lot of plugins/extensions and easy to use and > have better documentation and books etc. > > please suggest me so without wasting more time I can start learning > thanks in advance :) > -- > http://mail.python.org/mailman/listinfo/python-list > You see, in my experience, if you are trying to find the best before starting (to learn), probably might never going to start. I don't know what's your Python experience but Django is a decent option to start over! To start Django, the documentation is one of the best way to start over!! Since, you are already into web dev using php, drupal etc. Unless you are very particular in starting with Django... I suggest you to take a look into other areas of Python. May be Network programming or systems programming or getting around algorithms - trying to learn some mind blowing algos.. hack around on network.. Come back and do Django.. you will see a lot of fresh ideas!! -------------- next part -------------- An HTML attachment was scrubbed... URL: From modulok at gmail.com Sun Apr 21 08:19:07 2013 From: modulok at gmail.com (Modulok) Date: Sun, 21 Apr 2013 06:19:07 -0600 Subject: django vs zope vs web2py In-Reply-To: <2dc047ad-6b38-422f-8aa6-fca662b89c64@googlegroups.com> References: <2dc047ad-6b38-422f-8aa6-fca662b89c64@googlegroups.com> Message-ID: > Hi everyone, > few months back I decided to adopt python for my all sort of work including > web programming... > -- > http://mail.python.org/mailman/listinfo/python-list > Pick Django or web2py. You'll be happy with either. (I have no experience with zope.) They're both full featured do-everything-you-ever-wanted frameworks with great communities and lots of documentation. You can buy books on either. I'd say web2py is a little more elegant and easier to get started with. (An admittedly subjective claim.) Django has a little larger community and has more third party stuff. If you just need to "get it done" and don't care about how it happens, they're both excellent. You'll meet deadlines with either of them. The communities are smart the docs are great. You can't really go wrong any way you slice it. There's more third party documentation and books for Django right now but that's just because Django came out first. Give it another couple years and there won't be much difference. Basically, flip a coin and just go with it. And now for the gritty details approach... The problem with web frameworks is they are "magic", i.e. things just happen. It's the price we pay for using a high level abstraction. The higher the abstraction the more magic there is. Often times magic is good. It saves us time and money. However depending on your needs, other options are worth considering. If you are willing to invest a lot of time not being initially productive but learn a *ton* in exchange, you can use something like cherrypy. (Don't get me wrong, I love and often use cherrypy.) It's dirt simple and works. However, because it's so simple it doesn't do half of what you need for a non-trivial production site. Result? You'll have to fill in the tool chain gaps with other modules. This is what web frameworks do for you. If you go the cherrypy route you'll need to learn other things like like markup languages and some kind of way to talk to a database. Security is also entirely in your hands. You'll learn a ton about HTTP, SQL, markup languages, web security, encryption, etc. You'll be basically re-creating a web framework of your own brand. Again it's a time spent vs. knowledge gained trade off. For a template language I really liked wheezy.template but it's a little too new for me to feel comfortable using it on any big project. It has a very simple inheritance model, which is refreshing. I hope to use it more in the future. I usually use Mako for my templates. By 'template' I mean any template, not just HTML. I use mako for HTML, documentation, I even use mako to write SQL templates. The inheritance model of Mako takes a little more mental gymnastics to wrap your head around than the simpler (read nicer) wheezy.template model, but it's a more mature code base. (Not as mature as cheetah.) I had only minor experience with cheetah but found I preferred Mako. It was a matter of taste. There's nothing wrong with cheetah. As for database access: sqlalchemy is truly excellent and very flexible. For most things sqlalchemy is great. However for some projects it may contain too much magic. (Again we're going deeper.) Sometimes a backend-specific module is called for, in which case psycopg2 on postgresql is nice. The ability to use python context managers as transaction blocks is very clean. In short, how much do you want to learn? Do you prefer a top-down or bottom-up approach? Gritty details or elegant abstractions? -Modulok- From alokmahor at gmail.com Sun Apr 21 10:42:03 2013 From: alokmahor at gmail.com (Alok Singh Mahor) Date: Sun, 21 Apr 2013 20:12:03 +0530 Subject: django vs zope vs web2py In-Reply-To: References: <2dc047ad-6b38-422f-8aa6-fca662b89c64@googlegroups.com> Message-ID: On Sun, Apr 21, 2013 at 5:49 PM, Modulok wrote: > > Hi everyone, > > few months back I decided to adopt python for my all sort of work > including > > web programming... > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > Pick Django or web2py. You'll be happy with either. (I have no experience > with > zope.) > > They're both full featured do-everything-you-ever-wanted frameworks with > great > communities and lots of documentation. You can buy books on either. I'd say > web2py is a little more elegant and easier to get started with. (An > admittedly > subjective claim.) Django has a little larger community and has more third > party stuff. > > If you just need to "get it done" and don't care about how it happens, > they're > both excellent. You'll meet deadlines with either of them. The communities > are > smart the docs are great. You can't really go wrong any way you slice it. > There's more third party documentation and books for Django right now but > that's just because Django came out first. Give it another couple years and > there won't be much difference. > > Basically, flip a coin and just go with it. > > > > And now for the gritty details approach... > > The problem with web frameworks is they are "magic", i.e. things just > happen. > It's the price we pay for using a high level abstraction. The higher the > abstraction the more magic there is. Often times magic is good. It saves us > time and money. However depending on your needs, other options are worth > considering. > > If you are willing to invest a lot of time not being initially productive > but > learn a *ton* in exchange, you can use something like cherrypy. (Don't get > me > wrong, I love and often use cherrypy.) It's dirt simple and works. However, > because it's so simple it doesn't do half of what you need for a > non-trivial > production site. Result? You'll have to fill in the tool chain gaps with > other > modules. This is what web frameworks do for you. > > If you go the cherrypy route you'll need to learn other things like like > markup > languages and some kind of way to talk to a database. Security is also > entirely > in your hands. You'll learn a ton about HTTP, SQL, markup languages, web > security, encryption, etc. You'll be basically re-creating a web framework > of > your own brand. Again it's a time spent vs. knowledge gained trade off. > > For a template language I really liked wheezy.template but it's a little > too > new for me to feel comfortable using it on any big project. It has a very > simple inheritance model, which is refreshing. I hope to use it more in the > future. > > I usually use Mako for my templates. By 'template' I mean any template, not > just HTML. I use mako for HTML, documentation, I even use mako to write SQL > templates. The inheritance model of Mako takes a little more mental > gymnastics > to wrap your head around than the simpler (read nicer) wheezy.template > model, > but it's a more mature code base. (Not as mature as cheetah.) I had only > minor > experience with cheetah but found I preferred Mako. It was a matter of > taste. > There's nothing wrong with cheetah. > > As for database access: sqlalchemy is truly excellent and very flexible. > For > most things sqlalchemy is great. However for some projects it may contain > too > much magic. (Again we're going deeper.) Sometimes a backend-specific > module is > called for, in which case psycopg2 on postgresql is nice. The ability to > use > python context managers as transaction blocks is very clean. > > In short, how much do you want to learn? Do you prefer a top-down or > bottom-up > approach? Gritty details or elegant abstractions? > > -Modulok- > thanks a lot Rusi, Roy Smith, Surya and Modulok I am sticking to django. In future I will touch web2py also -------------- next part -------------- An HTML attachment was scrubbed... URL: From lordmax at gmail.com Sun Apr 21 02:20:45 2013 From: lordmax at gmail.com (LordMax) Date: Sat, 20 Apr 2013 23:20:45 -0700 (PDT) Subject: ask for note keeper tomboy's style Message-ID: <833d0c05-56de-46bb-98b1-64b4ec92d7fa@googlegroups.com> Hi to all. I am new to python and I was asked to implement a system of notes in tomboy's style for my company. As one of the requirements is the ability to synchronize notes between multiple PC (program level or through cloud-folder does not matter) I was wondering if there is something similar where I can work on. Do you have any suggestions? thank you very much From torriem at gmail.com Sun Apr 21 13:42:06 2013 From: torriem at gmail.com (Michael Torrie) Date: Sun, 21 Apr 2013 11:42:06 -0600 Subject: ask for note keeper tomboy's style In-Reply-To: <833d0c05-56de-46bb-98b1-64b4ec92d7fa@googlegroups.com> References: <833d0c05-56de-46bb-98b1-64b4ec92d7fa@googlegroups.com> Message-ID: <517424EE.5020901@gmail.com> On 04/21/2013 12:20 AM, LordMax wrote: > Hi to all. > > I am new to python and I was asked to implement a system of notes in > tomboy's style for my company. > > As one of the requirements is the ability to synchronize notes > between multiple PC (program level or through cloud-folder does not > matter) I was wondering if there is something similar where I can > work on. > > Do you have any suggestions? TomBoy is written in C#, so why not start hacking on its code directly. True it uses GTK#, but that is available on Windows and OS X. If you need to start from scratch, you will probably want to develop a server system to keep all the notes. You can use any python web framework you want for that, and SQL of some kind for the data. Just develop an RPC api (using XMLRPC, SOAP, or REST) and then your clients (be it browser-based or conventional apps) can interface with it over that api. You might also consider that there are numerous commercial packages that already do most everything your company needs on a variety of platforms including handhelds. For example, Evernote. Good luck. From walterhurry at lavabit.com Sun Apr 21 16:31:32 2013 From: walterhurry at lavabit.com (Walter Hurry) Date: Sun, 21 Apr 2013 20:31:32 +0000 (UTC) Subject: ask for note keeper tomboy's style References: <833d0c05-56de-46bb-98b1-64b4ec92d7fa@googlegroups.com> Message-ID: On Sun, 21 Apr 2013 11:42:06 -0600, Michael Torrie wrote: > On 04/21/2013 12:20 AM, LordMax wrote: >> Hi to all. >> >> I am new to python and I was asked to implement a system of notes in >> tomboy's style for my company. >> >> As one of the requirements is the ability to synchronize notes between >> multiple PC (program level or through cloud-folder does not matter) I >> was wondering if there is something similar where I can work on. >> >> Do you have any suggestions? > > TomBoy is written in C#, so why not start hacking on its code directly. > True it uses GTK#, but that is available on Windows and OS X. > > If you need to start from scratch, you will probably want to develop a > server system to keep all the notes. You can use any python web > framework you want for that, and SQL of some kind for the data. Just > develop an RPC api (using XMLRPC, SOAP, or REST) and then your clients > (be it browser-based or conventional apps) can interface with it over > that api. > > You might also consider that there are numerous commercial packages that > already do most everything your company needs on a variety of platforms > including handhelds. For example, Evernote. Wake up. It's homework. From greg.ewing at canterbury.ac.nz Sun Apr 21 04:42:03 2013 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 21 Apr 2013 20:42:03 +1200 Subject: ANN: Albow 2.2.0 Message-ID: ALBOW - A Little Bit of Widgetry for PyGame Version 2.2 is now available. http://www.cosc.canterbury.ac.nz/greg.ewing/python/Albow/ Highlights of this version: * Multichoice control * Powerful new facilities for hot-linking controls to application data There are also many other improvements and bug fixes. See the Change Log for details. What is Albow? Albow is a library for creating GUIs using PyGame that I have been developing over the course of several PyWeek competitions. I am documenting and releasing it as a separate package so that others may benefit from it, and so that it will be permissible for use in future PyGame entries. The download includes HTML documentation and some example programs demonstrating most of the library's features. You can also see some screenshots and browse the documentation on-line. -- Gregory Ewing greg.ewing at canterbury.ac.nz From rosuav at gmail.com Sun Apr 21 09:46:27 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 21 Apr 2013 23:46:27 +1000 Subject: Porting 2.x to 3.3: BaseHTTPServer Message-ID: I'm porting an old project to Python 3, with the intention of making one codebase that will still run on 2.6/2.7 as well as 3.2+ (or 3.3+, if 3.2 is in any way annoying). My first step was to run the code through 2to3, and the basics are already sorted out by that. Got one question though, and it's more of an advice one. In the current version of the code, I use BaseHTTPServer as the main structure of the request handler. 2to3 translated this into http.server, which seems to be the nearest direct translation. But is that the best way to go about making a simple HTTP server? Also, it's expecting bytes everywhere, and I can't find a simple way to declare an encoding and let self.wfile.write() accept str. Do I have to explicitly encode everything that I write, or is there a cleaner way? (I could always make my own helper function, but would prefer something standard if there's a way.) The current version of the code is at: https://github.com/Rosuav/Yosemite It's ugly in quite a few places; when I wrote most of that, I was fairly new to Python, so I made a lot of naughty mistakes (bare except clauses all over the place, ugh!). Adding support for Python 3 seems like a good excuse to clean all that up, too :) ChrisA From roy at panix.com Sun Apr 21 10:01:14 2013 From: roy at panix.com (Roy Smith) Date: Sun, 21 Apr 2013 10:01:14 -0400 Subject: Porting 2.x to 3.3: BaseHTTPServer References: Message-ID: In article , Chris Angelico wrote: > In the current version of the code, I use BaseHTTPServer as the main > structure of the request handler. 2to3 translated this into > http.server, which seems to be the nearest direct translation. But is > that the best way to go about making a simple HTTP server? For most purposes, I would suggest one of the third-party web frameworks. For simple things, I'm partial to Tornado, but it's not the only choice. The advantage of these frameworks is they give you a lot of boilerplate code that handles all the low-level protocol gunk and lets you concentrate on writing your application logic. My gut feeling is that nobody should ever be using BaseHTTPServer for anything other than as a learning exercise (or as a base on which to build other frameworks). It's just too low level. I haven't used the 3.x http.server, but http.server looks like much of the same. From rosuav at gmail.com Sun Apr 21 10:13:48 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 22 Apr 2013 00:13:48 +1000 Subject: Porting 2.x to 3.3: BaseHTTPServer In-Reply-To: References: Message-ID: On Mon, Apr 22, 2013 at 12:01 AM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> In the current version of the code, I use BaseHTTPServer as the main >> structure of the request handler. 2to3 translated this into >> http.server, which seems to be the nearest direct translation. But is >> that the best way to go about making a simple HTTP server? > > For most purposes, I would suggest one of the third-party web > frameworks. For simple things, I'm partial to Tornado, but it's not the > only choice. The advantage of these frameworks is they give you a lot > of boilerplate code that handles all the low-level protocol gunk and > lets you concentrate on writing your application logic. > > My gut feeling is that nobody should ever be using BaseHTTPServer for > anything other than as a learning exercise (or as a base on which to > build other frameworks). It's just too low level. I haven't used the > 3.x http.server, but http.server looks like much of the same. Have a look at the code in question: https://github.com/Rosuav/Yosemite/blob/master/Yosemite.py#L81 It's REALLY simple. I don't need any sort of framework; it's basically just using a web browser as its UI, to save on writing a client. So I'm looking for the simplest possible option; I don't need security or anything (this is designed for a trusted LAN), nor scaleability (we're talking queries per hour, not per second). I'm actually looking at cutting it back even further. There are os.system() calls that I'm thinking should possibly become popen(), and maybe copy a binary into /tmp and giving a full path to it, as sometimes this is used on a low-end system and needs to perform actions with low latency. ChrisA From storchaka at gmail.com Sun Apr 21 14:01:50 2013 From: storchaka at gmail.com (Serhiy Storchaka) Date: Sun, 21 Apr 2013 21:01:50 +0300 Subject: Porting 2.x to 3.3: BaseHTTPServer In-Reply-To: References: Message-ID: 21.04.13 16:46, Chris Angelico ???????(??): > Also, it's expecting bytes everywhere, and I can't find a simple way > to declare an encoding and let self.wfile.write() accept str. Do I > have to explicitly encode everything that I write, or is there a > cleaner way? io.TextIOWrapper From ryacobellis at luc.edu Sun Apr 21 10:09:20 2013 From: ryacobellis at luc.edu (Robert Yacobellis) Date: Sun, 21 Apr 2013 09:09:20 -0500 Subject: suggestion for a small addition to the Python 3 list class Message-ID: <5173ACC00200007C000B7024@gwiawt1.is-svr.luc.edu> Greetings, I'm an instructor of Computer Science at Loyola University, Chicago, and I and Dr. Harrington (copied on this email) teach sections of COMP 150, Introduction to Computing, using Python 3. One of the concepts we teach students is the str methods split() and join(). I have a suggestion for a small addition to the list class: add a join() method to lists. It would work in a similar way to how join works for str's, except that the object and method parameter would be reversed: .join(). Rationale: When I teach students about split(), I can intuitively tell them split() splits the string on its left on white space or a specified string. Explaining the current str join() method to them doesn't seem to make as much sense: use the string on the left to join the items in the list?? If the list class had a join method, it would be more intuitive to say "join the items in the list using the specified string (the method's argument)." This is similar to Scala's List mkString() method. I've attached a proposed implementation in Python code which is a little more general than what I've described. In this implementation the list can contain elements of any type, and the separator can also be any data type, not just str. I've noticed that the str join() method takes an iterable, so in the most general case I'm suggesting to add a join() method to every Python-provided iterable (however, for split() vs. join() it would be sufficient to just add a join() method to the list class). Please let me know your ideas, reactions, and comments on this suggestion. Thanks and regards, Dr. Robert (Bob) Yacobellis -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: join.py Type: application/octet-stream Size: 651 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: jointest.py Type: application/octet-stream Size: 1247 bytes Desc: not available URL: From lele at metapensiero.it Sun Apr 21 13:12:28 2013 From: lele at metapensiero.it (Lele Gaifax) Date: Sun, 21 Apr 2013 19:12:28 +0200 Subject: suggestion for a small addition to the Python 3 list class References: <5173ACC00200007C000B7024@gwiawt1.is-svr.luc.edu> Message-ID: <87vc7fvmdf.fsf@nautilus.nautilus> "Robert Yacobellis" writes: > I've noticed that the str join() method takes an iterable, so in the > most general case I'm suggesting to add a join() method to every > Python-provided iterable (however, for split() vs. join() it would be > sufficient to just add a join() method to the list class). That's the reasoning behind the rejection: to be friendly enough, you'd need to include the "join" method in the "sequence protocol", and implement it on every "sequence-like" object (be it some kind of UserList, or a generator, or an interator...) This question carries several references to the various threads on the subject: http://stackoverflow.com/questions/493819/python-join-why-is-it-string-joinlist-instead-of-list-joinstring 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 tjreedy at udel.edu Sun Apr 21 21:44:05 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Sun, 21 Apr 2013 21:44:05 -0400 Subject: suggestion for a small addition to the Python 3 list class In-Reply-To: <87vc7fvmdf.fsf@nautilus.nautilus> References: <5173ACC00200007C000B7024@gwiawt1.is-svr.luc.edu> <87vc7fvmdf.fsf@nautilus.nautilus> Message-ID: On 4/21/2013 1:12 PM, Lele Gaifax wrote: > "Robert Yacobellis" writes: > >> I've noticed that the str join() method takes an iterable, Specifically, it takes an iterable of strings. Any iterable can be made such iwth map(str, iterable) or map(repr, iterble). >> so in the >> most general case I'm suggesting to add a join() method to every >> Python-provided iterable (however, for split() vs. join() .split *could* have been changed in 3.0 to return an iterator rather than a list, as done with map, filter, and others. An itersplit method *might* be added in the future. it would be >> sufficient to just add a join() method to the list class). > > That's the reasoning behind the rejection: to be friendly enough, you'd > need to include the "join" method in the "sequence protocol", and > implement it on every "sequence-like" object (be it some kind of > UserList, or a generator, or an interator...) Plus, only lists of strings can be joined, not generic lists. > This question carries several references to the various threads on the > subject: > > http://stackoverflow.com/questions/493819/python-join-why-is-it-string-joinlist-instead-of-list-joinstring > > ciao, lele. > From steve+comp.lang.python at pearwood.info Sun Apr 21 15:53:27 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Apr 2013 19:53:27 GMT Subject: suggestion for a small addition to the Python 3 list class References: Message-ID: <517443b6$0$29977$c3e8da3$5496439d@news.astraweb.com> On Sun, 21 Apr 2013 09:09:20 -0500, Robert Yacobellis wrote: > Greetings, > > I'm an instructor of Computer Science at Loyola University, Chicago, and > I and Dr. Harrington (copied on this email) teach sections of COMP 150, > Introduction to Computing, using Python 3. One of the concepts we teach > students is the str methods split() and join(). I have a suggestion for > a small addition to the list class: add a join() method to lists. It > would work in a similar way to how join works for str's, except that the > object and method parameter would be reversed: .join( object>). That proposed interface doesn't make much sense to me. You're performing a string operation ("make a new string, using this string as a separator") not a list operation, so it's not really appropriate as a list method. It makes much more sense as a string method. It is also much more practical as a string method. This way, only two objects need a join method: strings, and bytes (or if you prefer, Unicode strings and byte strings). Otherwise, you would need to duplicate the method in every possible iterable object: - lists - tuples - dicts - OrderedDicts - sets - frozensets - iterators - generators - every object that obeys the sequence protocol - every object that obeys the iterator protocol (with the exception of iterable objects such as range objects that cannot contain strings). Every object would have to contain code that does exactly the same thing in every detail: walk the iterable, checking that the item is a string, and build up a new string with the given separator: class list: # also tuple, dict, set, frozenset, etc... def join(self, separator): ... Not only does that create a lot of duplicated code, but it also increases the burden on anyone creating an iterable class, including iterators and sequences. Anyone who writes their own iterable class has to write their own join method, which is actually trickier than it seems at first glance. (See below.) Any half-decent programmer would recognise the duplicated code and factor it out into an external function that takes a separator and a iterable object: def join(iterable, separator): # common code goes here... it's *all* common code, every object's # join method is identical That's exactly what Python already does, except it swaps the order of the arguments: def join(separator, iterable): ... and promotes it to a method on strings instead of a bare function. > Rationale: When I teach students about split(), I can intuitively tell > them split() splits the string on its left on white space or a specified > string. Explaining the current str join() method to them doesn't seem > to make as much sense: use the string on the left to join the items in > the list?? Yes, exactly. Makes perfect sense to me. > If the list class had a join method, it would be more > intuitive to say "join the items in the list using the specified string > (the method's argument)." You can still say that. You just have to move the parenthetical aside: "Join the items in the list (the method's argument) using the specified string." > This is similar to Scala's List mkString() method. This is one place where Scala gets it wrong. In my opinion, as a list method, mkString ought to operate on the entire list, not its individual items. The nearest equivalent in Python would be converting a list to a string using the repr() or str() functions: py> str([1, 2, 3]) '[1, 2, 3]' (which of course call the special methods __repr__ or __str__ on the list). > I've attached a proposed implementation in Python code which is a little > more general than what I've described. In this implementation the list > can contain elements of any type, and the separator can also be any data > type, not just str. Just for the record, the implementation you provide will be O(N**2) due to the repeated string concatenation, which means it will be *horribly* slow for large enough lists. It's actually quite difficult to efficiently join a lot of strings without using the str.join method. Repeated string concatenation will, in general, be slow due to the repeated copying of intermediate results. By shifting the burden of writing a join method onto everyone who creates a sequence type, we would end up with a lot of slow code. If you must have a convenience (inconvenience?) method on lists, the right way to do it is like this: class list2(list): def join(self, sep=' '): if isinstance(sep, (str, bytes)): return sep.join(self) raise TypeError -- Steven From jsf80238 at gmail.com Sun Apr 21 13:31:24 2013 From: jsf80238 at gmail.com (Jason Friedman) Date: Sun, 21 Apr 2013 11:31:24 -0600 Subject: Remove some images from a mail message Message-ID: I will be receiving email that contains, say, 10 images, and I want to forward that message on after removing, say, 5 of those images. I will remove based on size, for example 1679 bytes. I am aware that other images besides the unwanted ones could be 1679 bytes but this is unlikely and the impact of mistakes is small. I have figured out how to compose and send an email message from parts: from, to, subject, and some images. I was planning to read the incoming message, write the images I want to keep to files, then use those files to construct the outgoing message. I cannot figure out how to read the incoming message and extract the images. message_in = email.message_from_binary_file(open(file_name, "rb")) for part in message_in.walk(): print("-" * 80) print("type: " + part.get_content_maintype()) for key, value in part.items(): print("key: " + key) print("value: " + value) ------------------------- type: multipart key: Return-Path value: key: X-Original-To value: myuser at myhost ... key: Content-Type value: multipart/alternative; boundary="_000_A9E5330AAB8D0D4E8F9372F872EE8504010458F671hostden_" --_000_A9E5330AAB8D0D4E8F9372F872EE85040104591ECChostden_-- --_010_A9E5330AAB8D0D4E8F9372F872EE85040104591ECChostden_ Content-Type: image/png; name="image001.png" Content-Description: image001.png Content-Disposition: inline; filename="image001.png"; size=9257; creation-date="Mon, 15 Apr 2013 17:48:29 GMT"; modification-date="Mon, 15 Apr 2013 17:48:29 GMT" Content-ID: Content-Transfer-Encoding: base64 iVBORw0KGgoAAAANSUhEUgAAANcAAAAwCAYAAACCPO+PAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ bWFnZVJlYWR5ccllPAAAI8tJREFUeNrsXQlYVdUW/u+Fey+TCqgJTqA4i4rzjDM4pGaZU449yxAM Xy+bfY1WZpmZkpapZVpZmpmiKCqoOOGEGjmLI6AioMxcuO/f5+wLl0HFqVd59/ftz3sO+5yzzz7r ... ---------------------- I'm guessing my image is in there, how do I get it out? -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Sun Apr 21 16:13:36 2013 From: davea at davea.name (Dave Angel) Date: Sun, 21 Apr 2013 16:13:36 -0400 Subject: Remove some images from a mail message In-Reply-To: References: Message-ID: <51744870.1090704@davea.name> On 04/21/2013 01:31 PM, Jason Friedman wrote: > I will be receiving email that contains, say, 10 images, and I want to > forward that message on after removing, say, 5 of those images. I will > remove based on size, for example 1679 bytes. I am aware that other images > besides the unwanted ones could be 1679 bytes but this is unlikely and the > impact of mistakes is small. > > I have figured out how to compose and send an email message from parts: > from, to, subject, and some images. I was planning to read the incoming > message, write the images I want to keep to files, then use those files to > construct the outgoing message. > > I cannot figure out how to read the incoming message and extract the images. > > message_in = email.message_from_binary_file(open(file_name, "rb")) > for part in message_in.walk(): > print("-" * 80) > print("type: " + part.get_content_maintype()) > for key, value in part.items(): > print("key: " + key) > print("value: " + value) > > ------------------------- > > type: multipart > key: Return-Path > value: > key: X-Original-To > value: myuser at myhost > > ... > > key: Content-Type > value: multipart/alternative; > boundary="_000_A9E5330AAB8D0D4E8F9372F872EE8504010458F671hostden_" > > --_000_A9E5330AAB8D0D4E8F9372F872EE85040104591ECChostden_-- > > --_010_A9E5330AAB8D0D4E8F9372F872EE85040104591ECChostden_ > Content-Type: image/png; name="image001.png" > Content-Description: image001.png > Content-Disposition: inline; filename="image001.png"; size=9257; > creation-date="Mon, 15 Apr 2013 17:48:29 GMT"; > modification-date="Mon, 15 Apr 2013 17:48:29 GMT" > Content-ID: > Content-Transfer-Encoding: base64 > > iVBORw0KGgoAAAANSUhEUgAAANcAAAAwCAYAAACCPO+PAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ > bWFnZVJlYWR5ccllPAAAI8tJREFUeNrsXQlYVdUW/u+Fey+TCqgJTqA4i4rzjDM4pGaZU449yxAM > Xy+bfY1WZpmZkpapZVpZmpmiKCqoOOGEGjmLI6AioMxcuO/f5+wLl0HFqVd59/ftz3sO+5yzzz7r > > ... > > ---------------------- > > I'm guessing my image is in there, how do I get it out? > > > One possibility, see the base64 module: http://docs.python.org/library/base64.html -- DaveA From jsf80238 at gmail.com Tue Apr 23 08:17:00 2013 From: jsf80238 at gmail.com (Jason Friedman) Date: Tue, 23 Apr 2013 06:17:00 -0600 Subject: Remove some images from a mail message In-Reply-To: References: Message-ID: This seemed to work. #!/usr/bin/env python3 from email.mime.image import MIMEImage from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.iterators import typed_subpart_iterator from email.generator import Generator, BytesGenerator import email.iterators import os import sys import tempfile IGNORE_SET = set((588, 1279, 1275, 1576, 1272, 1591,)) IMAGE = "image" TEXT = "text" PLAIN = "plain" SUBJECT = "Subject" FROM = "From" TO = "To" DATE = "Date" WRITE_BINARY = "wb" READ_BINARY = "rb" output_message_file_name = "/home/jason/resulting_message" input_file_name = "/home/jason/example_message" with open(input_file_name, READ_BINARY) as reader: message_in = email.message_from_binary_file(reader) message_out = MIMEMultipart() header_field_list = (SUBJECT, FROM, DATE) for field_name in header_field_list: message_out.__setitem__(field_name, message_in[field_name]) message_out[TO] = "jason" temp_dir = tempfile.TemporaryDirectory() for part in typed_subpart_iterator(message_in, maintype=IMAGE): file_name = part.get_filename() full_path = os.path.join(temp_dir.name, file_name) with open(full_path, WRITE_BINARY) as writer: writer.write(part.get_payload(decode=True)) if os.stat(full_path).st_size not in IGNORE_SET: with open(full_path, READ_BINARY) as reader: attachment = MIMEImage(reader.read()) message_out.attach(attachment) for part in email.iterators.typed_subpart_iterator(message_in, maintype=TEXT, subtype=PLAIN): message_out.attach(part) with open(output_message_file_name, WRITE_BINARY) as writer: x = BytesGenerator(writer) x.flatten(message_out) -------------- next part -------------- An HTML attachment was scrubbed... URL: From jussij at zeusedit.com Sun Apr 21 20:37:18 2013 From: jussij at zeusedit.com (jussij at zeusedit.com) Date: Sun, 21 Apr 2013 17:37:18 -0700 (PDT) Subject: Weird behaviour? Message-ID: Can someone please explain the following behaviour? I downloaded and compiled the Python 2.7.2 code base. I then created this simple c:\temp\test.py macro: import sys def main(): print("Please Input 120: ") input = raw_input() print("Value Inputed: " + input) if str(input) == "120": print("Yes") else: print("No") main() If I run the macro using the -u (flush buffers) option the if statement always fails: C:\Temp>python.exe -u c:\temp\test.py Please Input 120: 120 Value Inputed: 120 No If I run the macro without the -u option the if statement works as expected: C:\Temp>python.exe c:\temp\test.py Please Input 120: 120 Value Inputed: 120 Yes What's going on? Cheers Jussi From rosuav at gmail.com Sun Apr 21 20:56:11 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 22 Apr 2013 10:56:11 +1000 Subject: Weird behaviour? In-Reply-To: References: Message-ID: On Mon, Apr 22, 2013 at 10:37 AM, wrote: > Can someone please explain the following behaviour? > > If I run the macro using the -u (flush buffers) option the if statement always fails: > > C:\Temp>python.exe -u c:\temp\test.py > Please Input 120: > 120 > Value Inputed: 120 > No Here's the essence of your program: print(repr(raw_input())) You can use that to verify what's going on. Try running that with and without the -u option; note, by the way, that -u actually means "unbuffered", not "flush buffers". You're running this under Windows. The convention on Windows is for end-of-line to be signalled with \r\n, but the convention inside Python is to use just \n. With the normal use of buffered and parsed input, this is all handled for you; with unbuffered input, that translation also seems to be disabled, so your string actually contains '120\r', as will be revealed by its repr(). By the way, raw_input() already returns a string. There's no need to str() it. :) ChrisA From steve+comp.lang.python at pearwood.info Sun Apr 21 21:05:11 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Apr 2013 01:05:11 GMT Subject: Weird behaviour? References: Message-ID: <51748cc7$0$29977$c3e8da3$5496439d@news.astraweb.com> On Sun, 21 Apr 2013 17:37:18 -0700, jussij wrote: > Can someone please explain the following behaviour? > > I downloaded and compiled the Python 2.7.2 code base. > > I then created this simple c:\temp\test.py macro: > > import sys > > def main(): > print("Please Input 120: ") > input = raw_input() > > print("Value Inputed: " + input) > > if str(input) == "120": > print("Yes") > else: > print("No") > > main() > > If I run the macro using the -u (flush buffers) option the if statement > always fails: > > C:\Temp>python.exe -u c:\temp\test.py Please Input 120: > 120 > Value Inputed: 120 > No I cannot confirm that behaviour. It works fine for me. Are you sure that the code you show above is *exactly* the code you're using? Actually, it cannot possibly be the exact code you are using, since it has been indented. What other changes did you make when retyping it in your message? Please copy and paste the actual code used, without retyping or making any modifications. If the problem still persists, try printing repr(input) and see what it shows. Also, a comment on your code: there is no need to call str(input), since input is already a string. If you replace the test: str(input) == '120' with just input == '120' does the problem go away? If so, then there's something funny going on with the call to str(). Please print(str), and see what it shows. -- Steven From rosuav at gmail.com Sun Apr 21 21:13:11 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 22 Apr 2013 11:13:11 +1000 Subject: Weird behaviour? In-Reply-To: <51748cc7$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <51748cc7$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Apr 22, 2013 at 11:05 AM, Steven D'Aprano wrote: > I cannot confirm that behaviour. It works fine for me. I should mention: Under Linux, there's no \r, so -u or no -u, the program will work fine. ChrisA From jussij at zeusedit.com Sun Apr 21 21:14:53 2013 From: jussij at zeusedit.com (jussij at zeusedit.com) Date: Sun, 21 Apr 2013 18:14:53 -0700 (PDT) Subject: Weird behaviour? In-Reply-To: <51748cc7$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <51748cc7$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1322e42d-9bcf-4c6c-9bcb-5fa715f7e7d6@googlegroups.com> On Monday, April 22, 2013 11:05:11 AM UTC+10, Steven D'Aprano wrote: > I cannot confirm that behaviour. It works fine for me. As Chris pointed out there is a \r character at the end of the string and that is causing the if to fail. I can now see the \r :) So this is *Windows only* behaviour. Cheers Jussi From jussij at zeusedit.com Sun Apr 21 21:11:04 2013 From: jussij at zeusedit.com (jussij at zeusedit.com) Date: Sun, 21 Apr 2013 18:11:04 -0700 (PDT) Subject: Weird behaviour? In-Reply-To: References: Message-ID: <17823701-a6f1-49ba-8246-b3f5d107ebc4@googlegroups.com> On Monday, April 22, 2013 10:56:11 AM UTC+10, Chris Angelico wrote: > so your string actually contains '120\r', as will be revealed > by its repr(). Thanks Chris. That makes sense. Cheers Jussi From steve+comp.lang.python at pearwood.info Sun Apr 21 21:19:11 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Apr 2013 01:19:11 GMT Subject: Weird behaviour? References: Message-ID: <5174900e$0$29977$c3e8da3$5496439d@news.astraweb.com> On Mon, 22 Apr 2013 10:56:11 +1000, Chris Angelico wrote: > You're running this under Windows. The convention on Windows is for > end-of-line to be signalled with \r\n, but the convention inside Python > is to use just \n. With the normal use of buffered and parsed input, > this is all handled for you; with unbuffered input, that translation > also seems to be disabled, so your string actually contains '120\r', as > will be revealed by its repr(). If that's actually the case, then I would call that a bug in raw_input. Actually, raw_input doesn't seem to cope well with embedded newlines even without the -u option. On Linux, I can embed a control character by typing Ctrl-V followed by Ctrl-. E.g. Ctrl-V Ctrl-M to embed a carriage return, Ctrl-V Ctrl-J to embed a newline. So watch: [steve at ando ~]$ python2.7 -c "x = raw_input('Hello? '); print repr(x)" Hello? 120^M^Jabc '120\r' Everything after the newline is lost. -- Steven From pruebauno at latinmail.com Mon Apr 22 10:29:57 2013 From: pruebauno at latinmail.com (nn) Date: Mon, 22 Apr 2013 07:29:57 -0700 (PDT) Subject: Weird behaviour? References: <5174900e$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Apr 21, 9:19?pm, Steven D'Aprano wrote: > On Mon, 22 Apr 2013 10:56:11 +1000, Chris Angelico wrote: > > You're running this under Windows. The convention on Windows is for > > end-of-line to be signalled with \r\n, but the convention inside Python > > is to use just \n. With the normal use of buffered and parsed input, > > this is all handled for you; with unbuffered input, that translation > > also seems to be disabled, so your string actually contains '120\r', as > > will be revealed by its repr(). > > If that's actually the case, then I would call that a bug in raw_input. > > Actually, raw_input doesn't seem to cope well with embedded newlines even > without the -u option. On Linux, I can embed a control character by > typing Ctrl-V followed by Ctrl-. E.g. Ctrl-V Ctrl-M to embed a > carriage return, Ctrl-V Ctrl-J to embed a newline. So watch: > > [steve at ando ~]$ python2.7 -c "x = raw_input('Hello? '); print repr(x)" > Hello? 120^M^Jabc > '120\r' > > Everything after the newline is lost. > > -- > Steven Maybe it is related to this bug? http://bugs.python.org/issue11272 From jussij at zeusedit.com Mon Apr 22 19:06:53 2013 From: jussij at zeusedit.com (jussij at zeusedit.com) Date: Mon, 22 Apr 2013 16:06:53 -0700 (PDT) Subject: Weird behaviour? In-Reply-To: References: <5174900e$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <603c9915-54a8-415e-a826-e3e73c5dcab3@googlegroups.com> On Tuesday, April 23, 2013 12:29:57 AM UTC+10, nn wrote: > Maybe it is related to this bug? > > http://bugs.python.org/issue11272 I'm running Python 2.7.2 (on Windows) and that version doesn't appear to have that bug: Python 2.7.2 (default, Apr 23 2013, 11:49:52) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print(repr(input())) "testing" 'testing' >>> Cheers Jussi From rosuav at gmail.com Mon Apr 22 20:04:27 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Apr 2013 10:04:27 +1000 Subject: Weird behaviour? In-Reply-To: <603c9915-54a8-415e-a826-e3e73c5dcab3@googlegroups.com> References: <5174900e$0$29977$c3e8da3$5496439d@news.astraweb.com> <603c9915-54a8-415e-a826-e3e73c5dcab3@googlegroups.com> Message-ID: On Tue, Apr 23, 2013 at 9:06 AM, wrote: > On Tuesday, April 23, 2013 12:29:57 AM UTC+10, nn wrote: > >> Maybe it is related to this bug? >> >> http://bugs.python.org/issue11272 > > I'm running Python 2.7.2 (on Windows) and that version doesn't appear to have that bug: > > Python 2.7.2 (default, Apr 23 2013, 11:49:52) [MSC v.1500 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> print(repr(input())) > "testing" > 'testing' > >>> Careful there; go with raw_input() on Py2. And then it does happen. ChrisA From steve+comp.lang.python at pearwood.info Mon Apr 22 20:31:55 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Apr 2013 00:31:55 GMT Subject: Weird behaviour? References: <5174900e$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5175d67b$0$29977$c3e8da3$5496439d@news.astraweb.com> On Mon, 22 Apr 2013 07:29:57 -0700, nn wrote: > On Apr 21, 9:19?pm, Steven D'Aprano +comp.lang.pyt... at pearwood.info> wrote: >> On Mon, 22 Apr 2013 10:56:11 +1000, Chris Angelico wrote: >> > You're running this under Windows. The convention on Windows is for >> > end-of-line to be signalled with \r\n, but the convention inside >> > Python is to use just \n. With the normal use of buffered and parsed >> > input, this is all handled for you; with unbuffered input, that >> > translation also seems to be disabled, so your string actually >> > contains '120\r', as will be revealed by its repr(). >> >> If that's actually the case, then I would call that a bug in raw_input. >> >> Actually, raw_input doesn't seem to cope well with embedded newlines >> even without the -u option. On Linux, I can embed a control character >> by typing Ctrl-V followed by Ctrl-. E.g. Ctrl-V Ctrl-M to embed a >> carriage return, Ctrl-V Ctrl-J to embed a newline. So watch: >> >> [steve at ando ~]$ python2.7 -c "x = raw_input('Hello? '); print repr(x)" >> Hello? 120^M^Jabc >> '120\r' >> >> Everything after the newline is lost. >> >> -- >> Steven > > Maybe it is related to this bug? > > http://bugs.python.org/issue11272 I doubt it, I'm not using Windows and that bug is specific to Windows. Here's the behaviour on Python 3.3: py> result = input("Type something with control chars: ") Type something with control chars: something ^T^M else and a second line py> print(repr(result)) 'something \x14\r else \nand a second line' Much better! -- Steven From josiah.carlson at gmail.com Mon Apr 22 00:51:50 2013 From: josiah.carlson at gmail.com (Josiah Carlson) Date: Sun, 21 Apr 2013 21:51:50 -0700 Subject: ANN: rom 0.10 - Redis object mapper for Python Message-ID: Hey everyone, I know, it's been several years since I announced anything on these lists, but I suspect that some of you may have uses for my new package, so here you go. The "rom" package is a Redis object mapper for Python. It sports an interface similar to Django's ORM, SQLAlchemy + Elixir, or Appengine's datastore. This is the initial release, so there may be some rough edges. I've included the basic intro for the package below. You can find the package at: https://www.github.com/josiahcarlson/rom https://pypi.python.org/pypi/rom Please CC me on any replies if you have any questions or comments. Thank you, - Josiah What's new? ========== Everything What ==== Rom is a package whose purpose is to offer active-record style data modeling within Redis from Python, similar to the semantics of Django ORM, SQLAlchemy + Elixir, Google's Appengine datastore, and others. Why === I was building a personal project, wanted to use Redis to store some of my data, but didn't want to hack it poorly. I looked at the existing Redis object mappers available in Python, but didn't like the features and functionality offered. What is available ================= Data types: * Strings, ints, floats, decimals * Json columns (for nested structures) * OneToMany and ManyToOne columns (for model references) Indexes: * Numeric range fetches, searches, and ordering * Full-word text search (find me entries with col X having words A and B) Other features: * Per-thread entity cache (to minimize round-trips, easy saving of all entities) -------------- next part -------------- An HTML attachment was scrubbed... URL: From padrino121 at email.com Sun Apr 21 22:33:26 2013 From: padrino121 at email.com (Brian Raymond) Date: Sun, 21 Apr 2013 22:33:26 -0400 Subject: How to get urllib2 HTTPConnection object, use httplib methods? Message-ID: <528127D2-7D12-473C-BBFE-5DA0CC3E5918@email.com> I have a httplib based application and in an effort to find a quick way to start leveraging urllib2, including NTLM authentication (via python-ntlm) I am hoping there is a way to utilize an HTTPConnection object opened by urllib2. The goal is to change the initial opener to use urllib2, after that continue to use httplib methods. Thanks. From diolu.remove_this_part at bigfoot.com Mon Apr 22 05:03:23 2013 From: diolu.remove_this_part at bigfoot.com (Olive) Date: Mon, 22 Apr 2013 11:03:23 +0200 Subject: pip does not find packages Message-ID: <20130422110323.395a439f@pcolivier.chezmoi.net> I am using virtualenv and pip (from archlinux). What I have done: virtualenv was installed by my distribution. I have made a virtual environment and activate it, it has installed pip, so far so good. Now I am trying to install package in the virtualenvironnement: pip install Impacket Downloading/unpacking Impacket Could not find any downloads that satisfy the requirement Impacket No distributions at all found for Impacket but Impacket is found by pip search Impacket Impacket - Network protocols Constructors and Dissectors exactly the same happens with pcapy. With PyGTK, the pip command just hang when trying to download it. What is going on? Maybe a misconfigured server? Is there anything that I can do? Olive From rustompmody at gmail.com Tue Apr 23 13:32:10 2013 From: rustompmody at gmail.com (rusi) Date: Tue, 23 Apr 2013 10:32:10 -0700 (PDT) Subject: pip does not find packages References: <20130422110323.395a439f@pcolivier.chezmoi.net> Message-ID: <6283cb64-7a83-435a-a0a0-84f1cb89c6fe@aw7g2000pbd.googlegroups.com> On Apr 22, 2:03?pm, Olive wrote: > I am using virtualenv and pip (from archlinux). What I have done: > virtualenv was installed by my distribution. I have made a virtual environment and activate it, it has installed pip, so far so good. > > Now I am trying to install package in the virtualenvironnement: > > pip install Impacket > Downloading/unpacking Impacket > ? Could not find any downloads that satisfy the requirement Impacket > No distributions at all found for Impacket > > but Impacket is found by > pip search Impacket > Impacket ? ? ? ? ? ? ? ? ?- Network protocols Constructors and Dissectors > > exactly the same happens with pcapy. With PyGTK, the pip command just hang when trying to download it. What is going on? Maybe a misconfigured server? Is there anything that I can do? There is a GG http://groups.google.com/group/python-virtualenv For things like virtualenv/pip/wheel etc > > Olive From chandan_psr at yahoo.co.in Mon Apr 22 05:34:08 2013 From: chandan_psr at yahoo.co.in (chandan kumar) Date: Mon, 22 Apr 2013 17:34:08 +0800 (SGT) Subject: Serial Port Issue Message-ID: <1366623248.70365.YahooMailClassic@web190503.mail.sg3.yahoo.com> Hi, I'm new to python and trying to learn serial communication using python.In this process i'm facing?serial?port issues.Please find the attached COMPorttest.py file ,correct me if anything wrong in the code.With my code it's always goes in to exception.I noted down the the COM port number ?from windows device manager list.? Operating system: XPPython Ver: 2.5Pyserial: 2.5 Even i tried from python shell passing below commands import serialser=ser=serial.Serial(port=21,baudrate=9600) I observe below error on python shell File "C:\Python25\lib\serial\serialwin32.py", line 55, in open? ? raise SerialException("could not open port: %s" % msg)SerialException: could not open port: (2, 'CreateFile', 'The system cannot find the file specified.') Thanks in advance. Best Regards,Chandan. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: COMPortTest.py URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: DeviceManager.PNG Type: image/png Size: 23011 bytes Desc: not available URL: From phil at petrasoft.net Mon Apr 22 11:13:44 2013 From: phil at petrasoft.net (Phil Birkelbach) Date: Mon, 22 Apr 2013 10:13:44 -0500 Subject: Serial Port Issue In-Reply-To: <1366623248.70365.YahooMailClassic@web190503.mail.sg3.yahoo.com> References: <1366623248.70365.YahooMailClassic@web190503.mail.sg3.yahoo.com> Message-ID: <4DC6A1D4-518F-4FD9-88C5-361975FD98F8@petrasoft.net> Have you tried 'port=20'? The documentation says that the port numbering starts at zero. I don't use Windows so I can't test it for you. You could also try port="COM21" Phil On Apr 22, 2013, at 4:34 AM, chandan kumar wrote: > Hi, > > I'm new to python and trying to learn serial communication using python.In this process i'm facing serial port issues.Please find the attached COMPorttest.py file ,correct me if anything wrong in the code.With my code it's always goes in to exception.I noted down the the COM port number from windows device manager list. > > Operating system: XP > Python Ver: 2.5 > Pyserial: 2.5 > > Even i tried from python shell passing below commands > > import serial > ser=ser=serial.Serial(port=21,baudrate=9600) > > I observe below error on python shell > > File "C:\Python25\lib\serial\serialwin32.py", line 55, in open > raise SerialException("could not open port: %s" % msg) > SerialException: could not open port: (2, 'CreateFile', 'The system cannot find the file specified.') > > Thanks in advance. > > Best Regards, > Chandan. > > > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From chandan_psr at yahoo.co.in Tue Apr 23 02:02:25 2013 From: chandan_psr at yahoo.co.in (chandan kumar) Date: Tue, 23 Apr 2013 14:02:25 +0800 (SGT) Subject: Serial Port Issue In-Reply-To: <4DC6A1D4-518F-4FD9-88C5-361975FD98F8@petrasoft.net> Message-ID: <1366696945.92791.YahooMailClassic@web190501.mail.sg3.yahoo.com> Thanks Phil,You are right .with Port=20 it started working. Regards,Chandan. --- On Mon, 22/4/13, Phil Birkelbach wrote: From: Phil Birkelbach Subject: Re: Serial Port Issue To: python-list at python.org Cc: "chandan kumar" Date: Monday, 22 April, 2013, 8:43 PM Have you tried 'port=20'? The documentation says that the port numbering starts at zero. ?I don't use Windows so I can't test it for you. You could also try port="COM21" Phil On Apr 22, 2013, at 4:34 AM, chandan kumar wrote: Hi, I'm new to python and trying to learn serial communication using python.In this process i'm facing?serial?port issues.Please find the attached COMPorttest.py file ,correct me if anything wrong in the code.With my code it's always goes in to exception.I noted down the the COM port number ?from windows device manager list.? Operating system: XPPython Ver: 2.5Pyserial: 2.5 Even i tried from python shell passing below commands import serialser=ser=serial.Serial(port=21,baudrate=9600) I observe below error on python shell File "C:\Python25\lib\serial\serialwin32.py", line 55, in open? ? raise SerialException("could not open port: %s" % msg)SerialException: could not open port: (2, 'CreateFile', 'The system cannot find the file specified.') Thanks in advance. Best Regards,Chandan. -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From kwpolska at gmail.com Mon Apr 22 11:31:15 2013 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Mon, 22 Apr 2013 17:31:15 +0200 Subject: Serial Port Issue In-Reply-To: <1366623248.70365.YahooMailClassic@web190503.mail.sg3.yahoo.com> References: <1366623248.70365.YahooMailClassic@web190503.mail.sg3.yahoo.com> Message-ID: On Mon, Apr 22, 2013 at 11:34 AM, chandan kumar wrote: > Python Ver: 2.5 Old. Please upgrade to 2.7.4 ASAP. > ser=ser=serial.Serial(port=21,baudrate=9600) That double `ser=` thing is not necessary. It should only be `ser = serial.Serial(port=21, baudrate=9600)`. Look at Phil Birkelbach?s post for a possible solution. -- Kwpolska | GPG KEY: 5EAAEA16 stop html mail | always bottom-post http://asciiribbon.org | http://caliburn.nl/topposting.html From megha at greybatter.com Mon Apr 22 06:13:27 2013 From: megha at greybatter.com (Megha Agrawal) Date: Mon, 22 Apr 2013 15:43:27 +0530 Subject: Error in "Import gv " module Message-ID: https://code.google.com/p/python-graph/wiki/Example When I am trying to run the code to draw a graph, given on above link, I am getting following error: ImportError: No module named gv What can be the reasons? Thank you! -------------- next part -------------- An HTML attachment was scrubbed... URL: From andipersti at gmail.com Mon Apr 22 06:31:20 2013 From: andipersti at gmail.com (Andreas Perstinger) Date: Mon, 22 Apr 2013 12:31:20 +0200 Subject: Error in "Import gv " module In-Reply-To: References: Message-ID: <51751178.5070204@gmail.com> On 22.04.2013 12:13, Megha Agrawal wrote: > https://code.google.com/p/python-graph/wiki/Example > > When I am trying to run the code to draw a graph, given on above link, I am > getting following error: > > ImportError: No module named gv > > What can be the reasons? Which OS? It looks like you are missing "graphviz" or you need to adapt your paths: https://code.google.com/p/python-graph/issues/detail?id=15 Bye, Andreas From andipersti at gmail.com Mon Apr 22 08:26:00 2013 From: andipersti at gmail.com (Andreas Perstinger) Date: Mon, 22 Apr 2013 14:26:00 +0200 Subject: Error in "Import gv " module In-Reply-To: <51751178.5070204@gmail.com> References: <51751178.5070204@gmail.com> Message-ID: <51752C58.4000701@gmail.com> Please avoid top posting and answer to the list. On 22.04.2013 12:38, Megha Agrawal wrote: > Widows 7, and i have pygraphviz library in python27-> lib-> > site-package folder. Sorry don't know much about Windows. Have you read through all the issues involving "import gv" errors?: https://code.google.com/p/python-graph/issues/list?can=1&q=import+gv&colspec=ID+Type+Status+Priority+Milestone+Owner+Summary&cells=tiles Bye, Andreas From megha at greybatter.com Mon Apr 22 08:43:03 2013 From: megha at greybatter.com (Megha Agrawal) Date: Mon, 22 Apr 2013 18:13:03 +0530 Subject: Error in "Import gv " module In-Reply-To: <51752C58.4000701@gmail.com> References: <51751178.5070204@gmail.com> <51752C58.4000701@gmail.com> Message-ID: yes, I did. They said, gv module doesn't exist for windows. On Mon, Apr 22, 2013 at 5:56 PM, Andreas Perstinger wrote: > Please avoid top posting and answer to the list. > > > On 22.04.2013 12:38, Megha Agrawal wrote: > >> Widows 7, and i have pygraphviz library in python27-> lib-> >> site-package folder. >> > > Sorry don't know much about Windows. > > Have you read through all the issues involving "import gv" errors?: > https://code.google.com/p/**python-graph/issues/list?can=** > 1&q=import+gv&colspec=ID+Type+**Status+Priority+Milestone+** > Owner+Summary&cells=tiles > > > Bye, Andreas > -- > http://mail.python.org/**mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From andipersti at gmail.com Mon Apr 22 11:00:39 2013 From: andipersti at gmail.com (Andreas Perstinger) Date: Mon, 22 Apr 2013 17:00:39 +0200 Subject: Error in "Import gv " module In-Reply-To: References: <51751178.5070204@gmail.com> <51752C58.4000701@gmail.com> Message-ID: <51755097.3090502@gmail.com> You are still top posting. On 22.04.2013 14:43, Megha Agrawal wrote: > yes, I did. They said, gv module doesn't exist for windows. Then I'm afraid you are out of luck. Two possible alternatives: 1) Save your graph to a file and use the command line tools: http://stackoverflow.com/a/12698636 2) Try some other Graphviz bindings. A quick search on PyPi gave me: https://pypi.python.org/pypi/pygraphviz/1.1 https://pypi.python.org/pypi/pydot/1.0.28 https://pypi.python.org/pypi/yapgvb/1.2.0 Bye, Andreas From davea at davea.name Mon Apr 22 06:38:04 2013 From: davea at davea.name (Dave Angel) Date: Mon, 22 Apr 2013 06:38:04 -0400 Subject: Error in "Import gv " module In-Reply-To: References: Message-ID: <5175130C.309@davea.name> On 04/22/2013 06:13 AM, Megha Agrawal wrote: > https://code.google.com/p/python-graph/wiki/Example > > When I am trying to run the code to draw a graph, given on above link, I am > getting following error: > > ImportError: No module named gv > > What can be the reasons? > > Simplest is that you haven't installed python-graph https://code.google.com/p/python-graph/downloads/list or, more directly, https://code.google.com/p/python-graph/ -- DaveA From blindanagram at nowhere.org Mon Apr 22 07:58:20 2013 From: blindanagram at nowhere.org (Blind Anagram) Date: Mon, 22 Apr 2013 12:58:20 +0100 Subject: List Count Message-ID: I would be grateful for any advice people can offer on the fastest way to count items in a sub-sequence of a large list. I have a list of boolean values that can contain many hundreds of millions of elements for which I want to count the number of True values in a sub-sequence, one from the start up to some value (say hi). I am currently using: sieve[:hi].count(True) but I believe this may be costly because it copies a possibly large part of the sieve. Ideally I would like to be able to use: sieve.count(True, hi) where 'hi' sets the end of the count but this function is, sadly, not available for lists. The use of a bytearray with a memoryview object instead of a list solves this particular problem but it is not a solution for me as it creates more problems than it solves in other aspects of the program. Can I assume that one possible solution would be to sub-class list and create a C based extension to provide list.count(value, limit)? Are there any other solutions that will avoid copying a large part of the list? From davea at davea.name Mon Apr 22 08:51:49 2013 From: davea at davea.name (Dave Angel) Date: Mon, 22 Apr 2013 08:51:49 -0400 Subject: List Count In-Reply-To: References: Message-ID: <51753265.30800@davea.name> On 04/22/2013 07:58 AM, Blind Anagram wrote: > I would be grateful for any advice people can offer on the fastest way > to count items in a sub-sequence of a large list. > > I have a list of boolean values that can contain many hundreds of > millions of elements for which I want to count the number of True values > in a sub-sequence, one from the start up to some value (say hi). > > I am currently using: > > sieve[:hi].count(True) > > but I believe this may be costly because it copies a possibly large part > of the sieve. > > Ideally I would like to be able to use: > > sieve.count(True, hi) > > where 'hi' sets the end of the count but this function is, sadly, not > available for lists. > > The use of a bytearray with a memoryview object instead of a list solves > this particular problem but it is not a solution for me as it creates > more problems than it solves in other aspects of the program. > > Can I assume that one possible solution would be to sub-class list and > create a C based extension to provide list.count(value, limit)? > > Are there any other solutions that will avoid copying a large part of > the list? > Instead of using the default slice notation, why not use itertools.islice() ? Something like (untested): import itertools it = itertools.islice(sieve, 0, hi) sum(itertools.imap(bool, it)) I only broke it into two lines for clarity. It could also be: sum(itertools.imap(bool, itertools.islice(sieve, 0, hi))) If you're using Python 3.x, say so, and I'm sure somebody can simplify these, since in Python 3, many functions already produce iterators instead of lists. -- DaveA From blindanagram at nowhere.org Mon Apr 22 09:03:25 2013 From: blindanagram at nowhere.org (Blind Anagram) Date: Mon, 22 Apr 2013 14:03:25 +0100 Subject: List Count In-Reply-To: References: Message-ID: <5175351D.9070102@nowhere.org> On 22/04/2013 13:51, Dave Angel wrote: > On 04/22/2013 07:58 AM, Blind Anagram wrote: >> I would be grateful for any advice people can offer on the fastest way >> to count items in a sub-sequence of a large list. >> >> I have a list of boolean values that can contain many hundreds of >> millions of elements for which I want to count the number of True values >> in a sub-sequence, one from the start up to some value (say hi). >> >> I am currently using: >> >> sieve[:hi].count(True) >> >> but I believe this may be costly because it copies a possibly large part >> of the sieve. >> >> Ideally I would like to be able to use: >> >> sieve.count(True, hi) >> >> where 'hi' sets the end of the count but this function is, sadly, not >> available for lists. >> >> The use of a bytearray with a memoryview object instead of a list solves >> this particular problem but it is not a solution for me as it creates >> more problems than it solves in other aspects of the program. >> >> Can I assume that one possible solution would be to sub-class list and >> create a C based extension to provide list.count(value, limit)? >> >> Are there any other solutions that will avoid copying a large part of >> the list? >> > > Instead of using the default slice notation, why not use > itertools.islice() ? > > Something like (untested): > > import itertools > > it = itertools.islice(sieve, 0, hi) > sum(itertools.imap(bool, it)) > > I only broke it into two lines for clarity. It could also be: > > sum(itertools.imap(bool, itertools.islice(sieve, 0, hi))) > > If you're using Python 3.x, say so, and I'm sure somebody can simplify > these, since in Python 3, many functions already produce iterators > instead of lists. Thanks, I'll look at these ideas. And, yes, my interest is mainly in Python 3. From blindanagram at nowhere.org Mon Apr 22 09:03:25 2013 From: blindanagram at nowhere.org (Blind Anagram) Date: Mon, 22 Apr 2013 14:03:25 +0100 Subject: List Count In-Reply-To: References: Message-ID: <5175351D.9070102@nowhere.org> On 22/04/2013 13:51, Dave Angel wrote: > On 04/22/2013 07:58 AM, Blind Anagram wrote: >> I would be grateful for any advice people can offer on the fastest way >> to count items in a sub-sequence of a large list. >> >> I have a list of boolean values that can contain many hundreds of >> millions of elements for which I want to count the number of True values >> in a sub-sequence, one from the start up to some value (say hi). >> >> I am currently using: >> >> sieve[:hi].count(True) >> >> but I believe this may be costly because it copies a possibly large part >> of the sieve. >> >> Ideally I would like to be able to use: >> >> sieve.count(True, hi) >> >> where 'hi' sets the end of the count but this function is, sadly, not >> available for lists. >> >> The use of a bytearray with a memoryview object instead of a list solves >> this particular problem but it is not a solution for me as it creates >> more problems than it solves in other aspects of the program. >> >> Can I assume that one possible solution would be to sub-class list and >> create a C based extension to provide list.count(value, limit)? >> >> Are there any other solutions that will avoid copying a large part of >> the list? >> > > Instead of using the default slice notation, why not use > itertools.islice() ? > > Something like (untested): > > import itertools > > it = itertools.islice(sieve, 0, hi) > sum(itertools.imap(bool, it)) > > I only broke it into two lines for clarity. It could also be: > > sum(itertools.imap(bool, itertools.islice(sieve, 0, hi))) > > If you're using Python 3.x, say so, and I'm sure somebody can simplify > these, since in Python 3, many functions already produce iterators > instead of lists. Thanks, I'll look at these ideas. And, yes, my interest is mainly in Python 3. From steve+comp.lang.python at pearwood.info Mon Apr 22 09:13:35 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Apr 2013 13:13:35 GMT Subject: List Count References: Message-ID: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> On Mon, 22 Apr 2013 12:58:20 +0100, Blind Anagram wrote: > I would be grateful for any advice people can offer on the fastest way > to count items in a sub-sequence of a large list. > > I have a list of boolean values that can contain many hundreds of > millions of elements for which I want to count the number of True values > in a sub-sequence, one from the start up to some value (say hi). > > I am currently using: > > sieve[:hi].count(True) > > but I believe this may be costly because it copies a possibly large part > of the sieve. Have you timed it? Because Python is a high-level language, it is rarely obvious what code will be fast. Yes, sieve[:hi] will copy the first hi entries, but that's likely to be fast, basically just a memcopy, unless sieve is huge and memory is short. In other words, unless your sieve is so huge that the operating system cannot find enough memory for it, making a copy is likely to be relatively insignificant. I've just tried seven different techniques to "optimize" this, and the simplest, most obvious technique is by far the fastest. Here are the seven different code snippets I measured, with results: sieve[:hi].count(True) sum(sieve[:hi]) sum(islice(sieve, hi)) sum(x for x in islice(sieve, hi) if x) sum(x for x in islice(sieve, hi) if x is True) sum(1 for x in islice(sieve, hi) if x is True) len(list(filter(None, islice(sieve, hi)))) Here's the code I used to time them. Just copy and paste into an interactive interpreter: === cut === import random sieve = [random.random() < 0.5 for i in range(10**7)] from timeit import Timer setup = """from __main__ import sieve from itertools import islice hi = 7*10**6 """ t1 = Timer("sieve[:hi].count(True)", setup) t2 = Timer("sum(sieve[:hi])", setup) t3 = Timer("sum(islice(sieve, hi))", setup) t4 = Timer("sum(x for x in islice(sieve, hi) if x)", setup) t5 = Timer("sum(x for x in islice(sieve, hi) if x is True)", setup) t6 = Timer("sum(1 for x in islice(sieve, hi) if x is True)", setup) t7 = Timer("len(list(filter(None, islice(sieve, hi))))", setup) for t in (t1, t2, t3, t4, t5, t6, t7): print( min(t.repeat(number=10)) ) === cut === On my computer, using Python 3.3, here are the timing results I get: 2.3714727330952883 7.96061935601756 7.230580328032374 10.080201900098473 11.544118068180978 9.216834562830627 3.499635103158653 Times shown are in seconds, and are for the best of three trials, each trial having 10 repetitions of the code being tested. As you can see, clever tricks using sum are horrible pessimisations, the only thing that comes close to the obvious solution is the one using filter. Although I have only tested a list with ten million items, not hundreds of millions, I don't expect that the results will be significantly different if you use a larger list, unless you are very short of memory. [...] > Can I assume that one possible solution would be to sub-class list and > create a C based extension to provide list.count(value, limit)? Of course. But don't optimize this until you know that you *need* to optimize it. Is it really a bottleneck in your code? There's no point in saving the 0.1 second it takes to copy the list if it takes 2 seconds to count the items regardless. > Are there any other solutions that will avoid copying a large part of > the list? Yes, but they're slower. Perhaps a better solution might be to avoid counting anything. If you can keep a counter, and each time you add a value to the list you update the counter, then getting the number of True values will be instantaneous. -- Steven From skip at pobox.com Mon Apr 22 09:57:26 2013 From: skip at pobox.com (Skip Montanaro) Date: Mon, 22 Apr 2013 08:57:26 -0500 Subject: List Count In-Reply-To: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: Numpy is a big improvement here. In Py 2.7 I get this output if I run Steven's benchmark: 2.10364603996 3.68471002579 4.01849389076 7.41974878311 10.4202470779 9.16782712936 3.36137390137 (confirming his results). If I then run the numpy idiom for this: ######################## import random from timeit import Timer import numpy sieve = numpy.array([random.random() < 0.5 for i in range(10**7)], dtype=bool) setup = """from __main__ import sieve from itertools import islice hi = 7*10**6 """ t1 = Timer("(True == sieve[:hi]).sum()", setup) print(min(t1.repeat(number=10))) ########################### I get : 0.344316959381 It likely consumes less space as well, since it doesn't store Python objects in the array. Skip From blindanagram at nowhere.org Mon Apr 22 10:15:19 2013 From: blindanagram at nowhere.org (Blind Anagram) Date: Mon, 22 Apr 2013 15:15:19 +0100 Subject: List Count In-Reply-To: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <517545F7.5090209@nowhere.org> On 22/04/2013 14:13, Steven D'Aprano wrote: > On Mon, 22 Apr 2013 12:58:20 +0100, Blind Anagram wrote: > >> I would be grateful for any advice people can offer on the fastest way >> to count items in a sub-sequence of a large list. >> >> I have a list of boolean values that can contain many hundreds of >> millions of elements for which I want to count the number of True values >> in a sub-sequence, one from the start up to some value (say hi). >> >> I am currently using: >> >> sieve[:hi].count(True) >> >> but I believe this may be costly because it copies a possibly large part >> of the sieve. > > Have you timed it? Because Python is a high-level language, it is rarely > obvious what code will be fast. Yes, sieve[:hi] will copy the first hi > entries, but that's likely to be fast, basically just a memcopy, unless > sieve is huge and memory is short. In other words, unless your sieve is > so huge that the operating system cannot find enough memory for it, > making a copy is likely to be relatively insignificant. > > I've just tried seven different techniques to "optimize" this, and the > simplest, most obvious technique is by far the fastest. Here are the > seven different code snippets I measured, with results: > > > sieve[:hi].count(True) > sum(sieve[:hi]) > sum(islice(sieve, hi)) > sum(x for x in islice(sieve, hi) if x) > sum(x for x in islice(sieve, hi) if x is True) > sum(1 for x in islice(sieve, hi) if x is True) > len(list(filter(None, islice(sieve, hi)))) Yes, I did time it and I agree with your results (where my tests overlap with yours). But when using a sub-sequence, I do suffer a significant reduction in speed for a count when compared with count on the full list. When the list is small enough not to cause memory allocation issues this is about 30% on 100,000,000 items. But when the list is 1,000,000,000 items, OS memory allocation becomes an issue and the cost on my system rises to over 600%. I agree that this is not a big issue but it seems to me a high price to pay for the lack of a sieve.count(value, limit), which I feel is a useful function (given that memoryview operations are not available for lists). > Of course. But don't optimize this until you know that you *need* to > optimize it. Is it really a bottleneck in your code? There's no point in > saving the 0.1 second it takes to copy the list if it takes 2 seconds to > count the items regardless. > >> Are there any other solutions that will avoid copying a large part of >> the list? > > Yes, but they're slower. > > Perhaps a better solution might be to avoid counting anything. If you can > keep a counter, and each time you add a value to the list you update the > counter, then getting the number of True values will be instantaneous. Creating the sieve is currently very fast as it is not done by adding single items but by adding a large number of items at the same time using a slice operation. I could count the items in each slice as it is added but this would add complexity that I would prefer to avoid because the creation of the sieve is quite tricky to get right and I would prefer not to fiddle with this. Thank you (and others) for advice on this. From oscar.j.benjamin at gmail.com Mon Apr 22 11:14:19 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 22 Apr 2013 16:14:19 +0100 Subject: List Count In-Reply-To: <517545F7.5090209@nowhere.org> References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> Message-ID: On 22 April 2013 15:15, Blind Anagram wrote: > On 22/04/2013 14:13, Steven D'Aprano wrote: >> On Mon, 22 Apr 2013 12:58:20 +0100, Blind Anagram wrote: >> >>> I would be grateful for any advice people can offer on the fastest way >>> to count items in a sub-sequence of a large list. >>> >>> I have a list of boolean values that can contain many hundreds of >>> millions of elements for which I want to count the number of True values >>> in a sub-sequence, one from the start up to some value (say hi). >>> >>> I am currently using: >>> >>> sieve[:hi].count(True) >>> >>> but I believe this may be costly because it copies a possibly large part >>> of the sieve. [snip] > > But when using a sub-sequence, I do suffer a significant reduction in > speed for a count when compared with count on the full list. When the > list is small enough not to cause memory allocation issues this is about > 30% on 100,000,000 items. But when the list is 1,000,000,000 items, OS > memory allocation becomes an issue and the cost on my system rises to > over 600%. Have you tried using numpy? I find that it reduces the memory required to store a list of bools by a factor of 4 on my 32 bit system. I would expect that to be a factor of 8 on a 64 bit system: >>> import sys >>> a = [True] * 1000000 >>> sys.getsizeof(a) 4000036 >>> import numpy >>> a = numpy.ndarray(1000000, bool) >>> sys.getsizeof(a) # This does not include the data buffer 40 >>> a.nbytes 1000000 The numpy array also has the advantage that slicing does not actually copy the data (as has already been mentioned). On this system slicing a numpy array has a 40 byte overhead regardless of the size of the slice. > I agree that this is not a big issue but it seems to me a high price to > pay for the lack of a sieve.count(value, limit), which I feel is a > useful function (given that memoryview operations are not available for > lists). It would be very easy to subclass list and add this functionality in cython if you decide that you do need a builtin method. Oscar From blindanagram at nowhere.org Mon Apr 22 11:50:16 2013 From: blindanagram at nowhere.org (Blind Anagram) Date: Mon, 22 Apr 2013 16:50:16 +0100 Subject: List Count In-Reply-To: References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> Message-ID: <51755C38.4000204@nowhere.org> On 22/04/2013 16:14, Oscar Benjamin wrote: > On 22 April 2013 15:15, Blind Anagram wrote: >> On 22/04/2013 14:13, Steven D'Aprano wrote: >>> On Mon, 22 Apr 2013 12:58:20 +0100, Blind Anagram wrote: >>> >>>> I would be grateful for any advice people can offer on the fastest way >>>> to count items in a sub-sequence of a large list. >>>> >>>> I have a list of boolean values that can contain many hundreds of >>>> millions of elements for which I want to count the number of True values >>>> in a sub-sequence, one from the start up to some value (say hi). >>>> >>>> I am currently using: >>>> >>>> sieve[:hi].count(True) >>>> >>>> but I believe this may be costly because it copies a possibly large part >>>> of the sieve. > [snip] >> >> But when using a sub-sequence, I do suffer a significant reduction in >> speed for a count when compared with count on the full list. When the >> list is small enough not to cause memory allocation issues this is about >> 30% on 100,000,000 items. But when the list is 1,000,000,000 items, OS >> memory allocation becomes an issue and the cost on my system rises to >> over 600%. > > Have you tried using numpy? I find that it reduces the memory required > to store a list of bools by a factor of 4 on my 32 bit system. I would > expect that to be a factor of 8 on a 64 bit system: > >>>> import sys >>>> a = [True] * 1000000 >>>> sys.getsizeof(a) > 4000036 >>>> import numpy >>>> a = numpy.ndarray(1000000, bool) >>>> sys.getsizeof(a) # This does not include the data buffer > 40 >>>> a.nbytes > 1000000 > > The numpy array also has the advantage that slicing does not actually > copy the data (as has already been mentioned). On this system slicing > a numpy array has a 40 byte overhead regardless of the size of the > slice. > >> I agree that this is not a big issue but it seems to me a high price to >> pay for the lack of a sieve.count(value, limit), which I feel is a >> useful function (given that memoryview operations are not available for >> lists). > > It would be very easy to subclass list and add this functionality in > cython if you decide that you do need a builtin method. Thanks Oscar, I'll take a look at this. But I was really wondering if there was a simple solution that worked without people having to add libraries to their basic Python installations. As I have never tried building an extension with cython, I am inclined to try this as a learning exercise if nothing else. From blindanagram at nowhere.org Mon Apr 22 11:50:16 2013 From: blindanagram at nowhere.org (Blind Anagram) Date: Mon, 22 Apr 2013 16:50:16 +0100 Subject: List Count In-Reply-To: References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> Message-ID: <51755C38.4000204@nowhere.org> On 22/04/2013 16:14, Oscar Benjamin wrote: > On 22 April 2013 15:15, Blind Anagram wrote: >> On 22/04/2013 14:13, Steven D'Aprano wrote: >>> On Mon, 22 Apr 2013 12:58:20 +0100, Blind Anagram wrote: >>> >>>> I would be grateful for any advice people can offer on the fastest way >>>> to count items in a sub-sequence of a large list. >>>> >>>> I have a list of boolean values that can contain many hundreds of >>>> millions of elements for which I want to count the number of True values >>>> in a sub-sequence, one from the start up to some value (say hi). >>>> >>>> I am currently using: >>>> >>>> sieve[:hi].count(True) >>>> >>>> but I believe this may be costly because it copies a possibly large part >>>> of the sieve. > [snip] >> >> But when using a sub-sequence, I do suffer a significant reduction in >> speed for a count when compared with count on the full list. When the >> list is small enough not to cause memory allocation issues this is about >> 30% on 100,000,000 items. But when the list is 1,000,000,000 items, OS >> memory allocation becomes an issue and the cost on my system rises to >> over 600%. > > Have you tried using numpy? I find that it reduces the memory required > to store a list of bools by a factor of 4 on my 32 bit system. I would > expect that to be a factor of 8 on a 64 bit system: > >>>> import sys >>>> a = [True] * 1000000 >>>> sys.getsizeof(a) > 4000036 >>>> import numpy >>>> a = numpy.ndarray(1000000, bool) >>>> sys.getsizeof(a) # This does not include the data buffer > 40 >>>> a.nbytes > 1000000 > > The numpy array also has the advantage that slicing does not actually > copy the data (as has already been mentioned). On this system slicing > a numpy array has a 40 byte overhead regardless of the size of the > slice. > >> I agree that this is not a big issue but it seems to me a high price to >> pay for the lack of a sieve.count(value, limit), which I feel is a >> useful function (given that memoryview operations are not available for >> lists). > > It would be very easy to subclass list and add this functionality in > cython if you decide that you do need a builtin method. Thanks Oscar, I'll take a look at this. But I was really wondering if there was a simple solution that worked without people having to add libraries to their basic Python installations. As I have never tried building an extension with cython, I am inclined to try this as a learning exercise if nothing else. From oscar.j.benjamin at gmail.com Mon Apr 22 12:06:12 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 22 Apr 2013 17:06:12 +0100 Subject: List Count In-Reply-To: <51755C38.4000204@nowhere.org> References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <51755C38.4000204@nowhere.org> Message-ID: On 22 April 2013 16:50, Blind Anagram wrote: >> >> It would be very easy to subclass list and add this functionality in >> cython if you decide that you do need a builtin method. [snip] > > But I was really wondering if there was a simple solution that worked > without people having to add libraries to their basic Python installations. There are simple solutions and some have already been listed. You are attempting to push your program to the limit of your hardware capabilities and it's natural that in a high-level language you'll often want special libraries for that. I don't know what your application is but I would say that my first port of call here would be to consider a different algorithmic approach. An obvious question would be about the sparsity of this data structure. How frequent are the values that you are trying to count? Would it make more sense to store a list of their indices? If the problem needs to be solved the way that you are currently doing it and the available methods are not fast enough then you will need to consider additional libraries. > > As I have never tried building an extension with cython, I am inclined > to try this as a learning exercise if nothing else. I definitely recommend this over writing a C extension directly. Oscar From blindanagram at nowhere.org Mon Apr 22 12:38:01 2013 From: blindanagram at nowhere.org (Blind Anagram) Date: Mon, 22 Apr 2013 17:38:01 +0100 Subject: List Count In-Reply-To: References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <51755C38.4000204@nowhere.org> Message-ID: <51756769.20206@nowhere.org> On 22/04/2013 17:06, Oscar Benjamin wrote: > On 22 April 2013 16:50, Blind Anagram wrote: >>> >>> It would be very easy to subclass list and add this functionality in >>> cython if you decide that you do need a builtin method. > [snip] >> >> But I was really wondering if there was a simple solution that worked >> without people having to add libraries to their basic Python installations. > > There are simple solutions and some have already been listed. You are > attempting to push your program to the limit of your hardware > capabilities and it's natural that in a high-level language you'll > often want special libraries for that. Hi Oscar Yes, but it is a tribute to Python that I can do this quite fast for huge lists provided that I only count on the full list. And, unless I have completely misunderstood Python internals, it would probably be just as fast on a sub-sequence if I had a list.count(value, limit) function (however, I admit that I could be wrong here since the fact that count on lists does not offer this may mean that it is not as easy to implement as it might seem). > I don't know what your application is but I would say that my first > port of call here would be to consider a different algorithmic > approach. An obvious question would be about the sparsity of this data > structure. How frequent are the values that you are trying to count? > Would it make more sense to store a list of their indices? Actually it is no more than a simple prime sieve implemented as a Python class (and, yes, I realize that there are plenty of these around). > If the problem needs to be solved the way that you are currently doing > it and the available methods are not fast enough then you will need to > consider additional libraries. >> >> As I have never tried building an extension with cython, I am inclined >> to try this as a learning exercise if nothing else. > > I definitely recommend this over writing a C extension directly. Thanks again - I will definitely look at this. Brian From blindanagram at nowhere.org Mon Apr 22 12:38:01 2013 From: blindanagram at nowhere.org (Blind Anagram) Date: Mon, 22 Apr 2013 17:38:01 +0100 Subject: List Count In-Reply-To: References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <51755C38.4000204@nowhere.org> Message-ID: <51756769.20206@nowhere.org> On 22/04/2013 17:06, Oscar Benjamin wrote: > On 22 April 2013 16:50, Blind Anagram wrote: >>> >>> It would be very easy to subclass list and add this functionality in >>> cython if you decide that you do need a builtin method. > [snip] >> >> But I was really wondering if there was a simple solution that worked >> without people having to add libraries to their basic Python installations. > > There are simple solutions and some have already been listed. You are > attempting to push your program to the limit of your hardware > capabilities and it's natural that in a high-level language you'll > often want special libraries for that. Hi Oscar Yes, but it is a tribute to Python that I can do this quite fast for huge lists provided that I only count on the full list. And, unless I have completely misunderstood Python internals, it would probably be just as fast on a sub-sequence if I had a list.count(value, limit) function (however, I admit that I could be wrong here since the fact that count on lists does not offer this may mean that it is not as easy to implement as it might seem). > I don't know what your application is but I would say that my first > port of call here would be to consider a different algorithmic > approach. An obvious question would be about the sparsity of this data > structure. How frequent are the values that you are trying to count? > Would it make more sense to store a list of their indices? Actually it is no more than a simple prime sieve implemented as a Python class (and, yes, I realize that there are plenty of these around). > If the problem needs to be solved the way that you are currently doing > it and the available methods are not fast enough then you will need to > consider additional libraries. >> >> As I have never tried building an extension with cython, I am inclined >> to try this as a learning exercise if nothing else. > > I definitely recommend this over writing a C extension directly. Thanks again - I will definitely look at this. Brian From skip at pobox.com Mon Apr 22 13:48:10 2013 From: skip at pobox.com (Skip Montanaro) Date: Mon, 22 Apr 2013 12:48:10 -0500 Subject: List Count In-Reply-To: <51756769.20206@nowhere.org> References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <51755C38.4000204@nowhere.org> <51756769.20206@nowhere.org> Message-ID: > But I was really wondering if there was a simple solution that worked > without people having to add libraries to their basic Python installations. I think installing numpy is approximately pip install numpy assuming you have write access to your site-packages directory. If not, install using --prefix and set PYTHONPATH accordingly. I forgot that Python also has an array module. With numpy available, mature, and well-supported, I imagine it doesn't get much love these days though. Still, I gave it a whirl: ####################################### import random import array from timeit import Timer import numpy stuff = [random.random() < 0.5 for i in range(10**7)] sieve1 = numpy.array(stuff, dtype=bool) sieve2 = array.array('B', stuff) setup = """from __main__ import sieve1, sieve2 from itertools import islice hi = 7*10**6 """ t1 = Timer("(True == sieve1[:hi]).sum()", setup) t2 = Timer("sieve2[:hi].count(True)", setup) # t3 = Timer("sum(islice(sieve, hi))", setup) # t4 = Timer("sum(x for x in islice(sieve, hi) if x)", setup) # t5 = Timer("sum(x for x in islice(sieve, hi) if x is True)", setup) # t6 = Timer("sum(1 for x in islice(sieve, hi) if x is True)", setup) # t7 = Timer("len(list(filter(None, islice(sieve, hi))))", setup) print(min(t1.repeat(number=10))) print(min(t2.repeat(number=10))) # for t in (t1, t2, t3, t4, t5, t6, t7): # print( min(t.repeat(number=10)) ) ####################################### Performance was not all that impressive: 0.340315103531 5.42102503777 Still, you might fiddle around with it a bit. Perhaps unsigned ints instead of unsigned bytes will provide more efficient counting... Skip From blindanagram at nowhere.org Mon Apr 22 15:22:16 2013 From: blindanagram at nowhere.org (Blind Anagram) Date: Mon, 22 Apr 2013 20:22:16 +0100 Subject: List Count In-Reply-To: References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <51755C38.4000204@nowhere.org> <51756769.20206@nowhere.org> Message-ID: On 22/04/2013 18:48, Skip Montanaro wrote: >> But I was really wondering if there was a simple solution that worked >> without people having to add libraries to their basic Python installations. > > I think installing numpy is approximately > > pip install numpy > > assuming you have write access to your site-packages directory. If > not, install using --prefix and set PYTHONPATH accordingly. > > I forgot that Python also has an array module. With numpy available, > mature, and well-supported, I imagine it doesn't get much love these > days though. Still, I gave it a whirl: > > ####################################### > import random > import array > from timeit import Timer > > import numpy > > stuff = [random.random() < 0.5 for i in range(10**7)] > sieve1 = numpy.array(stuff, dtype=bool) > sieve2 = array.array('B', stuff) > > setup = """from __main__ import sieve1, sieve2 > from itertools import islice > hi = 7*10**6 > """ > > t1 = Timer("(True == sieve1[:hi]).sum()", setup) > t2 = Timer("sieve2[:hi].count(True)", setup) > # t3 = Timer("sum(islice(sieve, hi))", setup) > # t4 = Timer("sum(x for x in islice(sieve, hi) if x)", setup) > # t5 = Timer("sum(x for x in islice(sieve, hi) if x is True)", setup) > # t6 = Timer("sum(1 for x in islice(sieve, hi) if x is True)", setup) > # t7 = Timer("len(list(filter(None, islice(sieve, hi))))", setup) > > print(min(t1.repeat(number=10))) > print(min(t2.repeat(number=10))) > # for t in (t1, t2, t3, t4, t5, t6, t7): > # print( min(t.repeat(number=10)) ) > ####################################### > > Performance was not all that impressive: > > 0.340315103531 > 5.42102503777 > > Still, you might fiddle around with it a bit. Perhaps unsigned ints > instead of unsigned bytes will provide more efficient counting... I spent a lot of time comparing python arrays and lists but found that lists were always much faster in this application. I do have numpy installed but I remember that when I did this (some time ago) it was far from easy with Python 3.x running natively on Windows x64. Brian From oscar.j.benjamin at gmail.com Mon Apr 22 16:18:15 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 22 Apr 2013 21:18:15 +0100 Subject: List Count In-Reply-To: <51756769.20206@nowhere.org> References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <51755C38.4000204@nowhere.org> <51756769.20206@nowhere.org> Message-ID: On 22 April 2013 17:38, Blind Anagram wrote: > On 22/04/2013 17:06, Oscar Benjamin wrote: > >> I don't know what your application is but I would say that my first >> port of call here would be to consider a different algorithmic >> approach. An obvious question would be about the sparsity of this data >> structure. How frequent are the values that you are trying to count? >> Would it make more sense to store a list of their indices? > > Actually it is no more than a simple prime sieve implemented as a Python > class (and, yes, I realize that there are plenty of these around). If I understand correctly, you have a list of roughly a billion True/False values indicating which integers are prime and which are not. You would like to discover how many prime numbers there are between two numbers a and b. You currently do this by counting the number of True values in your list between the indices a and b. If my description is correct then I would definitely consider using a different algorithmic approach. The density of primes from 1 to 1 billlion is about 5%. Storing the prime numbers themselves in a sorted list would save memory and allow a potentially more efficient way of counting the number of primes within some interval. To see how it saves memory (on a 64 bit system): $ python Python 2.7.3 (default, Sep 26 2012, 21:51:14) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> a = ([True] + [False]*19) * 50000 >>> len(a) 1000000 >>> sys.getsizeof(a) 8000072 >>> a = list(range(50000)) >>> sys.getsizeof(a) 450120 >>> sum(sys.getsizeof(x) for x in a) 1200000 So you're using about 1/5th of the memory with a list of primes compared to a list of True/False values. Further savings would be possible if you used an array to store the primes as 64 bit integers. In this case it would take about 400MB to store all the primes up to 1 billion. The more efficient way of counting the primes would then be to use the bisect module. This gives you a way of counting the primes between a and b with a cost that is logarithmic in the total number of primes stored rather than linear in the size of the range (e.g. b-a). For large enough primes/ranges this is certain to be faster. Whether it actually works that way for your numbers I can't say. Oscar From oscar.j.benjamin at gmail.com Mon Apr 22 17:03:39 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 22 Apr 2013 22:03:39 +0100 Subject: List Count In-Reply-To: References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <51755C38.4000204@nowhere.org> <51756769.20206@nowhere.org> Message-ID: On 22 April 2013 21:18, Oscar Benjamin wrote: > On 22 April 2013 17:38, Blind Anagram wrote: >> On 22/04/2013 17:06, Oscar Benjamin wrote: >> >>> I don't know what your application is but I would say that my first >>> port of call here would be to consider a different algorithmic >>> approach. An obvious question would be about the sparsity of this data >>> structure. How frequent are the values that you are trying to count? >>> Would it make more sense to store a list of their indices? >> >> Actually it is no more than a simple prime sieve implemented as a Python >> class (and, yes, I realize that there are plenty of these around). > > If I understand correctly, you have a list of roughly a billion > True/False values indicating which integers are prime and which are > not. You would like to discover how many prime numbers there are > between two numbers a and b. You currently do this by counting the > number of True values in your list between the indices a and b. > > If my description is correct then I would definitely consider using a > different algorithmic approach. The density of primes from 1 to 1 > billlion is about 5%. Storing the prime numbers themselves in a sorted > list would save memory and allow a potentially more efficient way of > counting the number of primes within some interval. In fact it is probably quicker if you don't mind using all that memory to just store the cumulative sum of your prime True/False indicator list. This would be the prime counting function pi(n). You can then count the primes between a and b in constant time with pi[b] - pi[a]. Oscar From blindanagram at nowhere.org Mon Apr 22 17:32:30 2013 From: blindanagram at nowhere.org (Blind Anagram) Date: Mon, 22 Apr 2013 22:32:30 +0100 Subject: List Count In-Reply-To: References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <51755C38.4000204@nowhere.org> <51756769.20206@nowhere.org> Message-ID: On 22/04/2013 22:03, Oscar Benjamin wrote: > On 22 April 2013 21:18, Oscar Benjamin wrote: >> On 22 April 2013 17:38, Blind Anagram wrote: >>> On 22/04/2013 17:06, Oscar Benjamin wrote: >>> >>>> I don't know what your application is but I would say that my first >>>> port of call here would be to consider a different algorithmic >>>> approach. An obvious question would be about the sparsity of this data >>>> structure. How frequent are the values that you are trying to count? >>>> Would it make more sense to store a list of their indices? >>> >>> Actually it is no more than a simple prime sieve implemented as a Python >>> class (and, yes, I realize that there are plenty of these around). >> >> If I understand correctly, you have a list of roughly a billion >> True/False values indicating which integers are prime and which are >> not. You would like to discover how many prime numbers there are >> between two numbers a and b. You currently do this by counting the >> number of True values in your list between the indices a and b. >> >> If my description is correct then I would definitely consider using a >> different algorithmic approach. The density of primes from 1 to 1 >> billlion is about 5%. Storing the prime numbers themselves in a sorted >> list would save memory and allow a potentially more efficient way of >> counting the number of primes within some interval. > > In fact it is probably quicker if you don't mind using all that memory > to just store the cumulative sum of your prime True/False indicator > list. This would be the prime counting function pi(n). You can then > count the primes between a and b in constant time with pi[b] - pi[a]. I did wonder whether, after creating the sieve, I should simply go through the list and replace the True values with a count. This would certainly speed up the prime count function, which is where the issue arises. I will try this and see what sort of performance trade-offs this involves. Brian From davea at davea.name Mon Apr 22 21:47:52 2013 From: davea at davea.name (Dave Angel) Date: Mon, 22 Apr 2013 21:47:52 -0400 Subject: List Count In-Reply-To: References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <51755C38.4000204@nowhere.org> <51756769.20206@nowhere.org> Message-ID: <5175E848.9060303@davea.name> On 04/22/2013 05:32 PM, Blind Anagram wrote: > On 22/04/2013 22:03, Oscar Benjamin wrote: >> On 22 April 2013 21:18, Oscar Benjamin wrote: >>> On 22 April 2013 17:38, Blind Anagram wrote: >>>> On 22/04/2013 17:06, Oscar Benjamin wrote: >>>> >>>>> I don't know what your application is but I would say that my first >>>>> port of call here would be to consider a different algorithmic >>>>> approach. An obvious question would be about the sparsity of this data >>>>> structure. How frequent are the values that you are trying to count? >>>>> Would it make more sense to store a list of their indices? >>>> >>>> Actually it is no more than a simple prime sieve implemented as a Python >>>> class (and, yes, I realize that there are plenty of these around). >>> >>> If I understand correctly, you have a list of roughly a billion >>> True/False values indicating which integers are prime and which are >>> not. You would like to discover how many prime numbers there are >>> between two numbers a and b. You currently do this by counting the >>> number of True values in your list between the indices a and b. >>> >>> If my description is correct then I would definitely consider using a >>> different algorithmic approach. The density of primes from 1 to 1 >>> billlion is about 5%. Storing the prime numbers themselves in a sorted >>> list would save memory and allow a potentially more efficient way of >>> counting the number of primes within some interval. >> >> In fact it is probably quicker if you don't mind using all that memory >> to just store the cumulative sum of your prime True/False indicator >> list. This would be the prime counting function pi(n). You can then >> count the primes between a and b in constant time with pi[b] - pi[a]. > > I did wonder whether, after creating the sieve, I should simply go > through the list and replace the True values with a count. This would > certainly speed up the prime count function, which is where the issue > arises. I will try this and see what sort of performance trade-offs > this involves. > By doing that replacement, you'd increase memory usage manyfold (maybe 3:1, I don't know). As long as you're only using bools in the list, you only have the list overhead to consider, because all the objects involved are already cached (True and False exist only once each). If you have integers, you'll need a new object for each nonzero count. -- DaveA From blindanagram at nowhere.org Tue Apr 23 03:02:26 2013 From: blindanagram at nowhere.org (Blind Anagram) Date: Tue, 23 Apr 2013 08:02:26 +0100 Subject: List Count In-Reply-To: References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <51755C38.4000204@nowhere.org> <51756769.20206@nowhere.org> Message-ID: On 23/04/2013 02:47, Dave Angel wrote: > On 04/22/2013 05:32 PM, Blind Anagram wrote: >> On 22/04/2013 22:03, Oscar Benjamin wrote: >>> On 22 April 2013 21:18, Oscar Benjamin >>> wrote: >>>> On 22 April 2013 17:38, Blind Anagram wrote: >>>>> On 22/04/2013 17:06, Oscar Benjamin wrote: >>>>> >>>>>> I don't know what your application is but I would say that my first >>>>>> port of call here would be to consider a different algorithmic >>>>>> approach. An obvious question would be about the sparsity of this >>>>>> data >>>>>> structure. How frequent are the values that you are trying to count? >>>>>> Would it make more sense to store a list of their indices? >>>>> >>>>> Actually it is no more than a simple prime sieve implemented as a >>>>> Python >>>>> class (and, yes, I realize that there are plenty of these around). >>>> >>>> If I understand correctly, you have a list of roughly a billion >>>> True/False values indicating which integers are prime and which are >>>> not. You would like to discover how many prime numbers there are >>>> between two numbers a and b. You currently do this by counting the >>>> number of True values in your list between the indices a and b. >>>> >>>> If my description is correct then I would definitely consider using a >>>> different algorithmic approach. The density of primes from 1 to 1 >>>> billlion is about 5%. Storing the prime numbers themselves in a sorted >>>> list would save memory and allow a potentially more efficient way of >>>> counting the number of primes within some interval. >>> >>> In fact it is probably quicker if you don't mind using all that memory >>> to just store the cumulative sum of your prime True/False indicator >>> list. This would be the prime counting function pi(n). You can then >>> count the primes between a and b in constant time with pi[b] - pi[a]. >> >> I did wonder whether, after creating the sieve, I should simply go >> through the list and replace the True values with a count. This would >> certainly speed up the prime count function, which is where the issue >> arises. I will try this and see what sort of performance trade-offs >> this involves. >> > > By doing that replacement, you'd increase memory usage manyfold (maybe > 3:1, I don't know). As long as you're only using bools in the list, you > only have the list overhead to consider, because all the objects > involved are already cached (True and False exist only once each). If > you have integers, you'll need a new object for each nonzero count. Thank you, Dave, you have answered a question that I was going to ask before I even asked it! From blindanagram at nowhere.org Mon Apr 22 17:25:50 2013 From: blindanagram at nowhere.org (Blind Anagram) Date: Mon, 22 Apr 2013 22:25:50 +0100 Subject: List Count In-Reply-To: References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <51755C38.4000204@nowhere.org> <51756769.20206@nowhere.org> Message-ID: <_umdnUiJWp9yN-jMnZ2dnUVZ7o-dnZ2d@brightview.co.uk> On 22/04/2013 21:18, Oscar Benjamin wrote: > On 22 April 2013 17:38, Blind Anagram wrote: [snip] > If my description is correct then I would definitely consider using a > different algorithmic approach. The density of primes from 1 to 1 > billlion is about 5%. Storing the prime numbers themselves in a sorted > list would save memory and allow a potentially more efficient way of > counting the number of primes within some interval. That is correct but I need to say that the lengths I have been describing are limiting cases - almost all of the time the sieve length will be quite small. But I was still interested to see if I could push the limit without changing the essential simplicity of the sieve. And here the cost of creating the slice (which I have measured) set me wondering why a list.count(value, limit) function did not exist. I also wondered whether I had missed any obvious way of avoiding the slicing cost (intellectually it seemed wrong to me to have to copy the list in order to count items within it). [snip] > > So you're using about 1/5th of the memory with a list of primes > compared to a list of True/False values. Further savings would be > possible if you used an array to store the primes as 64 bit integers. > In this case it would take about 400MB to store all the primes up to 1 > billion. I have looked at solutions based on listing primes and here I have found that they are very much slower than my existing solution when the sieve is not large (which is the majority use case). I have also tried counting using a loop such as: while i < limit: i = sieve.index(1, i) + 1 cnt += 1 but this is slower than count even on huge lists. Thank you again for your advice. Brian From oscar.j.benjamin at gmail.com Mon Apr 22 19:06:44 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 23 Apr 2013 00:06:44 +0100 Subject: List Count In-Reply-To: <_umdnUiJWp9yN-jMnZ2dnUVZ7o-dnZ2d@brightview.co.uk> References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <51755C38.4000204@nowhere.org> <51756769.20206@nowhere.org> <_umdnUiJWp9yN-jMnZ2dnUVZ7o-dnZ2d@brightview.co.uk> Message-ID: On 22 April 2013 22:25, Blind Anagram wrote: > On 22/04/2013 21:18, Oscar Benjamin wrote: >> On 22 April 2013 17:38, Blind Anagram wrote: > > I also wondered whether I had missed any obvious way of avoiding the > slicing cost (intellectually it seemed wrong to me to have to copy the > list in order to count items within it). [snip] > > I have looked at solutions based on listing primes and here I have found > that they are very much slower than my existing solution when the sieve > is not large (which is the majority use case). What matters is not so much the size of the sieve but the size of the interval you want to query. You say that slicing cost is somehow significant which suggests to me that it's not a small interval. An approach using a sorted list of primes and bisect would have a cost that is independent of the size of the interval (and depends only logarithmically on the size of the sieve). Oscar From steve+comp.lang.python at pearwood.info Mon Apr 22 19:28:17 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Apr 2013 23:28:17 GMT Subject: List Count References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <51755C38.4000204@nowhere.org> <51756769.20206@nowhere.org> <_umdnUiJWp9yN-jMnZ2dnUVZ7o-dnZ2d@brightview.co.uk> Message-ID: <5175c791$0$29977$c3e8da3$5496439d@news.astraweb.com> On Mon, 22 Apr 2013 22:25:50 +0100, Blind Anagram wrote: > I have looked at solutions based on listing primes and here I have found > that they are very much slower than my existing solution when the sieve > is not large (which is the majority use case). Yes. This is hardly surprising. Algorithms suitable for dealing with the first million primes are not suitable for dealing with the first trillion primes, and vice versa. We like to pretend that computer programming is an abstraction, and for small enough data we often can get away with that, but like all abstractions eventually it breaks and the cost of dealing with real hardware becomes significant. But I must ask, given that the primes are so widely distributed, why are you storing them in a list instead of a sparse array (i.e. a dict)? There are 50,847,534 primes less than or equal to 1,000,000,000, so you are storing roughly 18 False values for every True value. That ratio will only get bigger. With a billion entries, you are using 18 times more memory than necessary. -- Steven From blindanagram at nowhere.org Tue Apr 23 03:00:50 2013 From: blindanagram at nowhere.org (Blind Anagram) Date: Tue, 23 Apr 2013 08:00:50 +0100 Subject: List Count In-Reply-To: <5175c791$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <51755C38.4000204@nowhere.org> <51756769.20206@nowhere.org> <_umdnUiJWp9yN-jMnZ2dnUVZ7o-dnZ2d@brightview.co.uk> <5175c791$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 23/04/2013 00:28, Steven D'Aprano wrote: > On Mon, 22 Apr 2013 22:25:50 +0100, Blind Anagram wrote: > >> I have looked at solutions based on listing primes and here I have found >> that they are very much slower than my existing solution when the sieve >> is not large (which is the majority use case). > > Yes. This is hardly surprising. Algorithms suitable for dealing with the > first million primes are not suitable for dealing with the first trillion > primes, and vice versa. We like to pretend that computer programming is > an abstraction, and for small enough data we often can get away with > that, but like all abstractions eventually it breaks and the cost of > dealing with real hardware becomes significant. > > But I must ask, given that the primes are so widely distributed, why are > you storing them in a list instead of a sparse array (i.e. a dict)? There > are 50,847,534 primes less than or equal to 1,000,000,000, so you are > storing roughly 18 False values for every True value. That ratio will > only get bigger. With a billion entries, you are using 18 times more > memory than necessary. Because the majority use case for my Prime class is for a sieve that is not large. I am just pushing the envelope for a minority use case so that it still works for huge sieves, albeit inefficiently. I accept it is inefficient, but the fact remains that I can produce a sieve that can yield and count a billion primes in a reasonable time but this fails when I wish to count on a part of the sieve because this can double the memory requirement for the lack of a list.count(value, limit) function. I would not dream of doing this job by copying a slice in any other language that I have used so I was simply asking for advice to discover whether this copy could be avoided whilst staying with the simple sieve design. Thank you for your input. Brian From blindanagram at nowhere.org Tue Apr 23 02:45:58 2013 From: blindanagram at nowhere.org (Blind Anagram) Date: Tue, 23 Apr 2013 07:45:58 +0100 Subject: List Count In-Reply-To: References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <51755C38.4000204@nowhere.org> <51756769.20206@nowhere.org> <_umdnUiJWp9yN-jMnZ2dnUVZ7o-dnZ2d@brightview.co.uk> Message-ID: On 23/04/2013 00:06, Oscar Benjamin wrote: > On 22 April 2013 22:25, Blind Anagram wrote: >> On 22/04/2013 21:18, Oscar Benjamin wrote: >>> On 22 April 2013 17:38, Blind Anagram wrote: >> >> I also wondered whether I had missed any obvious way of avoiding the >> slicing cost (intellectually it seemed wrong to me to have to copy the >> list in order to count items within it). > [snip] >> >> I have looked at solutions based on listing primes and here I have found >> that they are very much slower than my existing solution when the sieve >> is not large (which is the majority use case). > > What matters is not so much the size of the sieve but the size of the > interval you want to query. You say that slicing cost is somehow > significant which suggests to me that it's not a small interval. An > approach using a sorted list of primes and bisect would have a cost > that is independent of the size of the interval (and depends only > logarithmically on the size of the sieve). The issue here is that the prime number count is only one of the features of the class so I would have to essentially rewrite it to use the technique you suggest. And I found in my experiments that creating the sieve in the form of a list of primes (either directly or by converting a linear sieve) is a great deal slower than a simple sieve for the majority use cases where the sieve is not huge. I don't want to take up peoples time but I am willing to expose the code to anyone who has an interest as I am sure that it has wrinkles that others with more experience with Python would find. But I would also be interested to discover whether there is a rationale for not offering list.count(value, limit) as this seems to me a useful function which I have found myself wanting more than once now. Thank you again for your input, which I appreciate. Brian From steve+comp.lang.python at pearwood.info Mon Apr 22 19:01:04 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Apr 2013 23:01:04 GMT Subject: List Count References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> Message-ID: <5175c12f$0$29977$c3e8da3$5496439d@news.astraweb.com> On Mon, 22 Apr 2013 15:15:19 +0100, Blind Anagram wrote: > But when using a sub-sequence, I do suffer a significant reduction in > speed for a count when compared with count on the full list. When the > list is small enough not to cause memory allocation issues this is about > 30% on 100,000,000 items. But when the list is 1,000,000,000 items, OS > memory allocation becomes an issue and the cost on my system rises to > over 600%. Buy more memory :-) > I agree that this is not a big issue but it seems to me a high price to > pay for the lack of a sieve.count(value, limit), which I feel is a > useful function (given that memoryview operations are not available for > lists). There is no need to complicate the count method for such a specialised use-case. A more general solution would be to provide list views. Another solution might be to use arrays rather than lists. Since your sieve list is homogeneous, you could possibly use an array of 1 or 0 bytes rather than a list of True or False bools. That would reduce the memory overhead by a factor of four, and similarly reduce the overhead of any copying: py> from array import array py> from sys import getsizeof py> L = [True, False, False, True]*1000 py> A = array('b', L) py> getsizeof(L) 16032 py> getsizeof(A) 4032 -- Steven From blindanagram at nowhere.org Tue Apr 23 03:05:53 2013 From: blindanagram at nowhere.org (Blind Anagram) Date: Tue, 23 Apr 2013 08:05:53 +0100 Subject: List Count In-Reply-To: <5175c12f$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <5175c12f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 23/04/2013 00:01, Steven D'Aprano wrote: > On Mon, 22 Apr 2013 15:15:19 +0100, Blind Anagram wrote: > >> But when using a sub-sequence, I do suffer a significant reduction in >> speed for a count when compared with count on the full list. When the >> list is small enough not to cause memory allocation issues this is about >> 30% on 100,000,000 items. But when the list is 1,000,000,000 items, OS >> memory allocation becomes an issue and the cost on my system rises to >> over 600%. > > Buy more memory :-) > > >> I agree that this is not a big issue but it seems to me a high price to >> pay for the lack of a sieve.count(value, limit), which I feel is a >> useful function (given that memoryview operations are not available for >> lists). > > There is no need to complicate the count method for such a specialised > use-case. A more general solution would be to provide list views. > > Another solution might be to use arrays rather than lists. Since your > sieve list is homogeneous, you could possibly use an array of 1 or 0 > bytes rather than a list of True or False bools. That would reduce the > memory overhead by a factor of four, and similarly reduce the overhead of > any copying: I did a lot of work comparing the overall performance of the sieve when using either lists or arrays and I found that lists were a lot faster for the majority use case when the sieve is not large. Brian From oscar.j.benjamin at gmail.com Tue Apr 23 07:08:32 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 23 Apr 2013 12:08:32 +0100 Subject: List Count In-Reply-To: References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <5175c12f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 23 April 2013 08:05, Blind Anagram wrote: > On 23/04/2013 00:01, Steven D'Aprano wrote: >> On Mon, 22 Apr 2013 15:15:19 +0100, Blind Anagram wrote: >> >>> But when using a sub-sequence, I do suffer a significant reduction in >>> speed for a count when compared with count on the full list. When the >>> list is small enough not to cause memory allocation issues this is about >>> 30% on 100,000,000 items. But when the list is 1,000,000,000 items, OS >>> memory allocation becomes an issue and the cost on my system rises to >>> over 600%. [snip] >> >> Another solution might be to use arrays rather than lists. Since your >> sieve list is homogeneous, you could possibly use an array of 1 or 0 >> bytes rather than a list of True or False bools. That would reduce the >> memory overhead by a factor of four, and similarly reduce the overhead of >> any copying: > > I did a lot of work comparing the overall performance of the sieve when > using either lists or arrays and I found that lists were a lot faster > for the majority use case when the sieve is not large. Okay, now I understand. I thought you were trying to optimise for large lists, but in fact you have already optimised for small lists. As a result you have made algorithmic choices that don't scale very well. Since you're still concerned about performance on small lists you don't want to rethink those choices. Instead you want a micro-optimisation that would compensate for them. Elsewhere you said: > I would not dream of doing this job by copying a slice in any other > language that I have used so I was simply asking for advice to discover > whether this copy could be avoided whilst staying with the simple sieve > design. So you already knew that there would be problems with this method, but you've chosen it anyway since it turned out to be fastest for small lists. You could always just do a different thing when the list is large: def pi(self, n): if n < 1000000: return self.indicator[:n].sum() else: return sum(itertools.islice(self.indicator, n)) However, if you really want to improve performance in computing pi(n) for large n you should just use one of the existing algorithms having sublinear space/time complexity. These also use evaluate pi(n) with sieves but the sieve only needs to be as big as sqrt(n) rather than n for the obvious method: http://en.wikipedia.org/wiki/Prime-counting_function#Algorithms_for_evaluating_.CF.80.28x.29 Oscar From blindanagram at nowhere.org Tue Apr 23 07:45:55 2013 From: blindanagram at nowhere.org (Blind Anagram) Date: Tue, 23 Apr 2013 12:45:55 +0100 Subject: List Count In-Reply-To: References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <5175c12f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 23/04/2013 12:08, Oscar Benjamin wrote: > On 23 April 2013 08:05, Blind Anagram wrote: >> On 23/04/2013 00:01, Steven D'Aprano wrote: >>> On Mon, 22 Apr 2013 15:15:19 +0100, Blind Anagram wrote: >>> >>>> But when using a sub-sequence, I do suffer a significant reduction in >>>> speed for a count when compared with count on the full list. When the >>>> list is small enough not to cause memory allocation issues this is about >>>> 30% on 100,000,000 items. But when the list is 1,000,000,000 items, OS >>>> memory allocation becomes an issue and the cost on my system rises to >>>> over 600%. > [snip] >>> >>> Another solution might be to use arrays rather than lists. Since your >>> sieve list is homogeneous, you could possibly use an array of 1 or 0 >>> bytes rather than a list of True or False bools. That would reduce the >>> memory overhead by a factor of four, and similarly reduce the overhead of >>> any copying: >> >> I did a lot of work comparing the overall performance of the sieve when >> using either lists or arrays and I found that lists were a lot faster >> for the majority use case when the sieve is not large. > > Okay, now I understand. I thought you were trying to optimise for > large lists, but in fact you have already optimised for small lists. > As a result you have made algorithmic choices that don't scale very > well. Since you're still concerned about performance on small lists > you don't want to rethink those choices. Instead you want a > micro-optimisation that would compensate for them. > > Elsewhere you said: > >> I would not dream of doing this job by copying a slice in any other >> language that I have used so I was simply asking for advice to discover >> whether this copy could be avoided whilst staying with the simple sieve >> design. > > So you already knew that there would be problems with this method, but > you've chosen it anyway since it turned out to be fastest for small > lists. You could always just do a different thing when the list is > large: Your analysis of my rationale is sound except that I only found out that I had a problem with counting in a subset of a list when I actually tried this for a huge sieve. It was only then that I discovered that there was no way of setting the upper limit in list.count(x) and hence that I would have to create a slice or find an alternative approach. I then wondered why count for lists has no limits whereas count for other objects (e.g. strings) has these. I also wondered whether there was an easy way of avoiding the slice, not that this is critical, but rather because it is just nice to have a sieve that still actually works for huge values, albeit inefficiently. > def pi(self, n): > if n < 1000000: > return self.indicator[:n].sum() > else: > return sum(itertools.islice(self.indicator, n)) > I have looked at itertools.islice as a complete replacement for count() where, on average, it was a lot slower. But I have not tried hybrid strategies as you suggest - I'll take a look at this. My thanks to you and others for the advice that has been offered. Brian From tjreedy at udel.edu Tue Apr 23 15:01:33 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Tue, 23 Apr 2013 15:01:33 -0400 Subject: List Count In-Reply-To: References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <5175c12f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/23/2013 7:45 AM, Blind Anagram wrote: > I then wondered why count for lists has no limits Probably because no one has asked for such, as least partly because it is not really needed. In any case, .count(s) is a generic method. It is part of the definition of a Sequence. It can also be implemented for non-sequence collections, such as a Tree class, that allow multiple occurrences of an item. > whereas count for other objects (e.g. strings) has these. Strings (of unicode or bytes) are exceptional in multiple ways. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Tue Apr 23 10:49:58 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Apr 2013 14:49:58 GMT Subject: List Count References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <5175c12f$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51769f96$0$29977$c3e8da3$5496439d@news.astraweb.com> On Tue, 23 Apr 2013 08:05:53 +0100, Blind Anagram wrote: > I did a lot of work comparing the overall performance of the sieve when > using either lists or arrays and I found that lists were a lot faster > for the majority use case when the sieve is not large. And when the sieve is large? I don't actually believe that the bottleneck is the cost of taking a list slice. That's pretty fast, even for huge lists, and all efforts to skip making a copy by using itertools.islice actually ended up slower. But suppose it is the bottleneck. Then *sooner or later* arrays will win over lists, simply because they're smaller. Of course, "sooner or later" might be much later. I expect that you will not find a single algorithm, or data structure, that works optimally for both small and huge inputs. In general, there are two strategies you might take: 1) Use an algorithm or data structure which is efficient for small inputs with small inputs, and after some cut-off size, swap to a different algorithm which is efficient for large inputs. That swap over may require a one-off conversion cost, but provided your sieve never shrinks, this may not matter. 2) Use only the algorithm for large inputs. For small inputs, the difference between the two is insignificant in absolute terms (who cares if the operation takes 5ms instead of 1ms?), but for large N, there is a clear winner. There's nothing that says you're limited to two algorithms. You may find that to really optimize things, you need three or more algorithms, each one optimized for a particular subset of inputs. Of course, all this added complexity is itself very costly. Is it worth it? -- Steven From blindanagram at nowhere.org Tue Apr 23 12:57:17 2013 From: blindanagram at nowhere.org (Blind Anagram) Date: Tue, 23 Apr 2013 17:57:17 +0100 Subject: List Count In-Reply-To: <51769f96$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <5175c12f$0$29977$c3e8da3$5496439d@news.astraweb.com> <51769f96$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 23/04/2013 15:49, Steven D'Aprano wrote: > On Tue, 23 Apr 2013 08:05:53 +0100, Blind Anagram wrote: > >> I did a lot of work comparing the overall performance of the sieve when >> using either lists or arrays and I found that lists were a lot faster >> for the majority use case when the sieve is not large. > > And when the sieve is large? I don't know but since the majority use case is when the sieve is small, it makes sense to choose a list. > I don't actually believe that the bottleneck is the cost of taking a list > slice. That's pretty fast, even for huge lists, and all efforts to skip > making a copy by using itertools.islice actually ended up slower. But > suppose it is the bottleneck. Then *sooner or later* arrays will win over > lists, simply because they're smaller. Maybe you have not noticed that, when I am discussing a huge sieve, I am simply pushing a sieve designed primarily for a small sieve lengths to the absolute limit. This is most definitely a minority use case. In pushing the size of the sieve upwards, it is the slice operation that is the first thing that 'breaks'. This is because the slice can be almost as big as the primary array so the OS gets driven into memory allocation problems for a sieve that is about half the length it would otherwise be. It still works but the cost of the slice once this point is reached rises from about 20% to over 600% because of all the paging going on. The unavailable list.count(value, limit) function would hence allow the sieve length to be up to twice as large before running into problems and would also cut the 20% slice cost I am seeing on smaller sieve lengths. So, all I was doing in asking for advice was to check whether there is an easy way of avoiding the slice copy, not because this is critical, but rather because it is a pity to limit the performance because Python forces a (strictly unnecessary) copy in order to perform a count within a part of a list. In other words, the lack of a list.count(value, limit) function makes Python less effective than it would otherwise be. I haven't looked at Python's C code base but I still wonder if there a good reason for NOT providing this? From oscar.j.benjamin at gmail.com Tue Apr 23 13:45:41 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 23 Apr 2013 18:45:41 +0100 Subject: List Count In-Reply-To: References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <5175c12f$0$29977$c3e8da3$5496439d@news.astraweb.com> <51769f96$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 23 April 2013 17:57, Blind Anagram wrote: > On 23/04/2013 15:49, Steven D'Aprano wrote: >> On Tue, 23 Apr 2013 08:05:53 +0100, Blind Anagram wrote: >> >>> I did a lot of work comparing the overall performance of the sieve when >>> using either lists or arrays and I found that lists were a lot faster >>> for the majority use case when the sieve is not large. >> >> And when the sieve is large? > > I don't know but since the majority use case is when the sieve is small, > it makes sense to choose a list. That's an odd comment given what you said at the start of this thread: Blind Anagram wrote: > I would be grateful for any advice people can offer on the fastest way > to count items in a sub-sequence of a large list. > > I have a list of boolean values that can contain many hundreds of > millions of elements for which I want to count the number of True values > in a sub-sequence, one from the start up to some value (say hi). >> I don't actually believe that the bottleneck is the cost of taking a list >> slice. That's pretty fast, even for huge lists, and all efforts to skip >> making a copy by using itertools.islice actually ended up slower. But >> suppose it is the bottleneck. Then *sooner or later* arrays will win over >> lists, simply because they're smaller. > > Maybe you have not noticed that, when I am discussing a huge sieve, I am > simply pushing a sieve designed primarily for a small sieve lengths to > the absolute limit. This is most definitely a minority use case. > > In pushing the size of the sieve upwards, it is the slice operation that > is the first thing that 'breaks'. This is because the slice can be > almost as big as the primary array so the OS gets driven into memory > allocation problems for a sieve that is about half the length it would > otherwise be. It still works but the cost of the slice once this point > is reached rises from about 20% to over 600% because of all the paging > going on. You keep mentioning that you want it to work with a large sieve. I would much rather compute the same quantities with a small sieve if possible. If you were using the Lehmer/Meissel algorithm you would be able to compute the same quantity (i.e. pi(1e9)) using a much smaller sieve with 30k items instead of 1e9. that would fit *very* comfortably in memory and you wouldn't even need to slice the list. Or to put it another way, you could compute pi(~1e18) using your current sieve without slicing or paging. If you want to lift the limit on computing pi(x) this is clearly the way to go. > > The unavailable list.count(value, limit) function would hence allow the > sieve length to be up to twice as large before running into problems and > would also cut the 20% slice cost I am seeing on smaller sieve lengths. > > So, all I was doing in asking for advice was to check whether there is > an easy way of avoiding the slice copy, not because this is critical, > but rather because it is a pity to limit the performance because Python > forces a (strictly unnecessary) copy in order to perform a count within > a part of a list. > > In other words, the lack of a list.count(value, limit) function makes > Python less effective than it would otherwise be. I haven't looked at > Python's C code base but I still wonder if there a good reason for NOT > providing this? If you feel that this is a good suggestion for an improvement to Python consider posting it on python-ideas. I wasn't aware of the equivalent functionality on strings but I see that the tuple.count() function is the same as list.count(). Oscar From blindanagram at nowhere.org Tue Apr 23 14:30:11 2013 From: blindanagram at nowhere.org (Blind Anagram) Date: Tue, 23 Apr 2013 19:30:11 +0100 Subject: List Count In-Reply-To: References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <5175c12f$0$29977$c3e8da3$5496439d@news.astraweb.com> <51769f96$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 23/04/2013 18:45, Oscar Benjamin wrote: >>>> I did a lot of work comparing the overall performance of the sieve when >>>> using either lists or arrays and I found that lists were a lot faster >>>> for the majority use case when the sieve is not large. >>> >>> And when the sieve is large? >> >> I don't know but since the majority use case is when the sieve is small, >> it makes sense to choose a list. > > That's an odd comment given what you said at the start of this thread: > > Blind Anagram wrote: >> I would be grateful for any advice people can offer on the fastest way >> to count items in a sub-sequence of a large list. >> >> I have a list of boolean values that can contain many hundreds of >> millions of elements for which I want to count the number of True values >> in a sub-sequence, one from the start up to some value (say hi). At this early stage in the discussion I was simply explaining the immediate context of the problem on which I was seeking advice. Here I didn't think it was necessary to expand on the wider context since there might have been an very easy way that people could suggest for avoiding the slice copy when counting on a part of a list. But there isn't, so the wider details then became important in explaining why some proposals might work for the limiting case but would not make sense within the overall context of use. And here I have said on more than one occasion that the huge sieve case is a minority use case. [snip] > You keep mentioning that you want it to work with a large sieve. I > would much rather compute the same quantities with a small sieve if > possible. If you were using the Lehmer/Meissel algorithm you would be > able to compute the same quantity (i.e. pi(1e9)) using a much smaller > sieve with 30k items instead of 1e9. that would fit *very* comfortably > in memory and you wouldn't even need to slice the list. Or to put it > another way, you could compute pi(~1e18) using your current sieve > without slicing or paging. If you want to lift the limit on computing > pi(x) this is clearly the way to go. If prime_pi for huge numbers was really important to me I wouldn't be using Python! This is just one of a number of functions implemented in the class. It is nice to have and it is also nice for testing purposes to be able to run it for large sieves. But it is by no means important enough to devote dedicated code to computing it. The prime generator within the class is far more important and is the workhorse for most uses [snip] >> In other words, the lack of a list.count(value, limit) function makes >> Python less effective than it would otherwise be. I haven't looked at >> Python's C code base but I still wonder if there a good reason for NOT >> providing this? > > If you feel that this is a good suggestion for an improvement to > Python consider posting it on python-ideas. I wasn't aware of the > equivalent functionality on strings but I see that the tuple.count() > function is the same as list.count(). To be honest, I am not really in a position to judge whether this is a 'good' suggestion. It has turned up as potentially useful in two cases for me but one of these (the one discussed here) is a minority use case. I would also be a bit worried about launching this into a group of Python experts who will almost certainly be even more demanding of explanations than you folk here! Brian From oscar.j.benjamin at gmail.com Tue Apr 23 15:16:51 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 23 Apr 2013 20:16:51 +0100 Subject: List Count In-Reply-To: References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <5175c12f$0$29977$c3e8da3$5496439d@news.astraweb.com> <51769f96$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 23 April 2013 19:30, Blind Anagram wrote: > On 23/04/2013 18:45, Oscar Benjamin wrote: > > [snip] >> You keep mentioning that you want it to work with a large sieve. I >> would much rather compute the same quantities with a small sieve if >> possible. If you were using the Lehmer/Meissel algorithm you would be >> able to compute the same quantity (i.e. pi(1e9)) using a much smaller >> sieve with 30k items instead of 1e9. that would fit *very* comfortably >> in memory and you wouldn't even need to slice the list. Or to put it >> another way, you could compute pi(~1e18) using your current sieve >> without slicing or paging. If you want to lift the limit on computing >> pi(x) this is clearly the way to go. > > If prime_pi for huge numbers was really important to me I wouldn't be > using Python! I would, at least to begin with. The advantage that Python has for this sort of thing is that it takes a minimal amount of programmer effort to implement these kind of algorithms. This is because you don't have to worry about nuts and bolts problems like integer overflow and memory allocation. You also have an abundance of different data structures to fulfil the big-O requirements of most algorithms. It's easy to make generators that can iterate over infinite or arbitrarily large sequences while still using constant memory. And so on... To implement the algorithm I mentioned in e.g. C would be considerably more work. C would, however, perform much better using your brute force approach and would lift the memory constraints of your program by a small (in asymptotic terms) amount. So I actually find that I can often get a faster program in Python simply because it's much easier to implement fancier algorithms with the optimal asymptotic performance that will ultimately outperform a brute force approach whichever language is used. Although, in saying that, those particular algorithms are probably most naturally implemented in a functional language like Haskell with scalable recursion. >>> In other words, the lack of a list.count(value, limit) function makes >>> Python less effective than it would otherwise be. I haven't looked at >>> Python's C code base but I still wonder if there a good reason for NOT >>> providing this? >> >> If you feel that this is a good suggestion for an improvement to >> Python consider posting it on python-ideas. I wasn't aware of the >> equivalent functionality on strings but I see that the tuple.count() >> function is the same as list.count(). > > To be honest, I am not really in a position to judge whether this is a > 'good' suggestion. It has turned up as potentially useful in two cases > for me but one of these (the one discussed here) is a minority use case. > I would also be a bit worried about launching this into a group of > Python experts who will almost certainly be even more demanding of > explanations than you folk here! I wouldn't worry about that. I've never felt the need for this but then I would probably use numpy to do what you're doing. It's certainly not an outlandish suggestion and I'd be surprised if no one agreed with the idea. Oscar From tjreedy at udel.edu Tue Apr 23 16:00:56 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Tue, 23 Apr 2013 16:00:56 -0400 Subject: List Count In-Reply-To: References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <5175c12f$0$29977$c3e8da3$5496439d@news.astraweb.com> <51769f96$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/23/2013 12:57 PM, Blind Anagram wrote: > So, all I was doing in asking for advice was to check whether there is > an easy way of avoiding the slice copy, And there is. > not because this is critical, > but rather because it is a pity to limit the performance because Python > forces a (strictly unnecessary) copy in order to perform a count within > a part of a list. Python does not force that. You have been given several simple no-copy alternatives. They happen to be slower *with CPython* because of the speed difference between Python code and C code. If the same timing tests were done with any of the implementations that execute python code faster, the results would likely be different. I thing str/byte/bytearray.count have more need for optional start,stop boundary parameters because a) people search in long texts and subtexts, more so I think that for other sequences, b) they search for substrings longer than 1 and hence c) the generic no-slice alternatives do not work for counting substrings. That said, I do see that tuple/list.index have had start, stop paramaters added, so doing the same for .count is conceivable. I just do not remember anyone else asking for such. The use case must be very rare. And as I said in my other post, .count(x) applies to any collections, but start,stop would only apply to sequences. > In other words, the lack of a list.count(value, limit) function makes > Python less effective than it would otherwise be. Untrue. The alternatives are just as *effective*. From oscar.j.benjamin at gmail.com Tue Apr 23 16:38:38 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 23 Apr 2013 21:38:38 +0100 Subject: List Count In-Reply-To: References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <5175c12f$0$29977$c3e8da3$5496439d@news.astraweb.com> <51769f96$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 23 April 2013 21:00, Terry Jan Reedy wrote: > > That said, I do see that tuple/list.index have had start, stop paramaters > added, so doing the same for .count is conceivable. Are those new? I don't remember them not being there. You need the start/stop parameters to be able to use index for finding all occurrences of an item rather than just the first: def indices(value, sequence): i = -1 while True: try: i = sequence.index(value, i + 1) except ValueError: return yield i I thought this was a common use case for .index() and that if the interface had been designed more recently then it might have just been an .indices() method that returned an iterator. Oscar From blindanagram at nowhere.org Tue Apr 23 16:41:03 2013 From: blindanagram at nowhere.org (Blind Anagram) Date: Tue, 23 Apr 2013 21:41:03 +0100 Subject: List Count In-Reply-To: References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <5175c12f$0$29977$c3e8da3$5496439d@news.astraweb.com> <51769f96$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 23/04/2013 21:00, Terry Jan Reedy wrote: > On 4/23/2013 12:57 PM, Blind Anagram wrote: > >> So, all I was doing in asking for advice was to check whether there is >> an easy way of avoiding the slice copy, > > And there is. > >> not because this is critical, >> but rather because it is a pity to limit the performance because Python >> forces a (strictly unnecessary) copy in order to perform a count within >> a part of a list. > > Python does not force that. You have been given several simple no-copy > alternatives. They happen to be slower *with CPython* because of the > speed difference between Python code and C code. If the same timing > tests were done with any of the implementations that execute python code > faster, the results would likely be different. Then being pedantic rather than colloquial, the lack of start, end parameters in the function list.count(value) means that anyone wishing to use this function on a part of a list is forced to slice the list and thereby invoke a possibly costly copy operation, one that is, in principle, not necessary in order to perform the underlying operation. [snip] >> In other words, the lack of a list.count(value, limit) function makes >> Python less effective than it would otherwise be. > > Untrue. The alternatives are just as *effective*. Then I fear that we will have to accept that we disagree on this. Brian From steve+comp.lang.python at pearwood.info Tue Apr 23 21:59:34 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Apr 2013 01:59:34 GMT Subject: List Count References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <5175c12f$0$29977$c3e8da3$5496439d@news.astraweb.com> <51769f96$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51773c85$0$29977$c3e8da3$5496439d@news.astraweb.com> On Tue, 23 Apr 2013 17:57:17 +0100, Blind Anagram wrote: > On 23/04/2013 15:49, Steven D'Aprano wrote: >> On Tue, 23 Apr 2013 08:05:53 +0100, Blind Anagram wrote: >> >>> I did a lot of work comparing the overall performance of the sieve >>> when using either lists or arrays and I found that lists were a lot >>> faster for the majority use case when the sieve is not large. >> >> And when the sieve is large? > > I don't know but since the majority use case is when the sieve is small, > it makes sense to choose a list. > >> I don't actually believe that the bottleneck is the cost of taking a >> list slice. That's pretty fast, even for huge lists, and all efforts to >> skip making a copy by using itertools.islice actually ended up slower. >> But suppose it is the bottleneck. Then *sooner or later* arrays will >> win over lists, simply because they're smaller. > > Maybe you have not noticed that, when I am discussing a huge sieve, I am > simply pushing a sieve designed primarily for a small sieve lengths to > the absolute limit. This is most definitely a minority use case. You don't say? I hadn't noticed the first three hundred times you mentioned it :-P In my opinion, it is more important to be efficient for large sieves, not small. As they say, for small N, everything is fast. Nobody is going to care about the difference between small-N taking 1ms or 10ms, but they will care about the difference between big-N taking 1 minute or 1 hour. So, as a general rule, optimize the expensive cases, and if the cheap cases are a little less cheap than they otherwise would have been, nobody will care or notice. Of course, it's your code, and you're free to make whatever trade-offs between time and space and programmer effort that you feel are best. I'm just making a suggestion. [...] > In other words, the lack of a list.count(value, limit) function makes > Python less effective than it would otherwise be. I haven't looked at > Python's C code base but I still wonder if there a good reason for NOT > providing this? The same reasons for not providing any other of an infinite number of potential features. You have to weigh up the potential benefits of the feature against the costs: - Is this a good use of developer time to build the feature? - Every new feature requires somebody to write it, somebody to check it, somebody to write tests for it, somebody to document it. Who is going to do all this work? - Every new feature increases the size and complexity of the language and makes it harder for people to learn. - Does this new feature actually have the advantages claimed? Many so- called optimizations actually turn out to be pessimizations instead. - Will the new feature be an attractive nuisance, fooling programmers into using it inappropriately? In this case, I would say that adding a limit argument to list.count is *absolutely not* worthwhile, because it is insufficiently general. To be general enough to be worthwhile, you would have to add three arguments: list.count(value, start=0, end=None, step=1) But even there I don't think it's general enough to cover the costs. I believe that a better solution would be to create list views to offer a subset of the list without actually copying. -- Steven From blindanagram at nowhere.org Wed Apr 24 05:01:36 2013 From: blindanagram at nowhere.org (Blind Anagram) Date: Wed, 24 Apr 2013 10:01:36 +0100 Subject: List Count In-Reply-To: <51773c85$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <5175377f$0$29977$c3e8da3$5496439d@news.astraweb.com> <517545F7.5090209@nowhere.org> <5175c12f$0$29977$c3e8da3$5496439d@news.astraweb.com> <51769f96$0$29977$c3e8da3$5496439d@news.astraweb.com> <51773c85$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 24/04/2013 02:59, Steven D'Aprano wrote: > On Tue, 23 Apr 2013 17:57:17 +0100, Blind Anagram wrote: [snip] > In my opinion, it is more important to be efficient for large sieves, not > small. As they say, for small N, everything is fast. Nobody is going to > care about the difference between small-N taking 1ms or 10ms, but they > will care about the difference between big-N taking 1 minute or 1 hour. > So, as a general rule, optimize the expensive cases, and if the cheap > cases are a little less cheap than they otherwise would have been, nobody > will care or notice. I agree in general but it is often the case that more sophisticated algorithms only gain traction over simpler ones at much higher points than might be expected from a simple analysis. In my experience a naive sieve is an efficient solution for a general purpose sieve class primarily intended for situations where the sieve length can be large but not huge. As I think you have pointed out, memory is cheap and the memory operations needed to do copying and counting operations are fast. So using up memory is not normally an issue. I have just found a situation where a copy can have a serious impact on performance in an admittedly limiting, minority use case. It the fact that this copy is not, in principle, necessary, that I find disappointing. [snip] > In this case, I would say that adding a limit argument to list.count is > *absolutely not* worthwhile, because it is insufficiently general. To be > general enough to be worthwhile, you would have to add three arguments: > > list.count(value, start=0, end=None, step=1) > > But even there I don't think it's general enough to cover the costs. I > believe that a better solution would be to create list views to offer a > subset of the list without actually copying. I don't know a great deal about Python internals but I suspect that these solutions would offer more but also cost more. So where the balance of advantages would lie is unclear. But I am not pushing for a particular (or, indeed, any) solution. From __peter__ at web.de Mon Apr 22 09:22:20 2013 From: __peter__ at web.de (Peter Otten) Date: Mon, 22 Apr 2013 15:22:20 +0200 Subject: List Count References: Message-ID: Blind Anagram wrote: > I would be grateful for any advice people can offer on the fastest way > to count items in a sub-sequence of a large list. > > I have a list of boolean values that can contain many hundreds of > millions of elements for which I want to count the number of True values > in a sub-sequence, one from the start up to some value (say hi). > > I am currently using: > > sieve[:hi].count(True) > > but I believe this may be costly because it copies a possibly large part > of the sieve. > > Ideally I would like to be able to use: > > sieve.count(True, hi) > > where 'hi' sets the end of the count but this function is, sadly, not > available for lists. > > The use of a bytearray with a memoryview object instead of a list solves > this particular problem but it is not a solution for me as it creates > more problems than it solves in other aspects of the program. > > Can I assume that one possible solution would be to sub-class list and > create a C based extension to provide list.count(value, limit)? > > Are there any other solutions that will avoid copying a large part of > the list? If the list doesn't change often you can convert it to a string >>> items = [True, False, False] * 10 >>> sitems = "".join("FT"[i] for i in items) >>> sitems 'TFFTFFTFFTFFTFFTFFTFFTFFTFFTFF' >>> sitems.count("T", 3, 10) 3 >>> sitems.count("F", 3, 10) 4 Or you use a[3:10].sum() on a boolean numpy array. Its slices are views rather than copies: >>> import numpy >>> a = numpy.array([True, False, False]*10) >>> a[3:10].sum() 3 From dihedral88888 at googlemail.com Mon Apr 22 09:36:29 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Mon, 22 Apr 2013 06:36:29 -0700 (PDT) Subject: List Count In-Reply-To: References: Message-ID: <8aa3c60d-ca53-4ba7-a396-66b806eb8067@googlegroups.com> Blind Anagram? 2013?4?22????UTC+8??7?58?20???? > I would be grateful for any advice people can offer on the fastest way > > to count items in a sub-sequence of a large list. > > > > I have a list of boolean values that can contain many hundreds of > > millions of elements for which I want to count the number of True values > > in a sub-sequence, one from the start up to some value (say hi). > > > > I am currently using: > > > > sieve[:hi].count(True) > > > > but I believe this may be costly because it copies a possibly large part > > of the sieve. > > > > Ideally I would like to be able to use: > > > > sieve.count(True, hi) > > > > where 'hi' sets the end of the count but this function is, sadly, not > > available for lists. > > > > The use of a bytearray with a memoryview object instead of a list solves > > this particular problem but it is not a solution for me as it creates > > more problems than it solves in other aspects of the program. > > > > Can I assume that one possible solution would be to sub-class list and > > create a C based extension to provide list.count(value, limit)? > > > > Are there any other solutions that will avoid copying a large part of > > the list? For those problems related to a homogeneous list of numbers , please check whether the arrays in numpy can fit your needs practically or not. Sometimes I work on numbers in varied ranges, then the list and the long integers in Python is really handy. From arif7d.auto at gmail.com Mon Apr 22 08:24:40 2013 From: arif7d.auto at gmail.com (arif7d.auto at gmail.com) Date: Mon, 22 Apr 2013 05:24:40 -0700 (PDT) Subject: Selenium Webdriver + Python (How to get started ??) Message-ID: Note that:- I have some experience of using Selenium IDE and Webdriver (Java). but no prior experience of Python. Now there is a project for which I will need to work with webdriver + Python. So far I have done following steps.. Install JDK Setup Eclipse download & Installed Python v3.3.1 Download & Installed Pydev (for Eclipse) also configured download & installed (Distribute + PIP) http://www.lfd.uci.edu/~gohlke/pythonlibs/#pip Installed Selenium using command prompt Running following commands from windows 7 command prompt, successfully opens firefox browser python >>>from selenium import webdriver >>>webdriver.Firefox() ---------- ISSUE is that, I do not know exact steps of creating a python webdriver test project. I create new Pydev project with a "src" folder and also used sample python code from internet but selenium classes cannot be recognized. I have tried various approaches to import libraries but none seems to work. Any one can guide me what i need to do step by step to successfully run a simple test via python webdriver!! (eclipse pydev) Thank you. From santiycr at gmail.com Tue Apr 23 11:55:19 2013 From: santiycr at gmail.com (Santi) Date: Tue, 23 Apr 2013 08:55:19 -0700 (PDT) Subject: Selenium Webdriver + Python (How to get started ??) In-Reply-To: References: Message-ID: <093d581b-9963-4432-b0c4-bc56ff4578d4@googlegroups.com> On Monday, April 22, 2013 8:24:40 AM UTC-4, arif7... at gmail.com wrote: > Note that:- I have some experience of using Selenium IDE and Webdriver (Java). but no prior experience of Python. > > > > Now there is a project for which I will need to work with webdriver + Python. > > > > So far I have done following steps.. > > > > Install JDK > > Setup Eclipse > > download & Installed Python v3.3.1 > > Download & Installed Pydev (for Eclipse) also configured > > download & installed (Distribute + PIP) http://www.lfd.uci.edu/~gohlke/pythonlibs/#pip > > Installed Selenium using command prompt > > > > Running following commands from windows 7 command prompt, successfully opens firefox browser > > > > python > > >>>from selenium import webdriver > > >>>webdriver.Firefox() > > > > ---------- > > > > ISSUE is that, I do not know exact steps of creating a python webdriver test project. > > > > I create new Pydev project with a "src" folder and also used sample python code from internet but selenium classes cannot be recognized. I have tried various approaches to import libraries but none seems to work. Any one can guide me what i need to do step by step to successfully run a simple test via python webdriver!! (eclipse pydev) > > > > Thank you. I'm guessing your PyDev setup is not configured to use pip and your dependencies? How about this: http://stackoverflow.com/questions/4631377/unresolved-import-issues-with-pydev-and-eclipse From r at ymond.co.za Mon Apr 22 08:39:43 2013 From: r at ymond.co.za (RBotha) Date: Mon, 22 Apr 2013 05:39:43 -0700 (PDT) Subject: Confusing Algorithm Message-ID: <09f7da52-b0d6-4167-957f-d207faf33d07@googlegroups.com> I'm facing the following problem: """ In a city of towerblocks, Spiderman can ?cover? all the towers by connecting the first tower with a spider-thread to the top of a later tower and then to a next tower and then to yet another tower until he reaches the end of the city. Threads are straight lines and cannot intersect towers. Your task is to write a program that finds the minimal number of threads to cover all the towers. The list of towers is given as a list of single digits indicating their height. -Example: List of towers: 1 5 3 7 2 5 2 Output: 4 """ I'm not sure how a 'towerblock' could be defined. How square does a shape have to be to qualify as a towerblock? Any help on solving this problem? Thank you. From rosuav at gmail.com Mon Apr 22 08:56:35 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 22 Apr 2013 22:56:35 +1000 Subject: Confusing Algorithm In-Reply-To: <09f7da52-b0d6-4167-957f-d207faf33d07@googlegroups.com> References: <09f7da52-b0d6-4167-957f-d207faf33d07@googlegroups.com> Message-ID: On Mon, Apr 22, 2013 at 10:39 PM, RBotha wrote: > I'm facing the following problem: > > """ > In a city of towerblocks, Spiderman can > ?cover? all the towers by connecting the > first tower with a spider-thread to the top > of a later tower and then to a next tower > and then to yet another tower until he > reaches the end of the city. Threads are > straight lines and cannot intersect towers. > Your task is to write a program that finds > the minimal number of threads to cover all > the towers. The list of towers is given as a > list of single digits indicating their height. > > -Example: > List of towers: 1 5 3 7 2 5 2 > Output: 4 > """ > > I'm not sure how a 'towerblock' could be defined. How square does a shape have to be to qualify as a towerblock? Any help on solving this problem? First start by clarifying the problem. My reading of this is that Spiderman iterates over the towers, connecting his thread from one to the next, but only so long as the towers get shorter: First thread 1 New thread 5-3 New thread 7-2 New thread 5-2 There are other possible readings of the problem. Once you fully understand the problem, write it out in pseudo-code - something like this: Iterate over towers sequentially If next tower is taller than current tower, new thread Report number of new threads And then turn it into code, and start running it and playing with it... and debugging it. (There's a small error in the pseudo-code I just posted; can you spot it?) Once you're at that point, if you get stuck, post your code and we can try to help. But fundamentally, I think you don't _need_ to define a towerblock. :) ChrisA From oscar.j.benjamin at gmail.com Mon Apr 22 10:57:52 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 22 Apr 2013 15:57:52 +0100 Subject: Confusing Algorithm In-Reply-To: References: <09f7da52-b0d6-4167-957f-d207faf33d07@googlegroups.com> Message-ID: On 22 April 2013 13:56, Chris Angelico wrote: > On Mon, Apr 22, 2013 at 10:39 PM, RBotha wrote: >> I'm facing the following problem: >> >> """ >> In a city of towerblocks, Spiderman can >> ?cover? all the towers by connecting the >> first tower with a spider-thread to the top >> of a later tower and then to a next tower >> and then to yet another tower until he >> reaches the end of the city. Threads are >> straight lines and cannot intersect towers. >> Your task is to write a program that finds >> the minimal number of threads to cover all >> the towers. The list of towers is given as a >> list of single digits indicating their height. >> >> -Example: >> List of towers: 1 5 3 7 2 5 2 >> Output: 4 >> """ >> >> I'm not sure how a 'towerblock' could be defined. How square does a shape have to be to qualify as a towerblock? Any help on solving this problem? > > First start by clarifying the problem. My reading of this is that > Spiderman iterates over the towers, connecting his thread from one to > the next, but only so long as the towers get shorter: > >>-Example: >>List of towers: 1 5 3 7 2 5 2 >>Output: 4 > > First thread > 1 > New thread > 5-3 > New thread > 7-2 > New thread > 5-2 > > There are other possible readings of the problem. I read it differently. I thought the threads would go 1->5->7->5->2. Oscar From rosuav at gmail.com Mon Apr 22 11:02:31 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Apr 2013 01:02:31 +1000 Subject: Confusing Algorithm In-Reply-To: References: <09f7da52-b0d6-4167-957f-d207faf33d07@googlegroups.com> Message-ID: On Tue, Apr 23, 2013 at 12:57 AM, Oscar Benjamin wrote: > On 22 April 2013 13:56, Chris Angelico wrote: >> There are other possible readings of the problem. > > I read it differently. I thought the threads would go 1->5->7->5->2. I hadn't thought of that one, but agreed, that's also plausible, and it results in an answer of 4. It's a stronger contender than the one I posited, because the wording implies that there are multiple ways to do it and you have to pick/find the best. Seems to me the problem's a little under-specified, tbh. ChrisA From auriocus at gmx.de Mon Apr 22 16:33:21 2013 From: auriocus at gmx.de (Christian Gollwitzer) Date: Mon, 22 Apr 2013 22:33:21 +0200 Subject: Confusing Algorithm In-Reply-To: References: <09f7da52-b0d6-4167-957f-d207faf33d07@googlegroups.com> Message-ID: Am 22.04.13 16:57, schrieb Oscar Benjamin: > On 22 April 2013 13:56, Chris Angelico wrote: >> On Mon, Apr 22, 2013 at 10:39 PM, RBotha wrote: >>> Threads are >>> straight lines and cannot intersect towers. >>> Your task is to write a program that finds >>> the minimal number of threads to cover all >>> the towers. >>> >>> -Example: >>> List of towers: 1 5 3 7 2 5 2 >>> Output: 4 > > > I read it differently. I thought the threads would go 1->5->7->5->2. > I'd agree with your interpretation. "Threads are straight lines and cannot intersect towers" - I read it such that the answer is the "convex hull" of the set of points given by the tower height. The convex hull can be computed for this 1D problem by initializing with line segments between every point and repeatedly pulling up every non-convex piece, if I'm not mistaken. Christian From ian.g.kelly at gmail.com Mon Apr 22 18:36:14 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 22 Apr 2013 16:36:14 -0600 Subject: Confusing Algorithm In-Reply-To: References: <09f7da52-b0d6-4167-957f-d207faf33d07@googlegroups.com> Message-ID: On Mon, Apr 22, 2013 at 2:33 PM, Christian Gollwitzer wrote: > I'd agree with your interpretation. "Threads are straight lines and cannot > intersect towers" - I read it such that the answer is the "convex hull" of > the set of points given by the tower height. The convex hull can be computed > for this 1D problem by initializing with > line segments between every point and repeatedly pulling up every > non-convex piece, if I'm not mistaken. I agree that seems the likely intention. One also must assume that the towers are evenly spaced and have point width, neither of which are stated in the problem. From djc at news.invalid Mon Apr 22 17:38:29 2013 From: djc at news.invalid (DJC) Date: Mon, 22 Apr 2013 22:38:29 +0100 Subject: Confusing Algorithm In-Reply-To: <09f7da52-b0d6-4167-957f-d207faf33d07@googlegroups.com> References: <09f7da52-b0d6-4167-957f-d207faf33d07@googlegroups.com> Message-ID: On 22/04/13 13:39, RBotha wrote: > I'm facing the following problem: > > """ > In a city of towerblocks, Spiderman can > ?cover? all the towers by connecting the > first tower with a spider-thread to the top > of a later tower and then to a next tower > and then to yet another tower until he > reaches the end of the city. Threads are > straight lines and cannot intersect towers. > Your task is to write a program that finds > the minimal number of threads to cover all > the towers. The list of towers is given as a > list of single digits indicating their height. > > -Example: > List of towers: 1 5 3 7 2 5 2 > Output: 4 > """ > > I'm not sure how a 'towerblock' could be defined. How square does a shape have to be to qualify as a towerblock? Any help on solving this problem? It's not the algorithm that's confusing, it's the problem. First clarify the problem. This appears to be a variation of the travelling-salesman problem. Except the position of the towers is not defined, only their height. So either the necessary information is missing or whoever set the problem intended something else. From timr at probo.com Wed Apr 24 02:18:07 2013 From: timr at probo.com (Tim Roberts) Date: Tue, 23 Apr 2013 23:18:07 -0700 Subject: Confusing Algorithm References: <09f7da52-b0d6-4167-957f-d207faf33d07@googlegroups.com> Message-ID: <16uen8hqv8gvmc51erptlrdtm7484u7s1b@4ax.com> RBotha wrote: > >I'm facing the following problem: > >""" >In a city of towerblocks, Spiderman can >?cover? all the towers by connecting the >first tower with a spider-thread to the top >of a later tower and then to a next tower >and then to yet another tower until he >reaches the end of the city. ... > >-Example: >List of towers: 1 5 3 7 2 5 2 >Output: 4 >""" > >I'm not sure how a 'towerblock' could be defined. How square does a shape have to be to qualify as a towerblock? Any help on solving this problem? Here's your city; [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ][ ][ ] [ ] [ ][ ][ ][ ][ ][ ] [ ][ ][ ][ ][ ][ ][ ] ------------------------------ A B C D E F G Once you see the picture, you can see that you'd thread from B to D without involving C. I think you'll go A to B to D to F to G -- 4 threads. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From alessandro.basili at cern.ch Mon Apr 22 09:34:02 2013 From: alessandro.basili at cern.ch (alb) Date: Mon, 22 Apr 2013 15:34:02 +0200 Subject: kbhit/getch python equivalent Message-ID: Hi everyone, I'm looking for a kbhit/getch equivalent in python in order to be able to stop my inner loop in a controlled way (communication with external hardware is involved and breaking it abruptly may cause unwanted errors on the protocol). I'm programming on *nix systems, no need to be portable on Windows. I've seen the msvcrt module, but it looks like is for Windows only. Any ideas/suggestions? Al -- A: Because it fouls the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail? From __peter__ at web.de Mon Apr 22 10:00:47 2013 From: __peter__ at web.de (Peter Otten) Date: Mon, 22 Apr 2013 16:00:47 +0200 Subject: kbhit/getch python equivalent References: Message-ID: alb wrote: > I'm looking for a kbhit/getch equivalent in python in order to be able > to stop my inner loop in a controlled way (communication with external > hardware is involved and breaking it abruptly may cause unwanted errors > on the protocol). > > I'm programming on *nix systems, no need to be portable on Windows. I've > seen the msvcrt module, but it looks like is for Windows only. > > Any ideas/suggestions? Curses? http://docs.python.org/dev/library/curses.html From invalid at invalid.invalid Mon Apr 22 10:10:02 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 22 Apr 2013 14:10:02 +0000 (UTC) Subject: kbhit/getch python equivalent References: Message-ID: On 2013-04-22, alb wrote: > I'm looking for a kbhit/getch equivalent in python in order to be able > to stop my inner loop in a controlled way (communication with external > hardware is involved and breaking it abruptly may cause unwanted errors > on the protocol). > > I'm programming on *nix systems, no need to be portable on Windows. I've > seen the msvcrt module, but it looks like is for Windows only. > > Any ideas/suggestions? Signals, ncurses, termios. -- Grant Edwards grant.b.edwards Yow! ANN JILLIAN'S HAIR at makes LONI ANDERSON'S gmail.com HAIR look like RICARDO MONTALBAN'S HAIR! From rosuav at gmail.com Mon Apr 22 11:08:21 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Apr 2013 01:08:21 +1000 Subject: kbhit/getch python equivalent In-Reply-To: References: Message-ID: On Mon, Apr 22, 2013 at 11:34 PM, alb wrote: > I'm looking for a kbhit/getch equivalent in python in order to be able > to stop my inner loop in a controlled way (communication with external > hardware is involved and breaking it abruptly may cause unwanted errors > on the protocol). Catch KeyboardInterrupt and hit Ctrl-C. ChrisA From woooee at gmail.com Mon Apr 22 16:30:50 2013 From: woooee at gmail.com (woooee at gmail.com) Date: Mon, 22 Apr 2013 13:30:50 -0700 (PDT) Subject: kbhit/getch python equivalent In-Reply-To: References: Message-ID: <2507c961-0e51-4df2-8a43-018735b3c367@googlegroups.com> > I'm looking for a kbhit/getch equivalent in python in order to be able to stop my inner loop in a controlled way (communication with external hardware is involved and breaking it abruptly may cause unwanted errors A curses example import curses stdscr = curses.initscr() curses.cbreak() stdscr.keypad(1) stdscr.addstr(0,10,"Hit 'q' to quit ") stdscr.refresh() key = '' while key != ord('q'): key = stdscr.getch() stdscr.addch(20,25,key) stdscr.refresh() curses.endwin() From thudfoo at gmail.com Tue Apr 30 10:06:34 2013 From: thudfoo at gmail.com (xDog Walker) Date: Tue, 30 Apr 2013 07:06:34 -0700 Subject: kbhit/getch python equivalent In-Reply-To: References: Message-ID: <201304300706.35307.thudfoo@gmail.com> On Monday 2013 April 22 06:34, alb wrote: > Hi everyone, > > I'm looking for a kbhit/getch equivalent in python in order to be able > to stop my inner loop in a controlled way (communication with external > hardware is involved and breaking it abruptly may cause unwanted errors > on the protocol). > > I'm programming on *nix systems, no need to be portable on Windows. http://code.activestate.com/search/recipes/#q=getch -- Yonder nor sorghum stenches shut ladle gulls stopper torque wet strainers. From werotizy at freent.dd Mon Apr 22 09:41:33 2013 From: werotizy at freent.dd (Tom P) Date: Mon, 22 Apr 2013 15:41:33 +0200 Subject: HTTPServer again Message-ID: Hi, a few weeks back I posed a question about passing static data to a request server, and thanks to some useful suggestions, got it working. I see yesterday there is a suggestion to use a framework like Tornado rather than base classes. However I can't figure achieve the same effect using Tornado (BTW this is all python 2.7). The key point is how to access the server class from within do_GET, and from the server class instance, to access its get and set methods. Here are some code fragments that work with HTTPServer: class MyHandler(BaseHTTPRequestHandler): def do_GET(self): ss = self.server tracks = ss.tracks . . . class MyWebServer(object): def get_params(self): return self.global_params def set_params(self, params): self.global_params = params def get_tracks(self): return self.tracks def __init__(self): self.global_params = "" self.tracks = setup_() myServer = HTTPServer myServer.tracks = self.get_tracks() myServer.params = self.get_params() self.server = myServer(('', 7878), MyHandler) print 'started httpserver on port 7878...' . . . . def main(): aServer = MyWebServer() aServer.runIt() if __name__ == '__main__': main() From sendtomrg at gmail.com Mon Apr 22 09:54:02 2013 From: sendtomrg at gmail.com (M.gowtham M.gowtham) Date: Mon, 22 Apr 2013 06:54:02 -0700 (PDT) Subject: comp.lang.python Message-ID: <796ed76b-e63c-4fed-915c-d56a635cec48@googlegroups.com> Hi, a few weeks back I posed a question about passing static data to a request server, and thanks to some useful suggestions, got it working. I see yesterday there is a suggestion to use a framework like Tornado rather than base classes. However I can't figure achieve the same effect using Tornado (BTW this is all python 2.7). The key point is how to access the server class from within do_GET, and from the server class instance, to access its get and set methods. Here are some code fragments that work with HTTPServer: class MyHandler(BaseHTTPRequestHandler): def do_GET(self): ss = self.server tracks = ss.tracks . . . class MyWebServer(object): def get_params(self): return self.global_params def set_params(self, params): self.global_params = params def get_tracks(self): return self.tracks def __init__(self): self.global_params = "" self.tracks = setup_() myServer = HTTPServer myServer.tracks = self.get_tracks() myServer.params = self.get_params() self.server = myServer(('', 7878), MyHandler) print 'started httpserver on port 7878...' . . . . def main(): aServer = MyWebServer() aServer.runIt() if __name__ == '__main__': main() Show trimmed content website--> http://www.win2job.info/ From rodrick.brown at gmail.com Mon Apr 22 10:54:31 2013 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Mon, 22 Apr 2013 10:54:31 -0400 Subject: error importing modules Message-ID: I'm using the fabric api (fabfile.org) I?m executing my fab script like the following: $ fab -H server set_nic_buffers -f set_nic_buffers.py Traceback (most recent call last): File "/usr/lib/python2.7/site-packages/fabric/main.py", line 739, in main *args, **kwargs File "/usr/lib/python2.7/site-packages/fabric/tasks.py", line 316, in execute multiprocessing File "/usr/lib/python2.7/site-packages/fabric/tasks.py", line 213, in _execute return task.run(*args, **kwargs) File "/usr/lib/python2.7/site-packages/fabric/tasks.py", line 123, in run return self.wrapped(*args, **kwargs) File "/home/rbrown/repos/unix-tools/tools/fabfiles/nb.py", line 5, in set_nic_buffers f_exec = modules.Fabexec('set_nic_buffers', '/var/tmp/unix-tools/tools/set_nic_buffers.sh') TypeError: 'module' object is not callable My paths all seem to be fine not sure what?s going on $ python -c 'import modules.Fabexec; print (modules.Fabexec)' Fabfiles |-- modules | |-- Fabexec.py | |-- Fabexec.pyc | |-- __init__.py | `-- __init__.pyc |-- systune.py |-- systune.pyc `-- set_nic_buffers.py --- set_nic_buffers.py --- import modules from modules import Fabexec def set_nic_buffers(): f_exec = modules.Fabexec('set_nic_buffers', '/var/tmp/unix-tools/tools/set_nic_buffers.sh') f_exec.run() --- Fabexec.py --- from fabric.api import run, cd, sudo, env from fabric.contrib import files from fabric.colors import green class Fabexec(object): repobase='/var/tmp/unix-tools' def __init__(self,script_name,install_script): self.script_name = script_name self.install_script = install_script def run(self): if files.exists(self.install_script): with cd(self.repobase): result = sudo(self.install_script + ' %s ' % env.host) if result.return_code != 0: print(red('Error occured executing %s' % self.install_script)) else: print(green('%s executed successfully')) else: print(red('Error no such dir %s try running repo deploy script to host %s' % (self.repobase, env.host))) raise SystemExit() -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Mon Apr 22 12:32:22 2013 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 22 Apr 2013 17:32:22 +0100 Subject: error importing modules In-Reply-To: References: Message-ID: <51756616.9040502@mrabarnett.plus.com> On 22/04/2013 15:54, Rodrick Brown wrote: > I'm using the fabric api (fabfile.org ) > > I?m executing my fab script like the following: > > $ fab -H server set_nic_buffers -f set_nic_buffers.py > Traceback (most recent call last): > File "/usr/lib/python2.7/site-packages/fabric/main.py", line 739, in main > *args, **kwargs > File "/usr/lib/python2.7/site-packages/fabric/tasks.py", line 316, in > execute > multiprocessing > File "/usr/lib/python2.7/site-packages/fabric/tasks.py", line 213, in > _execute > return task.run(*args, **kwargs) > File "/usr/lib/python2.7/site-packages/fabric/tasks.py", line 123, in run > return self.wrapped(*args, **kwargs) > File "/home/rbrown/repos/unix-tools/tools/fabfiles/nb.py", line 5, in > set_nic_buffers > f_exec = modules.Fabexec('set_nic_buffers', > '/var/tmp/unix-tools/tools/set_nic_buffers.sh') > TypeError: 'module' object is not callable > > My paths all seem to be fine not sure what?s going on > > $ python -c 'import modules.Fabexec; print (modules.Fabexec)' > > > Fabfiles > > |-- modules > | |-- Fabexec.py > | |-- Fabexec.pyc > | |-- __init__.py > | `-- __init__.pyc > |-- systune.py > |-- systune.pyc > `-- set_nic_buffers.py > > --- set_nic_buffers.py --- > import modules > from modules import Fabexec > def set_nic_buffers(): > f_exec = modules.Fabexec('set_nic_buffers', > '/var/tmp/unix-tools/tools/set_nic_buffers.sh') > f_exec.run() > 'modules.Fabexec' is the module/script 'Fabexec'. What you want is the 'Fabexec' class within the 'Fabexec' module. > --- Fabexec.py --- > from fabric.api import run, cd, sudo, env > from fabric.contrib import files > from fabric.colors import green > > class Fabexec(object): > > repobase='/var/tmp/unix-tools' > > def __init__(self,script_name,install_script): > self.script_name = script_name > self.install_script = install_script > > def run(self): > if files.exists(self.install_script): > with cd(self.repobase): > result = sudo(self.install_script + ' %s ' % env.host) > if result.return_code != 0: > print(red('Error occured executing %s' % > self.install_script)) > else: > print(green('%s executed successfully')) > else: > print(red('Error no such dir %s try running repo deploy > script to host %s' % (self.repobase, env.host))) > raise SystemExit() > > From webmaster at terradon.nl Mon Apr 22 12:16:01 2013 From: webmaster at terradon.nl (webmaster at terradon.nl) Date: Mon, 22 Apr 2013 09:16:01 -0700 (PDT) Subject: How to connect to a website? Message-ID: <566767a8-35cc-47f2-9f75-032ce5629b44@googlegroups.com> Hi, i just try to connect to a website, read that page and display the rules get from it. Then i get this error message: File "D:/Python/Py projects/socket test/sockettest.py", line 21, in fileobj.write("GET "+filename+" HTTP/1.0\n\n") io.UnsupportedOperation: not writable My code: # import sys for handling command line argument # import socket for network communications import sys, socket # hard-wire the port number for safety's sake # then take the names of the host and file from the command line port = 80 host = 'www.xxxxxxxx.nl' filename = 'index.php' # create a socket object called 'c' c = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # connect to the socket c.connect((host, port)) # create a file-like object to read fileobj = c.makefile('r', 1024) # Ask the server for the file fileobj.write("GET "+filename+" HTTP/1.0\n\n") # read the lines of the file object into a buffer, buff buff = fileobj.readlines() # step through the buffer, printing each line for line in buff: print (line) I started with invent games with python (book 1 & 2) Now I want to write a multiplayergame, which connects to a website, where all players and gamedata will be stored/controlled. Players need to subscribe and to login via the game software. (executable, made from python script) Sending gamedata preferable in JSON, because of low traffic resources then. No idea about how authentication proces should be done.... I made many searches with Google, but got confused about my first steps. I am new to python, but code for many years in php/mysql. Spent most time in an online chessgame project. From gordon at panix.com Mon Apr 22 12:38:47 2013 From: gordon at panix.com (John Gordon) Date: Mon, 22 Apr 2013 16:38:47 +0000 (UTC) Subject: How to connect to a website? References: <566767a8-35cc-47f2-9f75-032ce5629b44@googlegroups.com> Message-ID: In <566767a8-35cc-47f2-9f75-032ce5629b44 at googlegroups.com> webmaster at terradon.nl writes: > Hi, > i just try to connect to a website, read that page and display the rules get from it. > Then i get this error message: > File "D:/Python/Py projects/socket test/sockettest.py", line 21, in > fileobj.write("GET "+filename+" HTTP/1.0\n\n") > io.UnsupportedOperation: not writable I haven't worked with the socket library, but I think this error is because you specified a mode of 'r' when calling makefile(). fileobj is read-only, and you're trying to write to it. If you just want to connect to a website, try using the urllib2 module instead of socket. It's higher-level and handles a lot of details for you. Here's an example: import urllib2 request = urllib2.Request('http://www.voidspace.org.uk') response = urllib2.urlopen(request) content = response.readlines() -- 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 webmaster at terradon.nl Mon Apr 22 15:56:24 2013 From: webmaster at terradon.nl (webmaster at terradon.nl) Date: Mon, 22 Apr 2013 12:56:24 -0700 (PDT) Subject: How to connect to a website? In-Reply-To: References: <566767a8-35cc-47f2-9f75-032ce5629b44@googlegroups.com> Message-ID: <49b55b70-0283-484c-b517-5b1c5b1a2678@googlegroups.com> thanks! solved with: import urllib.request import urllib.parse user = 'user' pw = 'password' login_url = 'http://www.riskopoly.nl/test/index.php' data = urllib.parse.urlencode({'user': user, 'pw': pw}) data = data.encode('utf-8') # adding charset parameter to the Content-Type header. request = urllib.request.Request(login_url) request.add_header("Content-Type","application/x-www-form-urlencoded;charset=utf-8") f = urllib.request.urlopen(request, data) print(f.read().decode('utf-8')) And then i get next answer:
Array
(
    [pw] => password
    [user] => user
)
Solved and thanks again:) From python at mrabarnett.plus.com Mon Apr 22 12:40:19 2013 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 22 Apr 2013 17:40:19 +0100 Subject: How to connect to a website? In-Reply-To: <566767a8-35cc-47f2-9f75-032ce5629b44@googlegroups.com> References: <566767a8-35cc-47f2-9f75-032ce5629b44@googlegroups.com> Message-ID: <517567F3.2010506@mrabarnett.plus.com> On 22/04/2013 17:16, webmaster at terradon.nl wrote: > Hi, > i just try to connect to a website, read that page and display the rules get from it. > Then i get this error message: > > File "D:/Python/Py projects/socket test/sockettest.py", line 21, in > fileobj.write("GET "+filename+" HTTP/1.0\n\n") > io.UnsupportedOperation: not writable > > My code: > > # import sys for handling command line argument > # import socket for network communications > import sys, socket > > # hard-wire the port number for safety's sake > # then take the names of the host and file from the command line > port = 80 > host = 'www.xxxxxxxx.nl' > filename = 'index.php' > > # create a socket object called 'c' > c = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > > # connect to the socket > c.connect((host, port)) > > # create a file-like object to read > fileobj = c.makefile('r', 1024) You're creating a file-like object for reading... > > # Ask the server for the file > fileobj.write("GET "+filename+" HTTP/1.0\n\n") > ...and then trying to write to it. > # read the lines of the file object into a buffer, buff > buff = fileobj.readlines() > > # step through the buffer, printing each line > for line in buff: > print (line) > [snip] From alika.resumes at gmail.com Mon Apr 22 13:11:28 2013 From: alika.resumes at gmail.com (alika.resumes at gmail.com) Date: Mon, 22 Apr 2013 10:11:28 -0700 (PDT) Subject: Python Developer Needed in Ottawa Message-ID: Python Programmer need in Ottawa, Ontario Canada. Must be eligible to work in Canada and preferably already in Ottawa with a security clearance in place. Phone Al at (613) 425-1634 From anadionisio257 at gmail.com Mon Apr 22 14:13:38 2013 From: anadionisio257 at gmail.com (=?ISO-8859-1?Q?Ana_Dion=EDsio?=) Date: Mon, 22 Apr 2013 11:13:38 -0700 (PDT) Subject: Lists and arrays Message-ID: Hello! I need your help! I have an array and I need pick some data from that array and put it in a list, for example: array= [a,b,c,1,2,3] list=array[0]+ array[3]+ array[4] list: [a,1,2] When I do it like this: list=array[0]+ array[3]+ array[4] I get an error: "TypeError: unsupported operand type(s) for +: 'numpy.ndarray' and 'numpy.ndarray'" Can you help me? From davea at davea.name Mon Apr 22 14:34:42 2013 From: davea at davea.name (Dave Angel) Date: Mon, 22 Apr 2013 14:34:42 -0400 Subject: Lists and arrays In-Reply-To: References: Message-ID: <517582C2.7040202@davea.name> On 04/22/2013 02:13 PM, Ana Dion?sio wrote: > Hello! > > I need your help! > > I have an array I think you mean you have a numpy array, which is very different than a python array.array > and I need pick some data from that array and put it in a list, for example: > > array= [a,b,c,1,2,3] That's a list. > > list=array[0]+ array[3]+ array[4] Nothing wrong with that, other than that you just hid the name of the list type, making it tricky to later convert things to lists. > > list: [a,1,2] You'll never get that. When you assign an object to a list, the object itself is referenced in that list, not the name that it happened to have before. So if a was an object of type float and value 41.5, then you presumably want: mylist: [41.5, 1, 2] > > When I do it like this: list=array[0]+ array[3]+ array[4] I get an error: > > "TypeError: unsupported operand type(s) for +: 'numpy.ndarray' and 'numpy.ndarray'" > Apparently you did not use the line array= [a,b,c,1,2,3] as you said above, but some other assignment, perhaps using a numpy method or six. Worse, apparently the elements of that collection aren't simple numbers but some kind of numpy thingies as well. If you show what you actually did, probably someone here can help, though the more numpy you use, the less likely that it'll be me. If you really had a list, you wouldn't have gotten an error, but neither would you have gotten anything like you're asking. array[3] + array[4] == 1+2 == 3. If you're trying to make a list using + from a subscripted list, you'd have to enclose each integer in square brackets. mylist = [array[0]] + [array[3]] + [array[4]] Alternatively, you could just do mylist = [ array[0], array[3], array[4] ] -- DaveA From bc at freeuk.com Mon Apr 22 17:24:48 2013 From: bc at freeuk.com (BartC) Date: Mon, 22 Apr 2013 22:24:48 +0100 Subject: Lists and arrays In-Reply-To: References: Message-ID: "Ana Dion?sio" wrote in message news:de1cc79e-cbf7-4b0b-ae8e-18841a1ef095 at googlegroups.com... > Hello! > > I need your help! > > I have an array and I need pick some data from that array and put it in a > list, for example: > > array= [a,b,c,1,2,3] > > list=array[0]+ array[3]+ array[4] > > list: [a,1,2] > > When I do it like this: list=array[0]+ array[3]+ array[4] I get an error: > > "TypeError: unsupported operand type(s) for +: 'numpy.ndarray' and > 'numpy.ndarray'" You're calculating a+1+2. Probably a isn't something that can be added to 1+2. -- Bartc From dihedral88888 at googlemail.com Tue Apr 23 03:50:49 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Tue, 23 Apr 2013 00:50:49 -0700 (PDT) Subject: Lists and arrays In-Reply-To: References: Message-ID: <155ef657-aaff-4b31-aa55-ba76cdd179d7@googlegroups.com> Ana Dion?sio? 2013?4?23????UTC+8??2?13?38???? > Hello! > > > > I need your help! > > > > I have an array and I need pick some data from that array and put it in a list, for example: > > > > array= [a,b,c,1,2,3] > > > > list=array[0]+ array[3]+ array[4] > > > > list: [a,1,2] > > > > When I do it like this: list=array[0]+ array[3]+ array[4] I get an error: > > > > "TypeError: unsupported operand type(s) for +: 'numpy.ndarray' and 'numpy.ndarray'" > > > > Can you help me? The list part in Python is more versatile but definitely executed slower than the array in C. What I like is that maintaining the Python part is not as tedious and painful for the same programs in LISP. From denismfmcmahon at gmail.com Tue Apr 23 15:30:02 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Tue, 23 Apr 2013 19:30:02 +0000 (UTC) Subject: Lists and arrays References: Message-ID: On Mon, 22 Apr 2013 11:13:38 -0700, Ana Dion?sio wrote: > I have an array and I need pick some data from that array and put it in > a list, for example: > > array= [a,b,c,1,2,3] > > list=array[0]+ array[3]+ array[4] > > list: [a,1,2] > > When I do it like this: list=array[0]+ array[3]+ array[4] I get an > error: > > "TypeError: unsupported operand type(s) for +: 'numpy.ndarray' and > 'numpy.ndarray'" > > Can you help me? arr1 = [ 'a', 'b', 'c', 1, 2, 3 ] # populate a new list with individual members arr2 = [ arr1[0], arr1[3], arr1[5] ] # create a new list by adding slices together arr3 = arr1[:1] + arr1[2:4] + arr1[5:] print arr2 # output is: ['a', 1, 3] print arr3 # output is: ['a', 'c', 1, 3] -- Denis McMahon, denismfmcmahon at gmail.com From webmaster at terradon.nl Mon Apr 22 16:09:38 2013 From: webmaster at terradon.nl (webmaster at terradon.nl) Date: Mon, 22 Apr 2013 13:09:38 -0700 (PDT) Subject: How to get JSON values and how to trace sessions?? Message-ID: Hi all, from python I post data to a webpage using urllib and can print that content. See code below. But now i am wondering how to trace sessions? it is needed for a multiplayer game, connected to a webserver. How do i trace a PHP-session? I suppose i have to save a cookie with the sessionID from the webserver? Is this possible with Python? Are their other ways to keep control over which players sends the gamedata? Secondly, can i handle JSON values? I know how to create them serverside, but how do i handle that response in python? Thank you very much for any answer! Code: import urllib.request import urllib.parse user = 'user' pw = 'password' login_url = 'http://www.xxxxxxxx.nl/test/index.php' data = urllib.parse.urlencode({'user': user, 'pw': pw}) data = data.encode('utf-8') # adding charset parameter to the Content-Type header. request = urllib.request.Request(login_url) request.add_header("Content-Type","application/x-www-form-urlencoded;charset=utf-8") f = urllib.request.urlopen(request, data) print(f.read().decode('utf-8')) From rosuav at gmail.com Mon Apr 22 16:47:34 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Apr 2013 06:47:34 +1000 Subject: How to get JSON values and how to trace sessions?? In-Reply-To: References: Message-ID: On Tue, Apr 23, 2013 at 6:09 AM, wrote: > But now i am wondering how to trace sessions? it is needed for a multiplayer game, connected to a webserver. How do i trace a PHP-session? I suppose i have to save a cookie with the sessionID from the webserver? Is this possible with Python? Are their other ways to keep control over which players sends the gamedata? > > Secondly, can i handle JSON values? I know how to create them serverside, but how do i handle that response in python? Python has a JSON module that should do what you want: http://docs.python.org/3.3/library/json.html I don't know the details of cookie handling in Python, but this looks to be what you want: http://docs.python.org/3.3/library/http.cookiejar.html#http.cookiejar.CookieJar Tip: The Python docs can be searched very efficiently with a web search (eg Google, Bing, DuckDuckGo, etc). Just type "python" and whatever it is you want - chances are you'll get straight there. ChrisA From timr at probo.com Wed Apr 24 02:25:57 2013 From: timr at probo.com (Tim Roberts) Date: Tue, 23 Apr 2013 23:25:57 -0700 Subject: How to get JSON values and how to trace sessions?? References: Message-ID: webmaster at terradon.nl wrote: > >But now i am wondering how to trace sessions? it is needed for a >multiplayer game, connected to a webserver. How do i trace a PHP-session? >I suppose i have to save a cookie with the sessionID from the webserver? Yes. The server will send a Set-Cookie: header with your first response. You just need to return that in a Cookie: header with every request you make after that. >Are their other ways to keep control over which players sends the gamedata? Not sure what you mean. If the web site requires cookies, this is what you have to do. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From roozbeh73 at gmail.com Thu Apr 25 10:12:37 2013 From: roozbeh73 at gmail.com (Roozbeh) Date: Thu, 25 Apr 2013 07:12:37 -0700 (PDT) Subject: How to get JSON values and how to trace sessions?? In-Reply-To: References: Message-ID: You need to handle the cookie that comes with the server response. Example code: import urllib2 opener = urllib2.build_opener() opener.addheaders.append(('Cookie', 'cookiename=cookievalue')) f = opener.open("http://example.com/") From rodrick.brown at gmail.com Mon Apr 22 21:19:23 2013 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Mon, 22 Apr 2013 21:19:23 -0400 Subject: optomizations Message-ID: I would like some feedback on possible solutions to make this script run faster. The system is pegged at 100% CPU and it takes a long time to complete. #!/usr/bin/env python import gzip import re import os import sys from datetime import datetime import argparse if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-f', dest='inputfile', type=str, help='data file to parse') parser.add_argument('-o', dest='outputdir', type=str, default=os.getcwd(), help='Output directory') args = parser.parse_args() if len(sys.argv[1:]) < 1: parser.print_usage() sys.exit(-1) print(args) if args.inputfile and os.path.exists(args.inputfile): try: with gzip.open(args.inputfile) as datafile: for line in datafile: line = line.replace('mediacdn.xxx.com', 'media.xxx.com') line = line.replace('staticcdn.xxx.co.uk', ' static.xxx.co.uk') line = line.replace('cdn.xxx', 'www.xxx') line = line.replace('cdn.xxx', 'www.xxx') line = line.replace('cdn.xx', 'www.xx') siteurl = line.split()[6].split('/')[2] line = re.sub(r'\bhttps?://%s\b' % siteurl, "", line, 1) (day, month, year, hour, minute, second) = (line.split()[3]).replace('[','').replace(':','/').split('/') datelog = '{} {} {}'.format(month, day, year) dateobj = datetime.strptime(datelog, '%b %d %Y') outfile = '{}{}{}_combined.log'.format(dateobj.year, dateobj.month, dateobj.day) outdir = (args.outputdir + os.sep + siteurl) if not os.path.exists(outdir): os.makedirs(outdir) with open(outdir + os.sep + outfile, 'w+') as outf: outf.write(line) except IOError, err: sys.stderr.write("Error unable to read or extract inputfile: {} {}\n".format(args.inputfile, err)) sys.exit(-1) -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Apr 22 21:38:17 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Apr 2013 11:38:17 +1000 Subject: optomizations In-Reply-To: References: Message-ID: On Tue, Apr 23, 2013 at 11:19 AM, Rodrick Brown wrote: > with gzip.open(args.inputfile) as datafile: > for line in datafile: > outfile = '{}{}{}_combined.log'.format(dateobj.year, > dateobj.month, dateobj.day) > outdir = (args.outputdir + os.sep + siteurl) > > with open(outdir + os.sep + outfile, 'w+') as outf: > outf.write(line) You're opening files and closing them again for every line. This wouldn't cause you to spin the CPU (more likely it'd thrash the hard disk - unless you have an SSD), but it is certainly an optimization target. Can you know in advance what files you need? If not, I'd try something like this: outf = {} # Might want a better name though ..... outfile = ... if outfile not in outf: os.makedirs(...) outf[outfile] = open(...) outf[outfile].write(line) for f in outf.values(): f.close() Open files only as needed, close 'em all at the end. ChrisA From roy at panix.com Mon Apr 22 21:53:11 2013 From: roy at panix.com (Roy Smith) Date: Mon, 22 Apr 2013 21:53:11 -0400 Subject: optomizations References: Message-ID: In article , Rodrick Brown wrote: > I would like some feedback on possible solutions to make this script run > faster. If I had to guess, I would think this stuff: > line = line.replace('mediacdn.xxx.com', 'media.xxx.com') > line = line.replace('staticcdn.xxx.co.uk', ' > static.xxx.co.uk') > line = line.replace('cdn.xxx', 'www.xxx') > line = line.replace('cdn.xxx', 'www.xxx') > line = line.replace('cdn.xx', 'www.xx') > siteurl = line.split()[6].split('/')[2] > line = re.sub(r'\bhttps?://%s\b' % siteurl, "", line, 1) You make 6 copies of every line. That's slow. But I'm also going to quote something I wrote here a couple of months back: > I've been doing some log analysis. It's been taking a grovelingly long > time, so I decided to fire up the profiler and see what's taking so > long. I had a pretty good idea of where the ONLY TWO POSSIBLE hotspots > might be (looking up IP addresses in the geolocation database, or > producing some pretty pictures using matplotlib). It was just a matter > of figuring out which it was. > > As with most attempts to out-guess the profiler, I was totally, > absolutely, and embarrassingly wrong. So, my real advice to you is to fire up the profiler and see what it says. From rosuav at gmail.com Mon Apr 22 22:03:35 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Apr 2013 12:03:35 +1000 Subject: optomizations In-Reply-To: References: Message-ID: On Tue, Apr 23, 2013 at 11:53 AM, Roy Smith wrote: > In article , > Rodrick Brown wrote: > >> I would like some feedback on possible solutions to make this script run >> faster. > > If I had to guess, I would think this stuff: > >> line = line.replace('mediacdn.xxx.com', 'media.xxx.com') >> line = line.replace('staticcdn.xxx.co.uk', ' >> static.xxx.co.uk') >> line = line.replace('cdn.xxx', 'www.xxx') >> line = line.replace('cdn.xxx', 'www.xxx') >> line = line.replace('cdn.xx', 'www.xx') >> siteurl = line.split()[6].split('/')[2] >> line = re.sub(r'\bhttps?://%s\b' % siteurl, "", line, 1) > > You make 6 copies of every line. That's slow. One of those is a regular expression substitution, which is also likely to be a hot-spot. But definitely profile. ChrisA From drsalists at gmail.com Mon Apr 22 23:15:46 2013 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 22 Apr 2013 20:15:46 -0700 Subject: optomizations In-Reply-To: References: Message-ID: On Mon, Apr 22, 2013 at 6:53 PM, Roy Smith wrote: > > So, my real advice to you is to fire up the profiler and see what it > says. I agree. Fire up a line-oriented profiler and only then start trying to improve the hot spots. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rodrick.brown at gmail.com Tue Apr 23 00:20:59 2013 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Tue, 23 Apr 2013 00:20:59 -0400 Subject: optomizations In-Reply-To: References: Message-ID: <-8482653543988991153@unknownmsgid> On Apr 22, 2013, at 11:18 PM, Dan Stromberg wrote: On Mon, Apr 22, 2013 at 6:53 PM, Roy Smith wrote: > > So, my real advice to you is to fire up the profiler and see what it > says. I agree. Fire up a line-oriented profiler and only then start trying to improve the hot spots. Got a doc or URL I have no experience working with python profilers. -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Tue Apr 23 00:38:28 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Apr 2013 04:38:28 GMT Subject: optomizations References: Message-ID: <51761044$0$29872$c3e8da3$5496439d@news.astraweb.com> On Tue, 23 Apr 2013 00:20:59 -0400, Rodrick Brown wrote: > Got a doc or URL I have no experience working with python profilers. https://duckduckgo.com/html/?q=python%20profiler This is also good: http://pymotw.com/2/profile/ -- Steven From steve+comp.lang.python at pearwood.info Tue Apr 23 00:00:21 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Apr 2013 04:00:21 GMT Subject: optomizations References: Message-ID: <51760754$0$29872$c3e8da3$5496439d@news.astraweb.com> On Mon, 22 Apr 2013 21:19:23 -0400, Rodrick Brown wrote: > I would like some feedback on possible solutions to make this script run > faster. > The system is pegged at 100% CPU and it takes a long time to complete. Have you profiled the app to see where it is spending all its time? What does "a long time" mean? For instance: "It takes two hours to process a 15KB file" -- you have a problem. "It takes 20 minutes to process a 15GB file" -- and why are you complaining? Or somewhere in the middle... But before profiling, I suggest you clean up the program. For example: if args.inputfile and os.path.exists(args.inputfile): Don't do that. There really isn't any point in checking whether the input file exists, since: 1) Just because it exists doesn't mean you can read it; 2) Just because you can read it doesn't mean it is a valid gzip file; 3) Just because it is a valid gzip file that you can read *now*, doesn't mean that it still will be in 10 milliseconds when you actually try to open the file. A lot can happen in 10ms, or 1ms. The file might be deleted, or overwritten, or permissions changed. Change that to: try: with gzip.open(args.inputfile) as datafile: for line in datafile: and catch the exception if the file doesn't exist, or cannot be read. Which you already do, which just demonstrates that the call to os.path.exists is a waste of effort. Then look for wasted effort like this: line = line.replace('cdn.xxx', 'www.xxx') line = line.replace('cdn.xx', 'www.xx') Surely the first line is redundant, since it would be correctly caught and replaced by the second? Also, you're searching the file system *for every line* in the input file. Pull this outside of the loop and have it run once: if not os.path.exists(outdir): os.makedirs(outdir) Likewise for opening and closing the output file, which you currently open and close it for every line. It only needs to be opened and closed once. If it comes down to micro-optimizations to shave a few microseconds off, consider using string % formatting rather than the format method. But really, if you find yourself shaving microseconds off something that runs for ten minutes, you have to ask why you're bothering. -- Steven From rosuav at gmail.com Tue Apr 23 00:08:33 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Apr 2013 14:08:33 +1000 Subject: optomizations In-Reply-To: <51760754$0$29872$c3e8da3$5496439d@news.astraweb.com> References: <51760754$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Apr 23, 2013 at 2:00 PM, Steven D'Aprano wrote: > Also, you're searching the file system *for every line* in the input > file. Pull this outside of the loop and have it run once: > > if not os.path.exists(outdir): > os.makedirs(outdir) > > Likewise for opening and closing the output file, which you currently > open and close it for every line. It only needs to be opened and closed > once. The outdir depends on the line, though. Hence my suggestion to retain the open files in a dictionary. ChrisA From ulrich.eckhardt at dominolaser.com Tue Apr 23 03:46:53 2013 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 23 Apr 2013 09:46:53 +0200 Subject: percent faster than format()? (was: Re: optomizations) In-Reply-To: <51760754$0$29872$c3e8da3$5496439d@news.astraweb.com> References: <51760754$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 23.04.2013 06:00, schrieb Steven D'Aprano: > If it comes down to micro-optimizations to shave a few microseconds off, > consider using string % formatting rather than the format method. Why? I don't see any obvious difference between the two... Greetings! Uli From kwpolska at gmail.com Tue Apr 23 04:26:38 2013 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Tue, 23 Apr 2013 10:26:38 +0200 Subject: percent faster than format()? (was: Re: optomizations) In-Reply-To: References: <51760754$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Apr 23, 2013 at 9:46 AM, Ulrich Eckhardt wrote: > Am 23.04.2013 06:00, schrieb Steven D'Aprano: >> >> If it comes down to micro-optimizations to shave a few microseconds off, >> consider using string % formatting rather than the format method. > > > Why? I don't see any obvious difference between the two... > > > Greetings! > > Uli > > -- > http://mail.python.org/mailman/listinfo/python-list $ python -m timeit "a = '{0} {1} {2}'.format(1, 2, 42)" 1000000 loops, best of 3: 0.824 usec per loop $ python -m timeit "a = '%s %s %s' % (1, 2, 42)" 10000000 loops, best of 3: 0.0286 usec per loop -- Kwpolska | GPG KEY: 5EAAEA16 stop html mail | always bottom-post http://asciiribbon.org | http://caliburn.nl/topposting.html From steve+comp.lang.python at pearwood.info Tue Apr 23 10:36:36 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Apr 2013 14:36:36 GMT Subject: percent faster than format()? (was: Re: optomizations) References: <51760754$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51769c74$0$29977$c3e8da3$5496439d@news.astraweb.com> On Tue, 23 Apr 2013 09:46:53 +0200, Ulrich Eckhardt wrote: > Am 23.04.2013 06:00, schrieb Steven D'Aprano: >> If it comes down to micro-optimizations to shave a few microseconds >> off, consider using string % formatting rather than the format method. > > Why? I don't see any obvious difference between the two... Possibly the state of the art has changed since then, but some years ago % formatting was slightly faster than the format method. Let's try it and see: # Using Python 3.3. py> from timeit import Timer py> setup = "a = 'spam'; b = 'ham'; c = 'eggs'" py> t1 = Timer("'%s, %s and %s for breakfast' % (a, b, c)", setup) py> t2 = Timer("'{}, {} and {} for breakfast'.format(a, b, c)", setup) py> print(min(t1.repeat())) 0.8319804421626031 py> print(min(t2.repeat())) 1.2395259491167963 Looks like the format method is about 50% slower. -- Steven From rosuav at gmail.com Tue Apr 23 10:52:58 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 24 Apr 2013 00:52:58 +1000 Subject: percent faster than format()? (was: Re: optomizations) In-Reply-To: <51769c74$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <51760754$0$29872$c3e8da3$5496439d@news.astraweb.com> <51769c74$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Apr 24, 2013 at 12:36 AM, Steven D'Aprano wrote: > # Using Python 3.3. > > py> from timeit import Timer > py> setup = "a = 'spam'; b = 'ham'; c = 'eggs'" > py> t1 = Timer("'%s, %s and %s for breakfast' % (a, b, c)", setup) > py> t2 = Timer("'{}, {} and {} for breakfast'.format(a, b, c)", setup) > py> print(min(t1.repeat())) > 0.8319804421626031 > py> print(min(t2.repeat())) > 1.2395259491167963 > > > Looks like the format method is about 50% slower. Figures on my hardware are (naturally) different, with a similar (but slightly more pronounced) difference: >>> sys.version '3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)]' >>> print(min(t1.repeat())) 1.4841416995735415 >>> print(min(t2.repeat())) 2.5459869899666074 >>> t3 = Timer("a+', '+b+' and '+c+' for breakfast'", setup) >>> print(min(t3.repeat())) 1.5707538248576327 >>> t4 = Timer("''.join([a, ', ', b, ' and ', c, ' for breakfast'])", setup) >>> print(min(t4.repeat())) 1.5026834416105999 So on the face of it, format() is slower than everything else by a good margin... until you note that repeat() is doing one million iterations, so those figures are effectively in microseconds. Yeah, I think I can handle a couple of microseconds. ChrisA From ulrich.eckhardt at dominolaser.com Tue Apr 23 10:57:58 2013 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 23 Apr 2013 16:57:58 +0200 Subject: percent faster than format()? In-Reply-To: References: <51760754$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 23.04.2013 10:26, schrieb Chris ?Kwpolska? Warrick: > On Tue, Apr 23, 2013 at 9:46 AM, Ulrich Eckhardt > wrote: >> Am 23.04.2013 06:00, schrieb Steven D'Aprano: >>> >>> If it comes down to micro-optimizations to shave a few microseconds off, >>> consider using string % formatting rather than the format method. >> >> >> Why? I don't see any obvious difference between the two... [...] > > $ python -m timeit "a = '{0} {1} {2}'.format(1, 2, 42)" > 1000000 loops, best of 3: 0.824 usec per loop > $ python -m timeit "a = '%s %s %s' % (1, 2, 42)" > 10000000 loops, best of 3: 0.0286 usec per loop > Well, I don't question that for at least some CPython implementations one is faster than the other. I don't see a reason why one must be faster than the other though. In other words, I don't understand where the other one needs more time to achieve basically the same. To me, the only difference is the syntax, but not greatly so. So again, why is one faster than the other? What am I missing? Uli From lele at metapensiero.it Tue Apr 23 11:44:15 2013 From: lele at metapensiero.it (Lele Gaifax) Date: Tue, 23 Apr 2013 17:44:15 +0200 Subject: percent faster than format()? References: <51760754$0$29872$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87d2tl8d68.fsf@nautilus.nautilus> Ulrich Eckhardt writes: > So again, why is one faster than the other? What am I missing? The .format() syntax is actually a function, and that alone carries some overload. Even optimizing the lookup may give a little advantage: >>> from timeit import Timer >>> setup = "a = 'spam'; b = 'ham'; c = 'eggs'" >>> t1 = Timer("'%s, %s and %s for breakfast' % (a, b, c)", setup) >>> t2 = Timer("'{}, {} and {} for breakfast'.format(a, b, c)", setup) >>> print(min(t1.repeat())) >>> print(min(t2.repeat())) >>> setup = "a = 'spam'; b = 'ham'; c = 'eggs'; f = '{}, {} and {} for breakfast'.format" >>> t3 = Timer("f(a, b, c)", setup) >>> print(min(t3.repeat())) 0.3076407820044551 0.44008257299719844 0.418146252995939 But building the call frame still takes its bit of time. 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 python at mrabarnett.plus.com Mon Apr 22 22:03:25 2013 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 23 Apr 2013 03:03:25 +0100 Subject: optomizations In-Reply-To: References: Message-ID: <5175EBED.1030707@mrabarnett.plus.com> On 23/04/2013 02:19, Rodrick Brown wrote: > I would like some feedback on possible solutions to make this script run > faster. > The system is pegged at 100% CPU and it takes a long time to complete. > > > #!/usr/bin/env python > > import gzip > import re > import os > import sys > from datetime import datetime > import argparse > > if __name__ == '__main__': > parser = argparse.ArgumentParser() > parser.add_argument('-f', dest='inputfile', type=str, help='data file to parse') > parser.add_argument('-o', dest='outputdir', type=str, default=os.getcwd(), help='Output directory') > args = parser.parse_args() > > if len(sys.argv[1:]) < 1: > parser.print_usage() > sys.exit(-1) > > print(args) > if args.inputfile and os.path.exists(args.inputfile): > try: > with gzip.open(args.inputfile) as datafile: > for line in datafile: > line = line.replace('mediacdn.xxx.com', 'media.xxx.com') > line = line.replace('staticcdn.xxx.co.uk', 'static.xxx.co.uk') These next 2 lines are duplicates; the second will have no effect (I think!). > line = line.replace('cdn.xxx', 'www.xxx') > line = line.replace('cdn.xxx', 'www.xxx') Won't the next line also do the work of the preceding 2 lines? > line = line.replace('cdn.xx', 'www.xx') > siteurl = line.split()[6].split('/')[2] > line = re.sub(r'\bhttps?://%s\b' % siteurl, "", line, 1) > > (day, month, year, hour, minute, second) = (line.split()[3]).replace('[','').replace(':','/').split('/') > datelog = '{} {} {}'.format(month, day, year) > dateobj = datetime.strptime(datelog, '%b %d %Y') > > outfile = '{}{}{}_combined.log'.format(dateobj.year, dateobj.month, dateobj.day) > outdir = (args.outputdir + os.sep + siteurl) > > if not os.path.exists(outdir): > os.makedirs(outdir) > > with open(outdir + os.sep + outfile, 'w+') as outf: > outf.write(line) > > except IOError, err: > sys.stderr.write("Error unable to read or extract inputfile: {} {}\n".format(args.inputfile, err)) > sys.exit(-1) > I wonder whether it'll make a difference if you read a chunk at a time (datafile.read(chunk_size) + datafile.readline() to ensure you have complete lines), perform the replacements on it (so that you're working on several lines in one go), and then split it into lines for further processing. Another thing you could try caching the result of parsing the date, using (month, day, year) the key and outfile as the value in a dict. A third thing you could try is not writing a file for every line (doesn't the 'w+' mode truncate the file?), but save the output for each chunk (see first suggestion) and then write the files afterwards, at the end of the chunk. From insideshoes at gmail.com Tue Apr 23 02:40:39 2013 From: insideshoes at gmail.com (inshu chauhan) Date: Tue, 23 Apr 2013 12:10:39 +0530 Subject: Running simultaneuos "FOR" loops Message-ID: i have to implement the below line in one of my code: for p in sorted(segments.iterkeys()) and for k in sorted(class_count.iterkeys()) and for j in sorted(pixel_count.iterkeys()): Its giving me a syntax error which is obvious, but how can I make all three for loop run simultaneously or any other way to do this simultaneous work ??? -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Apr 23 02:46:35 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Apr 2013 16:46:35 +1000 Subject: Running simultaneuos "FOR" loops In-Reply-To: References: Message-ID: On Tue, Apr 23, 2013 at 4:40 PM, inshu chauhan wrote: > i have to implement the below line in one of my code: > > for p in sorted(segments.iterkeys()) and for k in > sorted(class_count.iterkeys()) and for j in sorted(pixel_count.iterkeys()): > > Its giving me a syntax error which is obvious, but how can I make all three > for loop run simultaneously or any other way to do this simultaneous work > ??? Define simultaneously. Do the three dictionaries have the same number of keys? If so, look up zip() or itertools.izip; if not, you may have to more clearly define "simultaneous". ChrisA From insideshoes at gmail.com Tue Apr 23 02:58:38 2013 From: insideshoes at gmail.com (inshu chauhan) Date: Tue, 23 Apr 2013 12:28:38 +0530 Subject: Running simultaneuos "FOR" loops In-Reply-To: References: Message-ID: Yes Simultaneously means all three running at the same time, I looked up zip just now, but will it not disturb my dictionaries ? And yes the dictionaries have same number of keys. thanks On Tue, Apr 23, 2013 at 12:16 PM, Chris Angelico wrote: > On Tue, Apr 23, 2013 at 4:40 PM, inshu chauhan > wrote: > > i have to implement the below line in one of my code: > > > > for p in sorted(segments.iterkeys()) and for k in > > sorted(class_count.iterkeys()) and for j in > sorted(pixel_count.iterkeys()): > > > > Its giving me a syntax error which is obvious, but how can I make all > three > > for loop run simultaneously or any other way to do this simultaneous work > > ??? > > Define simultaneously. Do the three dictionaries have the same number > of keys? If so, look up zip() or itertools.izip; if not, you may have > to more clearly define "simultaneous". > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From insideshoes at gmail.com Tue Apr 23 03:03:56 2013 From: insideshoes at gmail.com (inshu chauhan) Date: Tue, 23 Apr 2013 12:33:56 +0530 Subject: Running simultaneuos "FOR" loops In-Reply-To: References: Message-ID: zip isn't doing the required On Tue, Apr 23, 2013 at 12:28 PM, inshu chauhan wrote: > Yes Simultaneously means all three running at the same time, I looked up > zip just now, but will it not disturb my dictionaries ? > And yes the dictionaries have same number of keys. > > thanks > > > On Tue, Apr 23, 2013 at 12:16 PM, Chris Angelico wrote: > >> On Tue, Apr 23, 2013 at 4:40 PM, inshu chauhan >> wrote: >> > i have to implement the below line in one of my code: >> > >> > for p in sorted(segments.iterkeys()) and for k in >> > sorted(class_count.iterkeys()) and for j in >> sorted(pixel_count.iterkeys()): >> > >> > Its giving me a syntax error which is obvious, but how can I make all >> three >> > for loop run simultaneously or any other way to do this simultaneous >> work >> > ??? >> >> Define simultaneously. Do the three dictionaries have the same number >> of keys? If so, look up zip() or itertools.izip; if not, you may have >> to more clearly define "simultaneous". >> >> ChrisA >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From insideshoes at gmail.com Tue Apr 23 03:13:07 2013 From: insideshoes at gmail.com (inshu chauhan) Date: Tue, 23 Apr 2013 12:43:07 +0530 Subject: Running simultaneuos "FOR" loops In-Reply-To: References: Message-ID: This statement is giving me the following error Statement: for p, k, j in zip(sorted(segments.iterkeys(), class_count.iterkeys(), pixel_count.iterkeys())): Error: Traceback (most recent call last): File "C:\Users\inshu\Desktop\Training_segs_trial2.py", line 170, in access_segments(segimage, data) File "C:\Users\inshu\Desktop\Training_segs_trial2.py", line 147, in access_segments for p, k, j in zip(sorted(segments.iterkeys(), class_count.iterkeys(), pixel_count.iterkeys())): TypeError: 'dictionary-keyiterator' object is not callable On Tue, Apr 23, 2013 at 12:33 PM, inshu chauhan wrote: > zip isn't doing the required > > > On Tue, Apr 23, 2013 at 12:28 PM, inshu chauhan wrote: > >> Yes Simultaneously means all three running at the same time, I looked up >> zip just now, but will it not disturb my dictionaries ? >> And yes the dictionaries have same number of keys. >> >> thanks >> >> >> On Tue, Apr 23, 2013 at 12:16 PM, Chris Angelico wrote: >> >>> On Tue, Apr 23, 2013 at 4:40 PM, inshu chauhan >>> wrote: >>> > i have to implement the below line in one of my code: >>> > >>> > for p in sorted(segments.iterkeys()) and for k in >>> > sorted(class_count.iterkeys()) and for j in >>> sorted(pixel_count.iterkeys()): >>> > >>> > Its giving me a syntax error which is obvious, but how can I make all >>> three >>> > for loop run simultaneously or any other way to do this simultaneous >>> work >>> > ??? >>> >>> Define simultaneously. Do the three dictionaries have the same number >>> of keys? If so, look up zip() or itertools.izip; if not, you may have >>> to more clearly define "simultaneous". >>> >>> ChrisA >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Apr 23 03:35:20 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 23 Apr 2013 17:35:20 +1000 Subject: Running simultaneuos "FOR" loops In-Reply-To: References: Message-ID: On Tue, Apr 23, 2013 at 5:13 PM, inshu chauhan wrote: > This statement is giving me the following error > > Statement: > for p, k, j in zip(sorted(segments.iterkeys(), class_count.iterkeys(), > pixel_count.iterkeys())): You probably want to sort them separately. By the way, using iterkeys() isn't going to do much for you, since you're sorting them; you need to see all the keys to sort them. ChrisA From ulrich.eckhardt at dominolaser.com Tue Apr 23 03:38:55 2013 From: ulrich.eckhardt at dominolaser.com (Ulrich Eckhardt) Date: Tue, 23 Apr 2013 09:38:55 +0200 Subject: Running simultaneuos "FOR" loops In-Reply-To: References: Message-ID: Am 23.04.2013 09:13, schrieb inshu chauhan: > This statement is giving me the following error > > Statement: > for p, k, j in zip(sorted(segments.iterkeys(), class_count.iterkeys(), > pixel_count.iterkeys())): > > Error: > Traceback (most recent call last): > File "C:\Users\inshu\Desktop\Training_segs_trial2.py", line 170, in > > access_segments(segimage, data) > File "C:\Users\inshu\Desktop\Training_segs_trial2.py", line 147, in > access_segments > for p, k, j in zip(sorted(segments.iterkeys(), class_count.iterkeys(), > pixel_count.iterkeys())): > TypeError: 'dictionary-keyiterator' object is not callable Which of the statements on that line causes the error? I guess asking yourself that question will lead you to the answer already! ;) Any reason you quoted your own and several others' messages, am I missing some reference there? Good luck! Uli From duncan.booth at invalid.invalid Tue Apr 23 04:59:37 2013 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 23 Apr 2013 08:59:37 GMT Subject: Running simultaneuos "FOR" loops References: Message-ID: inshu chauhan wrote: > This statement is giving me the following error > > Statement: > for p, k, j in zip(sorted(segments.iterkeys(), class_count.iterkeys(), > pixel_count.iterkeys())): > > Error: > Traceback (most recent call last): > File "C:\Users\inshu\Desktop\Training_segs_trial2.py", line 170, in > > access_segments(segimage, data) > File "C:\Users\inshu\Desktop\Training_segs_trial2.py", line 147, in > access_segments > for p, k, j in zip(sorted(segments.iterkeys(), > class_count.iterkeys(), > pixel_count.iterkeys())): > TypeError: 'dictionary-keyiterator' object is not callable > The second argument to `sorted()` is a comparison or key function, if you want to sort all three key lists you need to sort them separately. Try: for p, k, j in zip(sorted(segments), sorted(class_count), sorted(pixel_count)): also you don't need to call the `iterkeys()` method as you need them all to sort and just treating the dict as a sequence will do the right thing. -- Duncan Booth http://kupuguy.blogspot.com From davea at davea.name Tue Apr 23 08:23:37 2013 From: davea at davea.name (Dave Angel) Date: Tue, 23 Apr 2013 08:23:37 -0400 Subject: Running simultaneuos "FOR" loops In-Reply-To: References: Message-ID: <51767D49.7070904@davea.name> On 04/23/2013 02:58 AM, inshu chauhan wrote: > Yes Simultaneously means all three running at the same time, I looked up > zip just now, but will it not disturb my dictionaries ? > And yes the dictionaries have same number of keys. > More crucially, do all the dictionaries have the *same* keys? If so, then all the zip logic is unnecessary, as the p, k, and j values will always be identical. If they have the same keys, then do something like: for key in sorted(segments): val1 = segments[key] val2 = class_count[key] val3 = pixel_count[key] ... do something with those values If any of the keys is missing in one of the other dicts, you'll get an exception. You might also want to do a check of the size of the 3 dicts, just in case. -- DaveA From gary.herron at islandtraining.com Tue Apr 23 02:53:32 2013 From: gary.herron at islandtraining.com (Gary Herron) Date: Mon, 22 Apr 2013 23:53:32 -0700 Subject: Running simultaneuos "FOR" loops In-Reply-To: References: Message-ID: <51762FEC.4080603@islandtraining.com> On 04/22/2013 11:40 PM, inshu chauhan wrote: > i have to implement the below line in one of my code: > > for p in sorted(segments.iterkeys()) and for k in > sorted(class_count.iterkeys()) and for j in > sorted(pixel_count.iterkeys()): > > Its giving me a syntax error which is obvious, but how can I make all > three for loop run simultaneously or any other way to do > this simultaneous work ??? > > Be clearer about the problem please. Do you wish to produce a loop that: On pass 1, each of p,k, and t hold the first item of their respective lists, and on pass 2, each of p,k, and t hold the second item of their respective lists, and so on until one (or all) lists run out? If that is what you want, then check out the zip builtin function. But also consider this: Do you care what happens if one list runs out before the others? Or is it something else you want? Perhaps nested loops? for p in sorted(segments.iterkeys()): for k in sorted(class_count.iterkeys()): for j in sorted(pixel_count.iterkeys()): # This will be run with all possible combinations of p,k, and t. Gary Herron -------------- next part -------------- An HTML attachment was scrubbed... URL: From insideshoes at gmail.com Tue Apr 23 03:18:06 2013 From: insideshoes at gmail.com (inshu chauhan) Date: Tue, 23 Apr 2013 12:48:06 +0530 Subject: Running simultaneuos "FOR" loops In-Reply-To: <51762FEC.4080603@islandtraining.com> References: <51762FEC.4080603@islandtraining.com> Message-ID: Thanks Gary. > > Be clearer about the problem please. > > Do you wish to produce a loop that: > On pass 1, each of p,k, and t hold the first item of their respective > lists, and > on pass 2, each of p,k, and t hold the second item of their respective > lists, and > so on > until one (or all) lists run out? > Yes this is excatly what I want each loop holds the first item on each pass. > > If that is what you want, then check out the zip builtin function. But > also consider this: Do you care what happens if one list runs out before > the others? > Yes, but all dictionaries have same number of items. > > Or is it something else you want? Perhaps nested loops? > for p in sorted(segments.iterkeys()): > for k in sorted(class_count.iterkeys()): > for j in sorted(pixel_count.iterkeys()): > # This will be run with all possible combinations of p,k, and > t > No, I know about nested loops but I dont want that because all the loops have same number of items, inner loops will run out earlier. > > Gary Herron > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ngnedin at gmail.com Tue Apr 23 10:29:59 2013 From: ngnedin at gmail.com (Nick Gnedin) Date: Tue, 23 Apr 2013 09:29:59 -0500 Subject: distutils and libraries Message-ID: <51769AE7.2080505@gmail.com> Folks, I would like to install a Python module from a complete library. So, my question: if I already have a fully build Python module libMyModule.so, is there a way to use setup.py to just install it, skipping the build step? Here are details if needed: My build process consists of 2 steps - first, I build a static library libtemp.a (using CMake) that depends on 3rd party software. From that library I build a python module by compiling the file my_py.cpp that contains PyInit_MyModule function etc for proper module initialization. I can build that module in two ways: by using CMake or distutils. CMake builds the module properly, finding all dependencies, and when I install it manually, everything works just fine - but then the problem is that it has to be installed manually. With distutils, when I use module1 = Extension('ifrit', libraries = ['temp'], library_dirs = ['.'], sources = ['my_py.cpp']) the module is build and installed, but when I import it, it does not find the 3rd party libraries and complain about undefined symbols. Adding all 3rd party library paths to setup.py is not an option - those can be installed by a user anywhere. So, ideally, I would like to do something like that module1 = Extension('ifrit', libraries = ['MyModule'], sources = []) where libMyModule.so is a complete Python module build by CMake, but that does not work because setup.py still tries to build the module from an already existing complete module, and just creates an empty library. So, my question again: if I already have a fully build Python module libMyModule.so, is there a way to use setup.py to just install it, skipping the build step? Many thanks for any help, Nick Gnedin From daveb at tanagerproductions.com Tue Apr 23 10:52:56 2013 From: daveb at tanagerproductions.com (Dave Butler) Date: Tue, 23 Apr 2013 09:52:56 -0500 Subject: Finding referents with Gdb Message-ID: with gdb, can you find referents of an object given an object id? -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Tue Apr 23 11:40:31 2013 From: roy at panix.com (Roy Smith) Date: 23 Apr 2013 11:40:31 -0400 Subject: Nested iteration? Message-ID: In reviewing somebody else's code today, I found the following construct (eliding some details): f = open(filename) for line in f: if re.search(pattern1, line): outer_line = f.next() for inner_line in f: if re.search(pattern2, inner_line): inner_line = f.next() Somewhat to my surprise, the code worked. I didn't know it was legal to do nested iterations over the same iterable (not to mention mixing calls to next() with for-loops). Is this guaranteed to work in all situations? From oscar.j.benjamin at gmail.com Tue Apr 23 12:05:13 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 23 Apr 2013 17:05:13 +0100 Subject: Nested iteration? In-Reply-To: References: Message-ID: On 23 April 2013 16:40, Roy Smith wrote: > In reviewing somebody else's code today, I found the following > construct (eliding some details): > > f = open(filename) > for line in f: > if re.search(pattern1, line): > outer_line = f.next() > for inner_line in f: > if re.search(pattern2, inner_line): > inner_line = f.next() > > Somewhat to my surprise, the code worked. I didn't know it was legal > to do nested iterations over the same iterable (not to mention mixing > calls to next() with for-loops). Is this guaranteed to work in all > situations? For Python 3 you'd need next(f) instead of f.next(). Otherwise, yes, this works just fine with any non-restarting iterator (i.e. so that __iter__ just returns self rather than a new iterator). I recently posted in another thread about why it's a bad idea to call next() without catching StopIteration though. I wouldn't accept the code above for that reason. Oscar From ian.g.kelly at gmail.com Tue Apr 23 12:05:26 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 23 Apr 2013 10:05:26 -0600 Subject: Nested iteration? In-Reply-To: References: Message-ID: On Tue, Apr 23, 2013 at 9:40 AM, Roy Smith wrote: > In reviewing somebody else's code today, I found the following > construct (eliding some details): > > f = open(filename) > for line in f: > if re.search(pattern1, line): > outer_line = f.next() > for inner_line in f: > if re.search(pattern2, inner_line): > inner_line = f.next() > > Somewhat to my surprise, the code worked. I didn't know it was legal > to do nested iterations over the same iterable (not to mention mixing > calls to next() with for-loops). Is this guaranteed to work in all > situations? Yes, although the results will be different depending on whether the iterable stores its iteration state on itself (like a file object) or in the iterator (like a list). In the latter case, you would simply have two independent simultaneous iterations of the same object. You can replicate the same effect in the latter case though by getting an iterator from the object and explicitly looping over the same iterator, like so: i = iter(range(10)) for x in i: if x % 4 == 1: for y in i: if y % 4 == 3: print("%d + %d = %d" % (x, y, x+y)) break From __peter__ at web.de Tue Apr 23 12:15:42 2013 From: __peter__ at web.de (Peter Otten) Date: Tue, 23 Apr 2013 18:15:42 +0200 Subject: Nested iteration? References: Message-ID: Roy Smith wrote: > In reviewing somebody else's code today, I found the following > construct (eliding some details): > > f = open(filename) > for line in f: > if re.search(pattern1, line): > outer_line = f.next() > for inner_line in f: > if re.search(pattern2, inner_line): > inner_line = f.next() > > Somewhat to my surprise, the code worked. I didn't know it was legal > to do nested iterations over the same iterable (not to mention mixing > calls to next() with for-loops). Is this guaranteed to work in all > situations? That depends on what you mean by "all". A well-behaved iterator like Python's file object allows mixing of for loops and next(...) calls, but stupid people who deserve to burn in hell sometimes do class MyIterable: def __iter__(self): reset_internal_counter() return self with the consequence that every for loop implicitly resets the iterator's state. From rosuav at gmail.com Tue Apr 23 12:21:25 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 24 Apr 2013 02:21:25 +1000 Subject: Nested iteration? In-Reply-To: References: Message-ID: On Wed, Apr 24, 2013 at 1:40 AM, Roy Smith wrote: > In reviewing somebody else's code today, I found the following > construct (eliding some details): > > f = open(filename) > for line in f: > if re.search(pattern1, line): > outer_line = f.next() > for inner_line in f: > if re.search(pattern2, inner_line): > inner_line = f.next() > > Somewhat to my surprise, the code worked. I didn't know it was legal > to do nested iterations over the same iterable (not to mention mixing > calls to next() with for-loops). Is this guaranteed to work in all > situations? The definition of the for loop is sufficiently simple that this is safe, with the caveat already mentioned (that __iter__ is just returning self). And calling next() inside the loop will simply terminate the loop if there's nothing there, so I'd not have a problem with code like that - for instance, if I wanted to iterate over pairs of lines, I'd happily do this: for line1 in f: line2=next(f) print(line2) print(line1) That'll happily swap pairs, ignoring any stray line at the end of the file. Why bother catching StopIteration just to break? ChrisA From ian.g.kelly at gmail.com Tue Apr 23 12:30:47 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 23 Apr 2013 10:30:47 -0600 Subject: Nested iteration? In-Reply-To: References: Message-ID: On Tue, Apr 23, 2013 at 10:21 AM, Chris Angelico wrote: > The definition of the for loop is sufficiently simple that this is > safe, with the caveat already mentioned (that __iter__ is just > returning self). And calling next() inside the loop will simply > terminate the loop if there's nothing there, so I'd not have a problem > with code like that - for instance, if I wanted to iterate over pairs > of lines, I'd happily do this: > > for line1 in f: > line2=next(f) > print(line2) > print(line1) > > That'll happily swap pairs, ignoring any stray line at the end of the > file. Why bother catching StopIteration just to break? The next() there will *not* "simply terminate the loop" if it raises a StopIteration; for loops do not catch StopIteration exceptions that are raised from the body of the loop. The StopIteration will continue to propagate until it is caught or it reaches the sys.excepthook. In unusual circumstances, it is even possible that it could cause some *other* loop higher in the stack to break (i.e. if the current code is being run as a result of the next() method being called by the looping construct). From ian.g.kelly at gmail.com Tue Apr 23 12:39:26 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 23 Apr 2013 10:39:26 -0600 Subject: Nested iteration? In-Reply-To: References: Message-ID: On Tue, Apr 23, 2013 at 10:30 AM, Ian Kelly wrote: > On Tue, Apr 23, 2013 at 10:21 AM, Chris Angelico wrote: >> The definition of the for loop is sufficiently simple that this is >> safe, with the caveat already mentioned (that __iter__ is just >> returning self). And calling next() inside the loop will simply >> terminate the loop if there's nothing there, so I'd not have a problem >> with code like that - for instance, if I wanted to iterate over pairs >> of lines, I'd happily do this: >> >> for line1 in f: >> line2=next(f) >> print(line2) >> print(line1) >> >> That'll happily swap pairs, ignoring any stray line at the end of the >> file. Why bother catching StopIteration just to break? > > The next() there will *not* "simply terminate the loop" if it raises a > StopIteration; for loops do not catch StopIteration exceptions that > are raised from the body of the loop. The StopIteration will continue > to propagate until it is caught or it reaches the sys.excepthook. In > unusual circumstances, it is even possible that it could cause some > *other* loop higher in the stack to break (i.e. if the current code is > being run as a result of the next() method being called by the looping > construct). To expand on this, the prevailing wisdom here is that calls to next() should always be guarded with a StopIteration exception handler. The one exception to this is when the next() call is inside the body of a generator function, and the exception handler would cause the generator to exit anyway; in that case there is little difference between "except StopIteration: return" and letting the StopIteration propagate to the generator object. From rosuav at gmail.com Tue Apr 23 12:42:41 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 24 Apr 2013 02:42:41 +1000 Subject: Nested iteration? In-Reply-To: References: Message-ID: On Wed, Apr 24, 2013 at 2:30 AM, Ian Kelly wrote: > On Tue, Apr 23, 2013 at 10:21 AM, Chris Angelico wrote: >> The definition of the for loop is sufficiently simple that this is >> safe, with the caveat already mentioned (that __iter__ is just >> returning self). And calling next() inside the loop will simply >> terminate the loop if there's nothing there, so I'd not have a problem >> with code like that - for instance, if I wanted to iterate over pairs >> of lines, I'd happily do this: >> >> for line1 in f: >> line2=next(f) >> print(line2) >> print(line1) >> >> That'll happily swap pairs, ignoring any stray line at the end of the >> file. Why bother catching StopIteration just to break? > > The next() there will *not* "simply terminate the loop" if it raises a > StopIteration; for loops do not catch StopIteration exceptions that > are raised from the body of the loop. The StopIteration will continue > to propagate until it is caught or it reaches the sys.excepthook. In > unusual circumstances, it is even possible that it could cause some > *other* loop higher in the stack to break (i.e. if the current code is > being run as a result of the next() method being called by the looping > construct). Ah, whoops, my bad. This is what I get for not checking. I know I've done weird stuff with for loops before, but I guess it was fiddling inside the top of it, not in its body. I love this list. If I make a mistake, it's sure to be caught by someone else. The record is guaranteed to be set straight. Thanks Ian! ChrisA From steve+comp.lang.python at pearwood.info Tue Apr 23 12:53:25 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Apr 2013 16:53:25 GMT Subject: Nested iteration? References: Message-ID: <5176bc85$0$29977$c3e8da3$5496439d@news.astraweb.com> On Wed, 24 Apr 2013 02:42:41 +1000, Chris Angelico wrote: > I love this list. If I make a mistake, it's sure to be caught by someone > else. No it's not! Are-you-here-for-the-five-minute-argument-or-the-full-ten-minutes-ly y'rs, -- Steven From oscar.j.benjamin at gmail.com Tue Apr 23 17:29:07 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 23 Apr 2013 22:29:07 +0100 Subject: Nested iteration? In-Reply-To: References: Message-ID: On 23 April 2013 17:30, Ian Kelly wrote: > On Tue, Apr 23, 2013 at 10:21 AM, Chris Angelico wrote: >> The definition of the for loop is sufficiently simple that this is >> safe, with the caveat already mentioned (that __iter__ is just >> returning self). And calling next() inside the loop will simply >> terminate the loop if there's nothing there, so I'd not have a problem >> with code like that - for instance, if I wanted to iterate over pairs >> of lines, I'd happily do this: >> >> for line1 in f: >> line2=next(f) >> print(line2) >> print(line1) >> >> That'll happily swap pairs, ignoring any stray line at the end of the >> file. Why bother catching StopIteration just to break? > > The next() there will *not* "simply terminate the loop" if it raises a > StopIteration; for loops do not catch StopIteration exceptions that > are raised from the body of the loop. The StopIteration will continue > to propagate until it is caught or it reaches the sys.excepthook. In > unusual circumstances, it is even possible that it could cause some > *other* loop higher in the stack to break (i.e. if the current code is > being run as a result of the next() method being called by the looping > construct). I don't find that the circumstances are unusual. Pretty much any time one of the functions in the call stack is a generator this problem will occur if StopIteration propagates. I just thought I'd add that Python 3 has a convenient way to avoid this problem with next() which is to use the starred unpacking syntax: >>> numbers = [1, 2, 3, 4] >>> first, *numbers = numbers >>> first 1 >>> for x in numbers: ... print(x) ... 2 3 4 >>> first, *numbers = [] Traceback (most recent call last): File "", line 1, in ValueError: need more than 0 values to unpack Since we get a ValueError instead of a StopIteration we don't have the described problem. Oscar From joshua.landau.ws at gmail.com Tue Apr 23 17:41:00 2013 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Tue, 23 Apr 2013 22:41:00 +0100 Subject: Nested iteration? In-Reply-To: References: Message-ID: On 23 April 2013 22:29, Oscar Benjamin wrote: > I just thought I'd add that Python 3 has a convenient way to avoid > this problem with next() which is to use the starred unpacking syntax: > > >>> numbers = [1, 2, 3, 4] > >>> first, *numbers = numbers > That creates a new list every time. You'll not want that over try-next-except if you're doing this in a loop, and on addition (if you were talking in context) your method will exhaust the iterator in the outer loop. -------------- next part -------------- An HTML attachment was scrubbed... URL: From oscar.j.benjamin at gmail.com Tue Apr 23 18:42:39 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 23 Apr 2013 23:42:39 +0100 Subject: Nested iteration? In-Reply-To: References: Message-ID: On 23 April 2013 22:41, Joshua Landau wrote: > On 23 April 2013 22:29, Oscar Benjamin wrote: >> >> I just thought I'd add that Python 3 has a convenient way to avoid >> this problem with next() which is to use the starred unpacking syntax: >> >> >>> numbers = [1, 2, 3, 4] >> >>> first, *numbers = numbers > > > That creates a new list every time. You'll not want that over > try-next-except if you're doing this in a loop, and on addition (if you were > talking in context) your method will exhaust the iterator in the outer loop. Oh, you're right. I'm not using Python 3 yet and I assumed without checking that it would be giving me an iterator rather than unpacking everything into a list. Then the best I can think of is a helper function: >>> def unpack(iterable, count): ... iterator = iter(iterable) ... for n in range(count): ... yield next(iterator) ... yield iterator ... >>> numbers = [1, 2, 3, 4] >>> first, numbers = unpack(numbers, 1) >>> first 1 >>> numbers >>> list(numbers) [2, 3, 4] >>> first, numbers = unpack([], 1) Traceback (most recent call last): File "", line 1, in ValueError: need more than 0 values to unpack Oscar From steve+comp.lang.python at pearwood.info Tue Apr 23 12:35:10 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Apr 2013 16:35:10 GMT Subject: Nested iteration? References: Message-ID: <5176b83e$0$29977$c3e8da3$5496439d@news.astraweb.com> On Tue, 23 Apr 2013 11:40:31 -0400, Roy Smith wrote: > In reviewing somebody else's code today, I found the following construct > (eliding some details): > > f = open(filename) > for line in f: > if re.search(pattern1, line): > outer_line = f.next() > for inner_line in f: > if re.search(pattern2, inner_line): > inner_line = f.next() > > Somewhat to my surprise, the code worked. I didn't know it was legal to > do nested iterations over the same iterable (not to mention mixing calls > to next() with for-loops). Is this guaranteed to work in all > situations? In "all" situations? No of course not, this is Python, you can write nasty code that explodes the *second* time you iterate over it, but not the first. class Demo: flag = False def __iter__(self): if self.flag: raise RuntimeError("don't do that!") self.flag = True return iter([1, 2, 3]) But under normal circumstances with normal iterables, yes, it's fine. If the object is a sequence, like lists or strings, each for-loop is independent of the others: py> s = "ab" py> for c in s: ... for k in s: ... print c, k ... a a a b b a b b If the object is an iterator, each loop consumes a single value: py> it = iter("abcd") py> for c in it: ... for k in it: ... print c, k ... a b a c a d Each time you call next(), a single value is consumed. It doesn't matter whether you have one for-loop calling next() behind the scenes, or ten loops, or you call next() yourself, the same rule applies. -- Steven From tjreedy at udel.edu Tue Apr 23 16:49:30 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Tue, 23 Apr 2013 16:49:30 -0400 Subject: Nested iteration? In-Reply-To: References: Message-ID: On 4/23/2013 11:40 AM, Roy Smith wrote: > In reviewing somebody else's code today, I found the following > construct (eliding some details): > > f = open(filename) > for line in f: > if re.search(pattern1, line): > outer_line = f.next() > for inner_line in f: > if re.search(pattern2, inner_line): > inner_line = f.next() Did you possibly elide a 'break' after the inner_line assignment? > Somewhat to my surprise, the code worked. Without a break, the inner loop will continue iterating through the rest of the file (billions of lines?) looking for pattern2 and re-binding inner-line if there is another line or raising StopIteration if there is not. Does this really constitute 'working'? This is quite aside from issue of what one wants if there is no pattern1 or if there is no line after the first match (probably not StopIteration) or if there is no pattern2. > I didn't know it was legal to do nested iterations over the same iterable Yes, but the effect is quite different for iterators (start where the outer iteration left off) and non-iterators (restart at the beginning). r = range(2) for i in r: for j in r: print(i,j) # this is a common idiom to get all pairs 0 0 0 1 1 0 1 1 ri= iter(range(3)) for i in ri: for j in ri: print(i,j) # this is somewhat deceptive as the outer loop executes just once 0 1 0 2 I personally would add a 'break' after 'outer_line = next(f)', since the first loop is effectively done anyway at that point, and dedent the second for statement. I find to following clearer ri= iter(range(3)) for i in ri: break for j in ri: print(i,j) # this makes it clear that the first loop executes just once 0 1 0 2 I would only nest if the inner loop could terminate without exhausting the iterator and I wanted the outer loop to then resume. __ Terry Jan Reedy From joshua.landau.ws at gmail.com Tue Apr 23 17:14:09 2013 From: joshua.landau.ws at gmail.com (Joshua Landau) Date: Tue, 23 Apr 2013 22:14:09 +0100 Subject: Nested iteration? In-Reply-To: References: Message-ID: On 23 April 2013 21:49, Terry Jan Reedy wrote: > ri= iter(range(3)) > for i in ri: > for j in ri: > print(i,j) > # this is somewhat deceptive as the outer loop executes just once > 0 1 > 0 2 > > I personally would add a 'break' after 'outer_line = next(f)', since the > first loop is effectively done anyway at that point, and dedent the second > for statement. I find to following clearer > > ri= iter(range(3)) > for i in ri: > break > for j in ri: > print(i,j) > # this makes it clear that the first loop executes just once > 0 1 > 0 2 > > I would only nest if the inner loop could terminate without exhausting the > iterator and I wanted the outer loop to then resume. > Surely a normal programmer would think "next(ri, None)" rather than a loop that just breaks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From hossamalagmy at gmail.com Tue Apr 23 12:31:12 2013 From: hossamalagmy at gmail.com (23alagmy) Date: Tue, 23 Apr 2013 09:31:12 -0700 (PDT) Subject: =?windows-1256?B?x83h7CDjzOPm2skg393Rx8og3e3TIMjm3yBmYWNlYg==?= =?windows-1256?B?b29rIGNvdmVycyAyMDEz?= Message-ID: <6e8c8a6a-564f-401a-b694-84054729cf5d@r7g2000vbw.googlegroups.com> ???? ?????? ????? ??? ??? facebook covers 2013 http://natigtas7ab.blogspot.com/2013/04/facebook-covers-2013.html From r.koebler at yahoo.de Tue Apr 23 16:36:23 2013 From: r.koebler at yahoo.de (Roland Koebler) Date: Tue, 23 Apr 2013 22:36:23 +0200 Subject: ANN: template-engine pyratemp 0.3.0/0.2.3 Message-ID: <20130423203622.GA22318@localhost> Hi, since there were some questions about template-engines some time ago, I would like to announce: - I updated my comparison and benchmarks of several template-engines on http://www.simple-is-better.org/template/ - I have released a new version of my small and simple but powerful and pythonic template-engine "pyratemp": ============================================= pyratemp 0.3.0 / 0.2.3 released -- 2013-04-03 ============================================= A new version of pyratemp is released, which officially adds Python 3 support; and a backport of this version to Python <=2.5: - 0.3.0 for Python >=2.6 / 3.x - 0.2.3 for Python <=2.5 No changes in your templates and your Python-code should be necessary, except if you use cmp() / xrange() in your templates, which are gone in Python 3 and pyratemp 0.3.0/0.2.3. About pyratemp -------------- pyratemp is a small, simple and powerful template-engine for Python. Changes ------- see http://www.simple-is-better.org/template/pyratemp-latest/NEWS The main changes are: - Python 3 support - added setup.py for installation via distutils - renamed yaml2pyratemp.py to pyratemp_tool.py - added LaTeX- and mail-header-escaping - removed cmp(), xrange() from the template-functions Resources --------- Homepage, documentation, download and mailinglists: http://www.simple-is-better.org/template/pyratemp.html Download: - http://www.simple-is-better.org/template/pyratemp-0.3.0.tgz - http://www.simple-is-better.org/template/pyratemp-0.2.3.tgz on PyPI: - https://pypi.python.org/pypi/pyratemp/0.3.0 - https://pypi.python.org/pypi/pyratemp/0.2.3 --- Roland From rodrick.brown at gmail.com Tue Apr 23 17:14:50 2013 From: rodrick.brown at gmail.com (Rodrick Brown) Date: Tue, 23 Apr 2013 17:14:50 -0400 Subject: datetime.strptime() not padding 0's Message-ID: I thought I read some where that strptime() will pad 0's for day's for some reason this isnt working for me and I'm wondering if i'm doing something wrong. >>> from datetime import datetime >>> dt = datetime.strptime('Apr 9 2013', '%b %d %Y') >>> dt.day 9 >>> How can I get strptime to run 09? instead of 9 --RB -------------- next part -------------- An HTML attachment was scrubbed... URL: From gordon at panix.com Tue Apr 23 17:38:18 2013 From: gordon at panix.com (John Gordon) Date: Tue, 23 Apr 2013 21:38:18 +0000 (UTC) Subject: datetime.strptime() not padding 0's References: Message-ID: In Rodrick Brown writes: > I thought I read some where that strptime() will pad 0's for day's for some > reason this isnt working for me and I'm wondering if i'm doing something > wrong. > >>> from datetime import datetime > >>> dt = datetime.strptime('Apr 9 2013', '%b %d %Y') > >>> dt.day > 9 > How can I get strptime to run 09? instead of 9 dt.day is just an integer. If you want to print it with zero padding, use a format string: >>> n = 9 >>> print n 9 >>> print '%02d' % n 09 or for python 3: >>> print("{0:02d}".format(n)) 09 -- 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 kyle at pobox.com Tue Apr 23 17:41:34 2013 From: kyle at pobox.com (Kyle Shannon) Date: Tue, 23 Apr 2013 15:41:34 -0600 Subject: datetime.strptime() not padding 0's In-Reply-To: References: Message-ID: On Tue, Apr 23, 2013 at 3:14 PM, Rodrick Brown wrote: > I thought I read some where that strptime() will pad 0's for day's for some > reason this isnt working for me and I'm wondering if i'm doing something > wrong. > >>>> from datetime import datetime >>>> dt = datetime.strptime('Apr 9 2013', '%b %d %Y') >>>> dt.day > 9 >>>> > > How can I get strptime to run 09? instead of 9 > > > --RB > > -- > http://mail.python.org/mailman/listinfo/python-list > dt.day is an integer: >>> from datetime import datetime >>> dt = datetime.strptime('Apr 9 2013', '%b %d %Y') >>> type(dt.day) I think you are confusing strftime() with strptime(): >>> dt.strftime('%b %D %Y') 'Apr 04/09/13 2013' or if you just want a 0 padded string for the day, use string formatting: >>> s = '%02d' % dt.day >>> type(s) >>> s '09' From kyle at pobox.com Tue Apr 23 17:44:08 2013 From: kyle at pobox.com (Kyle Shannon) Date: Tue, 23 Apr 2013 15:44:08 -0600 Subject: datetime.strptime() not padding 0's In-Reply-To: References: Message-ID: On Tue, Apr 23, 2013 at 3:41 PM, Kyle Shannon wrote: > On Tue, Apr 23, 2013 at 3:14 PM, Rodrick Brown wrote: >> I thought I read some where that strptime() will pad 0's for day's for some >> reason this isnt working for me and I'm wondering if i'm doing something >> wrong. >> >>>>> from datetime import datetime >>>>> dt = datetime.strptime('Apr 9 2013', '%b %d %Y') >>>>> dt.day >> 9 >>>>> >> >> How can I get strptime to run 09? instead of 9 >> >> >> --RB >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > dt.day is an integer: > >>>> from datetime import datetime >>>> dt = datetime.strptime('Apr 9 2013', '%b %d %Y') >>>> type(dt.day) > > > I think you are confusing strftime() with strptime(): > >>>> dt.strftime('%b %D %Y') > 'Apr 04/09/13 2013' > > or if you just want a 0 padded string for the day, use string formatting: > >>>> s = '%02d' % dt.day >>>> type(s) > >>>> s > '09' Whoops, wrong cut/paste, I meant: >>> dt.strftime('%b %d %Y') 'Apr 09 2013' From anadionisio257 at gmail.com Tue Apr 23 17:39:17 2013 From: anadionisio257 at gmail.com (=?ISO-8859-1?Q?Ana_Dion=EDsio?=) Date: Tue, 23 Apr 2013 14:39:17 -0700 (PDT) Subject: Reading a CSV file Message-ID: <9d0d46e5-b579-4edc-be34-0aa8798b66f8@googlegroups.com> Hello! I need to read a CSV file that has "n" rows and "m" columns and if a certain condition is met, for exameple n==200, it prints all the columns in that row. How can I do this? I tried to save all the data in a multi-dimensional array but I get this error: "ValueError: array is too big." Thank you! From drsalists at gmail.com Tue Apr 23 17:49:47 2013 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 23 Apr 2013 14:49:47 -0700 Subject: Reading a CSV file In-Reply-To: <9d0d46e5-b579-4edc-be34-0aa8798b66f8@googlegroups.com> References: <9d0d46e5-b579-4edc-be34-0aa8798b66f8@googlegroups.com> Message-ID: On Tue, Apr 23, 2013 at 2:39 PM, Ana Dion?sio wrote: > Hello! > > I need to read a CSV file that has "n" rows and "m" columns and if a > certain condition is met, for exameple n==200, it prints all the columns in > that row. How can I do this? I tried to save all the data in a > multi-dimensional array but I get this error: > > "ValueError: array is too big Use: csv.reader(*csvfile*, *dialect='excel'*, ***fmtparams*)? This will allow you to iterate over the values, instead of reading them all into memory at once. csv.reader is documented at: http://docs.python.org/3/library/csv.html http://docs.python.org/2/library/csv.html -------------- next part -------------- An HTML attachment was scrubbed... URL: From anadionisio257 at gmail.com Tue Apr 23 17:58:01 2013 From: anadionisio257 at gmail.com (=?ISO-8859-1?Q?Ana_Dion=EDsio?=) Date: Tue, 23 Apr 2013 14:58:01 -0700 (PDT) Subject: Reading a CSV file In-Reply-To: References: <9d0d46e5-b579-4edc-be34-0aa8798b66f8@googlegroups.com> Message-ID: <665fa76f-3a19-414b-8524-c2a5bfa8b21b@googlegroups.com> Thank you, but can you explain it a little better? I am just starting in python and I don't think I understood how to apply your awnser From drsalists at gmail.com Tue Apr 23 18:34:56 2013 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 23 Apr 2013 15:34:56 -0700 Subject: Reading a CSV file In-Reply-To: <665fa76f-3a19-414b-8524-c2a5bfa8b21b@googlegroups.com> References: <9d0d46e5-b579-4edc-be34-0aa8798b66f8@googlegroups.com> <665fa76f-3a19-414b-8524-c2a5bfa8b21b@googlegroups.com> Message-ID: On Tue, Apr 23, 2013 at 2:58 PM, Ana Dion?sio wrote: > Thank you, but can you explain it a little better? I am just starting in > python and I don't think I understood how to apply your awnser > -- > http://mail.python.org/mailman/listinfo/python-list > #!/usr/local/pypy-1.9/bin/pypy import csv def main(): with open('test.csv', 'r') as file_: for row in csv.reader(file_, delimiter="|"): print row main() # Example input: # abc|def|ghi # jkl|mno|pqr In this way, you get one row at a time, instead of all rows at once. HTH -------------- next part -------------- An HTML attachment was scrubbed... URL: From anadionisio257 at gmail.com Tue Apr 23 18:40:42 2013 From: anadionisio257 at gmail.com (=?ISO-8859-1?Q?Ana_Dion=EDsio?=) Date: Tue, 23 Apr 2013 15:40:42 -0700 (PDT) Subject: Reading a CSV file In-Reply-To: <665fa76f-3a19-414b-8524-c2a5bfa8b21b@googlegroups.com> References: <9d0d46e5-b579-4edc-be34-0aa8798b66f8@googlegroups.com> <665fa76f-3a19-414b-8524-c2a5bfa8b21b@googlegroups.com> Message-ID: <54f430e9-b0f0-42ab-86c3-37dfb3bc45bd@googlegroups.com> The condition I want to meet is in the first column, so is there a way to read only the first column and if the condition is true, print the rest? From fabiosantosart at gmail.com Tue Apr 23 19:30:12 2013 From: fabiosantosart at gmail.com (=?ISO-8859-1?Q?F=E1bio_Santos?=) Date: Wed, 24 Apr 2013 00:30:12 +0100 Subject: Reading a CSV file In-Reply-To: <54f430e9-b0f0-42ab-86c3-37dfb3bc45bd@googlegroups.com> References: <9d0d46e5-b579-4edc-be34-0aa8798b66f8@googlegroups.com> <665fa76f-3a19-414b-8524-c2a5bfa8b21b@googlegroups.com> <54f430e9-b0f0-42ab-86c3-37dfb3bc45bd@googlegroups.com> Message-ID: The enumerate function should allow you to check whether you are in the first iteration. Like so: for row_number, row in enumerate(csv.reader(<...>)): if enumerate == 0: if : break ... Enumerate allows you to know how far into the iteration you are. You could use the iterator's next() method too. On 23 Apr 2013 23:53, "Ana Dion?sio" wrote: > > The condition I want to meet is in the first column, so is there a way to read only the first column and if the condition is true, print the rest? > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Tue Apr 23 23:18:13 2013 From: davea at davea.name (Dave Angel) Date: Tue, 23 Apr 2013 23:18:13 -0400 Subject: Reading a CSV file In-Reply-To: <54f430e9-b0f0-42ab-86c3-37dfb3bc45bd@googlegroups.com> References: <9d0d46e5-b579-4edc-be34-0aa8798b66f8@googlegroups.com> <665fa76f-3a19-414b-8524-c2a5bfa8b21b@googlegroups.com> <54f430e9-b0f0-42ab-86c3-37dfb3bc45bd@googlegroups.com> Message-ID: <51774EF5.3090904@davea.name> On 04/23/2013 06:40 PM, Ana Dion?sio wrote: > The condition I want to meet is in the first column, so is there a way to read only the first column and if the condition is true, print the rest? > The CSV module will read a row at a time, but nothing gets printed till you print it. So starting with Dan's code, row[0] is column one of a given row, while row[1] is the next column, and so on. import csv def main(): with open('test.csv', 'r') as file_: for row in csv.reader(file_, delimiter="|"): if row[0] == "special": print row[1:] #print columns starting at the second -- DaveA From vasudevram at gmail.com Tue Apr 23 17:50:22 2013 From: vasudevram at gmail.com (vasudevram) Date: Tue, 23 Apr 2013 14:50:22 -0700 (PDT) Subject: What is the reason for defining classes within classes in Python? Message-ID: <4e46cc04-248e-4594-a24a-b272648a5e66@googlegroups.com> Hi list, I saw an example of defining a class within another class, here, in the docs for peewee, a simple ORM for Python: http://peewee.readthedocs.org/en/latest/peewee/quickstart.html In what way is this useful? Thanks, Vasudev From ian.g.kelly at gmail.com Tue Apr 23 18:22:57 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 23 Apr 2013 16:22:57 -0600 Subject: What is the reason for defining classes within classes in Python? In-Reply-To: <4e46cc04-248e-4594-a24a-b272648a5e66@googlegroups.com> References: <4e46cc04-248e-4594-a24a-b272648a5e66@googlegroups.com> Message-ID: On Tue, Apr 23, 2013 at 3:50 PM, vasudevram wrote: > > Hi list, > > I saw an example of defining a class within another class, here, in the docs for peewee, a simple ORM for Python: > > http://peewee.readthedocs.org/en/latest/peewee/quickstart.html > > In what way is this useful? In that particular case they're just using it as a namespace. Django does the same thing. From vasudevram at gmail.com Tue Apr 23 19:13:57 2013 From: vasudevram at gmail.com (vasudevram) Date: Tue, 23 Apr 2013 16:13:57 -0700 (PDT) Subject: What is the reason for defining classes within classes in Python? In-Reply-To: References: <4e46cc04-248e-4594-a24a-b272648a5e66@googlegroups.com> Message-ID: On Wednesday, April 24, 2013 3:52:57 AM UTC+5:30, Ian wrote: > On Tue, Apr 23, 2013 at 3:50 PM, vasudevram wrote: > > > > > > Hi list, > > > > > > I saw an example of defining a class within another class, here, in the docs for peewee, a simple ORM for Python: > > > > > > http://peewee.readthedocs.org/en/latest/peewee/quickstart.html > > > > > > In what way is this useful? > > > > In that particular case they're just using it as a namespace. Django > > does the same thing. Not clear. An example or more explanation might help, if you can. Thanks. From wuwei23 at gmail.com Tue Apr 23 20:50:36 2013 From: wuwei23 at gmail.com (alex23) Date: Tue, 23 Apr 2013 17:50:36 -0700 (PDT) Subject: What is the reason for defining classes within classes in Python? References: <4e46cc04-248e-4594-a24a-b272648a5e66@googlegroups.com> Message-ID: <2cec7512-997e-4f1f-9580-592495d449df@ys5g2000pbc.googlegroups.com> On Apr 24, 9:13?am, vasudevram wrote: > On Wednesday, April 24, 2013 3:52:57 AM UTC+5:30, Ian wrote: > > On Tue, Apr 23, 2013 at 3:50 PM, vasudevram ?wrote: > > > I saw an example of defining a class within another class > > > In what way is this useful? > > > In that particular case they're just using it as a namespace. > > Not clear. An example or more explanation might help, if you can. Thanks. Namespaces are used to allow for the same label to be applied to different concepts without the labels conflicting with each other. If I was writing a program that dealt with the mathematics of morality, I might want to use the sine function and refer to it in the standard way as 'sin', and I might also want to store a value representing your lack of goodness as 'sin'. As you can't use the same label in the same scope to refer to two different objects, one way of dealing with this that lets you still use what you feel are the most appropriate names is to put them into a namespace. So you could express this as: class Math(object): sin = function() class Morality(object): sin = True Then in your code you can clearly distinguish between the two by using Math.sin and Morality.sin. Modules & packages are also namespaces, so in this example we'd replace the Math class with `import math`, which has a sin function defined within it. A nested class definition will be defined as an attribute of the class its defined within: >>> class Outer(object): ... foo = 'FOO' ... class Inner(object): ... bar = 'BAR' ... >>> Outer.Inner >>> Outer.Inner.bar 'BAR' With peewee, the Model class looks for a Meta attribute and uses attributes on it to perform some tasks, like where to retrieve/store the model data. This allows for a way of distinguishing between attributes used to define fields, and attributes needed for those tasks. It also means your Models can use field names that the class would otherwise reserve for its own internal purposes: class DatabaseDetails(Model): # these attributes are fields database = CharField() owner = CharField() # ...but the Meta attribute isn't class Meta: # these attributes are used by the Model class database = db Here, database as a field is a text string that could contain a database name, while DatabaseDetails.Meta.database contains a reference to an actual database where the DatabaseDetails record would be stored. From vasudevram at gmail.com Wed Apr 24 07:01:46 2013 From: vasudevram at gmail.com (vasudevram) Date: Wed, 24 Apr 2013 04:01:46 -0700 (PDT) Subject: What is the reason for defining classes within classes in Python? In-Reply-To: <2cec7512-997e-4f1f-9580-592495d449df@ys5g2000pbc.googlegroups.com> References: <4e46cc04-248e-4594-a24a-b272648a5e66@googlegroups.com> <2cec7512-997e-4f1f-9580-592495d449df@ys5g2000pbc.googlegroups.com> Message-ID: <7143de25-61a1-4eaf-abd1-2eab03c913f8@googlegroups.com> On Wednesday, April 24, 2013 6:20:36 AM UTC+5:30, alex23 wrote: > On Apr 24, 9:13?am, vasudevram wrote: > > > On Wednesday, April 24, 2013 3:52:57 AM UTC+5:30, Ian wrote: > > > > On Tue, Apr 23, 2013 at 3:50 PM, vasudevram ?wrote: > > > > > I saw an example of defining a class within another class > > > > > In what way is this useful? > > > > > > > In that particular case they're just using it as a namespace. > > > > > > Not clear. An example or more explanation might help, if you can. Thanks. > > > > Namespaces are used to allow for the same label to be applied to > > different concepts without the labels conflicting with each other. If > > I was writing a program that dealt with the mathematics of morality, I > > might want to use the sine function and refer to it in the standard > > way as 'sin', and I might also want to store a value representing your > > lack of goodness as 'sin'. As you can't use the same label in the same > > scope to refer to two different objects, one way of dealing with this > > that lets you still use what you feel are the most appropriate names > > is to put them into a namespace. So you could express this as: > > > > class Math(object): > > sin = function() > > > > class Morality(object): > > sin = True > > > > Then in your code you can clearly distinguish between the two by using > > Math.sin and Morality.sin. Modules & packages are also namespaces, so > > in this example we'd replace the Math class with `import math`, which > > has a sin function defined within it. > > > > A nested class definition will be defined as an attribute of the class > > its defined within: > > > > >>> class Outer(object): > > ... foo = 'FOO' > > ... class Inner(object): > > ... bar = 'BAR' > > ... > > >>> Outer.Inner > > > > >>> Outer.Inner.bar > > 'BAR' > > > > With peewee, the Model class looks for a Meta attribute and uses > > attributes on it to perform some tasks, like where to retrieve/store > > the model data. This allows for a way of distinguishing between > > attributes used to define fields, and attributes needed for those > > tasks. It also means your Models can use field names that the class > > would otherwise reserve for its own internal purposes: > > > > class DatabaseDetails(Model): > > # these attributes are fields > > database = CharField() > > owner = CharField() > > > > # ...but the Meta attribute isn't > > class Meta: > > # these attributes are used by the Model class > > database = db > > > > Here, database as a field is a text string that could contain a > > database name, while DatabaseDetails.Meta.database contains a > > reference to an actual database where the DatabaseDetails record would > > be stored. Actually, I did know what namespaces are in general. What I didn't get was how the inner class Meta in the peewee example was being used as a namespace. Your explanation makes things very clear. Thank you. Just one other doubt: > >>> Outer.Inner > > > In the above output, I would have thought Python would print __main__.Outer.Inner or Outer.Inner instead of __main__.Inner, since Inner is an attribute of Outer? From __peter__ at web.de Wed Apr 24 08:00:55 2013 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Apr 2013 14:00:55 +0200 Subject: What is the reason for defining classes within classes in Python? References: <4e46cc04-248e-4594-a24a-b272648a5e66@googlegroups.com> <2cec7512-997e-4f1f-9580-592495d449df@ys5g2000pbc.googlegroups.com> <7143de25-61a1-4eaf-abd1-2eab03c913f8@googlegroups.com> Message-ID: vasudevram wrote: > On Wednesday, April 24, 2013 6:20:36 AM UTC+5:30, alex23 wrote: >> >> A nested class definition will be defined as an attribute of the class >> >> its defined within: >> >> >> >> >>> class Outer(object): >> >> ... foo = 'FOO' >> >> ... class Inner(object): >> >> ... bar = 'BAR' >> >> ... >> >> >>> Outer.Inner > Just one other doubt: > >> >>> Outer.Inner >> >> >> > > In the above output, I would have thought Python would print > __main__.Outer.Inner or Outer.Inner instead of __main__.Inner, since Inner > is an attribute of Outer? The Python developers seem to agree with you and have made the compiler smart enough to accomodate your expectations in Python 3.3: $ cat tmp.py class Outer: class Inner: pass print(Outer.Inner) $ python3.2 tmp.py $ python3.3 tmp.py From vasudevram at gmail.com Wed Apr 24 09:29:05 2013 From: vasudevram at gmail.com (vasudevram) Date: Wed, 24 Apr 2013 06:29:05 -0700 (PDT) Subject: What is the reason for defining classes within classes in Python? In-Reply-To: References: <4e46cc04-248e-4594-a24a-b272648a5e66@googlegroups.com> <2cec7512-997e-4f1f-9580-592495d449df@ys5g2000pbc.googlegroups.com> <7143de25-61a1-4eaf-abd1-2eab03c913f8@googlegroups.com> Message-ID: <8ec3f486-0996-4642-9d1a-90925a889307@googlegroups.com> Interesting. Thank you. From pengyu.ut at gmail.com Tue Apr 23 18:36:14 2013 From: pengyu.ut at gmail.com (Peng Yu) Date: Tue, 23 Apr 2013 17:36:14 -0500 Subject: using pandoc instead of rst to document python Message-ID: Hi, I'm wondering if it possible to use pandoc instead of rst to document python. Is there a documentation system support this format of python document? -- Regards, Peng From michael.weylandt at gmail.com Tue Apr 23 18:40:31 2013 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Tue, 23 Apr 2013 18:40:31 -0400 Subject: using pandoc instead of rst to document python In-Reply-To: References: Message-ID: On Tue, Apr 23, 2013 at 6:36 PM, Peng Yu wrote: > Hi, > > I'm wondering if it possible to use pandoc instead of rst to document > python. Is there a documentation system support this format of python > document? Pandoc is a converter while rst is a format so they're not directly comparable; pandoc can convert _to_ and _from_ rst to a wide variety of other formats, but you still have to write documentation in one format or another. If you want to use an rst-centric documentation tool, you can write in, e.g., Markdown, convert to rst and then run your other tool on it. Michael From pengyu.ut at gmail.com Tue Apr 23 19:14:08 2013 From: pengyu.ut at gmail.com (Peng Yu) Date: Tue, 23 Apr 2013 18:14:08 -0500 Subject: using pandoc instead of rst to document python In-Reply-To: References: Message-ID: On Tue, Apr 23, 2013 at 5:40 PM, R. Michael Weylandt wrote: > On Tue, Apr 23, 2013 at 6:36 PM, Peng Yu wrote: >> Hi, >> >> I'm wondering if it possible to use pandoc instead of rst to document >> python. Is there a documentation system support this format of python >> document? Sorry for the confusion. When I said pandoc, I meant pandoc's markdown. http://johnmacfarlane.net/pandoc/README.html#pandocs-markdown > Pandoc is a converter while rst is a format so they're not directly > comparable; pandoc can convert _to_ and _from_ rst to a wide variety > of other formats, but you still have to write documentation in one > format or another. If you want to use an rst-centric documentation > tool, you can write in, e.g., Markdown, convert to rst and then run > your other tool on it. I currently use sphinx to generate the doc (in rst). How to figure it to support pandoc's markdown? -- Regards, Peng From michael.weylandt at gmail.com Wed Apr 24 13:21:54 2013 From: michael.weylandt at gmail.com (R. Michael Weylandt) Date: Wed, 24 Apr 2013 18:21:54 +0100 Subject: using pandoc instead of rst to document python In-Reply-To: References: Message-ID: On Wed, Apr 24, 2013 at 12:14 AM, Peng Yu wrote: > I currently use sphinx to generate the doc (in rst). How to figure it > to support pandoc's markdown? If I understand the desired workflow, it's just 1) write in markdown; 2) then run pandoc to convert to rst; 3) then run Sphinx to render html or whatever you want. You could even script this in python ;-) Michael From animemaiden21 at gmail.com Tue Apr 23 19:41:27 2013 From: animemaiden21 at gmail.com (animemaiden) Date: Tue, 23 Apr 2013 16:41:27 -0700 (PDT) Subject: AttributeError Problem Message-ID: <4dfb3ca3-a539-48ec-aae8-0be22471cea4@googlegroups.com> Hi, I'm trying to display a graph in Tkinter that reads a graph from a file and displays it on a panel which the first line in the file contains a number that indicates the number of vertices (n). The vertices are labeled as 0,1,?,n-1. Each subsequent line, with the format u x y v1, v2, ?describes that the vertex u is located at position (x,y) with the edges (u,1). (u,v2), and so on. I'm using Python 3.2.3 and I keep getting this error: numberOfVertices = int(infile.readline().decode()) # Read the first line from the file AttributeError: 'str' object has no attribute 'readline' Here is my code: from tkinter import * # Import tkinter from tkinter import filedialog def displayGraph(canvas, vertices, edges): radius = 3 for vertex, x, y in vertices: canvas.create_text(x - 2 * radius, y - 2 * radius, text = str(vertex), tags = "graph") canvas.create_oval(x - radius, y - radius, x + radius, y + radius, fill = "black", tags = "graph") for v1, v2 in edges: canvas.create_line(vertices[v1][1], vertices[v1][2], vertices[v2][1], vertices[v2][2], tags = "graph") def main(): infile = filedialog.askopenfilename() numberOfVertices = int(infile.readline().decode()) # Read the first line from the file print(numberOfVertices) vertices = [] edges = [] for i in range(numberOfVertices): items = infile.readline().strip().split() # Read the info for one vertex vertices.append([int(items[0]), int(items[1]), int(items[2])]) for j in range(3, len(items)): edges.append([int(items[0]), int(items[j])]) print(vertices) print(edges) infile.close() # Close the input file window = Tk() # Create a window window.title("Display a Graph") # Set title frame1 = Frame(window) # Hold four labels for displaying cards frame1.pack() canvas = Canvas(frame1, width = 300, height = 200) canvas.pack() displayGraph(canvas, vertices, edges) window.mainloop() # Create an event loop main() From animemaiden21 at gmail.com Tue Apr 23 19:42:46 2013 From: animemaiden21 at gmail.com (animemaiden) Date: Tue, 23 Apr 2013 16:42:46 -0700 (PDT) Subject: AttributeError Problem In-Reply-To: <4dfb3ca3-a539-48ec-aae8-0be22471cea4@googlegroups.com> References: <4dfb3ca3-a539-48ec-aae8-0be22471cea4@googlegroups.com> Message-ID: <52948e97-0c4a-44d5-aa54-192e587d62b3@googlegroups.com> On Tuesday, April 23, 2013 7:41:27 PM UTC-4, animemaiden wrote: > Hi, > > > > I'm trying to display a graph in Tkinter that reads a graph from a file and displays it on a panel which the first line in the file contains a number that indicates the number of vertices (n). The vertices are labeled as 0,1,?,n-1. Each subsequent line, with the format u x y v1, v2, ?describes that the vertex u is located at position (x,y) with the edges (u,1). (u,v2), and so on. > > > > > > I'm using Python 3.2.3 and I keep getting this error: > > > > numberOfVertices = int(infile.readline().decode()) # Read the first line from the file > > AttributeError: 'str' object has no attribute 'readline' > > > > > > Here is my code: > > > > from tkinter import * # Import tkinter > > from tkinter import filedialog > > > > > > > > def displayGraph(canvas, vertices, edges): > > radius = 3 > > for vertex, x, y in vertices: > > canvas.create_text(x - 2 * radius, y - 2 * radius, text = str(vertex), tags = "graph") > > canvas.create_oval(x - radius, y - radius, x + radius, y + radius, fill = "black", tags = "graph") > > > > for v1, v2 in edges: > > canvas.create_line(vertices[v1][1], vertices[v1][2], vertices[v2][1], vertices[v2][2], tags = "graph") > > > > def main(): > > > > infile = filedialog.askopenfilename() > > > > > > numberOfVertices = int(infile.readline().decode()) # Read the first line from the file > > print(numberOfVertices) > > > > vertices = [] > > edges = [] > > for i in range(numberOfVertices): > > items = infile.readline().strip().split() # Read the info for one vertex > > vertices.append([int(items[0]), int(items[1]), int(items[2])]) > > for j in range(3, len(items)): > > edges.append([int(items[0]), int(items[j])]) > > > > print(vertices) > > print(edges) > > > > infile.close() # Close the input file > > > > window = Tk() # Create a window > > window.title("Display a Graph") # Set title > > > > frame1 = Frame(window) # Hold four labels for displaying cards > > frame1.pack() > > canvas = Canvas(frame1, width = 300, height = 200) > > canvas.pack() > > > > displayGraph(canvas, vertices, edges) > > > > window.mainloop() # Create an event loop > > > > main() Also, it reads data from a file. From skip at pobox.com Tue Apr 23 20:02:08 2013 From: skip at pobox.com (Skip Montanaro) Date: Tue, 23 Apr 2013 19:02:08 -0500 Subject: AttributeError Problem In-Reply-To: <4dfb3ca3-a539-48ec-aae8-0be22471cea4@googlegroups.com> References: <4dfb3ca3-a539-48ec-aae8-0be22471cea4@googlegroups.com> Message-ID: > numberOfVertices = int(infile.readline().decode()) # Read the first line from the file > AttributeError: 'str' object has no attribute 'readline' ... > infile = filedialog.askopenfilename() This is just returning a filename. You need to open it to get a file object. For example: infile = filedialog.askopenfilename() fd = open(infile) ... numberOfVertices = int(fd.readline().decode()) Skip From animemaiden21 at gmail.com Tue Apr 23 20:28:30 2013 From: animemaiden21 at gmail.com (animemaiden) Date: Tue, 23 Apr 2013 17:28:30 -0700 (PDT) Subject: AttributeError Problem In-Reply-To: References: <4dfb3ca3-a539-48ec-aae8-0be22471cea4@googlegroups.com> Message-ID: <18292d0f-1f6f-411a-b348-a5f292e2af51@googlegroups.com> On Tuesday, April 23, 2013 8:02:08 PM UTC-4, Skip Montanaro wrote: > > numberOfVertices = int(infile.readline().decode()) # Read the first line from the file > > > AttributeError: 'str' object has no attribute 'readline' > > ... > > > infile = filedialog.askopenfilename() > > > > This is just returning a filename. You need to open it to get a file > > object. For example: > > > > infile = filedialog.askopenfilename() > > fd = open(infile) > > ... > > numberOfVertices = int(fd.readline().decode()) > > > > Skip Thanks, but now I have this error AttributeError: 'str' object has no attribute 'decode' From python at mrabarnett.plus.com Tue Apr 23 21:17:48 2013 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 24 Apr 2013 02:17:48 +0100 Subject: AttributeError Problem In-Reply-To: <18292d0f-1f6f-411a-b348-a5f292e2af51@googlegroups.com> References: <4dfb3ca3-a539-48ec-aae8-0be22471cea4@googlegroups.com> <18292d0f-1f6f-411a-b348-a5f292e2af51@googlegroups.com> Message-ID: <517732BC.4010204@mrabarnett.plus.com> On 24/04/2013 01:28, animemaiden wrote: > On Tuesday, April 23, 2013 8:02:08 PM UTC-4, Skip Montanaro wrote: >> > numberOfVertices = int(infile.readline().decode()) # Read the first line from the file >> >> > AttributeError: 'str' object has no attribute 'readline' >> >> ... >> >> > infile = filedialog.askopenfilename() >> >> >> >> This is just returning a filename. You need to open it to get a file >> >> object. For example: >> >> >> >> infile = filedialog.askopenfilename() >> >> fd = open(infile) >> >> ... >> >> numberOfVertices = int(fd.readline().decode()) >> >> >> >> Skip > Thanks, but now I have this error AttributeError: 'str' object has no attribute 'decode' > You already have a string (the line) that you've read from the file, so what are you trying to 'decode' anyway? Just remove that erroneous method call. From haoyi.sg at gmail.com Wed Apr 24 00:24:09 2013 From: haoyi.sg at gmail.com (Haoyi Li) Date: Tue, 23 Apr 2013 21:24:09 -0700 (PDT) Subject: ANN: MacroPy: bringing Macros to Python Message-ID: <678cacd1-6cae-40b1-a282-80e8dca0c04b@googlegroups.com> MacroPy is a pure-python library that allows user-defined AST rewrites as part of the import process (using PEP 302). In short, it makes mucking around with Python's semantics so easy as to be almost trivial: you write a function that takes an AST and returns an AST, register it as a macro, and you're off to the races. To give a sense of it, I just finished implementing Scala/Groovy style anonymous lambdas: map(f%(_ + 1), [1, 2, 3]) #[2, 3, 4] reduce(f%(_ + _), [1, 2, 3]) #6 ...which took about half an hour and 30 lines of code, start to finish. We're currently working on implementing destructuring-pattern-matching on objects (i.e. like in Haskell/Scala) and a clone of .NET's LINQ to SQL. It's still very much a work in progress, but we have a list of pretty cool macros already done, which shows off what you can do with it. If anyone else was thinking about messing around with the semantics of the Python language but was too scared to jump into the CPython internals, this offers a somewhat easier path. Thanks! -Haoyi From silideba at gmail.com Wed Apr 24 01:12:43 2013 From: silideba at gmail.com (Debashish Saha) Date: Wed, 24 Apr 2013 10:42:43 +0530 Subject: problem with saving data in a text file Message-ID: I tried the following: Am_cor=np.vectorize(Am_cor) #plt.plot(t, signal, color='blue', label='Original signal') fig=plt.figure() plt.xlabel('Time(minute)') plt.ylabel('$ Re()$') plt.xlim([t[0], t[-1]]) plt.ylim((-.3*a1-a1,a1+.3*a1)) plt.grid() plt.plot(t,Am_cor(t),'o-',label='with parallax', markersize=2) plt.legend(loc="best") plt.show() f = open("Amp_cor_with_parallax(sd=.001)Ilamda=5.txt", "w") f.write("# time(minute) \t Amp_cor_with_parallax(sd=.001) \n") # column names np.savetxt(f, np.array([t, Am_cor(t)]).T) f.close() now the error which I am getting is 166 else: 167 filename = fname --> 168 exec compile(scripttext, filename, 'exec') in glob, loc 169 else: 170 def execfile(fname, *where): C:\Users\as\desktop\24_04_13\testing23_04.py in () 191 f = open("Amp_cor_with_parallax(sd=.001)Ilamda=5.txt", "w") 192 f.write("# time(minute) \t Amp_cor_with_parallax(sd=.001) \n") # column names --> 193 np.savetxt(f, np.array([t, Am_cor(t)]).T) 194 f.close() 195 error: First argument must be a callable function. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sara.lochtie at gmail.com Wed Apr 24 02:22:29 2013 From: sara.lochtie at gmail.com (Sara Lochtie) Date: Tue, 23 Apr 2013 23:22:29 -0700 (PDT) Subject: QTableWidget updating columns in a single row Message-ID: <1a87f00d-636d-4795-80d5-7bf196d1177f@googlegroups.com> I have written a GUI that gets data sent to it in real time and this data is displayed in a table. Every time data is sent in it is displayed in the table in a new row. My problem is that I would like to have the data just replace the old in the first row. The table has 6 columns (A, B, C, D, E, F) I want the new data to continue replacing the old data in the same row unless the data that goes under column A changes, at which point a new row would be added. Does anyone have tips on how to approach this? I can post a portion of my code to get a better idea of what I have done. From kwpolska at gmail.com Wed Apr 24 03:58:36 2013 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Wed, 24 Apr 2013 09:58:36 +0200 Subject: QTableWidget updating columns in a single row In-Reply-To: <1a87f00d-636d-4795-80d5-7bf196d1177f@googlegroups.com> References: <1a87f00d-636d-4795-80d5-7bf196d1177f@googlegroups.com> Message-ID: On Wed, Apr 24, 2013 at 8:22 AM, Sara Lochtie wrote: > I have written a GUI that gets data sent to it in real time and this data is displayed in a table. Every time data is sent in it is displayed in the table in a new row. My problem is that I would like to have the data just replace the old in the first row. > > The table has 6 columns (A, B, C, D, E, F) I want the new data to continue replacing the old data in the same row unless the data that goes under column A changes, at which point a new row would be added. > > Does anyone have tips on how to approach this? I can post a portion of my code to get a better idea of what I have done. > > > -- > http://mail.python.org/mailman/listinfo/python-list My suggestion: compare the new data?s column A with the existing data (store a copy of the old data somewhere?). If it differs, add a new row; if it doesn?t, change an existing one. If you need help with the exact implementation, show the *entire* code. -- Kwpolska | GPG KEY: 5EAAEA16 stop html mail | always bottom-post http://asciiribbon.org | http://caliburn.nl/topposting.html From sara.lochtie at gmail.com Wed Apr 24 13:12:40 2013 From: sara.lochtie at gmail.com (Sara Lochtie) Date: Wed, 24 Apr 2013 10:12:40 -0700 (PDT) Subject: QTableWidget updating columns in a single row In-Reply-To: <1a87f00d-636d-4795-80d5-7bf196d1177f@googlegroups.com> References: <1a87f00d-636d-4795-80d5-7bf196d1177f@googlegroups.com> Message-ID: <5c8ead62-ebc8-429c-a531-9592a958983d@googlegroups.com> On Tuesday, April 23, 2013 11:22:29 PM UTC-7, Sara Lochtie wrote: > I have written a GUI that gets data sent to it in real time and this data is displayed in a table. Every time data is sent in it is displayed in the table in a new row. My problem is that I would like to have the data just replace the old in the first row. > > > > The table has 6 columns (A, B, C, D, E, F) I want the new data to continue replacing the old data in the same row unless the data that goes under column A changes, at which point a new row would be added. > > > > Does anyone have tips on how to approach this? I can post a portion of my code to get a better idea of what I have done. So that is where I am stuck. I don't how to compare them and I am trying to avoiding saving the data to a file. This is the code that I have: if msg.arg2() != ERROR: entry = (A, B, C, D, E, F) self.data.append(entry) data = self.data # Display how many runs occurred self.statusBar().showMessage('Data read. %s Run(s) Occurred.' % self.runCount) # Populates table by adding only new entries to the end of the table lastRow = self.table.rowCount() self.table.setRowCount(len(data)) for entryPos in range(lastRow, len(data)): for fieldPos in range(6): item = QtGui.QTableWidgetItem(str(data[entryPos][fieldPos])) self.table.setItem(entryPos, fieldPos, item) self.table.resizeColumnsToContents() self.table.horizontalHeader().setStretchLastSection(True) self.currentRunLabel.setText('Current Run: ' + str(self.runCount)) self.currentLineLabel.setText('Number of lines: ' + str(len(self.data))) print('End of %s. run: %s. entries found' % (self.runCount, len(self.data))) From kwpolska at gmail.com Wed Apr 24 13:57:26 2013 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Wed, 24 Apr 2013 19:57:26 +0200 Subject: QTableWidget updating columns in a single row In-Reply-To: <5c8ead62-ebc8-429c-a531-9592a958983d@googlegroups.com> References: <1a87f00d-636d-4795-80d5-7bf196d1177f@googlegroups.com> <5c8ead62-ebc8-429c-a531-9592a958983d@googlegroups.com> Message-ID: On Wed, Apr 24, 2013 at 7:12 PM, Sara Lochtie wrote: > So that is where I am stuck. I don't how to compare them and I am trying to avoiding saving the data to a file. To a file? Just store it in a class attribute and you will be fine. You have it in self.data already. Unless that structure doesn?t work, then ?mirror? your table in a Python array. (alternatively, you could query QTableWidgetItem.text() for every existing item, but that?s crazy.) -- Kwpolska | GPG KEY: 5EAAEA16 stop html mail | always bottom-post http://asciiribbon.org | http://caliburn.nl/topposting.html From vincent.vandevyvre at swing.be Wed Apr 24 14:51:04 2013 From: vincent.vandevyvre at swing.be (Vincent Vande Vyvre) Date: Wed, 24 Apr 2013 20:51:04 +0200 Subject: QTableWidget updating columns in a single row In-Reply-To: <5c8ead62-ebc8-429c-a531-9592a958983d@googlegroups.com> References: <1a87f00d-636d-4795-80d5-7bf196d1177f@googlegroups.com> <5c8ead62-ebc8-429c-a531-9592a958983d@googlegroups.com> Message-ID: <51782998.8000505@swing.be> Le 24/04/2013 19:12, Sara Lochtie a ?crit : > On Tuesday, April 23, 2013 11:22:29 PM UTC-7, Sara Lochtie wrote: >> I have written a GUI that gets data sent to it in real time and this data is displayed in a table. Every time data is sent in it is displayed in the table in a new row. My problem is that I would like to have the data just replace the old in the first row. >> >> >> >> The table has 6 columns (A, B, C, D, E, F) I want the new data to continue replacing the old data in the same row unless the data that goes under column A changes, at which point a new row would be added. >> >> >> >> Does anyone have tips on how to approach this? I can post a portion of my code to get a better idea of what I have done. > So that is where I am stuck. I don't how to compare them and I am trying to avoiding saving the data to a file. > > This is the code that I have: > > > > > > if msg.arg2() != ERROR: > entry = (A, B, C, D, E, F) > self.data.append(entry) > > data = self.data > > # Display how many runs occurred > self.statusBar().showMessage('Data read. %s Run(s) Occurred.' % self.runCount) > > # Populates table by adding only new entries to the end of the table > lastRow = self.table.rowCount() > self.table.setRowCount(len(data)) > for entryPos in range(lastRow, len(data)): > for fieldPos in range(6): > item = QtGui.QTableWidgetItem(str(data[entryPos][fieldPos])) > self.table.setItem(entryPos, fieldPos, item) > self.table.resizeColumnsToContents() > self.table.horizontalHeader().setStretchLastSection(True) > self.currentRunLabel.setText('Current Run: ' + str(self.runCount)) > self.currentLineLabel.setText('Number of lines: ' + str(len(self.data))) > print('End of %s. run: %s. entries found' % (self.runCount, len(self.data))) As sayed by Chris "Kwpolska", you can compare the new data with the data of the first row. Something like that: # Get the content of row 0, column A first = str(self.table.item(0, 0).text()) for entryPos in range(lastRow, len(data)): if str(data[entryPos][0]) == first: self.update_first_row(data[entryPos]) else: self.add_new_row(data[entryPos]) -- Vincent V.V. Oqapy . Qarte . PaQager From sara.lochtie at gmail.com Fri Apr 26 15:14:11 2013 From: sara.lochtie at gmail.com (Sara Lochtie) Date: Fri, 26 Apr 2013 12:14:11 -0700 (PDT) Subject: QTableWidget updating columns in a single row In-Reply-To: References: <1a87f00d-636d-4795-80d5-7bf196d1177f@googlegroups.com> <5c8ead62-ebc8-429c-a531-9592a958983d@googlegroups.com> Message-ID: <2eebd06b-67d8-47ef-b297-5ed866f98582@googlegroups.com> On Wednesday, April 24, 2013 11:51:04 AM UTC-7, Vincent Vande Vyvre wrote: Thanks. I think I should be able to figure out from here. I appreciate all of the help! > Le 24/04/2013 19:12, Sara Lochtie a ?crit : > > > On Tuesday, April 23, 2013 11:22:29 PM UTC-7, Sara Lochtie wrote: > > >> I have written a GUI that gets data sent to it in real time and this data is displayed in a table. Every time data is sent in it is displayed in the table in a new row. My problem is that I would like to have the data just replace the old in the first row. > > >> > > >> > > >> > > >> The table has 6 columns (A, B, C, D, E, F) I want the new data to continue replacing the old data in the same row unless the data that goes under column A changes, at which point a new row would be added. > > >> > > >> > > >> > > >> Does anyone have tips on how to approach this? I can post a portion of my code to get a better idea of what I have done. > > > So that is where I am stuck. I don't how to compare them and I am trying to avoiding saving the data to a file. > > > > > > This is the code that I have: > > > > > > > > > > > > > > > > > > if msg.arg2() != ERROR: > > > entry = (A, B, C, D, E, F) > > > self.data.append(entry) > > > > > > data = self.data > > > > > > # Display how many runs occurred > > > self.statusBar().showMessage('Data read. %s Run(s) Occurred.' % self.runCount) > > > > > > # Populates table by adding only new entries to the end of the table > > > lastRow = self.table.rowCount() > > > self.table.setRowCount(len(data)) > > > for entryPos in range(lastRow, len(data)): > > > for fieldPos in range(6): > > > item = QtGui.QTableWidgetItem(str(data[entryPos][fieldPos])) > > > self.table.setItem(entryPos, fieldPos, item) > > > self.table.resizeColumnsToContents() > > > self.table.horizontalHeader().setStretchLastSection(True) > > > self.currentRunLabel.setText('Current Run: ' + str(self.runCount)) > > > self.currentLineLabel.setText('Number of lines: ' + str(len(self.data))) > > > print('End of %s. run: %s. entries found' % (self.runCount, len(self.data))) > > As sayed by Chris "Kwpolska", you can compare the new data with the data > > of the first row. > > > > Something like that: > > > > # Get the content of row 0, column A > > first = str(self.table.item(0, 0).text()) > > > > for entryPos in range(lastRow, len(data)): > > if str(data[entryPos][0]) == first: > > self.update_first_row(data[entryPos]) > > > > else: > > self.add_new_row(data[entryPos]) > > -- > > Vincent V.V. > > Oqapy . Qarte > > . PaQager From jaorozco at estudiantes.uci.cu Wed Apr 24 02:05:50 2013 From: jaorozco at estudiantes.uci.cu (Jorge Alberto Diaz Orozco) Date: Wed, 24 Apr 2013 02:05:50 -0400 (EDT) Subject: examples of pyraknet In-Reply-To: Message-ID: <03558163-c17d-486d-aab3-a525bcce7f9a@ucimail4.uci.cu> do anyone has examples of pyraknet??? I've being seen these ones (http://nullege.com/codes/search/pyraknet) but I still don't understand lot of things about it and I can't find anything else. http://www.uci.cu From pabloblo85 at gmail.com Wed Apr 24 03:33:30 2013 From: pabloblo85 at gmail.com (pabloblo85 at gmail.com) Date: Wed, 24 Apr 2013 00:33:30 -0700 (PDT) Subject: Fixing escaped characters python-xbee Message-ID: <704e1981-1e13-4030-b4ca-a7305ec98b32@googlegroups.com> I am using a XBee to receive data from an arduino network. But they have AP=2 which means escaped characters are used when a 11 or 13 appears (and some more...) When this occurs, XBee sends 7D and inmediatly XOR operation with char and 0x20. I am trying to recover the original character in python but I don't know ho to do it. I tried something like this: read = ser.read(4) #Read 4 chars from serial port for x in range (0,4): if(toHex(read[x]) != '7d'): #toHex converts it to hexadecimal just for checking purposes if(x < 3): read[x] = logical_xor(read[x+1], 20) #XOR for y in range (x+1,3): read[y] = read[y+1] read[3] = ser.read() else: read[x] = logical_xor(ser.read(), 20) #XOR data = struct.unpack(' References: <704e1981-1e13-4030-b4ca-a7305ec98b32@googlegroups.com> Message-ID: <5177B995.10200@mrabarnett.plus.com> On 24/04/2013 08:33, pabloblo85 at gmail.com wrote: > I am using a XBee to receive data from an arduino network. > > But they have AP=2 which means escaped characters are used when a 11 or 13 appears (and some more...) > > When this occurs, XBee sends 7D and inmediatly XOR operation with char and 0x20. > > I am trying to recover the original character in python but I don't know ho to do it. > > I tried something like this: > > read = ser.read(4) #Read 4 chars from serial port > for x in range (0,4): > if(toHex(read[x]) != '7d'): #toHex converts it to hexadecimal just for checking purposes > if(x < 3): > read[x] = logical_xor(read[x+1], 20) #XOR > for y in range (x+1,3): > read[y] = read[y+1] > read[3] = ser.read() > else: > read[x] = logical_xor(ser.read(), 20) #XOR > > data = struct.unpack(' > logical_xor is: > > def logical_xor(str1, str2): > return bool(str1) ^ bool(str2) > > I check if 7D character is in the first 3 chars read, I use the next char to convert it, if it is the 4th, I read another one. > > But I read in python strings are inmutables and I can't change their value once they have one. > > What would you do in this case? I started some days ago with python and I don't know how to solve this kind of things... > You could try converting to a list, which is mutable. # Python 3 read = list(ser.read(4)) pos = 0 try: while True: pos = read.index(0x7D, pos) del read[pos] read.extend(ser.read()) read[pos] ^= 0x20 except ValueError: # There are no (more) 0x7D in the data. pass data = struct.unpack(' Message-ID: pabloblo85 at gmail.com wrote: > I am using a XBee to receive data from an arduino network. > > But they have AP=2 which means escaped characters are used when a 11 or 13 > appears (and some more...) > > When this occurs, XBee sends 7D and inmediatly XOR operation with char and > 0x20. > > I am trying to recover the original character in python but I don't know > ho to do it. > > I tried something like this: > > read = ser.read(4) #Read 4 chars from serial port > for x in range (0,4): > if(toHex(read[x]) != '7d'): #toHex converts it to hexadecimal just for > checking purposes if(x < 3): > read[x] = logical_xor(read[x+1], 20) #XOR > for y in range (x+1,3): > read[y] = read[y+1] > read[3] = ser.read() > else: > read[x] = logical_xor(ser.read(), 20) #XOR > > data = struct.unpack(' > logical_xor is: > > def logical_xor(str1, str2): > return bool(str1) ^ bool(str2) > > I check if 7D character is in the first 3 chars read, I use the next char > to convert it, if it is the 4th, I read another one. > > But I read in python strings are inmutables and I can't change their value > once they have one. > > What would you do in this case? I started some days ago with python and I > don't know how to solve this kind of things... As you cannot change the old string you have to compose a new one. I think the simplest approach is to always read one byte, and if it's the escape marker read another one and decode it. The decoded bytes/chars are then stored in a list and finally joined: # Python 2 # untested def read_nbytes(ser, n): accu = [] for i in xrange(n): b = ser.read(1) if b == "\x7d": b = chr(ord(ser.read(1)) ^ 0x20) accu.append(b) return "".join(accu) b = read_nbytes(ser, 4) data = struct.unpack(' References: <704e1981-1e13-4030-b4ca-a7305ec98b32@googlegroups.com> Message-ID: > > the following in gmane.comp.python.general: > > > > > I am using a XBee to receive data from an arduino network. > > > > > > But they have AP=2 which means escaped characters are used when a 11 or 13 appears (and some more...) > > > > > > When this occurs, XBee sends 7D and inmediatly XOR operation with char and 0x20. > > > > > > I am trying to recover the original character in python but I don't know ho to do it. > > > > > > I tried something like this: > > > > > > read = ser.read(4) #Read 4 chars from serial port > > > > Why read 4 at a time if you need to detect the escape marker... > > > > PSEUDO_CODE -- UNTESTED: > > > > for c in ser.read(): #presumes it will function as an iterator > > if ord(c) == 0x7D: > > c =chr(ord(ser.read(1)) ^ 0x20) > > #do something with c (save to a list for later joining as a > > string?) > > #probably need some condition to exit the read loop too > > > def logical_xor(str1, str2): > > > return bool(str1) ^ bool(str2) > > > > > bool() returns True or False based on the argument... Any non-empty > > string will be True. Instead what you want is to x-or the bits of the > > character itself. > > -- It works! Thank you so much. Now I can go ahead with my work! From roozbeh73 at gmail.com Wed Apr 24 05:13:45 2013 From: roozbeh73 at gmail.com (Roozbeh) Date: Wed, 24 Apr 2013 02:13:45 -0700 (PDT) Subject: Using SciPy in application Message-ID: <437ea69e-fa1b-42e9-a09a-23b6f94182f2@googlegroups.com> Hi all, I want to use spline interpolation function from SciPy in an application and at the same time, I don't want the end user to have to install SciPy separately. Is there a way around this problem? Thanks in advance for your help From oscar.j.benjamin at gmail.com Wed Apr 24 07:04:27 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 24 Apr 2013 12:04:27 +0100 Subject: Using SciPy in application In-Reply-To: <437ea69e-fa1b-42e9-a09a-23b6f94182f2@googlegroups.com> References: <437ea69e-fa1b-42e9-a09a-23b6f94182f2@googlegroups.com> Message-ID: On 24 April 2013 10:13, Roozbeh wrote: > > I want to use spline interpolation function from SciPy in an application and at the same time, I don't want the end user to have to install SciPy separately. Is there a way around this problem? They cannot use the function from scipy if scipy is not installed. There are three ways round this problem: 1) Rewrite the interpolation function you need in your own code. 2) Require the user to install scipy. 3) Require the user to install some other package that has interpolation functions. Rewriting the interpolation function is probably not that difficult depending on the type of interpolation you're using. Oscar From robert.kern at gmail.com Wed Apr 24 07:10:57 2013 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Apr 2013 16:40:57 +0530 Subject: Using SciPy in application In-Reply-To: References: <437ea69e-fa1b-42e9-a09a-23b6f94182f2@googlegroups.com> Message-ID: On 2013-04-24 16:34, Oscar Benjamin wrote: > On 24 April 2013 10:13, Roozbeh wrote: >> >> I want to use spline interpolation function from SciPy in an application and at the same time, I don't want the end user to have to install SciPy separately. Is there a way around this problem? > > They cannot use the function from scipy if scipy is not installed. > There are three ways round this problem: > 1) Rewrite the interpolation function you need in your own code. Variant: 1.a) Copy the interpolation code from scipy into your own code. -- 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 roozbeh73 at gmail.com Wed Apr 24 07:26:54 2013 From: roozbeh73 at gmail.com (Roozbeh) Date: Wed, 24 Apr 2013 04:26:54 -0700 (PDT) Subject: Using SciPy in application In-Reply-To: <437ea69e-fa1b-42e9-a09a-23b6f94182f2@googlegroups.com> References: <437ea69e-fa1b-42e9-a09a-23b6f94182f2@googlegroups.com> Message-ID: <3f26ef88-c1ab-4acc-b153-f47dbda1b27e@googlegroups.com> On Wednesday, April 24, 2013 11:13:45 AM UTC+2, Roozbeh wrote: > Hi all, I want to use spline interpolation function from SciPy in an application and at the same time, I don't want the end user to have to install SciPy separately. Is there a way around this problem? Thanks in advance for your help From roozbeh73 at gmail.com Wed Apr 24 07:29:37 2013 From: roozbeh73 at gmail.com (Roozbeh) Date: Wed, 24 Apr 2013 04:29:37 -0700 (PDT) Subject: Using SciPy in application In-Reply-To: <437ea69e-fa1b-42e9-a09a-23b6f94182f2@googlegroups.com> References: <437ea69e-fa1b-42e9-a09a-23b6f94182f2@googlegroups.com> Message-ID: On Wednesday, April 24, 2013 11:13:45 AM UTC+2, Roozbeh wrote: > Hi all, I want to use spline interpolation function from SciPy in an application and at the same time, I don't want the end user to have to install SciPy separately. Is there a way around this problem? Thanks in advance for your help The thing is that the SciPy code for spline interpolation imports NumPy which also I don't want to use. So, I think I will have to write the code myself I guess. From roozbeh73 at gmail.com Wed Apr 24 07:34:44 2013 From: roozbeh73 at gmail.com (Roozbeh) Date: Wed, 24 Apr 2013 04:34:44 -0700 (PDT) Subject: Using SciPy in application In-Reply-To: <437ea69e-fa1b-42e9-a09a-23b6f94182f2@googlegroups.com> References: <437ea69e-fa1b-42e9-a09a-23b6f94182f2@googlegroups.com> Message-ID: <411a5ceb-b575-4217-b39b-504fdef4b4d4@googlegroups.com> On Wednesday, April 24, 2013 11:13:45 AM UTC+2, Roozbeh wrote: > Hi all, I want to use spline interpolation function from SciPy in an application and at the same time, I don't want the end user to have to install SciPy separately. Is there a way around this problem? Thanks in advance for your help Any idea where can I find the recipe for the spline interpolation that does not rely on NumPy and/or SciPy and is written pure Python (no C code)? From robert.kern at gmail.com Wed Apr 24 07:40:14 2013 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Apr 2013 17:10:14 +0530 Subject: Using SciPy in application In-Reply-To: <411a5ceb-b575-4217-b39b-504fdef4b4d4@googlegroups.com> References: <437ea69e-fa1b-42e9-a09a-23b6f94182f2@googlegroups.com> <411a5ceb-b575-4217-b39b-504fdef4b4d4@googlegroups.com> Message-ID: On 2013-04-24 17:04, Roozbeh wrote: > On Wednesday, April 24, 2013 11:13:45 AM UTC+2, Roozbeh wrote: >> Hi all, I want to use spline interpolation function from SciPy in an application and at the same time, I don't want the end user to have to install SciPy separately. Is there a way around this problem? Thanks in advance for your help > > Any idea where can I find the recipe for the spline interpolation that does not rely on NumPy and/or SciPy and is written pure Python (no C code)? If Google can't find it, it probably doesn't exist. Very few people would do this without numpy. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From zdoor at xs4all.nl Wed Apr 24 07:57:39 2013 From: zdoor at xs4all.nl (Alex van der Spek) Date: 24 Apr 2013 11:57:39 GMT Subject: Using SciPy in application References: <437ea69e-fa1b-42e9-a09a-23b6f94182f2@googlegroups.com> <411a5ceb-b575-4217-b39b-504fdef4b4d4@googlegroups.com> Message-ID: <5177c8b3$0$15972$e4fe514c@news2.news.xs4all.nl> On Wed, 24 Apr 2013 04:34:44 -0700, Roozbeh wrote: The scipy interpolation routines (splev, splrep, etc.) are on netlib: http://www.netlib.org/dierckx/ This gives you FORTRAN source codes which you will have to compile yourself to either a DLL or an SO. Call them from python using ctypes. I have done that for a number of the dierckx routines. No problems at all. Hope this helps, Alex van der Spek > On Wednesday, April 24, 2013 11:13:45 AM UTC+2, Roozbeh wrote: >> Hi all, I want to use spline interpolation function from SciPy in an >> application and at the same time, I don't want the end user to have to >> install SciPy separately. Is there a way around this problem? Thanks in >> advance for your help > > Any idea where can I find the recipe for the spline interpolation that > does not rely on NumPy and/or SciPy and is written pure Python (no C > code)? From maarten.sneep at knmi.nl Wed Apr 24 10:49:44 2013 From: maarten.sneep at knmi.nl (Maarten) Date: Wed, 24 Apr 2013 07:49:44 -0700 (PDT) Subject: Using SciPy in application In-Reply-To: References: <437ea69e-fa1b-42e9-a09a-23b6f94182f2@googlegroups.com> <411a5ceb-b575-4217-b39b-504fdef4b4d4@googlegroups.com> Message-ID: <0c70e98a-aa20-4128-9389-80c56c0e4c21@googlegroups.com> On Wednesday, April 24, 2013 1:40:14 PM UTC+2, Robert Kern wrote: > On 2013-04-24 17:04, Roozbeh wrote: > > > On Wednesday, April 24, 2013 11:13:45 AM UTC+2, Roozbeh wrote: > > >> Hi all, I want to use spline interpolation function from SciPy in an application and at the same time, I don't want the end user to have to install SciPy separately. Is there a way around this problem? Thanks in advance for your help > > > Any idea where can I find the recipe for the spline interpolation that does not rely on NumPy and/or SciPy and is written pure Python (no C code)? > > > If Google can't find it, it probably doesn't exist. Very few people would do this without numpy. A trivial 'pure python spline' google search yields this: http://urchin.earth.li/~twic/splines.py (Warning: old code, python 2.2 era). Maarten From miki.tebeka at gmail.com Wed Apr 24 09:52:50 2013 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 24 Apr 2013 06:52:50 -0700 (PDT) Subject: Using SciPy in application In-Reply-To: <437ea69e-fa1b-42e9-a09a-23b6f94182f2@googlegroups.com> References: <437ea69e-fa1b-42e9-a09a-23b6f94182f2@googlegroups.com> Message-ID: <4038d07a-abcf-4e23-9bd7-a2dfc8293f59@googlegroups.com> > I want to use spline interpolation function from SciPy in an application and at the same time, I don't want the end user to have to install SciPy separately. You can pack you application with py2exe, pyinstaller ... and then they won't even need to install Python. Another option (which is not always possible) is to make you application a web site and then only you need to install SciPy on the server. From roozbeh73 at gmail.com Wed Apr 24 10:41:53 2013 From: roozbeh73 at gmail.com (Roozbeh) Date: Wed, 24 Apr 2013 07:41:53 -0700 (PDT) Subject: Using SciPy in application In-Reply-To: <4038d07a-abcf-4e23-9bd7-a2dfc8293f59@googlegroups.com> References: <437ea69e-fa1b-42e9-a09a-23b6f94182f2@googlegroups.com> <4038d07a-abcf-4e23-9bd7-a2dfc8293f59@googlegroups.com> Message-ID: <57adee3e-986d-4b23-bf2c-38bd3b0c8e4f@googlegroups.com> On Wednesday, April 24, 2013 3:52:50 PM UTC+2, Miki Tebeka wrote: > > I want to use spline interpolation function from SciPy in an application and at the same time, I don't want the end user to have to install SciPy separately. You can pack you application with py2exe, pyinstaller ... and then they won't even need to install Python. Another option (which is not always possible) is to make you application a web site and then only you need to install SciPy on the server. I thought about the py2exe option but the problem is, this application is a plug-in written for Abaqus CAE and hence it will use the python version that comes with Abaqus CAE distribution and Abaqus must be able to compile the Python codes every time on the start-up otherwise it won't recognize the plug-in and thats why SciPy and NumPy are also not an option. I guess as Alex said, I will have to use DLLs or write it myself. From invalid at invalid.invalid Wed Apr 24 15:18:40 2013 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 24 Apr 2013 19:18:40 +0000 (UTC) Subject: Using SciPy in application References: <437ea69e-fa1b-42e9-a09a-23b6f94182f2@googlegroups.com> Message-ID: On 2013-04-24, Roozbeh wrote: > I want to use spline interpolation function from SciPy in an > application and at the same time, I don't want the end user to have > to install SciPy separately. Is there a way around this problem? You could bundle you app along with python and SciPy and whatever other libraries are required using py2exe, py2app, cx_Freeze, Freeze, etc. -- Grant Edwards grant.b.edwards Yow! JAPAN is a WONDERFUL at planet -- I wonder if we'll gmail.com ever reach their level of COMPARATIVE SHOPPING ... From wolfgang.maier at biologie.uni-freiburg.de Wed Apr 24 09:36:48 2013 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Wed, 24 Apr 2013 13:36:48 +0000 (UTC) Subject: ALL function arguments in a common dictionary Message-ID: Hi everybody, what is the recommended way of stuffing *all* function arguments (not just the ones passed by **kwargs) into a common dictionary? The following sort of works when used as the first block in a function: try: kwargs.update(locals()) except NameError: kwargs = locals().copy() except that it's nesting pre-existing kwargs. Thanks for your help, Wolfgang From fabiosantosart at gmail.com Wed Apr 24 09:48:56 2013 From: fabiosantosart at gmail.com (=?ISO-8859-1?Q?F=E1bio_Santos?=) Date: Wed, 24 Apr 2013 14:48:56 +0100 Subject: ALL function arguments in a common dictionary In-Reply-To: References: Message-ID: A quick hack: >>> from inspect import getargspec >>> >>> def func(a, b, c=3, **kwargs): ... out_dict = {} ... args, _, keywords, _ = getargspec(func) ... for argname in args: ... out_dict[argname] = locals()[argname] ... if keywords: ... out_dict.update(locals()[keywords]) ... return out_dict ... >>> func(1,2, gah=123) {'a': 1, 'c': 3, 'b': 2, 'gah': 123} >>> On Wed, Apr 24, 2013 at 2:36 PM, Wolfgang Maier wrote: > Hi everybody, > what is the recommended way of stuffing *all* function arguments (not just > the ones passed by **kwargs) into a common dictionary? > > The following sort of works when used as the first block in a function: > try: > kwargs.update(locals()) > except NameError: > kwargs = locals().copy() > > except that it's nesting pre-existing kwargs. > > Thanks for your help, > Wolfgang > > -- > http://mail.python.org/mailman/listinfo/python-list -- F?bio Santos From jkn+gg at nicorp.co.uk Wed Apr 24 12:54:14 2013 From: jkn+gg at nicorp.co.uk (The Night Tripper) Date: Wed, 24 Apr 2013 17:54:14 +0100 Subject: improvements sought re. logging across modules Message-ID: Hi all I have a small suite of python modules, say A.py B.py C.py which can be invoked in a variety of ways. eg. 1) A.py is invoked directly; this imports and uses B.py and C.py 2) B.py is invoked; this imports and uses A.py and C.py I use the logging module in all of these python modules, and I want to be able to use a single logger across the entire suite of whichever set of scripts is running. The way I do this at the moment is to have a separate module mylogger.py: == mylogger.py == import logging class MyLogger: #using python 2.4 ;-o def __init__(self): self.log = logging.getLogger(MY_APP_NAME) def setupLogging(self): self.log.setlevel(logging.DEBUG) # ... # our singleton logging object mylogger = Mylogger() # EOF and then in my other modules A.py, B.py etc. I have something like: == A.py == import mylogger gLog = mylogger.mylogger if __name__ == "__main__": gLog.setupLogging() gLog.info("Module A running as main") main() #EOF == B.py == import mylogger gLog = mylogger.mylogger if __name__ == "__main__": gLog.setupLogging() gLog.info("Module B running as main") main() # EOF This works, but I can't help thinking I'm missing a trick here. Any suggestions? Thanks j^n From fabiosantosart at gmail.com Wed Apr 24 13:29:35 2013 From: fabiosantosart at gmail.com (=?ISO-8859-1?Q?F=E1bio_Santos?=) Date: Wed, 24 Apr 2013 18:29:35 +0100 Subject: improvements sought re. logging across modules In-Reply-To: References: Message-ID: Maybe import mylogger.mylogger as gLog? I don't know what you mean by "missing a trick". Your example seems pretty pythonic to me, except for the fact that you use a singleton where you could have a couple of functions and use the module as the namespace. On 24 Apr 2013 17:58, "The Night Tripper" wrote: > Hi all > I have a small suite of python modules, say > > A.py > B.py > C.py > > which can be invoked in a variety of ways. eg. > > 1) A.py is invoked directly; this imports and uses B.py and C.py > > 2) B.py is invoked; this imports and uses A.py and C.py > > I use the logging module in all of these python modules, and I want to be > able to use a single logger across the entire suite of whichever set of > scripts is running. > > The way I do this at the moment is to have a separate module mylogger.py: > > == mylogger.py == > > import logging > > class MyLogger: #using python 2.4 ;-o > def __init__(self): > self.log = logging.getLogger(MY_APP_NAME) > def setupLogging(self): > self.log.setlevel(logging.DEBUG) > # ... > > # our singleton logging object > mylogger = Mylogger() > # EOF > > and then in my other modules A.py, B.py etc. I have something like: > > == A.py == > > import mylogger > gLog = mylogger.mylogger > > if __name__ == "__main__": > gLog.setupLogging() > gLog.info("Module A running as main") > main() > #EOF > > == B.py == > > import mylogger > gLog = mylogger.mylogger > > if __name__ == "__main__": > gLog.setupLogging() > gLog.info("Module B running as main") > main() > # EOF > > This works, but I can't help thinking I'm missing a trick here. Any > suggestions? > > Thanks > j^n > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kwpolska at gmail.com Wed Apr 24 13:43:31 2013 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Wed, 24 Apr 2013 19:43:31 +0200 Subject: improvements sought re. logging across modules In-Reply-To: References: Message-ID: On Wed, Apr 24, 2013 at 6:54 PM, The Night Tripper wrote: > Hi all > I have a small suite of python modules, say > > A.py > B.py > C.py > > which can be invoked in a variety of ways. eg. > > 1) A.py is invoked directly; this imports and uses B.py and C.py > > 2) B.py is invoked; this imports and uses A.py and C.py > > I use the logging module in all of these python modules, and I want to be > able to use a single logger across the entire suite of whichever set of > scripts is running. > > The way I do this at the moment is to have a separate module mylogger.py: > > == mylogger.py == > > import logging > > class MyLogger: #using python 2.4 ;-o > def __init__(self): > self.log = logging.getLogger(MY_APP_NAME) > def setupLogging(self): > self.log.setlevel(logging.DEBUG) > # ... > > # our singleton logging object > mylogger = Mylogger() > # EOF > > and then in my other modules A.py, B.py etc. I have something like: > > == A.py == > > import mylogger > gLog = mylogger.mylogger > > if __name__ == "__main__": > gLog.setupLogging() > gLog.info("Module A running as main") > main() > #EOF > > == B.py == > > import mylogger > gLog = mylogger.mylogger > > if __name__ == "__main__": > gLog.setupLogging() > gLog.info("Module B running as main") > main() > # EOF > > This works, but I can't help thinking I'm missing a trick here. Any > suggestions? > > Thanks > j^n > > -- > http://mail.python.org/mailman/listinfo/python-list No need to do such magic. Just set logging up as you would normally. The first logging instance should pick up logs from everywhere. For example: === aurqt/aqds.py === class AQDS: logging.basicConfig(format='%(asctime)-15s [%(levelname)-7s] ' ':%(name)-10s: %(message)s', filename=os.path.join(confdir, 'aurqt.log'), level=logging.DEBUG) log = logging.getLogger('aurqt') console = logging.StreamHandler() console.setLevel(logging.INFO) console.setFormatter(logging.Formatter('[%(levelname)-7s] ' ':%(name)-10s: %(message)s')) logging.getLogger('').addHandler(console) log.info('*** aurqt v' + __version__) === pkgbuilder/pbds.py === class PBDS: logging.basicConfig(format='%(asctime)-15s [%(levelname)-7s] ' ':%(name)-10s: %(message)s', filename=os.path.join(confdir, 'pkgbuilder.log'), level=logging.DEBUG) log = logging.getLogger('pkgbuilder') log.info('*** PKGBUILDer v' + __version__) === aurqt/__init__.py === from .aqds import AQDS DS = AQDS() import pkgbuilder # ? also imports pkgbuilder.DS = pkgbuilder.pbds.PBDS() === bin/aurqt output === [INFO ] :aurqt : *** aurqt v0.1.0 [INFO ] :requests.packages.urllib3.connectionpool: Starting new HTTPS connection (1): aur.archlinux.org [WARNING] :pkgbuilder: tty-clock version is a date, ignored for downgrade. === {confdir}/aurqt.log === 2013-04-24 19:34:21,079 [INFO ] :aurqt : *** aurqt v0.1.0 2013-04-24 19:35:19,096 [WARNING] :requests.packages.urllib3.connectionpool: Starting new HTTPS connection (1): aur.archlinux.org 2013-04-24 19:35:21,004 [WARNING] :pkgbuilder: tty-clock version is a date, ignored for downgrade. -- Kwpolska | GPG KEY: 5EAAEA16 stop html mail | always bottom-post http://asciiribbon.org | http://caliburn.nl/topposting.html From davea at davea.name Wed Apr 24 13:55:12 2013 From: davea at davea.name (Dave Angel) Date: Wed, 24 Apr 2013 13:55:12 -0400 Subject: improvements sought re. logging across modules In-Reply-To: References: Message-ID: <51781C80.2020406@davea.name> On 04/24/2013 12:54 PM, The Night Tripper wrote: > Hi all > I have a small suite of python modules, say > > A.py > B.py > C.py > > which can be invoked in a variety of ways. eg. > > 1) A.py is invoked directly; this imports and uses B.py and C.py > > 2) B.py is invoked; this imports and uses A.py and C.py > Right there you have a potential problem. Unless you make those imports conditional, you have an import loop, which can be a minor problem, or a big one. Whenever you find loops in the import call tree, please break them. The best way is to move the interdependencies into yet another module, and let both A and B import that one. -- DaveA From danielkersgaard at gmail.com Wed Apr 24 13:08:13 2013 From: danielkersgaard at gmail.com (Daniel Kersgaard) Date: Wed, 24 Apr 2013 10:08:13 -0700 (PDT) Subject: My gui Message-ID: <09b96d6b-6db3-42a2-88d3-5fe16984fed1@googlegroups.com> Today, being the last day of lectures at school, my instructor ran briefly through Tkninter and GUIs. I'd been looking forward to this particular lesson all semester, but when I got home and copied a sample program from my textbook verbatim, IDLE does nothing. No error, no nothing. Any ideas? Here is the code from my program. I'm not sure if this is appropriate, but suggestions are helpful. import tkinter import tkinter.messagebox class MyGui: def _init_(self): self.main_window = tkinter.Tk() self.top_frame = tkinter.Frame(self.main_window) self.bottom_frame = tkinter.Frame(self.main_window) self.prompt_label = tkinter.Label(self.top_frame, text = 'Enter a distance in Kilometers: ') self.kilo_entry = tkinter.Entry(self.top_frame, width = 10) self.prompt_label.pack(side = 'left') self.kilo_entry.pack(side = 'left') self.calc_button = tkinter.Button(self.bottom_frame, text = 'Convert', command = self.convert) self.quit_button = tkinter.Button(self.bottom_frame, text = 'Quit', command = self.main_window.destroy) self.calc_button.pack(side = 'left') self.quit_button.pack(side = 'left') self.top_frame.pack() self.bottom_frame.pack() tkinter.mainloop() def convert(self): kilo = float(self.kilo_entry.get()) miles = kilo * 0.6214 tkinter.messagebox.showinfo('Result', str(kilo) + ' kilometers is equal to ' + str(miles) + 'miles.') poop = MyGui() From davea at davea.name Wed Apr 24 13:46:22 2013 From: davea at davea.name (Dave Angel) Date: Wed, 24 Apr 2013 13:46:22 -0400 Subject: My gui In-Reply-To: <09b96d6b-6db3-42a2-88d3-5fe16984fed1@googlegroups.com> References: <09b96d6b-6db3-42a2-88d3-5fe16984fed1@googlegroups.com> Message-ID: <51781A6E.2000703@davea.name> On 04/24/2013 01:08 PM, Daniel Kersgaard wrote: > Today, being the last day of lectures at school, my instructor ran briefly through Tkninter and GUIs. I'd been looking forward to this particular lesson all semester, but when I got home and copied a sample program from my textbook verbatim, IDLE does nothing. No error, no nothing. Any ideas? Here is the code from my program. I'm not sure if this is appropriate, but suggestions are helpful. > > import tkinter > import tkinter.messagebox > > class MyGui: > def _init_(self): > self.main_window = tkinter.Tk() > > self.top_frame = tkinter.Frame(self.main_window) > self.bottom_frame = tkinter.Frame(self.main_window) > > self.prompt_label = tkinter.Label(self.top_frame, text = 'Enter a distance in Kilometers: ') > self.kilo_entry = tkinter.Entry(self.top_frame, width = 10) > > self.prompt_label.pack(side = 'left') > self.kilo_entry.pack(side = 'left') > > self.calc_button = tkinter.Button(self.bottom_frame, text = 'Convert', command = self.convert) > > self.quit_button = tkinter.Button(self.bottom_frame, text = 'Quit', command = self.main_window.destroy) > > self.calc_button.pack(side = 'left') > self.quit_button.pack(side = 'left') > > self.top_frame.pack() > self.bottom_frame.pack() > > tkinter.mainloop() > > def convert(self): > kilo = float(self.kilo_entry.get()) > > miles = kilo * 0.6214 > > tkinter.messagebox.showinfo('Result', str(kilo) + ' kilometers is equal to ' + str(miles) + 'miles.') > > poop = MyGui() > I'm not an IDLE user, but I wouldn't be surprised if IDLE interferes with some GUI apps. I'd run your code from the bash prompt. -- DaveA From kwpolska at gmail.com Wed Apr 24 13:53:34 2013 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Wed, 24 Apr 2013 19:53:34 +0200 Subject: My gui In-Reply-To: <09b96d6b-6db3-42a2-88d3-5fe16984fed1@googlegroups.com> References: <09b96d6b-6db3-42a2-88d3-5fe16984fed1@googlegroups.com> Message-ID: On Wed, Apr 24, 2013 at 7:08 PM, Daniel Kersgaard wrote: > Today, being the last day of lectures at school, my instructor ran briefly through Tkninter and GUIs. I'd been looking forward to this particular lesson all semester, but when I got home and copied a sample program from my textbook verbatim, IDLE does nothing. No error, no nothing. Any ideas? Here is the code from my program. I'm not sure if this is appropriate, but suggestions are helpful. > > import tkinter > import tkinter.messagebox > > class MyGui: > def _init_(self): > self.main_window = tkinter.Tk() > > self.top_frame = tkinter.Frame(self.main_window) > self.bottom_frame = tkinter.Frame(self.main_window) > > self.prompt_label = tkinter.Label(self.top_frame, text = 'Enter a distance in Kilometers: ') > self.kilo_entry = tkinter.Entry(self.top_frame, width = 10) > > self.prompt_label.pack(side = 'left') > self.kilo_entry.pack(side = 'left') > > self.calc_button = tkinter.Button(self.bottom_frame, text = 'Convert', command = self.convert) > > self.quit_button = tkinter.Button(self.bottom_frame, text = 'Quit', command = self.main_window.destroy) > > self.calc_button.pack(side = 'left') > self.quit_button.pack(side = 'left') > > self.top_frame.pack() > self.bottom_frame.pack() > > tkinter.mainloop() > > def convert(self): > kilo = float(self.kilo_entry.get()) > > miles = kilo * 0.6214 > > tkinter.messagebox.showinfo('Result', str(kilo) + ' kilometers is equal to ' + str(miles) + 'miles.') > > poop = MyGui() > > -- > http://mail.python.org/mailman/listinfo/python-list poop? Seriously? You aren?t serious about that copying, right? Your code seems to be missing a lot of important stuff. You don?t inherit from tkinter.Frame. Compare your program to the sample ?Hello world!? program: http://docs.python.org/2/library/tkinter.html#a-simple-hello-world-program ? unfortunately, I am not a fan and I am not knowledgeable about tkinter, but I can see a lot of stuff is missing. Please try fixing it and running it _outside of IDLE_, which is also built in Tk. This may cause problems (but don?t worry, the code you pasted doesn?t work anyways.) -- Kwpolska | GPG KEY: 5EAAEA16 stop html mail | always bottom-post http://asciiribbon.org | http://caliburn.nl/topposting.html From arnodel at gmail.com Wed Apr 24 15:42:48 2013 From: arnodel at gmail.com (Arnaud Delobelle) Date: Wed, 24 Apr 2013 20:42:48 +0100 Subject: My gui In-Reply-To: References: <09b96d6b-6db3-42a2-88d3-5fe16984fed1@googlegroups.com> Message-ID: On 24 April 2013 18:53, Chris ?Kwpolska? Warrick wrote: > On Wed, Apr 24, 2013 at 7:08 PM, Daniel Kersgaard > wrote: >> Today, being the last day of lectures at school, my instructor ran briefly through Tkninter and GUIs. I'd been looking forward to this particular lesson all semester, but when I got home and copied a sample program from my textbook verbatim, IDLE does nothing. No error, no nothing. Any ideas? Here is the code from my program. I'm not sure if this is appropriate, but suggestions are helpful. >> >> import tkinter >> import tkinter.messagebox >> >> class MyGui: >> def _init_(self): >> self.main_window = tkinter.Tk() >> >> self.top_frame = tkinter.Frame(self.main_window) >> self.bottom_frame = tkinter.Frame(self.main_window) >> >> self.prompt_label = tkinter.Label(self.top_frame, text = 'Enter a distance in Kilometers: ') >> self.kilo_entry = tkinter.Entry(self.top_frame, width = 10) >> >> self.prompt_label.pack(side = 'left') >> self.kilo_entry.pack(side = 'left') >> >> self.calc_button = tkinter.Button(self.bottom_frame, text = 'Convert', command = self.convert) >> >> self.quit_button = tkinter.Button(self.bottom_frame, text = 'Quit', command = self.main_window.destroy) >> >> self.calc_button.pack(side = 'left') >> self.quit_button.pack(side = 'left') >> >> self.top_frame.pack() >> self.bottom_frame.pack() >> >> tkinter.mainloop() >> >> def convert(self): >> kilo = float(self.kilo_entry.get()) >> >> miles = kilo * 0.6214 >> >> tkinter.messagebox.showinfo('Result', str(kilo) + ' kilometers is equal to ' + str(miles) + 'miles.') >> >> poop = MyGui() >> >> -- >> http://mail.python.org/mailman/listinfo/python-list > > poop? Seriously? You aren?t serious about that copying, right? > > Your code seems to be missing a lot of important stuff. You don?t > inherit from tkinter.Frame. Compare your program to the sample ?Hello > world!? program: His class is not a frame, it's just a container for the tkinter code. It's a bit unusual but it looks correct to me (apart from the single underscores in __init__() as spotted by Ned Batchelder). -- Arnaud From neilc at norwich.edu Wed Apr 24 16:26:39 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 24 Apr 2013 20:26:39 GMT Subject: My gui References: <09b96d6b-6db3-42a2-88d3-5fe16984fed1@googlegroups.com> Message-ID: On 2013-04-24, Arnaud Delobelle wrote: > His class is not a frame, it's just a container for the tkinter > code. It's a bit unusual but it looks correct to me (apart from > the single underscores in __init__() as spotted by Ned > Batchelder). I dunno if it makes any difference, but it's usual to call mainloop of the root window, rather than tkinter.mainloop. -- Neil Cerutti From tjreedy at udel.edu Wed Apr 24 22:51:49 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Wed, 24 Apr 2013 22:51:49 -0400 Subject: My gui In-Reply-To: References: <09b96d6b-6db3-42a2-88d3-5fe16984fed1@googlegroups.com> Message-ID: On 4/24/2013 1:53 PM, Chris ?Kwpolska? Warrick wrote: > Please try fixing it and running it _outside of IDLE_, which is also > built in Tk The default mode of Idle runs user code in a separate process. Editing tkinter code with Idle and running it (in the separate process) should be no problem. From ned at nedbatchelder.com Wed Apr 24 14:08:29 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 24 Apr 2013 14:08:29 -0400 Subject: My gui In-Reply-To: <09b96d6b-6db3-42a2-88d3-5fe16984fed1@googlegroups.com> References: <09b96d6b-6db3-42a2-88d3-5fe16984fed1@googlegroups.com> Message-ID: <51781F9D.4090302@nedbatchelder.com> On 4/24/2013 1:08 PM, Daniel Kersgaard wrote: > Today, being the last day of lectures at school, my instructor ran briefly through Tkninter and GUIs. I'd been looking forward to this particular lesson all semester, but when I got home and copied a sample program from my textbook verbatim, IDLE does nothing. No error, no nothing. Any ideas? Here is the code from my program. I'm not sure if this is appropriate, but suggestions are helpful. > > import tkinter > import tkinter.messagebox > > class MyGui: > def_init_(self): You need to define __init__, not _init_. Python special methods are named with double underscore leading and trailing, and __x__ is pronounced "dunder-x". --Ned. From rosuav at gmail.com Wed Apr 24 23:17:26 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 25 Apr 2013 13:17:26 +1000 Subject: My gui In-Reply-To: <09b96d6b-6db3-42a2-88d3-5fe16984fed1@googlegroups.com> References: <09b96d6b-6db3-42a2-88d3-5fe16984fed1@googlegroups.com> Message-ID: On Thu, Apr 25, 2013 at 3:08 AM, Daniel Kersgaard wrote: > import tkinter > import tkinter.messagebox > > class MyGui: > def _init_(self): > ... all code here > > poop = MyGui() As already mentioned, changing that to __init__ makes everything work (I just tested in Python 3.3 on Windows). But since Python is not Java, there's no reason to bury all this code in a class; just move all that code flush left and abandon the explicit instantiation. The constructor doesn't return until the window's been closed, so there's really no point in returning an object. (Maybe if you remove the mainloop() call, you could possibly make use of two of these sorts of windows, but YAGNI - don't bother with the complexity required to handle multiple simultaneous windows until you have a use-case.) So here's a direct translation to top-level code: import tkinter import tkinter.messagebox def convert(): kilo = float(kilo_entry.get()) miles = kilo * 0.6214 tkinter.messagebox.showinfo('Result', str(kilo) + ' kilometers is equal to ' + str(miles) + 'miles.') main_window = tkinter.Tk() top_frame = tkinter.Frame(main_window) bottom_frame = tkinter.Frame(main_window) prompt_label = tkinter.Label(top_frame, text = 'Enter a distance in Kilometers: ') kilo_entry = tkinter.Entry(top_frame, width = 10) prompt_label.pack(side = 'left') kilo_entry.pack(side = 'left') calc_button = tkinter.Button(bottom_frame, text = 'Convert', command = convert) quit_button = tkinter.Button(bottom_frame, text = 'Quit', command = main_window.destroy) calc_button.pack(side = 'left') quit_button.pack(side = 'left') top_frame.pack() bottom_frame.pack() tkinter.mainloop() -- cut -- (You may want to bury the code inside a main(), but that's optional too.) And here's a slightly modified version: import tkinter import tkinter.messagebox main_window = tkinter.Tk() top_frame = tkinter.Frame(main_window) bottom_frame = tkinter.Frame(main_window) tkinter.Label(top_frame, text = 'Enter a distance in Kilometers: ').pack(side = 'left') km_entry = tkinter.Entry(top_frame, width = 10); km_entry.pack(side = 'left') def convert(): km = float(km_entry.get()) miles = km * 0.6214 tkinter.messagebox.showinfo('Result', '%.2f kilometers is equal to %.2f miles.' % (km, miles) ) tkinter.Button(bottom_frame, text = 'Convert', command = convert).pack(side = 'left') tkinter.Button(bottom_frame, text = 'Quit', command = main_window.destroy).pack(side = 'left') top_frame.pack() bottom_frame.pack() tkinter.mainloop() -- cut -- I've removed some redundant variables (you don't need to hang onto references to your labels,just pack 'em in and be done), and reordered the code a bit to put the Convert button's function right near where the Convert button is created (take your pick - do you prefer that, or to have all the other functions up top? Both are viable); I also changed your message box to use percent-formatting with fixed decimals rather than str(), to tidy up the display a bit. Oh, and renamed "kilo" to "km", because to me "kilo" means "kilogram". :) This version of the code isn't necessarily better in every way, but it's different. Like the Oracle in The Matrix, I want you to make up your own mind as to what you ought to do; maybe you'll like some of my changes, maybe you won't, but either way you're making an intelligent decision about code style :) ChrisA From hossamalagmy at gmail.com Wed Apr 24 13:40:49 2013 From: hossamalagmy at gmail.com (23alagmy) Date: Wed, 24 Apr 2013 10:40:49 -0700 (PDT) Subject: A Healthy Alternative to Takeaway Regret Message-ID: A Healthy Alternative to Takeaway Regret http://natigtas7ab.blogspot.com/2013/03/a-healthy-alternative-to-takeaway-regret.html From ppv.grps at gmail.com Wed Apr 24 15:06:27 2013 From: ppv.grps at gmail.com (Forafo San) Date: Wed, 24 Apr 2013 12:06:27 -0700 (PDT) Subject: Weird python behavior Message-ID: <4d64ae22-0fb6-4675-80c9-7ecdda7ad4d2@googlegroups.com> Hello All, I'm running Python version 2.7.3_6 on a FreeBSD system. The following session in a Python interpreter throws a mysterious TypeError: ------------------------------------------ [ppvora at snowfall ~/xbrl]$ python Python 2.7.3 (default, Apr 22 2013, 18:42:18) [GCC 4.2.1 20070719 [FreeBSD]] on freebsd8 Type "help", "copyright", "credits" or "license" for more information. >>> import glob Traceback (most recent call last): File "", line 1, in File "glob.py", line 14, in myl = glob.glob('data/*.xml') TypeError: 'module' object is not callable ------------------------------------------ The file glob.py that the error refers to was run under another screen session. It's a mystery why even that program threw an error. Regardless, why should that session throw an import error in this session? Weird. Any help is appreciated. Thanks, -Premal From neilc at norwich.edu Wed Apr 24 15:08:27 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 24 Apr 2013 19:08:27 GMT Subject: Weird python behavior References: <4d64ae22-0fb6-4675-80c9-7ecdda7ad4d2@googlegroups.com> Message-ID: On 2013-04-24, Forafo San wrote: > Hello All, > I'm running Python version 2.7.3_6 on a FreeBSD system. The following session in a Python interpreter throws a mysterious TypeError: > > ------------------------------------------ > [ppvora at snowfall ~/xbrl]$ python > Python 2.7.3 (default, Apr 22 2013, 18:42:18) > [GCC 4.2.1 20070719 [FreeBSD]] on freebsd8 > Type "help", "copyright", "credits" or "license" for more information. >>>> import glob > Traceback (most recent call last): > File "", line 1, in > File "glob.py", line 14, in > myl = glob.glob('data/*.xml') > TypeError: 'module' object is not callable > ------------------------------------------ > The file glob.py that the error refers to was run under another > screen session. It's a mystery why even that program threw an > error. Regardless, why should that session throw an import > error in this session? Weird. Any help is appreciated. Thanks, 'Cause Python's import statement looks in the current directory first for files to import. So you're importing your own error-riddled and mortal glob.py, rather than Python's pristine and Olympian glob.py. -- Neil Cerutti "This room is an illusion and is a trap devisut by Satan. Go ahead and dauntlessly! Make rapid progres!" --Ghosts 'n Goblins From ppv.grps at gmail.com Wed Apr 24 15:19:45 2013 From: ppv.grps at gmail.com (Forafo San) Date: Wed, 24 Apr 2013 12:19:45 -0700 (PDT) Subject: Weird python behavior In-Reply-To: References: <4d64ae22-0fb6-4675-80c9-7ecdda7ad4d2@googlegroups.com> Message-ID: <68daf2e4-f6f7-4511-bc33-b475326403d7@googlegroups.com> On Wednesday, April 24, 2013 3:08:27 PM UTC-4, Neil Cerutti wrote: > On 2013-04-24, Forafo San wrote: > > > Hello All, > > > I'm running Python version 2.7.3_6 on a FreeBSD system. The following session in a Python interpreter throws a mysterious TypeError: > > > > > > ------------------------------------------ > > > [ppvora at snowfall ~/xbrl]$ python > > > Python 2.7.3 (default, Apr 22 2013, 18:42:18) > > > [GCC 4.2.1 20070719 [FreeBSD]] on freebsd8 > > > Type "help", "copyright", "credits" or "license" for more information. > > >>>> import glob > > > Traceback (most recent call last): > > > File "", line 1, in > > > File "glob.py", line 14, in > > > myl = glob.glob('data/*.xml') > > > TypeError: 'module' object is not callable > > > ------------------------------------------ > > > The file glob.py that the error refers to was run under another > > > screen session. It's a mystery why even that program threw an > > > error. Regardless, why should that session throw an import > > > error in this session? Weird. Any help is appreciated. Thanks, > > > > 'Cause Python's import statement looks in the current directory > > first for files to import. So you're importing your own > > error-riddled and mortal glob.py, rather than Python's pristine > > and Olympian glob.py. > > > > -- > > Neil Cerutti > > "This room is an illusion and is a trap devisut by Satan. Go > > ahead and dauntlessly! Make rapid progres!" > > --Ghosts 'n Goblins OK, lesson learned: Take care not to have module names that conflict with python's built ins. Sorry for being so obtuse. From timr at probo.com Fri Apr 26 02:04:57 2013 From: timr at probo.com (Tim Roberts) Date: Thu, 25 Apr 2013 23:04:57 -0700 Subject: Weird python behavior References: <4d64ae22-0fb6-4675-80c9-7ecdda7ad4d2@googlegroups.com> <68daf2e4-f6f7-4511-bc33-b475326403d7@googlegroups.com> Message-ID: <876kn81bbsbptkfj4gpusl5fs13mudumfq@4ax.com> Forafo San wrote: > >OK, lesson learned: Take care not to have module names that conflict with python's built ins. Sorry for being so obtuse. You don't have to apologize. We've all been bitten by this at least once. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rustompmody at gmail.com Fri Apr 26 02:25:23 2013 From: rustompmody at gmail.com (rusi) Date: Thu, 25 Apr 2013 23:25:23 -0700 (PDT) Subject: Weird python behavior References: <4d64ae22-0fb6-4675-80c9-7ecdda7ad4d2@googlegroups.com> <68daf2e4-f6f7-4511-bc33-b475326403d7@googlegroups.com> <876kn81bbsbptkfj4gpusl5fs13mudumfq@4ax.com> Message-ID: On Apr 26, 11:04?am, Tim Roberts wrote: > Forafo San wrote: > > >OK, lesson learned: Take care not to have module names that conflict with python's built ins. Sorry for being so obtuse. > > You don't have to apologize. ?We've all been bitten by this at least once. Yes? When it comes to keywords it is reasonable to expect the programmer to know all the keywords and if he uses one for a function/variable the error will be immediate. When it comes to modules it is less reasonable to expect the programmer to know all available modules. To present these kind of errors, Erlang has a concept of sticky modules -- those that come from the system -- for which special efforts need to be made to 'unstick' them if one wants them overridden. This is helpful because the default which is to raise an error, is in most cases a more sound option than to silently override a builtin. From rustompmody at gmail.com Fri Apr 26 03:04:05 2013 From: rustompmody at gmail.com (rusi) Date: Fri, 26 Apr 2013 00:04:05 -0700 (PDT) Subject: Weird python behavior References: <4d64ae22-0fb6-4675-80c9-7ecdda7ad4d2@googlegroups.com> <68daf2e4-f6f7-4511-bc33-b475326403d7@googlegroups.com> <876kn81bbsbptkfj4gpusl5fs13mudumfq@4ax.com> Message-ID: <8af40dff-4af3-4c52-80a2-40f8289a49c5@k8g2000pbf.googlegroups.com> On Apr 26, 11:25?am, rusi wrote: > To present these kind of errors, Erlang has a concept of sticky > modules -- those that come from the system? ??present?? should have been 'prevent' From wrw at mac.com Wed Apr 24 15:25:48 2013 From: wrw at mac.com (William Ray Wing) Date: Wed, 24 Apr 2013 15:25:48 -0400 Subject: Finding the source of an exception in a python multiprocessing program Message-ID: <733559EE-CBDC-406A-8018-78CD41E2C445@mac.com> I run a bit of python code that monitors my connection to the greater Internet. It checks connectivity to the requested target IP addresses, logging both successes and failures, once every 15 seconds. I see failures quite regularly, predictably on Sunday nights after midnight when various networks are undergoing maintenance. I'm trying to use python's multiprocessing library to run multiple copies in parallel to check connectivity to different parts of the country (they in no way interact with each other). On rare occasions (maybe once every couple of months) I get the following exception and traceback: Traceback (most recent call last): File "./CM_Harness.py", line 12, in Foo = pool.map(monitor, targets) # and hands off two targets File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 227, in map return self.map_async(func, iterable, chunksize).get() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 528, in get raise self._value IndexError: list index out of range The code where the traceback occurs is: #!/usr/bin/env python """ Harness to call multiple parallel copies of the basic monitor program """ from multiprocessing import Pool from Connection_Monitor import monitor targets = ["8.8.8.8", "www.ncsa.edu"] pool = Pool(processes=2) # start 2 worker processes Foo = pool.map(monitor, targets) # and hands off two targets Line 12, in my code is simply the line that launches the underlying monitor code. I'm assuming that the real error is occurring in the monitor program that is being launched, but I'm at a loss as to what to do to get a better handle on what's going wrong. Since, as I said, I see failures quite regularly, typically on Sunday nights after midnight when various networks are undergoing maintenance, I don't _think_ the exception is being triggered by that sort of failure. When I look at the pool module, the error is occurring in get(self, timeout=None) on the line after the final else: def get(self, timeout=None): self.wait(timeout) if not self._ready: raise TimeoutError if self._success: return self._value else: raise self._value Python v 2.7.3, from Python.org, running on Mac OS-X 10.8.3 Thanks for any suggestions, Bill From neilc at norwich.edu Wed Apr 24 16:31:39 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 24 Apr 2013 20:31:39 GMT Subject: Finding the source of an exception in a python multiprocessing program References: Message-ID: On 2013-04-24, William Ray Wing wrote: > When I look at the pool module, the error is occurring in > get(self, timeout=None) on the line after the final else: > > def get(self, timeout=None): > self.wait(timeout) > if not self._ready: > raise TimeoutError > if self._success: > return self._value > else: > raise self._value The code that's failing is in self.wait. Somewhere in there you must be masking an exception and storing it in self._value instead of letting it propogate and crash your program. This is hiding the actual context. -- Neil Cerutti From wrw at mac.com Wed Apr 24 17:09:20 2013 From: wrw at mac.com (William Ray Wing) Date: Wed, 24 Apr 2013 17:09:20 -0400 Subject: Finding the source of an exception in a python multiprocessing program In-Reply-To: References: Message-ID: <5BC4D9D9-D757-40F3-81CA-CF4FA5C73A96@mac.com> On Apr 24, 2013, at 4:31 PM, Neil Cerutti wrote: > On 2013-04-24, William Ray Wing wrote: >> When I look at the pool module, the error is occurring in >> get(self, timeout=None) on the line after the final else: >> >> def get(self, timeout=None): >> self.wait(timeout) >> if not self._ready: >> raise TimeoutError >> if self._success: >> return self._value >> else: >> raise self._value > > The code that's failing is in self.wait. Somewhere in there you > must be masking an exception and storing it in self._value > instead of letting it propogate and crash your program. This is > hiding the actual context. > > -- > Neil Cerutti > -- > http://mail.python.org/mailman/listinfo/python-list I'm sorry, I'm not following you. The "get" routine (and thus self.wait) is part of the "pool" module in the Python multiprocessing library. None of my code has a class or function named "get". -Bill From davea at davea.name Wed Apr 24 19:26:36 2013 From: davea at davea.name (Dave Angel) Date: Wed, 24 Apr 2013 19:26:36 -0400 Subject: Finding the source of an exception in a python multiprocessing program In-Reply-To: <5BC4D9D9-D757-40F3-81CA-CF4FA5C73A96@mac.com> References: <5BC4D9D9-D757-40F3-81CA-CF4FA5C73A96@mac.com> Message-ID: <51786A2C.4020306@davea.name> On 04/24/2013 05:09 PM, William Ray Wing wrote: > On Apr 24, 2013, at 4:31 PM, Neil Cerutti wrote: > >> On 2013-04-24, William Ray Wing wrote: >>> When I look at the pool module, the error is occurring in >>> get(self, timeout=None) on the line after the final else: >>> >>> def get(self, timeout=None): >>> self.wait(timeout) >>> if not self._ready: >>> raise TimeoutError >>> if self._success: >>> return self._value >>> else: >>> raise self._value >> >> The code that's failing is in self.wait. Somewhere in there you >> must be masking an exception and storing it in self._value >> instead of letting it propogate and crash your program. This is >> hiding the actual context. >> >> -- >> Neil Cerutti >> -- >> http://mail.python.org/mailman/listinfo/python-list > > I'm sorry, I'm not following you. The "get" routine (and thus self.wait) is part of the "pool" module in the Python multiprocessing library. > None of my code has a class or function named "get". > > -Bill > My question is why bother with multithreading? Why not just do these as separate processes? You said "they in no way interact with each other" and that's a clear clue that separate processes would be cleaner. Without knowing anything about those libraries, I'd guess that somewhere they do store state in a global attribute or equivalent, and when that is accessed by both threads, it can crash. Separate processes will find it much more difficult to interact, which is a good thing most of the time. Further, they seem to be scheduled more efficiently because of the GIL, though that may not make that much difference when you're time-limited by network data. -- DaveA From oscar.j.benjamin at gmail.com Wed Apr 24 20:00:54 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 25 Apr 2013 01:00:54 +0100 Subject: Finding the source of an exception in a python multiprocessing program In-Reply-To: <51786A2C.4020306@davea.name> References: <5BC4D9D9-D757-40F3-81CA-CF4FA5C73A96@mac.com> <51786A2C.4020306@davea.name> Message-ID: On 25 April 2013 00:26, Dave Angel wrote: > On 04/24/2013 05:09 PM, William Ray Wing wrote: >> >> On Apr 24, 2013, at 4:31 PM, Neil Cerutti wrote: >> >>> On 2013-04-24, William Ray Wing wrote: >>>> >>>> When I look at the pool module, the error is occurring in >>>> get(self, timeout=None) on the line after the final else: >>>> >>>> def get(self, timeout=None): >>>> self.wait(timeout) >>>> if not self._ready: >>>> raise TimeoutError >>>> if self._success: >>>> return self._value >>>> else: >>>> raise self._value >>> >>> >>> The code that's failing is in self.wait. Somewhere in there you >>> must be masking an exception and storing it in self._value >>> instead of letting it propogate and crash your program. This is >>> hiding the actual context. >>> >>> -- >>> Neil Cerutti >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >> >> >> I'm sorry, I'm not following you. The "get" routine (and thus self.wait) >> is part of the "pool" module in the Python multiprocessing library. >> None of my code has a class or function named "get". >> >> -Bill >> > > My question is why bother with multithreading? Why not just do these as > separate processes? You said "they in no way interact with each other" and > that's a clear clue that separate processes would be cleaner. It's using multiprocessing rather than threads: they are separate processes. > > Without knowing anything about those libraries, I'd guess that somewhere > they do store state in a global attribute or equivalent, and when that is > accessed by both threads, it can crash. It's state that is passed to it by the subprocess and should only be accessed by the top-level process after the subprocess completes (I think!). > > Separate processes will find it much more difficult to interact, which is a > good thing most of the time. Further, they seem to be scheduled more > efficiently because of the GIL, though that may not make that much > difference when you're time-limited by network data. They are separate processes and do not share the GIL (unless I'm very much mistaken). Also I think the underlying program is limited by the call to sleep for 15 seconds. Oscar From davea at davea.name Wed Apr 24 20:11:51 2013 From: davea at davea.name (Dave Angel) Date: Wed, 24 Apr 2013 20:11:51 -0400 Subject: Finding the source of an exception in a python multiprocessing program In-Reply-To: References: <5BC4D9D9-D757-40F3-81CA-CF4FA5C73A96@mac.com> <51786A2C.4020306@davea.name> Message-ID: <517874C7.5070903@davea.name> On 04/24/2013 08:00 PM, Oscar Benjamin wrote: > On 25 April 2013 00:26, Dave Angel wrote: >> On 04/24/2013 05:09 PM, William Ray Wing wrote: >>> >>> >>> >>> >> >> My question is why bother with multithreading? Why not just do these as >> separate processes? You said "they in no way interact with each other" and >> that's a clear clue that separate processes would be cleaner. > > It's using multiprocessing rather than threads: they are separate processes. > You're right; I was completely off base. brain-freeze. >> >> > > It's state that is passed to it by the subprocess and should only be > accessed by the top-level process after the subprocess completes (I > think!). > >> >> Separate processes will find it much more difficult to interact, which is a >> good thing most of the time. Further, they seem to be scheduled more >> efficiently because of the GIL, though that may not make that much >> difference when you're time-limited by network data. > > They are separate processes and do not share the GIL (unless I'm very > much mistaken). No, you're not mistaken. Somehow I interpreted the original as saying multi-thread, and everything else was wrong as a result. Now it sounds like a bug in, or misuse of, the Pool class. -- DaveA From neilc at norwich.edu Thu Apr 25 08:37:03 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 25 Apr 2013 12:37:03 GMT Subject: Finding the source of an exception in a python multiprocessing program References: Message-ID: On 2013-04-24, William Ray Wing wrote: > On Apr 24, 2013, at 4:31 PM, Neil Cerutti wrote: > >> On 2013-04-24, William Ray Wing wrote: >>> When I look at the pool module, the error is occurring in >>> get(self, timeout=None) on the line after the final else: >>> >>> def get(self, timeout=None): >>> self.wait(timeout) >>> if not self._ready: >>> raise TimeoutError >>> if self._success: >>> return self._value >>> else: >>> raise self._value >> >> The code that's failing is in self.wait. Somewhere in there you >> must be masking an exception and storing it in self._value >> instead of letting it propogate and crash your program. This is >> hiding the actual context. > > I'm sorry, I'm not following you. The "get" routine (and thus > self.wait) is part of the "pool" module in the Python > multiprocessing library. None of my code has a class or > function named "get". Oops! I failed to notice it was part of the pool module and not your own code. -- Neil Cerutti From oscar.j.benjamin at gmail.com Wed Apr 24 18:37:28 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 24 Apr 2013 23:37:28 +0100 Subject: Finding the source of an exception in a python multiprocessing program In-Reply-To: <733559EE-CBDC-406A-8018-78CD41E2C445@mac.com> References: <733559EE-CBDC-406A-8018-78CD41E2C445@mac.com> Message-ID: On 24 April 2013 20:25, William Ray Wing wrote: > I run a bit of python code that monitors my connection to the greater Internet. It checks connectivity to the requested target IP addresses, logging both successes and failures, once every 15 seconds. I see failures quite regularly, predictably on Sunday nights after midnight when various networks are undergoing maintenance. I'm trying to use python's multiprocessing library to run multiple copies in parallel to check connectivity to different parts of the country (they in no way interact with each other). > > On rare occasions (maybe once every couple of months) I get the following exception and traceback: > > Traceback (most recent call last): > File "./CM_Harness.py", line 12, in > Foo = pool.map(monitor, targets) # and hands off two targets > File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 227, in map > return self.map_async(func, iterable, chunksize).get() > File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 528, in get > raise self._value > IndexError: list index out of range > > The code where the traceback occurs is: > > #!/usr/bin/env python > > """ Harness to call multiple parallel copies > of the basic monitor program > """ > > from multiprocessing import Pool > from Connection_Monitor import monitor > > targets = ["8.8.8.8", "www.ncsa.edu"] > pool = Pool(processes=2) # start 2 worker processes > Foo = pool.map(monitor, targets) # and hands off two targets > > > Line 12, in my code is simply the line that launches the underlying monitor code. I'm assuming that the real error is occurring in the monitor program that is being launched, but I'm at a loss as to what to do to get a better handle on what's going wrong. Since, as I said, I see failures quite regularly, typically on Sunday nights after midnight when various networks are undergoing maintenance, I don't _think_ the exception is being triggered by that sort of failure. > > When I look at the pool module, the error is occurring in get(self, timeout=None) on the line after the final else: > > def get(self, timeout=None): > self.wait(timeout) > if not self._ready: > raise TimeoutError > if self._success: > return self._value > else: > raise self._value > > > Python v 2.7.3, from Python.org, running on Mac OS-X 10.8.3 This looks to me like a bug in multiprocessing but I'm not very experienced with it. Perhaps it would be good to open an issue on the tracker. It might not be solvable without an easier way of reproducing it though. Oscar From python at mrabarnett.plus.com Wed Apr 24 18:54:23 2013 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 24 Apr 2013 23:54:23 +0100 Subject: Finding the source of an exception in a python multiprocessing program In-Reply-To: <733559EE-CBDC-406A-8018-78CD41E2C445@mac.com> References: <733559EE-CBDC-406A-8018-78CD41E2C445@mac.com> Message-ID: <5178629F.8080009@mrabarnett.plus.com> On 24/04/2013 20:25, William Ray Wing wrote: > I run a bit of python code that monitors my connection to the greater Internet. It checks connectivity to the requested target IP addresses, logging both successes and failures, once every 15 seconds. I see failures quite regularly, predictably on Sunday nights after midnight when various networks are undergoing maintenance. I'm trying to use python's multiprocessing library to run multiple copies in parallel to check connectivity to different parts of the country (they in no way interact with each other). > > On rare occasions (maybe once every couple of months) I get the following exception and traceback: > > Traceback (most recent call last): > File "./CM_Harness.py", line 12, in > Foo = pool.map(monitor, targets) # and hands off two targets > File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 227, in map > return self.map_async(func, iterable, chunksize).get() > File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 528, in get > raise self._value > IndexError: list index out of range > > The code where the traceback occurs is: > > #!/usr/bin/env python > > """ Harness to call multiple parallel copies > of the basic monitor program > """ > > from multiprocessing import Pool > from Connection_Monitor import monitor > > targets = ["8.8.8.8", "www.ncsa.edu"] > pool = Pool(processes=2) # start 2 worker processes > Foo = pool.map(monitor, targets) # and hands off two targets > > > Line 12, in my code is simply the line that launches the underlying monitor code. I'm assuming that the real error is occurring in the monitor program that is being launched, but I'm at a loss as to what to do to get a better handle on what's going wrong. Since, as I said, I see failures quite regularly, typically on Sunday nights after midnight when various networks are undergoing maintenance, I don't _think_ the exception is being triggered by that sort of failure. > [snip] If the exception is being raised by 'monitor', you could try catching the exception within that (or write a simple wrapper function which calls it), write the traceback to a logfile, and then re-raise. From webmaster at terradon.nl Wed Apr 24 16:59:51 2013 From: webmaster at terradon.nl (webmaster at terradon.nl) Date: Wed, 24 Apr 2013 13:59:51 -0700 (PDT) Subject: how to: multiplayer game connecting to central server effectively? Message-ID: hi, I struggle for some days about a "model" for a multiplayer game application. I read so much from my enemy Google, i got lost by all that info and dont know which path i should chose. a multiplayer game application, sending/receiving instantly every change in the game to a central webserver, http://www.xxxxx.com, probably via socket connection? which system/module should i use for this contineous connection and where can i find a good tutorial, which a beginner like me can understand a bit? (i have read too many too complicated/technical artickles, but no nice tutorials). i have tried and accompished an urllib connection, with get and post variabels, but that will be polling, with all the http-overhead for every poll. I think this is also to slow and no "real" updating of the game status. Thanks in advance for any hint/tutorial i get:) From gordon at panix.com Wed Apr 24 17:48:39 2013 From: gordon at panix.com (John Gordon) Date: Wed, 24 Apr 2013 21:48:39 +0000 (UTC) Subject: how to: multiplayer game connecting to central server effectively? References: Message-ID: In webmaster at terradon.nl writes: > i have tried and accompished an urllib connection, with get and post > variabels, but that will be polling, with all the http-overhead for every > poll. I think this is also to slow and no "real" updating of the game status. Http can still work, depending on what kind of game it is. For example a game where only the current player can make decisions and the other players just sit and watch (like Risk), or a game where each player submits a move and the server applies the game rules to resolve the outcome (like Rock-Scissors-Paper). But a truly interactive game would probably require something more, like an active socket connection. -- 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 fabiosantosart at gmail.com Wed Apr 24 18:06:56 2013 From: fabiosantosart at gmail.com (=?ISO-8859-1?Q?F=E1bio_Santos?=) Date: Wed, 24 Apr 2013 23:06:56 +0100 Subject: how to: multiplayer game connecting to central server effectively? In-Reply-To: References: Message-ID: This series of articles is flash-based, and the examples apparently don't run, but it is a great read on all the problems you face when coding several kinds of multiplayer games, and the variety of things you can do to fix it: http://playerio.com/documentation/tutorials/building-flash-multiplayer-games-tutorial/ Did you know that Age of Empires was actually internally turn-based, in order to avoid syncing problems? On Wed, Apr 24, 2013 at 10:48 PM, John Gordon wrote: > In webmaster at terradon.nl writes: > >> i have tried and accompished an urllib connection, with get and post >> variabels, but that will be polling, with all the http-overhead for every >> poll. I think this is also to slow and no "real" updating of the game status. > > Http can still work, depending on what kind of game it is. For example > a game where only the current player can make decisions and the other > players just sit and watch (like Risk), or a game where each player submits > a move and the server applies the game rules to resolve the outcome (like > Rock-Scissors-Paper). > > But a truly interactive game would probably require something more, like > an active socket connection. > > -- > 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" > > -- > http://mail.python.org/mailman/listinfo/python-list -- F?bio Santos From rosuav at gmail.com Wed Apr 24 22:55:46 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 25 Apr 2013 12:55:46 +1000 Subject: how to: multiplayer game connecting to central server effectively? In-Reply-To: References: Message-ID: On Thu, Apr 25, 2013 at 6:59 AM, wrote: > hi, > I struggle for some days about a "model" for a multiplayer game application. > I read so much from my enemy Google, i got lost by all that info and dont know which path i should chose. > > a multiplayer game application, sending/receiving instantly every change in the game to a central webserver, http://www.xxxxx.com, probably via socket connection? > > which system/module should i use for this contineous connection and where can i find a good tutorial, which a beginner like me can understand a bit? (i have read too many too complicated/technical artickles, but no nice tutorials). > > i have tried and accompished an urllib connection, with get and post variabels, but that will be polling, with all the http-overhead for every poll. I think this is also to slow and no "real" updating of the game status. > > Thanks in advance for any hint/tutorial i get:) The easiest way to start would be a MUD or chat server. Establish a TCP socket, then whenever anything happens, report the change to all connected sockets. In its simplest form: * Accept connection * Wait for login (or, for a simple test, just "Enter your name: " would do) * Add connection to pool * Whenever a line of text is received, prepend the name and send it to every connection in the pool. That's a basic chat server. A MUD adds only a small bit of complication: you need some form of command parser, and not everything will announce to all connected clients. I can walk you through a lot of this, but I haven't done most of it in Python; there's another language, very similar in semantics, which is better suited to MUD building: Pike. But it's all similar enough that you'll be able to do it in either. The project you're looking at sounds to me like it'd be well implemented as a MUD-style connection with a fancy client in front of it. Debug your system using the MUD connection, and make sure you don't have any security holes that can be exploited by someone switching out your client for a custom one; because, believe you me, someone will figure out how to do it. (If you're concerned about privacy, you can easily switch in SSL/TLS, while not fundamentally changing any of your code.) Start with something as simple as you possibly can, and then add complication only as you find you need it. Here's the module you'll be wanting: http://docs.python.org/3.3/library/socket.html (By the way, you won't be connecting to a *web* server. Your central server will be quite separate from that system. It might happen to be the same computer, but there's no real connection.) ChrisA From webmaster at terradon.nl Thu Apr 25 02:02:33 2013 From: webmaster at terradon.nl (webmaster at terradon.nl) Date: Wed, 24 Apr 2013 23:02:33 -0700 (PDT) Subject: how to: multiplayer game connecting to central server effectively? In-Reply-To: References: Message-ID: <180e5688-33ba-4a27-b86d-e3f273f793cc@googlegroups.com> The idea is a risk game application and data collected and controlled by a gameserver, which happens to be a webserver too. But for learning the principles, i want to start with tic-tac-toe multiplayer. Thanks for your answers, I will read all your advices first now. From anadionisio257 at gmail.com Wed Apr 24 19:01:01 2013 From: anadionisio257 at gmail.com (=?ISO-8859-1?Q?Ana_Dion=EDsio?=) Date: Wed, 24 Apr 2013 16:01:01 -0700 (PDT) Subject: Scan CSV file and saving it into an array Message-ID: <1533da3c-a297-41a0-a575-968a86120a5b@googlegroups.com> Hello! I have this script that scans a csv file and if the value in the first column == 200 it saves that row into an array. The problem is, I need to save that row and the next 10 rows in that same array. What can I add to the script so it does that? I tried to do for row in len(10): but I get an error. p = csv.reader(open('file.csv'), delimiter=';') a=[0]*2881 a = numpy.array(a, dtype=dict) for row in p: if row[0]=="200": a=row break print a From rhodri at wildebst.demon.co.uk Wed Apr 24 19:21:18 2013 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 25 Apr 2013 00:21:18 +0100 Subject: Scan CSV file and saving it into an array References: <1533da3c-a297-41a0-a575-968a86120a5b@googlegroups.com> Message-ID: On Thu, 25 Apr 2013 00:01:01 +0100, Ana Dion?sio wrote: > I tried to do for row in len(10): but I get an error. Please remember to tell us what error, with the traceback, so that we can make fun of you for not reading it :-) In this case it's pretty obvious; Python will complain that you can't call len() on an integer (because it's not a container type, so the whole idea of "length" is meaningless). You probably meant to use "range(10)" instead of "len(10)", but then "row" would be the integers from 0 to 9 inclusive, which isn't what you want either. What you actually want to do is "row = p.next()" (in Python 2.x) or "row = next(p)" (in Python 3.x) to get the next row from the CSV file, add it to the array and repeat until you have ten more lines. Another for-loop will make this less tedious to write. Odd that this subject should have come up so many times in various guises in the last week or two. -- Rhodri James *-* Wildebeest Herder to the Masses From davea at davea.name Wed Apr 24 19:47:16 2013 From: davea at davea.name (Dave Angel) Date: Wed, 24 Apr 2013 19:47:16 -0400 Subject: Scan CSV file and saving it into an array In-Reply-To: References: <1533da3c-a297-41a0-a575-968a86120a5b@googlegroups.com> Message-ID: <51786F04.1090102@davea.name> On 04/24/2013 07:21 PM, Rhodri James wrote: > On Thu, 25 Apr 2013 00:01:01 +0100, Ana Dion?sio > wrote: > > > Odd that this subject should have come up so many times in various > guises in the last week or two. > Not that odd. In a larger classroom I'd expect several of the students to have enough internet savvy to find a forum like this. -- DaveA From davea at davea.name Wed Apr 24 20:01:13 2013 From: davea at davea.name (Dave Angel) Date: Wed, 24 Apr 2013 20:01:13 -0400 Subject: Scan CSV file and saving it into an array In-Reply-To: <1533da3c-a297-41a0-a575-968a86120a5b@googlegroups.com> References: <1533da3c-a297-41a0-a575-968a86120a5b@googlegroups.com> Message-ID: <51787249.7030607@davea.name> On 04/24/2013 07:01 PM, Ana Dion?sio wrote: > Hello! > > I have this script that scans a csv file and if the value in the first column == 200 it saves that row into an array. No it doesn't. It creates a list, then overwrites it with a numpy array, then overwrites that with a list of strings representing one row. If you want to really use a Python array, then read here: http://docs.python.org/2/library/array.html It'd probably be best to start with a precise problem statement, presumably copied from your textbook or assignment sheet. What python version is this for? And what OS? (that affects whether you need a file mode) Exactly what data structure are you trying to build? What type of a csv file are you trying to use? Is there a standard header line? How big might the file be? What behavior do you want if there's no line that begins with the field "200"? Or if there's more than one such line? Or if there are less than 10 lines following it in the file? What about a field of "0200"? > > The problem is, I need to save that row and the next 10 rows in that same array. What can I add to the script so it does that? I tried to do for row in len(10): but I get an error. > When you say "get an error" it could be one of many things. In this case, it's obvious, since len() doesn't make sense with an integer parameter. But in general you want to say either: 1) it gave me the wrong result. I expected AAAA and got BBBB 2) it did nothing at all. 3) it gave an exception, and here's the full traceback. > > p = csv.reader(open('file.csv'), delimiter=';') > a=[0]*2881 > a = numpy.array(a, dtype=dict) These two lines do nothing useful, and they confuse the reader of the code, since they imply that the list will end up of size 2881, and/or as a numpy array. > for row in p: > if row[0]=="200": > a=row > break missing else clause. How do you detect that there was no match? > print a > -- DaveA From oscar.j.benjamin at gmail.com Wed Apr 24 20:21:43 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 25 Apr 2013 01:21:43 +0100 Subject: Scan CSV file and saving it into an array In-Reply-To: <1533da3c-a297-41a0-a575-968a86120a5b@googlegroups.com> References: <1533da3c-a297-41a0-a575-968a86120a5b@googlegroups.com> Message-ID: On 25 April 2013 00:01, Ana Dion?sio wrote: > Hello! > > I have this script that scans a csv file and if the value in the first column == 200 it saves that row into an array. > > The problem is, I need to save that row and the next 10 rows in that same array. What can I add to the script so it does that? I tried to do for row in len(10): but I get an error. > > > p = csv.reader(open('file.csv'), delimiter=';') > a=[0]*2881 > a = numpy.array(a, dtype=dict) You shouldn't be using a numpy array for this; use a list instead. I suggest that you have a go at the Python tutorial and avoid using numpy until you are more confident with the basics of Python itself. The tutorial (for Python 2) is here: http://docs.python.org/2/tutorial/ Oscar From roy at panix.com Wed Apr 24 19:50:33 2013 From: roy at panix.com (Roy Smith) Date: Wed, 24 Apr 2013 19:50:33 -0400 Subject: epiphany Message-ID: I discovered something really neat today. We've got a system with a bunch of rules. Each rule is a method which returns True or False. At some point, we need to know if all the rules are True. Complicating things, not all the rules are implemented. Those that are not implemented raise NotImplementedError. We used to have some ugly logic which kept track of which rules were active and only evaluated those. So, here's the neat thing. It turns out that bool(NotImplemented) returns True. By changing the unimplemented rules from raising NotImplementedError to returning NotImplemented, the whole thing becomes: return all(r() for r in rules) From steve+comp.lang.python at pearwood.info Wed Apr 24 21:35:07 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Apr 2013 01:35:07 GMT Subject: epiphany References: Message-ID: <5178884b$0$29977$c3e8da3$5496439d@news.astraweb.com> On Wed, 24 Apr 2013 19:50:33 -0400, Roy Smith wrote: > I discovered something really neat today. > > We've got a system with a bunch of rules. Each rule is a method which > returns True or False. At some point, we need to know if all the rules > are True. Complicating things, not all the rules are implemented. Those > that are not implemented raise NotImplementedError. NotImplementedError is intended to be raised by abstract base classes to indicate a method that must be overridden. I also use it as a place- holder for functions or methods I haven't actually written yet. I'm not sure what semantics you're giving NotImplementedError in your code, but I wonder whether a neater solution might be to just use rule = None for unimplemented rules, rather than: def unimplemented(): raise NotImplementedError rule = unimplemented Then your logic for seeing if all rules return true would become: all(r() for r in rules if r is not None) and for seeing if all rules return true or are unimplemented: all(r is None or r() for r in rules) > We used to have some ugly logic which kept track of which rules were > active and only evaluated those. I don't see why you would need anything like that. Reading further on, I see that you are counting unimplemented rules as true, for some reason which I don't understand. (Knowing nothing of your use-case, I would have expected intuitively that unimplemented rules count as not true.) A simple helper function will do the job: def eval(rule): try: return rule() except NotImplementedError: return True everything_is_true = all(eval(r) for r in rules) No need for complicated ugly logic keeping track of what rules are implemented. But if you're worried about the cost of catching those exceptions (you've profiled your code, right?) then that's easy with a decorator: def not_implemented(func): @functools.wraps(func) def inner(*args, **kw): raise NotImplementedError inner.ni = True return inner # Decorate only the rules you want to be unimplemented. @not_implemented def my_rule(): pass everything_is_true = all(r() for r in rules if not hasattr(r, 'ni')) Note that if you could reverse the logic so that unimplemented rules count as not true, this will also work: try: everything_is_true = all(r() for r in rules) except NotImplementedError: everything_is_true = False > So, here's the neat thing. It turns out that bool(NotImplemented) > returns True. By changing the unimplemented rules from raising > NotImplementedError to returning NotImplemented, the whole thing > becomes: > > return all(r() for r in rules) Objects are supposed to return NotImplemented from special dunder methods like __add__, __lt__, etc. to say "I don't know how to implement this method for the given argument". Python will then try calling the other object's special method. If both objects return NotImplemented, Python falls back on whatever default behaviour is appropriate. So, knowing nothing of your application, I fear that this is an abuse of NotImplemented's semantics. If a rule returns NotImplemented, I would expect your application to fall back on a different rule. If that's not the case, you're using it in a non-standard way that will cause confusion for those with expectations of what NotImplemented means. -- Steven From roy at panix.com Wed Apr 24 21:41:26 2013 From: roy at panix.com (Roy Smith) Date: Wed, 24 Apr 2013 21:41:26 -0400 Subject: epiphany References: <5178884b$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <5178884b$0$29977$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > I don't see why you would need anything like that. Reading further on, I > see that you are counting unimplemented rules as true, for some reason > which I don't understand. The top-level logic we need to enforce is "this configuration doesn't violate any rules". From rosuav at gmail.com Wed Apr 24 22:20:45 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 25 Apr 2013 12:20:45 +1000 Subject: epiphany In-Reply-To: References: <5178884b$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Apr 25, 2013 at 11:41 AM, Roy Smith wrote: > In article <5178884b$0$29977$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> I don't see why you would need anything like that. Reading further on, I >> see that you are counting unimplemented rules as true, for some reason >> which I don't understand. > > The top-level logic we need to enforce is "this configuration doesn't > violate any rules". Then have your unimplemented rules simply return True. Easy! ChrisA From ethan at stoneleaf.us Wed Apr 24 22:28:30 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 24 Apr 2013 19:28:30 -0700 Subject: epiphany In-Reply-To: References: <5178884b$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <517894CE.2050904@stoneleaf.us> On 04/24/2013 07:20 PM, Chris Angelico wrote: > On Thu, Apr 25, 2013 at 11:41 AM, Roy Smith wrote: >> In article <5178884b$0$29977$c3e8da3$5496439d at news.astraweb.com>, >> Steven D'Aprano wrote: >> >>> I don't see why you would need anything like that. Reading further on, I >>> see that you are counting unimplemented rules as true, for some reason >>> which I don't understand. >> >> The top-level logic we need to enforce is "this configuration doesn't >> violate any rules". > > Then have your unimplemented rules simply return True. Easy! And less clear. -- ~Ethan~ From roy at panix.com Wed Apr 24 22:33:00 2013 From: roy at panix.com (Roy Smith) Date: Wed, 24 Apr 2013 22:33:00 -0400 Subject: epiphany References: <5178884b$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Chris Angelico wrote: > On Thu, Apr 25, 2013 at 11:41 AM, Roy Smith wrote: > > In article <5178884b$0$29977$c3e8da3$5496439d at news.astraweb.com>, > > Steven D'Aprano wrote: > > > >> I don't see why you would need anything like that. Reading further on, I > >> see that you are counting unimplemented rules as true, for some reason > >> which I don't understand. > > > > The top-level logic we need to enforce is "this configuration doesn't > > violate any rules". > > Then have your unimplemented rules simply return True. Easy! > > ChrisA It's nice to have tri-state logic: * This rule passes * This rule fails * This rule was not evaluated What I've got now expresses that perfectly. From ethan at stoneleaf.us Wed Apr 24 22:25:37 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 24 Apr 2013 19:25:37 -0700 Subject: epiphany In-Reply-To: <5178884b$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <5178884b$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51789421.6010503@stoneleaf.us> On 04/24/2013 06:35 PM, Steven D'Aprano wrote: > Objects are supposed to return NotImplemented from special dunder methods > like __add__, __lt__, etc. to say "I don't know how to implement this > method for the given argument". Python will then try calling the other > object's special method. If both objects return NotImplemented, Python > falls back on whatever default behaviour is appropriate. > > So, knowing nothing of your application, I fear that this is an abuse of > NotImplemented's semantics. If a rule returns NotImplemented, I would > expect your application to fall back on a different rule. If that's not > the case, you're using it in a non-standard way that will cause confusion > for those with expectations of what NotImplemented means. Why would you assume some random application is going to deal with NotImplemented the same way the python interpreter does? And even the interpreter isn't consistent -- sometimes it will return false (__eq__) and sometimes it will raise an Exception (__add__). I hardly think it an abuse of NotImplemented to signal something is not implemented when NotImplemented means, um, not implemented. possibly-not-implemented-ly yours, -- ~Ethan~ From steve+comp.lang.python at pearwood.info Thu Apr 25 00:32:27 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Apr 2013 04:32:27 GMT Subject: epiphany References: <5178884b$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5178b1db$0$29977$c3e8da3$5496439d@news.astraweb.com> On Wed, 24 Apr 2013 19:25:37 -0700, Ethan Furman wrote: > On 04/24/2013 06:35 PM, Steven D'Aprano wrote: >> Objects are supposed to return NotImplemented from special dunder >> methods like __add__, __lt__, etc. to say "I don't know how to >> implement this method for the given argument". Python will then try >> calling the other object's special method. If both objects return >> NotImplemented, Python falls back on whatever default behaviour is >> appropriate. >> >> So, knowing nothing of your application, I fear that this is an abuse >> of NotImplemented's semantics. If a rule returns NotImplemented, I >> would expect your application to fall back on a different rule. If >> that's not the case, you're using it in a non-standard way that will >> cause confusion for those with expectations of what NotImplemented >> means. > > Why would you assume some random application is going to deal with > NotImplemented the same way the python interpreter does? Why would you assume that some random application is going to treat x==y the same way the Python interpreter does? Just because you can design your objects to do anything you want doesn't mean you should. Breaking conventions carries costs by the mere fact that you're breaking conventions. There are established semantics that an experienced Python developer will expect for NotImplemented, and doing something else risks causing confusion and mistakes. Or worse, bugs. If there is any chance that a rule might be called in a context where the Python interpreter gets to interpret the return result before you see it, then returning NotImplemented could lead to difficult to debug problems. > And even the > interpreter isn't consistent -- sometimes it will return false (__eq__) > and sometimes it will raise an Exception (__add__). As I said: "If both objects return NotImplemented, Python falls back on whatever default behaviour is appropriate." If neither object knows how to compare the other for equality, the appropriate behaviour is to treat them as unequal. If neither object knows how to add itself to the other, the appropriate behaviour is to raise an exception. > I hardly think it an abuse of NotImplemented to signal something is not > implemented when NotImplemented means, um, not implemented. It doesn't just mean "not implemented in general", it has a specific meaning: "I don't know what to do here, let the other object handle it". As I have repeatedly said, I don't know the context of the application, but from what little has been described, this part of it doesn't feel to me like a good, clean design. I might be wrong, but from the outside it feels like the API should be that rules return a three-state logic instance: True, False, Unknown where Unknown can be trivially created with Unknown = object() The semantics of NotImplementedError is that it is an *error*, and that doesn't sound appropriate given the example shown. Why would a rule that raises an *error* exception be treated as if it had passed? That's just wrong. The semantics of NotImplemented is that it is a signal for one object to say "I don't know how to do this, let somebody else try". That also doesn't seem appropriate. There's no sign that Roy's application does the equivalent to this: result = rule() if result is NotImplemented: result = another_rule() if result is NotImplemented: result = some_default Since rules apparently take no arguments, either: 1) they rely on global state, which is a nasty design; or 2) rules actually have a fixed return result, in which case why make them functions in the first place? Since both possibilities seem stupid, and I do not believe that Roy actually is stupid, I suspect that his example over-simplifies the situation. But I can't comment on the infinite number of things that his code might do, I can only comment on the examples as actually given, and as given, I don't think that either NotImplementedError or NotImplemented is a clean solution to the problem. -- Steven From roy at panix.com Thu Apr 25 08:36:34 2013 From: roy at panix.com (Roy Smith) Date: Thu, 25 Apr 2013 08:36:34 -0400 Subject: epiphany References: <5178884b$0$29977$c3e8da3$5496439d@news.astraweb.com> <5178b1db$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <5178b1db$0$29977$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > The semantics of NotImplemented is that it is a signal for one object to > say "I don't know how to do this, let somebody else try". That's precisely the logic here. The rule says, "I don't know how to tell you if this is OK or not, ask another rule". > Since rules apparently take no arguments, either: > > 1) they rely on global state, which is a nasty design; or > > 2) rules actually have a fixed return result, in which case why make them > functions in the first place? Yes, rules take arguments. I elided them from the original description since it wasn't germane to what I was trying to show. > Since both possibilities seem stupid, and I do not believe that Roy > actually is stupid, I am honored that you have such a high opinion of me :-) Here's what the docs say about NotImplemented: > This type has a single value. There is a single object with this > value. This object is accessed through the built-in name > NotImplemented. Numeric methods and rich comparison methods may > return this value if they do not implement the operation for the > operands provided. (The interpreter will then try the reflected > operation, or some other fallback, depending on the operator.) Its > truth value is true. It gives an example of a use by numeric methods. It doesn't say that's the only thing it can be used for. It also says, "Its truth value is true". Why would they document that fact if you weren't supposed to use it as a boolean operand? From steve+comp.lang.python at pearwood.info Thu Apr 25 08:52:33 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Apr 2013 12:52:33 GMT Subject: epiphany References: <5178884b$0$29977$c3e8da3$5496439d@news.astraweb.com> <5178b1db$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <51792710$0$29977$c3e8da3$5496439d@news.astraweb.com> On Thu, 25 Apr 2013 08:36:34 -0400, Roy Smith wrote: > In article <5178b1db$0$29977$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: > >> The semantics of NotImplemented is that it is a signal for one object >> to say "I don't know how to do this, let somebody else try". > > That's precisely the logic here. The rule says, "I don't know how to > tell you if this is OK or not, ask another rule". Sounds good to me then. It looks like your design is actually much closer to what I believe the standard Python semantics are intended to be than it appeared at first. [...] > Here's what the docs say about NotImplemented: > >> This type has a single value. There is a single object with this value. >> This object is accessed through the built-in name NotImplemented. >> Numeric methods and rich comparison methods may return this value if >> they do not implement the operation for the operands provided. (The >> interpreter will then try the reflected operation, or some other >> fallback, depending on the operator.) Its truth value is true. > > It gives an example of a use by numeric methods. It doesn't say that's > the only thing it can be used for. Right. You can do a lot of things in Python, including shooting your foot off :-) but that doesn't mean you should. The further away from standard Python conventions you get, the more wary you should be. That's all. > It also says, "Its truth value is true". Why would they document that > fact if you weren't supposed to use it as a boolean operand? You can use *anything* in Python in a boolean context. That's a language feature: all objects are either truthy or falsey. As for why it is documented for NotImplemented, I guess that's because some people might guess that it is falsey, like None. -- Steven From roy at panix.com Thu Apr 25 09:15:01 2013 From: roy at panix.com (Roy Smith) Date: Thu, 25 Apr 2013 09:15:01 -0400 Subject: epiphany References: <5178884b$0$29977$c3e8da3$5496439d@news.astraweb.com> <5178b1db$0$29977$c3e8da3$5496439d@news.astraweb.com> <51792710$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <51792710$0$29977$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > > It also says, "Its truth value is true". Why would they document that > > fact if you weren't supposed to use it as a boolean operand? > > You can use *anything* in Python in a boolean context. That's a language > feature: all objects are either truthy or falsey. As for why it is > documented for NotImplemented, I guess that's because some people might > guess that it is falsey, like None. That was part of what added the epiphanality to the experience. My first guess was exactly as you say, that bool(NotImplemented) would be false. Once I discovered that it was true, the rest immediately fell into place and many lines of code got replaced by the simple: return all(r(...) for r in rules) ^ | +---- stuff that I'm not showing goes here :-) From dihedral88888 at googlemail.com Sun Apr 28 17:14:14 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Sun, 28 Apr 2013 14:14:14 -0700 (PDT) Subject: epiphany In-Reply-To: References: Message-ID: <3f095bcc-5685-4724-8ecf-8486da458b64@googlegroups.com> Roy Smith? 2013?4?25????UTC+8??7?50?33???? > I discovered something really neat today. > > > > We've got a system with a bunch of rules. Each rule is a method which > > returns True or False. At some point, we need to know if all the rules > > are True. Complicating things, not all the rules are implemented. > > Those that are not implemented raise NotImplementedError. > > > > We used to have some ugly logic which kept track of which rules were > > active and only evaluated those. > > > > So, here's the neat thing. It turns out that bool(NotImplemented) > > returns True. By changing the unimplemented rules from raising > > NotImplementedError to returning NotImplemented, the whole thing becomes: > > > > return all(r() for r in rules) Problems of rules in Boolean algebra or the bi-level logic inference engine in AI were all solved long time ago in the text book about AI. There are some variations about the multi-level or the continuous level logic engine with some new phases in Fuzzy theory in the expert system. A dynamical typed language is better to be used in this kind of problems. From spluque at gmail.com Wed Apr 24 23:35:14 2013 From: spluque at gmail.com (Seb) Date: Wed, 24 Apr 2013 22:35:14 -0500 Subject: IPython in Emacs Message-ID: <87li87nuz1.fsf@kolob.subpolar.dyndns.org> Hi, Please excuse the slightly off-topic query. I'm learning Python, using the IPython (0.13) shell, and wanted to run it from Emacs 24. AFAICT, python.el is the most actively developed library, and is included in Emacs. How do experienced Python programmers set up their python.el to make the best of it? I've done it following the recommendations given in the library?: (setq python-shell-interpreter "ipython" python-shell-interpreter-args "" python-shell-prompt-regexp "In \\[[0-9]+\\]: " python-shell-prompt-output-regexp "Out\\[[0-9]+\\]: " python-shell-completion-setup-code "from IPython.core.completerlib import module_completion" python-shell-completion-module-string-code "';'.join(module_completion('''%s'''))\n" python-shell-completion-string-code "';'.join(get_ipython().Completer.all_completions('''%s'''))\n") but this may be a little outdated as it refers to IPython 0.11. Thanks, Seb +--- Footnotes ---+ ? Ignored recommended setting for `python-shell-interpreter-args' From rustompmody at gmail.com Thu Apr 25 00:38:04 2013 From: rustompmody at gmail.com (rusi) Date: Wed, 24 Apr 2013 21:38:04 -0700 (PDT) Subject: IPython in Emacs References: Message-ID: <774a9ef7-dadd-4769-998c-d24cceb1b6a0@j5g2000pby.googlegroups.com> On Apr 25, 8:35?am, Seb wrote: > Hi, > > Please excuse the slightly off-topic query. ?I'm learning Python, using > the IPython (0.13) shell, and wanted to run it from Emacs 24. ?AFAICT, > python.el is the most actively developed library, and is included in > Emacs. ?How do experienced Python programmers set up their python.el to > make the best of it? ?I've done it following the recommendations given > in the library?: > > (setq > ?python-shell-interpreter "ipython" > ?python-shell-interpreter-args "" > ?python-shell-prompt-regexp "In \\[[0-9]+\\]: " > ?python-shell-prompt-output-regexp "Out\\[[0-9]+\\]: " > ?python-shell-completion-setup-code > ?"from IPython.core.completerlib import module_completion" > ?python-shell-completion-module-string-code > ?"';'.join(module_completion('''%s'''))\n" > ?python-shell-completion-string-code > ?"';'.join(get_ipython().Completer.all_completions('''%s'''))\n") > > but this may be a little outdated as it refers to IPython 0.11. > > Thanks, > Seb > > +--- Footnotes ---+ > ? Ignored recommended setting for `python-shell-interpreter-args' There were some ipython+emacs+windows bugs: https://bugs.launchpad.net/ipython/+bug/290228 Last I tried nearly 2 years, they were still there http://groups.google.com/group/comp.lang.python/browse_thread/thread/36e757567f28368e [Since you did not say whether you are on windows or *nix, just saying] From spluque at gmail.com Thu Apr 25 09:01:37 2013 From: spluque at gmail.com (Seb) Date: Thu, 25 Apr 2013 08:01:37 -0500 Subject: IPython in Emacs References: <774a9ef7-dadd-4769-998c-d24cceb1b6a0@j5g2000pby.googlegroups.com> Message-ID: <878v46ojbi.fsf@kolob.subpolar.dyndns.org> On Wed, 24 Apr 2013 21:38:04 -0700 (PDT), rusi wrote: > There were some ipython+emacs+windows bugs: > https://bugs.launchpad.net/ipython/+bug/290228 > Last I tried nearly 2 years, they were still there > http://groups.google.com/group/comp.lang.python/browse_thread/thread/36e757567f28368e On Debian here, so not a problem. Thanks, -- Seb From rustompmody at gmail.com Thu Apr 25 09:54:33 2013 From: rustompmody at gmail.com (rusi) Date: Thu, 25 Apr 2013 06:54:33 -0700 (PDT) Subject: IPython in Emacs References: <774a9ef7-dadd-4769-998c-d24cceb1b6a0@j5g2000pby.googlegroups.com> Message-ID: On Apr 25, 6:01?pm, Seb wrote: > On Wed, 24 Apr 2013 21:38:04 -0700 (PDT), > > rusi wrote: > > There were some ipython+emacs+windows bugs: > >https://bugs.launchpad.net/ipython/+bug/290228 > > Last I tried nearly 2 years, they were still there > >http://groups.google.com/group/comp.lang.python/browse_thread/thread/... > > On Debian here, so not a problem. Ok me too :-) A quick try of your startup code did not work for me. There is a perennial clash in emacs between python.el and python- mode.el -- I guess its that. Which do you use? What are your commands for eval-buffer and start-interpreter? From spluque at gmail.com Thu Apr 25 18:18:44 2013 From: spluque at gmail.com (Seb) Date: Thu, 25 Apr 2013 17:18:44 -0500 Subject: IPython in Emacs References: <774a9ef7-dadd-4769-998c-d24cceb1b6a0@j5g2000pby.googlegroups.com> Message-ID: <87txmul0e3.fsf@kolob.subpolar.dyndns.org> On Thu, 25 Apr 2013 06:54:33 -0700 (PDT), rusi wrote: > On Apr 25, 6:01?pm, Seb wrote: >> On Wed, 24 Apr 2013 21:38:04 -0700 (PDT), >> rusi wrote: >> > There were some ipython+emacs+windows bugs: >> >https://bugs.launchpad.net/ipython/+bug/290228 > Last I tried nearly >> 2 years, they were still there >> >http://groups.google.com/group/comp.lang.python/browse_thread/thread/... >> On Debian here, so not a problem. > Ok me too :-) > A quick try of your startup code did not work for me. There is a > perennial clash in emacs between python.el and python- mode.el -- I > guess its that. Which do you use? The first. I don't have anything python-related in ~/.emacs other than what I showed. Works fine for me, except for weird things like multiple input prompts in the IPython shell at startup, which seem to come from each statement in the variables I showed. Similar things happen when sending code from the script buffer. > What are your commands for eval-buffer and start-interpreter? I don't understand what you're asking. I evaluate the script buffer with `python-shell-send-buffer' and start IPython with `run-python'. -- Seb From rustompmody at gmail.com Fri Apr 26 00:06:03 2013 From: rustompmody at gmail.com (rusi) Date: Thu, 25 Apr 2013 21:06:03 -0700 (PDT) Subject: IPython in Emacs References: <774a9ef7-dadd-4769-998c-d24cceb1b6a0@j5g2000pby.googlegroups.com> Message-ID: <014b6c7b-b21b-466d-b807-78c2f33f3e0e@pa2g2000pbb.googlegroups.com> On Apr 26, 3:18?am, Seb wrote: > > I don't understand what you're asking. I evaluate the script buffer > with `python-shell-send-buffer' and start IPython with `run-python'. There are two emacs python modes -- one which comes builtin with emacs -- python.el, one which (used to?) come with python -- python-mode.el. My impression is that most pythonistas preferred the python-mode earlier. Not so sure now. You can get it from https://launchpad.net/python-mode/ Heres a minimal setup for python-mode +ipython (everything's probably not working) (add-to-list 'load-path "~/.emacs.d/downloads/python-mode") ;; Or whatever is your path for python-mode.el (autoload 'python-mode "python-mode" "Python Mode." t) (add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode)) (add-to-list 'interpreter-mode-alist '("python" . python-mode)) ;; A first cut at replicating your settings of ipython for python-mode (setq py-python-command "ipython" ; python-shell-interpreter py-python-command-args '("") ; python-shell-interpreter-args ; Should it be -i? py-shell-input-prompt-1-regexp "In \\[[0-9]+\\]: " ; Other variables dont exist or cant find ; Not really explored ipython.el ) From cmpython at gmail.com Thu Apr 25 01:05:52 2013 From: cmpython at gmail.com (CM) Date: Wed, 24 Apr 2013 22:05:52 -0700 (PDT) Subject: Pythonic way to count sequences Message-ID: I have to count the number of various two-digit sequences in a list such as this: mylist = [(2,4), (2,4), (3,4), (4,5), (2,1)] # (Here the (2,4) sequence appears 2 times.) and tally up the results, assigning each to a variable. The inelegant first pass at this was something like... # Create names and set them all to 0 alpha = 0 beta = 0 delta = 0 gamma = 0 # etc... # loop over all the tuple sequences and increment appropriately for sequence_tuple in list_of_tuples: if sequence_tuple == (1,2): alpha += 1 if sequence_tuple == (2,4): beta += 1 if sequence_tuple == (2,5): delta +=1 # etc... But I actually have more than 10 sequence types. # Finally, I need a list created like this: result_list = [alpha, beta, delta, gamma] #etc...in that order I can sense there is very likely an elegant/Pythonic way to do this, and probably with a dict, or possibly with some Python structure I don't typically use. Suggestions sought. Thanks. From rosuav at gmail.com Thu Apr 25 01:26:48 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 25 Apr 2013 15:26:48 +1000 Subject: Pythonic way to count sequences In-Reply-To: References: Message-ID: On Thu, Apr 25, 2013 at 3:05 PM, CM wrote: > I have to count the number of various two-digit sequences in a list > such as this: > > mylist = [(2,4), (2,4), (3,4), (4,5), (2,1)] # (Here the (2,4) > sequence appears 2 times.) > > and tally up the results, assigning each to a variable. You can use a tuple as a dictionary key, just like you would a string. So you can count them up directly with a dictionary: count = {} for sequence_tuple in list_of_tuples: count[sequence_tuple] = count.get(sequence_tuple,0) + 1 Also, since this is such a common thing to do, there's a standard library way of doing it: import collections count = collections.Counter(list_of_tuples) This doesn't depend on knowing ahead of time what your elements will be. At the end of it, you can simply iterate over 'count' and get all your counts: for sequence,number in count.items(): print("%d of %r" % (number,sequence)) ChrisA From storchaka at gmail.com Thu Apr 25 08:36:47 2013 From: storchaka at gmail.com (Serhiy Storchaka) Date: Thu, 25 Apr 2013 15:36:47 +0300 Subject: Pythonic way to count sequences In-Reply-To: References: Message-ID: 25.04.13 08:26, Chris Angelico ???????(??): > So you can count them up directly with a dictionary: > > count = {} > for sequence_tuple in list_of_tuples: > count[sequence_tuple] = count.get(sequence_tuple,0) + 1 Or alternatives: count = {} for sequence_tuple in list_of_tuples: if sequence_tuple] in count: count[sequence_tuple] += 1 else: count[sequence_tuple] = 1 count = {} for sequence_tuple in list_of_tuples: try: count[sequence_tuple] += 1 except KeyError: count[sequence_tuple] = 1 import collections count = collections.defaultdict(int) for sequence_tuple in list_of_tuples: count[sequence_tuple] += 1 But of course collections.Counter is a preferable way now. From steve+comp.lang.python at pearwood.info Thu Apr 25 02:14:16 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Apr 2013 06:14:16 GMT Subject: Pythonic way to count sequences References: Message-ID: <5178c9b8$0$29977$c3e8da3$5496439d@news.astraweb.com> On Wed, 24 Apr 2013 22:05:52 -0700, CM wrote: > I have to count the number of various two-digit sequences in a list such > as this: > > mylist = [(2,4), (2,4), (3,4), (4,5), (2,1)] # (Here the (2,4) sequence > appears 2 times.) > > and tally up the results, assigning each to a variable. The inelegant > first pass at this was something like... > > # Create names and set them all to 0 > alpha = 0 > beta = 0 > delta = 0 > gamma = 0 > # etc... Do they absolutely have to be global variables like that? Seems like a bad design, especially if you don't know in advance exactly how many there are. > # loop over all the tuple sequences and increment appropriately for > sequence_tuple in list_of_tuples: > if sequence_tuple == (1,2): > alpha += 1 > if sequence_tuple == (2,4): > beta += 1 > if sequence_tuple == (2,5): > delta +=1 > # etc... But I actually have more than 10 sequence types. counts = {} for t in list_of_tuples: counts[t] = counts.get(t, 0) + 1 Or, use collections.Counter: from collections import Counter counts = Counter(list_of_tuples) > # Finally, I need a list created like this: result_list = [alpha, beta, > delta, gamma] #etc...in that order Dicts are unordered, so getting the results in a specific order will be a bit tricky. You could do this: results = sorted(counts.items(), key=lambda t: t[0]) results = [t[1] for t in results] if you are lucky enough to have the desired order match the natural order of the tuples. Otherwise: desired_order = [(2, 3), (3, 1), (1, 2), ...] results = [counts.get(t, 0) for t in desired_order] -- Steven From denismfmcmahon at gmail.com Thu Apr 25 19:29:28 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Thu, 25 Apr 2013 23:29:28 +0000 (UTC) Subject: Pythonic way to count sequences References: Message-ID: On Wed, 24 Apr 2013 22:05:52 -0700, CM wrote: > I have to count the number of various two-digit sequences in a list such > as this: > > mylist = [(2,4), (2,4), (3,4), (4,5), (2,1)] # (Here the (2,4) sequence > appears 2 times.) > > and tally up the results, assigning each to a variable. The inelegant > first pass at this was something like... > > # Create names and set them all to 0 alpha = 0 beta = 0 delta = 0 gamma > = 0 # etc... > > # loop over all the tuple sequences and increment appropriately for > sequence_tuple in list_of_tuples: > if sequence_tuple == (1,2): > alpha += 1 > if sequence_tuple == (2,4): > beta += 1 > if sequence_tuple == (2,5): > delta +=1 > # etc... But I actually have more than 10 sequence types. > > # Finally, I need a list created like this: > result_list = [alpha, beta, delta, gamma] #etc...in that order > > I can sense there is very likely an elegant/Pythonic way to do this, and > probably with a dict, or possibly with some Python structure I don't > typically use. Suggestions sought. Thanks. mylist = [ (3,3), (1,2), "fred", ("peter",1,7), 1, 19, 37, 28.312, ("monkey"), "fred", "fred", (1,2) ] bits = {} for thing in mylist: if thing in bits: bits[thing] += 1 else: bits[thing] = 1 for thing in bits: print thing, " occurs ", bits[thing], " times" outputs: (1, 2) occurs 2 times 1 occurs 1 times ('peter', 1, 7) occurs 1 times (3, 3) occurs 1 times 28.312 occurs 1 times fred occurs 3 times 19 occurs 1 times monkey occurs 1 times 37 occurs 1 times if you want to check that thing is a 2 int tuple then use something like: for thing in mylist: if isinstance( thing, tuple ) and len( thing ) == 2 and isinstance ( thing[0], ( int, long ) ) and isinstance( thing[1], ( int, long) ): if thing in bits: bits[thing] += 1 else: bits[thing] = 1 -- Denis McMahon, denismfmcmahon at gmail.com From modulok at gmail.com Thu Apr 25 21:16:11 2013 From: modulok at gmail.com (Modulok) Date: Thu, 25 Apr 2013 19:16:11 -0600 Subject: Pythonic way to count sequences In-Reply-To: References: Message-ID: On 4/25/13, Denis McMahon wrote: > On Wed, 24 Apr 2013 22:05:52 -0700, CM wrote: > >> I have to count the number of various two-digit sequences in a list such >> as this: >> >> mylist = [(2,4), (2,4), (3,4), (4,5), (2,1)] # (Here the (2,4) sequence >> appears 2 times.) >> >> and tally up the results, assigning each to a variable. ... Consider using the ``collections`` module:: from collections import Counter mylist = [(2,4), (2,4), (3,4), (4,5), (2,1)] count = Counter() for k in mylist: count[k] += 1 print(count) # Output looks like this: # Counter({(2, 4): 2, (4, 5): 1, (3, 4): 1, (2, 1): 1}) You then have access to methods to return the most common items, etc. See more examples here: http://docs.python.org/3.3/library/collections.html#collections.Counter Good luck! -Modulok- From m.gilson1 at gmail.com Thu Apr 25 22:40:36 2013 From: m.gilson1 at gmail.com (Matthew Gilson) Date: Thu, 25 Apr 2013 22:40:36 -0400 Subject: Pythonic way to count sequences In-Reply-To: References: Message-ID: <5179E924.2080108@gmail.com> A Counter is definitely the way to go about this. Just as a little more information. The below example can be simplified: from collections import Counter count = Counter(mylist) With the other example, you could have achieved the same thing (and been backward compatible to python2.5) with from collections import defaultdict count = defaultdict(int) for k in mylist: count[k] += 1 On 4/25/13 9:16 PM, Modulok wrote: > On 4/25/13, Denis McMahon wrote: >> On Wed, 24 Apr 2013 22:05:52 -0700, CM wrote: >> >>> I have to count the number of various two-digit sequences in a list such >>> as this: >>> >>> mylist = [(2,4), (2,4), (3,4), (4,5), (2,1)] # (Here the (2,4) sequence >>> appears 2 times.) >>> >>> and tally up the results, assigning each to a variable. > ... > > Consider using the ``collections`` module:: > > > from collections import Counter > > mylist = [(2,4), (2,4), (3,4), (4,5), (2,1)] > count = Counter() > for k in mylist: > count[k] += 1 > > print(count) > > # Output looks like this: > # Counter({(2, 4): 2, (4, 5): 1, (3, 4): 1, (2, 1): 1}) > > > You then have access to methods to return the most common items, etc. See more > examples here: > > http://docs.python.org/3.3/library/collections.html#collections.Counter > > > Good luck! > -Modulok- From cmpython at gmail.com Thu Apr 25 22:40:15 2013 From: cmpython at gmail.com (CM) Date: Thu, 25 Apr 2013 19:40:15 -0700 (PDT) Subject: Pythonic way to count sequences References: Message-ID: <2a29a04e-ace9-43d2-98b8-9c45c9b963a4@g9g2000yqh.googlegroups.com> Thank you, everyone, for the answers. Very helpful and knowledge- expanding. From llanitedave at veawb.coop Thu Apr 25 01:49:25 2013 From: llanitedave at veawb.coop (llanitedave) Date: Wed, 24 Apr 2013 22:49:25 -0700 (PDT) Subject: Comparison Style Message-ID: <125c8f33-1a62-4dc0-9341-a2d8f7b58058@googlegroups.com> Given that s = some static value i = a value incremented during a loop I'm used to comparing them as if i == s: # some code But for some unknown reason I did a switch if s == i: # same code It didn't seem to make any difference at first glance, so I just got to wondering -- Is there a standard for comparison order? Is there any kind of performance difference? Is there even a tradition for one or the other? Are there any gotchas? Do I need to get a hobby? From rosuav at gmail.com Thu Apr 25 01:57:49 2013 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 25 Apr 2013 15:57:49 +1000 Subject: Comparison Style In-Reply-To: <125c8f33-1a62-4dc0-9341-a2d8f7b58058@googlegroups.com> References: <125c8f33-1a62-4dc0-9341-a2d8f7b58058@googlegroups.com> Message-ID: On Thu, Apr 25, 2013 at 3:49 PM, llanitedave wrote: > Given that > > s = some static value > i = a value incremented during a loop > > I'm used to comparing them as > > if i == s: > # some code > > But for some unknown reason I did a switch > > if s == i: > # same code > > It didn't seem to make any difference at first glance, so I just got to wondering -- It won't make any difference in any sort of sane code. If there's any situation in which == is not reflexive, something seriously nasty is going on. > Is there a standard for comparison order? Is there any kind of performance difference? Is there even a tradition for one or the other? Are there any gotchas? It's conventional to compare variables to constants, not constants to variables (even in C where there's the possibility of mucking up the operator, most people still compare variables to constants). I'd normally use "i == s" there, treating s as a constant for the purpose of the loop. Unless you're deliberately being poetical, language such as "Three is the number thou shalt count" is distinctly abnormal, so saying "if (5 == i)" is equally awkward. It's nothing major; mostly it's like the algebraic convention of putting the more-known elements earlier in a term (eg 2?ix - 2 is known, 3.14159.... is mostly known, i is imaginary but at least it's constant, and x is unknown). > Do I need to get a hobby? I thought programming WAS a hobby? ChrisA From rosuav at gmail.com Thu Apr 25 22:48:35 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 26 Apr 2013 12:48:35 +1000 Subject: Comparison Style In-Reply-To: References: <125c8f33-1a62-4dc0-9341-a2d8f7b58058@googlegroups.com> Message-ID: On Fri, Apr 26, 2013 at 12:37 PM, Dennis Lee Bieber wrote: > On Thu, 25 Apr 2013 15:57:49 +1000, Chris Angelico > declaimed the following in gmane.comp.python.general: >> It's conventional to compare variables to constants, not constants to >> variables (even in C where there's the possibility of mucking up the >> operator, most people still compare variables to constants). > > The main reason for /literal/ first is to trap C/C++ assignment as > expression. > > if (x = 5) > > ends up assigning x the value 5 and THEN, since 5 is "true" executing > the "then" part. > > if (5 = x) > > OTOH is a compiler error. > Aware of this. My point is that, even though there's a good reason for putting the constant first, it's still FAR more common to put the variable first. Also, this protection helps only when the "constant" is actually something the compiler knows is a constant - it doesn't work in a search function, for instance: char *strchr(char *string, char findme) { while (*string) { if (*string==findme) return string; ++string; } return 0; } If you switch the order of operands in that, the compiler won't help you. Plus it "reads" wrong. So the convention is still variable==constant. ChrisA From davea at davea.name Thu Apr 25 23:43:08 2013 From: davea at davea.name (Dave Angel) Date: Thu, 25 Apr 2013 23:43:08 -0400 Subject: Comparison Style In-Reply-To: References: <125c8f33-1a62-4dc0-9341-a2d8f7b58058@googlegroups.com> Message-ID: <5179F7CC.9040207@davea.name> On 04/25/2013 10:48 PM, Chris Angelico wrote: > Also, this protection helps only when the "constant" > is actually something the compiler knows is a constant - it doesn't > work in a search function, for instance: > > char *strchr(char *string, char findme) { > while (*string) { > if (*string==findme) return string; > ++string; > } > return 0; > } Sure, but if I were coding in C again, I'd have made that function signature char *strchr(char *string, const char findme) { or maybe char *strchr(const char *string, const char findme) { > > If you switch the order of operands in that, the compiler won't help > you. Yes, it would. > Plus it "reads" wrong. So the convention is still > variable==constant. In my case, after having it drilled in that you're "supposed" to put the constant first, I realized that I never had any problem with using =, because as soon as I questioned the order, I just double-checked that I was using ==. At that point, there was no longer any benefit to making the order backwards. -- DaveA From roy at panix.com Sat Apr 27 17:03:15 2013 From: roy at panix.com (Roy Smith) Date: Sat, 27 Apr 2013 17:03:15 -0400 Subject: Comparison Style References: <125c8f33-1a62-4dc0-9341-a2d8f7b58058@googlegroups.com> Message-ID: In article , Chris Angelico wrote: > If you switch the order of operands in that, the compiler won't help > you. Plus it "reads" wrong. So the convention is still > variable==constant. I just found a nice example of putting the constant first. I've just done a whole bunch of ugly math to find some slice limits. To make sure they're sane, I'm writing: assert 5 <= i < j < original_song_count I can't think of any way to write that which would be as clean and easy to read. From tjreedy at udel.edu Sat Apr 27 17:40:46 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Sat, 27 Apr 2013 17:40:46 -0400 Subject: Comparison Style In-Reply-To: References: <125c8f33-1a62-4dc0-9341-a2d8f7b58058@googlegroups.com> Message-ID: On 4/27/2013 5:03 PM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> If you switch the order of operands in that, the compiler won't help >> you. Plus it "reads" wrong. So the convention is still >> variable==constant. > > I just found a nice example of putting the constant first. I've just > done a whole bunch of ugly math to find some slice limits. To make sure > they're sane, I'm writing: > > assert 5 <= i < j < original_song_count > > I can't think of any way to write that which would be as clean and easy > to read. Chained comparisons like this are standard math notation, which is why Python 'does the right thing' with them. From llanitedave at veawb.coop Thu Apr 25 10:19:04 2013 From: llanitedave at veawb.coop (llanitedave) Date: Thu, 25 Apr 2013 07:19:04 -0700 (PDT) Subject: Comparison Style In-Reply-To: References: <125c8f33-1a62-4dc0-9341-a2d8f7b58058@googlegroups.com> Message-ID: <852a4378-5af6-4c11-a87e-07387516be0d@googlegroups.com> On Wednesday, April 24, 2013 10:57:49 PM UTC-7, Chris Angelico wrote: > On Thu, Apr 25, 2013 at 3:49 PM, llanitedave wrote: > > > Given that > > > > > > s = some static value > > > i = a value incremented during a loop > > > > > > I'm used to comparing them as > > > > > > if i == s: > > > # some code > > > > > > But for some unknown reason I did a switch > > > > > > if s == i: > > > # same code > > > > > > It didn't seem to make any difference at first glance, so I just got to wondering -- > > > > It won't make any difference in any sort of sane code. If there's any > > situation in which == is not reflexive, something seriously nasty is > > going on. > > > > > Is there a standard for comparison order? Is there any kind of performance difference? Is there even a tradition for one or the other? Are there any gotchas? > > > > It's conventional to compare variables to constants, not constants to > > variables (even in C where there's the possibility of mucking up the > > operator, most people still compare variables to constants). I'd > > normally use "i == s" there, treating s as a constant for the purpose > > of the loop. Unless you're deliberately being poetical, language such > > as "Three is the number thou shalt count" is distinctly abnormal, so > > saying "if (5 == i)" is equally awkward. It's nothing major; mostly > > it's like the algebraic convention of putting the more-known elements > > earlier in a term (eg 2?ix - 2 is known, 3.14159.... is mostly known, > > i is imaginary but at least it's constant, and x is unknown). > > Thanks, Chris. That's kind of along the lines of what I was thinking. Visually, the code just looked wrong, and I figure if for no other reasons than readability it's preferable in the traditional way. It's nice to know, though, that the next time dyslexia strikes it's not necessarily a horrible thing. > > > Do I need to get a hobby? > > > > I thought programming WAS a hobby? > I meant a safer, easier, and more mainstream hobby, like base jumping or motorcycle aerobatics or something. From rosuav at gmail.com Thu Apr 25 12:25:07 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 26 Apr 2013 02:25:07 +1000 Subject: Comparison Style In-Reply-To: <852a4378-5af6-4c11-a87e-07387516be0d@googlegroups.com> References: <125c8f33-1a62-4dc0-9341-a2d8f7b58058@googlegroups.com> <852a4378-5af6-4c11-a87e-07387516be0d@googlegroups.com> Message-ID: On Fri, Apr 26, 2013 at 12:19 AM, llanitedave wrote: > On Wednesday, April 24, 2013 10:57:49 PM UTC-7, Chris Angelico wrote: >> I thought programming WAS a hobby? >> > > I meant a safer, easier, and more mainstream hobby, like base jumping or motorcycle aerobatics or something. Good point. With the sort of thinking you're demonstrating here, you should consider a job working with Spike Milligna (the well-known typing error). I believe there ought to be an office cubicle available for you in one of the excellent organizations devoted to Milliganesque thinkers and computer programmers - the walls are nicely padded... ChrisA From square.steve at gmail.com Thu Apr 25 14:31:04 2013 From: square.steve at gmail.com (Steve Simmons) Date: Thu, 25 Apr 2013 19:31:04 +0100 Subject: Comparison Style In-Reply-To: References: <125c8f33-1a62-4dc0-9341-a2d8f7b58058@googlegroups.com> <852a4378-5af6-4c11-a87e-07387516be0d@googlegroups.com> Message-ID: <7e697911-9653-4839-9273-7a9ea8a08cde@email.android.com> Chris Angelico wrote: With the sort of thinking you're demonstrating here, you should consider a job working with Spike Milligna (the well known typing error). Errr , I think you'll find that he's joined the choir invisibule. Mind you, he did say he was ill! Sent from a Galaxy far far away From llanitedave at veawb.coop Thu Apr 25 16:13:21 2013 From: llanitedave at veawb.coop (llanitedave) Date: Thu, 25 Apr 2013 13:13:21 -0700 (PDT) Subject: Comparison Style In-Reply-To: References: <125c8f33-1a62-4dc0-9341-a2d8f7b58058@googlegroups.com> <852a4378-5af6-4c11-a87e-07387516be0d@googlegroups.com> Message-ID: On Thursday, April 25, 2013 11:31:04 AM UTC-7, Steve Simmons wrote: > Chris Angelico wrote: > > > > With the sort of thinking you're demonstrating here, you > > should consider a job working with Spike Milligna (the well known typing error). > > > > Errr , I think you'll find that he's joined the choir invisibule. Mind you, he did say he was ill! > > > > Sent from a Galaxy far far away Did you ever hear him sing? He's better off in the choir inaudible. As am I... From neilc at norwich.edu Thu Apr 25 16:15:30 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 25 Apr 2013 20:15:30 GMT Subject: Comparison Style References: <125c8f33-1a62-4dc0-9341-a2d8f7b58058@googlegroups.com> <852a4378-5af6-4c11-a87e-07387516be0d@googlegroups.com> Message-ID: On 2013-04-25, llanitedave wrote: >> Errr , I think you'll find that he's joined the choir >> invisibule. Mind you, he did say he was ill! >> >> Sent from a Galaxy far far away > > Did you ever hear him sing? He's better off in the choir > inaudible. Well I've never heard either one. -- Neil Cerutti From square.steve at gmail.com Thu Apr 25 16:35:01 2013 From: square.steve at gmail.com (Steve Simmons) Date: Thu, 25 Apr 2013 21:35:01 +0100 Subject: Comparison Style In-Reply-To: References: <125c8f33-1a62-4dc0-9341-a2d8f7b58058@googlegroups.com> <852a4378-5af6-4c11-a87e-07387516be0d@googlegroups.com> Message-ID: <63c4c12b-ccb6-4eef-9fa2-106e37e09a50@email.android.com> llanitedave wrote: >On Thursday, April 25, 2013 11:31:04 AM UTC-7, Steve Simmons wrote: >> Chris Angelico wrote: >> >> >> >> With the sort of thinking you're demonstrating here, you >> >> should consider a job working with Spike Milligna (the well known >typing error). >> >> >> >> Errr , I think you'll find that he's joined the choir invisibule. >Mind you, he did say he was ill! >> >> >> >> Sent from a Galaxy far far away > > >Did you ever hear him sing? He's better off in the choir inaudible. > >As am I... >-- >http://mail.python.org/mailman/listinfo/python-list The Ying Tong song - a classic of its time. But eminently suited to the chorally challenged. Sent from a Galaxy far far away -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Fri Apr 26 05:02:52 2013 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 26 Apr 2013 10:02:52 +0100 Subject: Comparison Style In-Reply-To: <63c4c12b-ccb6-4eef-9fa2-106e37e09a50@email.android.com> References: <125c8f33-1a62-4dc0-9341-a2d8f7b58058@googlegroups.com> <852a4378-5af6-4c11-a87e-07387516be0d@googlegroups.com> <63c4c12b-ccb6-4eef-9fa2-106e37e09a50@email.android.com> Message-ID: On 25/04/2013 21:35, Steve Simmons wrote: > > > The Ying Tong song - a classic of its time. But eminently suited to the > chorally challenged. > Released on a classic EP with Major Dennis Bloodnok's Rock and Roll Call Rumba, I'm walking Backwards for Christmas and Bluebottle Blues. Bravado, bravado. What a voice! (What a bank balance!) -- If you're using GoogleCrap? please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence From priisdk at gmail.com Thu Apr 25 04:27:54 2013 From: priisdk at gmail.com (priisdk at gmail.com) Date: Thu, 25 Apr 2013 01:27:54 -0700 (PDT) Subject: Single-event-mode plotting Message-ID: <0dac961c-66a3-4c13-8c38-e485b8dec8dc@googlegroups.com> I have some questions on the example below. My intention is to replace the y values with data from some sensor connected to the computer, and to make it work in what could be called 'single-event-mode' which means that I only want to plot and store data whenever the mouse is clicked. I have made the plotting with VPython, and I have also considered matplotlib. However, with either of these modules I cannot see how to answer the questions 1 and 2 below. Is there some other graphical module that will be better suited? Notice, that I use Python 3.2. 1) Can I modify the program so that the clicks should be done in the testdisplay window on not in the scene window? 2) In the testdisplay I only want to see the actual blue point together with the hitherto stored green points. And not only that: I want to free all earlier blue points from memory. How can I do that? Poul Riis from time import * import visual.graph as visualgraph from visual import * scene=display(x=0, y=0, width=300, height=100,foreground=color.black, background=color.white) ch='' txt='' inputtext='tmax: ' labeltext=label(pos=(0,0,0),text=inputtext) while ch!='\n': ch=scene.kb.getkey() txt=txt+ch if ch!='\n': labeltext.text=inputtext+txt tmax=eval(txt) #labeltext.visible=0 testdisplay=visualgraph.gdisplay(title='Test', xtitle='x', ytitle='y', x=0, y=75, width=500, height=500,foreground=color.black, background=color.white) testcurve = visualgraph.gcurve(color=color.blue,display=testdisplay) testdots = visualgraph.gdots(color=color.red,display=testdisplay,size=5) mousedots = visualgraph.gdots(color=color.green,display=testdisplay,size=10) finalcurve = visualgraph.gcurve(color=color.magenta,display=testdisplay) tarray=[] yarray=[] tstart=time() t=time()-tstart while t1: mousedots.plot(pos=(t,y)) scene.mouse.events = 0 tarray.append(t) yarray.append(y) for i in range(0,len(tarray)): finalcurve.plot(pos=(tarray[i],yarray[i])) From eschneider92 at comcast.net Thu Apr 25 04:47:17 2013 From: eschneider92 at comcast.net (eschneider92 at comcast.net) Date: Thu, 25 Apr 2013 01:47:17 -0700 (PDT) Subject: Guess the Number Repeat Message-ID: How do I make the following program play the 'guess the number game' twice? import random guessesTaken = 0 print('Hello! What is your name?') myName = input() number = random.randint(1, 20) print('Well, ' + myName + ', I am thinking of a number between 1 and 20.') while guessesTaken < 6: print('Take a guess.') guess = input() guess = int(guess) print('You have ' + str(5 - guessesTaken) + ' guesses left.') guessesTaken = guessesTaken + 1 if guess < number: print('Your guess is too low.') if guess > number: print('Your guess is too high.') if guess == number: break if guess == number: guessesTaken = str(guessesTaken) print('Good job, ' + myName + '! You guessed my number in ' + guessesTaken + ' guesses!') if guess != number: number = str(number) print('Nope. The number I was thinking of was ' + number) From __peter__ at web.de Thu Apr 25 05:22:24 2013 From: __peter__ at web.de (Peter Otten) Date: Thu, 25 Apr 2013 11:22:24 +0200 Subject: Guess the Number Repeat References: Message-ID: eschneider92 at comcast.net wrote: > How do I make the following program play the 'guess the number game' > twice? > > import random > guessesTaken = 0 > print('Hello! What is your name?') > myName = input() > number = random.randint(1, 20) > print('Well, ' + myName + ', I am thinking of a number between 1 and 20.') > while guessesTaken < 6: > print('Take a guess.') > guess = input() > guess = int(guess) > print('You have ' + str(5 - guessesTaken) + ' guesses left.') > guessesTaken = guessesTaken + 1 > if guess < number: > print('Your guess is too low.') > if guess > number: > print('Your guess is too high.') > if guess == number: > break > if guess == number: > guessesTaken = str(guessesTaken) > print('Good job, ' + myName + '! You guessed my number in ' + > guessesTaken + ' guesses!') > if guess != number: > number = str(number) > print('Nope. The number I was thinking of was ' + number) If you put everything needed to guess once into a function like in the following example. Once you have reorganised #first version -- flat guess = int(input("guess my number: ")) if guess == 42: print("congrats") else: print("sorry, you're wrong") into #second version -- using a function def guess_number(): guess = int(input("guess my number: ")) if guess == 42: print("congrats") else: print("sorry, you're wrong") guess_number() you can easily modify the script to invoke the guess_number() function inside a loop: #third version -- calling the function from within a loop def guess_number(): guess = int(input("guess my number: ")) if guess == 42: print("congrats") else: print("sorry, you're wrong") for i in range(2): print("round", i+1) guess_number() From amachu at amachu.me Thu Apr 25 06:46:01 2013 From: amachu at amachu.me (=?UTF-8?B?4K6G4K6u4K6+4K6a4K+N4K6a4K+B?=) Date: Thu, 25 Apr 2013 16:16:01 +0530 Subject: Libroffice PMT equivalent in python Message-ID: <51790969.7000700@amachu.me> Hi, Are there equivalent in any Python libraries that could match function like PMT in libreoffice? Refer: https://help.libreoffice.org/Calc/Financial_Functions_Part_Two#PMT -- Amachu From tjreedy at udel.edu Thu Apr 25 07:47:25 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Thu, 25 Apr 2013 07:47:25 -0400 Subject: Libroffice PMT equivalent in python In-Reply-To: <51790969.7000700@amachu.me> References: <51790969.7000700@amachu.me> Message-ID: On 4/25/2013 6:46 AM, ??????? wrote: > Hi, > > Are there equivalent in any Python libraries that could match function > like PMT in libreoffice? > > Refer: https://help.libreoffice.org/Calc/Financial_Functions_Part_Two#PMT try the packages listed at https://pypi.python.org/pypi?%3Aaction=search&term=finance&submit=search From vlastimil.brom at gmail.com Thu Apr 25 07:48:39 2013 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Thu, 25 Apr 2013 13:48:39 +0200 Subject: Libroffice PMT equivalent in python In-Reply-To: <51790969.7000700@amachu.me> References: <51790969.7000700@amachu.me> Message-ID: 2013/4/25 ??????? > Hi, > > Are there equivalent in any Python libraries that could match function > like PMT in libreoffice? > > Refer: https://help.libreoffice.org/Calc/Financial_Functions_Part_Two#PMT > > -- > > Amachu > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, you may check numpy http://www.numpy.org/ http://docs.scipy.org/doc/numpy/reference/generated/numpy.pmt.html >>> import numpy >>> numpy.pmt(1.99/100/12,36,25000) -715.95533443739942 >>> (The input in percent is to be divided by 100 and the output could be rounded separately, if needed.) hth, vbr -------------- next part -------------- An HTML attachment was scrubbed... URL: From maitreymishra23 at gmail.com Thu Apr 25 09:28:21 2013 From: maitreymishra23 at gmail.com (maitreymishra23 at gmail.com) Date: Thu, 25 Apr 2013 06:28:21 -0700 (PDT) Subject: Efficient way of looging in python Message-ID: <4a1fef39-38e6-48ef-9159-f11a83edb6c1@googlegroups.com> Hi, I need an efficient way of logging using python. My problem statemnt: 1. I have multiple processes using the same logging file. I need solutions to the following: a) If multiple processes are trying to write to the same file, I need to prevent that. Otherwise, the logging messages will be puzzling to the user as he would see logging messages from one module than may be some other following it. Please let me know if there is an efficient way to do it. Thanks! Br, Maitrey From skip at pobox.com Thu Apr 25 09:43:31 2013 From: skip at pobox.com (Skip Montanaro) Date: Thu, 25 Apr 2013 08:43:31 -0500 Subject: Efficient way of looging in python In-Reply-To: <4a1fef39-38e6-48ef-9159-f11a83edb6c1@googlegroups.com> References: <4a1fef39-38e6-48ef-9159-f11a83edb6c1@googlegroups.com> Message-ID: > a) If multiple processes are trying to write to the same file, I need to prevent that. Two things: Use some sort of file locking. You can get the lockfile module from PyPI. Include at least the process id as one of the logging fields in your formatter. I haven't don't enough with the logging module to know it it supports some sort of "name" field, which would make the different messages more easily distinguished, but if so, that would be a better alternative to the process id. Skip From roozbeh73 at gmail.com Thu Apr 25 10:04:03 2013 From: roozbeh73 at gmail.com (Roozbeh) Date: Thu, 25 Apr 2013 07:04:03 -0700 (PDT) Subject: Efficient way of looging in python In-Reply-To: <4a1fef39-38e6-48ef-9159-f11a83edb6c1@googlegroups.com> References: <4a1fef39-38e6-48ef-9159-f11a83edb6c1@googlegroups.com> Message-ID: <364c9a51-c341-414f-846c-91066854ff8b@googlegroups.com> You can also add several handlers to your logger with different levels, so that one Filehandler passes the errors to a log file and StreamHandler passes messages with a different level to the output stream. Also by setting the basicConfig of the logger you can format the log messages so that you would see where the messages are originating from. From jeanmichel at sequans.com Thu Apr 25 10:32:36 2013 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 25 Apr 2013 16:32:36 +0200 (CEST) Subject: Efficient way of looging in python In-Reply-To: <4a1fef39-38e6-48ef-9159-f11a83edb6c1@googlegroups.com> Message-ID: <1903172724.4590064.1366900356960.JavaMail.root@sequans.com> ----- Original Message ----- > Hi, > > I need an efficient way of logging using python. > My problem statemnt: > 1. I have multiple processes using the same logging file. > I need solutions to the following: > a) If multiple processes are trying to write to the same file, I need > to prevent that. Otherwise, the logging messages will be puzzling to > the user as he would see logging messages from one module than may > be some other following it. > > Please let me know if there is an efficient way to do it. > > Thanks! > > Br, > Maitrey > -- > http://mail.python.org/mailman/listinfo/python-list Everything you need should be explained here http://docs.python.org/release/3.2/howto/logging-cookbook.html#logging-to-a-single-file-from-multiple-processes Most of the concepts are applicable to any version of python I've done it with python 2.5. I used some Vinay's code posted on the net to implement a logging server, all my processes are logging to that server which is responsible for writing the file. JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. From eternaltheft at gmail.com Thu Apr 25 11:01:09 2013 From: eternaltheft at gmail.com (eternaltheft at gmail.com) Date: Thu, 25 Apr 2013 08:01:09 -0700 (PDT) Subject: How to return list of lists Message-ID: <36aee43c-9368-44c4-813c-ce93a781dfff@googlegroups.com> Hi guys, I'm having a lot of trouble with this. My understanding of python is very basic and I was wondering how I can return this table as a list of lists. 1 2 3 4 5 3 4 5 6 5 6 7 7 8 9 The function is def Table(n): Then how would I make it that when the value of n is 4 it returns [[1, 2, 3], [3, 4], [5]]. Thank you From wolfgang.maier at biologie.uni-freiburg.de Thu Apr 25 11:29:31 2013 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Thu, 25 Apr 2013 15:29:31 +0000 (UTC) Subject: How to return list of lists References: <36aee43c-9368-44c4-813c-ce93a781dfff@googlegroups.com> Message-ID: gmail.com> writes: > > Hi guys, I'm having a lot of trouble with this. > > My understanding of python is very basic and I was wondering how I can return this table as a list of lists. > > 1 2 3 4 5 > 3 4 5 6 > 5 6 7 > 7 8 > 9 > > The function is > def Table(n): > Then how would I make it that when the value of n is 4 it returns [[1, 2, 3], [3, 4], [5]]. > > Thank you > First of all, state your question precisely! I have no idea why with n=4 you would want to return that! Second, the solution of this sort of problem lies in list comprehensions combined with range(). Read up on those topics! Especially comprehensions are so fundamental to the language that you have know about them before you embark on any serious programming efforts. Best, Wolfgang From eternaltheft at gmail.com Thu Apr 25 11:41:55 2013 From: eternaltheft at gmail.com (Eternaltheft) Date: Thu, 25 Apr 2013 08:41:55 -0700 (PDT) Subject: How to return list of lists In-Reply-To: References: <36aee43c-9368-44c4-813c-ce93a781dfff@googlegroups.com> Message-ID: <15f9dbd3-d890-4e56-a9b8-cc9f7eebc6f9@googlegroups.com> On Thursday, April 25, 2013 11:29:31 PM UTC+8, Wolfgang Maier wrote: > gmail.com> writes: > > > > > > > > Hi guys, I'm having a lot of trouble with this. > > > > > > My understanding of python is very basic and I was wondering how I can > > return this table as a list of lists. > > > > > > 1 2 3 4 5 > > > 3 4 5 6 > > > 5 6 7 > > > 7 8 > > > 9 > > > > > > The function is > > > def Table(n): > > > Then how would I make it that when the value of n is 4 it returns [[1, 2, > > 3], [3, 4], [5]]. > > > > > > Thank you > > > > > > > First of all, state your question precisely! > > I have no idea why with n=4 you would want to return that! > > Second, the solution of this sort of problem lies in list comprehensions > > combined with range(). Read up on those topics! Especially comprehensions > > are so fundamental to the language that you have know about them before you > > embark on any serious programming efforts. > > Best, > > Wolfgang Ah sorry the task is to make a function for this: def tTable(n): tTable(n),even n, returns the initial triangular n-1 x n-1(triangular table i posted before) table as a list of lists. For example, tTable(4) returns [[1, 2, 3], [3, 4], [5]]. Sorry if i was a bit vague, but i don't know how to explain it any better :(. And thanks for the tips! I will definitely read up on it when i get the time. From wolfgang.maier at biologie.uni-freiburg.de Thu Apr 25 11:57:50 2013 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Thu, 25 Apr 2013 15:57:50 +0000 (UTC) Subject: How to return list of lists References: <36aee43c-9368-44c4-813c-ce93a781dfff@googlegroups.com> <15f9dbd3-d890-4e56-a9b8-cc9f7eebc6f9@googlegroups.com> Message-ID: Eternaltheft gmail.com> writes: > > Ah sorry the task is to make a function for this: > def tTable(n): > tTable(n),even n, returns the initial triangular n-1 x n-1(triangular table i posted before) table as a > list of lists. For example, tTable(4) returns [[1, 2, 3], [3, 4], [5]]. > > Sorry if i was a bit vague, but i don't know how to explain it any better :(. And thanks for the tips! I will > definitely read up on it when i get the time. > So if you posted this before, why are you asking again? Could you provide a link to the post? Otherwise, I guess I'll look for it when I get the time ;) From eternaltheft at gmail.com Thu Apr 25 12:05:32 2013 From: eternaltheft at gmail.com (Eternaltheft) Date: Thu, 25 Apr 2013 09:05:32 -0700 (PDT) Subject: How to return list of lists In-Reply-To: References: <36aee43c-9368-44c4-813c-ce93a781dfff@googlegroups.com> <15f9dbd3-d890-4e56-a9b8-cc9f7eebc6f9@googlegroups.com> Message-ID: <76ecaa39-1cce-45b6-931b-91b51b5f8ce7@googlegroups.com> Haha i'm confused? im guessing you mean the triangular table i said i posted before? its this one 1 2 3 4 5 3 4 5 6 5 6 7 7 8 9 this was the table in my original post From eternaltheft at gmail.com Thu Apr 25 12:06:37 2013 From: eternaltheft at gmail.com (Eternaltheft) Date: Thu, 25 Apr 2013 09:06:37 -0700 (PDT) Subject: How to return list of lists In-Reply-To: <76ecaa39-1cce-45b6-931b-91b51b5f8ce7@googlegroups.com> References: <36aee43c-9368-44c4-813c-ce93a781dfff@googlegroups.com> <15f9dbd3-d890-4e56-a9b8-cc9f7eebc6f9@googlegroups.com> <76ecaa39-1cce-45b6-931b-91b51b5f8ce7@googlegroups.com> Message-ID: On Friday, April 26, 2013 12:05:32 AM UTC+8, Eternaltheft wrote: > Haha i'm confused? im guessing you mean the triangular table i said i posted before? its this one > > > > 1 2 3 4 5 > > 3 4 5 6 > > 5 6 7 > > 7 8 > > 9 > > > > this was the table in my original post omg im an idiot, i didn't mention that the original table is the triangular table.. From rustompmody at gmail.com Thu Apr 25 11:46:10 2013 From: rustompmody at gmail.com (rusi) Date: Thu, 25 Apr 2013 08:46:10 -0700 (PDT) Subject: How to return list of lists References: <36aee43c-9368-44c4-813c-ce93a781dfff@googlegroups.com> Message-ID: <5b178abd-c62c-44c5-8b02-81c95659ec41@oy9g2000pbb.googlegroups.com> On Apr 25, 8:29?pm, Wolfgang Maier wrote: > ? gmail.com> writes: > > > > > Hi guys, I'm having a lot of trouble with this. > > > My understanding of python is very basic and I was wondering how I can > > return this table as a list of lists. > > > > > 1 ?2 ? ? ? 3 ? ? ? 4 ? ? ? 5 > > 3 ?4 ? ? ? 5 ? ? ? 6 > > 5 ?6 ? ? ? 7 > > 7 ?8 > > 9 > > > The function is > > def Table(n): > > Then how would I make it that when the value of n is 4 it returns [[1, 2, > 3], [3, 4], [5]]. > > > Thank you > > First of all, state your question precisely! > I have no idea why with n=4 you would want to return that! > Second, the solution of this sort of problem lies in list comprehensions > combined with range(). Read up on those topics! Especially comprehensions > are so fundamental to the language that you have know about them before you > embark on any serious programming efforts. > Best, > Wolfgang As Wolfgang says -- dunno why the 4 (my code below works for 3) And I wonder whether you are making us do your homework. Still heres something to start you off def row(max,n): return range(2*n-1, max+n) def tri(max): return [row(max,i) for i in range(1,max+1)] >>> tri(3) [[1, 2, 3], [3, 4], [5]] >>> From eternaltheft at gmail.com Thu Apr 25 11:53:22 2013 From: eternaltheft at gmail.com (Eternaltheft) Date: Thu, 25 Apr 2013 08:53:22 -0700 (PDT) Subject: How to return list of lists In-Reply-To: <36aee43c-9368-44c4-813c-ce93a781dfff@googlegroups.com> References: <36aee43c-9368-44c4-813c-ce93a781dfff@googlegroups.com> Message-ID: <1bdbdc34-85d8-4a49-9281-2ff42abb8c00@googlegroups.com> Definitely not, like i said I'm having trouble doing it, you didn't have to write a code for me, i just need an explanation on how to do it. sorry if it felt like i was trying to get my homework done From steve+comp.lang.python at pearwood.info Thu Apr 25 14:36:58 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Apr 2013 18:36:58 GMT Subject: How to return list of lists References: <36aee43c-9368-44c4-813c-ce93a781dfff@googlegroups.com> Message-ID: <517977ca$0$29977$c3e8da3$5496439d@news.astraweb.com> On Thu, 25 Apr 2013 08:01:09 -0700, eternaltheft wrote: > Hi guys, I'm having a lot of trouble with this. > > My understanding of python is very basic and I was wondering how I can > return this table as a list of lists. > > 1 2 3 4 5 > 3 4 5 6 > 5 6 7 > 7 8 > 9 Do you know how to build lists of numbers? a = [1, 2, 3, 4, 5] b = [3, 4, 5, 6] c = [5, 6, 7] d = [7, 8] e = [9] Now put them in a list: table = [a, b, c, d, e] print table Got that so far? Now let's see how you might do the same thing without typing up the inner lists by hand. For that, you want the range() function. a = range(1, 6) # 1 is included, 6 is excluded. b = range(3, 7) c = range(5, 8) # etc. Now let's do it without the temporary variables a, b, c, d, e. This time, start with the outer list, only with nothing in it. Then fill it using the range function. table = [] table.append(range(1, 6)) table.append(range(3, 7)) # etc. Now let's put this in a function: def table(n): # Returns a triangular table (list of lists). # So far, we ignore n and hard-code the table. We'll fix this later. table = [] table.append(range(1, 6)) table.append(range(3, 7)) # etc. return table You're about halfway there now. The easy half. You get to do the hard half :-) You need to think about how to turn a series of repeated appends into a loop, either a while loop or a for loop. I recommend you use a for-loop. Start by answering these questions: * if the argument to the function, n, is 4, how many rows and how many columns will the table have? * if n is 5, how many rows and columns will the table have? * in general, for some value of n, what will be the first row? * turn that into a call to range. Remember that if you call range with two arguments, the first argument is included, the second is excluded: range(5, 9) => [5, 6, 7, 8] * what will the second row be? Hint: the *first* number in the second row will be the first number of the first row PLUS TWO; the *last* number in the second row will be ... what? * turn that into a call to range. Can you see the pattern for how each call to range will vary from the last? * this suggests you want a for loop: for row number 1, 2, 3, ... table.append(make a row) Obviously that's not real Python code. You need to write the Python code. Write some code, and if you run into trouble, come back and ask for help. Good luck! -- Steven From eternaltheft at gmail.com Thu Apr 25 22:12:57 2013 From: eternaltheft at gmail.com (Eternaltheft) Date: Thu, 25 Apr 2013 19:12:57 -0700 (PDT) Subject: How to return list of lists In-Reply-To: <36aee43c-9368-44c4-813c-ce93a781dfff@googlegroups.com> References: <36aee43c-9368-44c4-813c-ce93a781dfff@googlegroups.com> Message-ID: <15dcd16d-a060-4ac1-b080-0270d9f3e3de@googlegroups.com> Thank you so much for the help, I get it now :D. I really appreciate you taking the time to explain it into detail for me From sn at sncs.se Thu Apr 25 11:09:55 2013 From: sn at sncs.se (sverker nilsson) Date: Thu, 25 Apr 2013 17:09:55 +0200 (CEST) Subject: Guppy-PE/Heapy 0.1.10 Message-ID: <881148509.678625.1366902595790.JavaMail.open-xchange@webmail.surftown.com> I am happy to announce Guppy-PE 0.1.10 Guppy-PE is a library and programming environment for Python, currently providing in particular the Heapy subsystem, which supports object and heap memory sizing, profiling and debugging. It also includes a prototypical specification language, the Guppy Specification Language (GSL), which can be used to formally specify aspects of Python programs and generate tests and documentation from a common source. The main news in this release: o Support for Python 2.7 However, there are still some problems with the tests that I haven't been able to sort out. o Some minor bug fixes License: MIT Guppy-PE 0.1.10 is available in source tarball format on the Python Package Index (a.k.a. Cheeseshop): http://pypi.python.org/pypi/guppy/0.1.10 The project homepage is on Sourceforge: http://guppy-pe.sourceforge.net Enjoy, Sverker Nilsson -------------- next part -------------- An HTML attachment was scrubbed... URL: From hossamalagmy at gmail.com Thu Apr 25 13:51:39 2013 From: hossamalagmy at gmail.com (23alagmy) Date: Thu, 25 Apr 2013 10:51:39 -0700 (PDT) Subject: HTC ChaCha review Message-ID: <607e6075-7056-4c29-8a54-310dff273280@b10g2000vbu.googlegroups.com> HTC ChaCha review http://natigtas7ab.blogspot.com/2012/10/htc-chacha-review.html From eric.frederich at gmail.com Thu Apr 25 16:00:12 2013 From: eric.frederich at gmail.com (Eric Frederich) Date: Thu, 25 Apr 2013 16:00:12 -0400 Subject: Python platform/framework for new RESTful web app Message-ID: If I wanted to create a new web application (RESTful) today with Python what are my options given the following requirements. * Google Account authentication * Facebook authentication * Managed hosting (like Google App Engine or Heroku) but with the ability to be self-hosted later down the road. I am familiar with Django (well I was a 3 years ago). I have played a little with web.py and like the ideas there. I like the idea of using something like GAE but don't want to be locked in. Is Django the answer? I think you can run Django on GAE (and obviously you can self-host it). I see there is a Django REST framework. Is this a good framework? Are there good Google and Facebook authentication extensions? Thanks, ~Eric -------------- next part -------------- An HTML attachment was scrubbed... URL: From kwpolska at gmail.com Sat Apr 27 08:18:45 2013 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Sat, 27 Apr 2013 14:18:45 +0200 Subject: Python platform/framework for new RESTful web app In-Reply-To: References: Message-ID: On Thu, Apr 25, 2013 at 10:00 PM, Eric Frederich wrote: > If I wanted to create a new web application (RESTful) today with Python what > are my options given the following requirements. > > * Google Account authentication > * Facebook authentication > * Managed hosting (like Google App Engine or Heroku) but with the ability to > be self-hosted later down the road. Plenty of combinations here. > I am familiar with Django (well I was a 3 years ago). > I have played a little with web.py and like the ideas there. 3 years is a long time, and a lot of stuff probably changed. I personally like Django and Flask, other people may suggest Pyramid. > I like the idea of using something like GAE but don't want to be locked in. So go with Heroku. GAE has many GAE-specific things, while on Heroku everything is standard and you can go self-hosted easily (just get a DB dump and a dump of your files). > Is Django the answer? Maybe. It depends on the size of your app and if you like Django. It?s subject to personal opinion. > I think you can run Django on GAE (and obviously you can self-host it). Yes, it works on GAE and Heroku just fine. > I see there is a Django REST framework. Is this a good framework? > Are there good Google and Facebook authentication extensions? That?s, again, subject to personal opinion, and I, for one, haven?t used any. -- Kwpolska | GPG KEY: 5EAAEA16 stop html mail | always bottom-post http://asciiribbon.org | http://caliburn.nl/topposting.html From fabiosantosart at gmail.com Sat Apr 27 08:46:27 2013 From: fabiosantosart at gmail.com (=?ISO-8859-1?Q?F=E1bio_Santos?=) Date: Sat, 27 Apr 2013 13:46:27 +0100 Subject: Python platform/framework for new RESTful web app In-Reply-To: References: Message-ID: For rest I would go with bottle. It's dead simple, and you can plug in anything you like. You can probably use django models as well, so you don't have to rewrite your model layer. Or django-smarter. On 27 Apr 2013 13:23, "Chris ?Kwpolska? Warrick" wrote: > On Thu, Apr 25, 2013 at 10:00 PM, Eric Frederich > wrote: > > If I wanted to create a new web application (RESTful) today with Python > what > > are my options given the following requirements. > > > > * Google Account authentication > > * Facebook authentication > > * Managed hosting (like Google App Engine or Heroku) but with the > ability to > > be self-hosted later down the road. > > Plenty of combinations here. > > > I am familiar with Django (well I was a 3 years ago). > > I have played a little with web.py and like the ideas there. > > 3 years is a long time, and a lot of stuff probably changed. I > personally like Django and Flask, other people may suggest Pyramid. > > > I like the idea of using something like GAE but don't want to be locked > in. > > So go with Heroku. GAE has many GAE-specific things, while on Heroku > everything is standard and you can go self-hosted easily (just get a > DB dump and a dump of your files). > > > Is Django the answer? > > Maybe. It depends on the size of your app and if you like Django. > It?s subject to personal opinion. > > > I think you can run Django on GAE (and obviously you can self-host it). > > Yes, it works on GAE and Heroku just fine. > > > I see there is a Django REST framework. Is this a good framework? > > Are there good Google and Facebook authentication extensions? > > That?s, again, subject to personal opinion, and I, for one, haven?t used > any. > > -- > Kwpolska | GPG KEY: 5EAAEA16 > stop html mail | always bottom-post > http://asciiribbon.org | http://caliburn.nl/topposting.html > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From yuyaxuan0 at gmail.com Thu Apr 25 17:18:58 2013 From: yuyaxuan0 at gmail.com (yuyaxuan0 at gmail.com) Date: Thu, 25 Apr 2013 14:18:58 -0700 (PDT) Subject: Quesion about running a exe file in Python(Not enough memory) Message-ID: <979ac07f-ce46-473a-ae46-cf53955f1a5f@googlegroups.com> Hey guys, I have a python script that will call an external exe file. Code is kind of like this: import sys import os from helper_functions import strContains if (len(sys.argv) != 4): print('Usage of script: export_mirax_data ') else: print('Script to export mirax data') print('---------------------------') # default parameters for exporting zoomLevel = 0 # 0 (original) - 9 (whole slide on one image) tileHeight = 2048 # has to be a multiple of 256 tileWidth = 2048 # has to be a multiple of 256 fileFormat = "png" # jpg, png and bmp are allowed mapFileFormat = "png" # xml, png and bmp are allowed # implicitly needed parameters MiraxSlideExporter = "MrxSlideExport.exe" slicePath = sys.argv[1] pathToResultData = sys.argv[2] tileHeight = sys.argv[3] tileWidth = sys.argv[3] # slices = os.listdir(pathToSourceMiraxData) # sys.argv[1] # sys.argv[2] # create command-line for system-call of mirax-slide-exporter # -e exports the slide # -i saves slide information in outputfolder # -a optional # -n only tiles which contain information are exported # -s + pathToSourceMiraxData + \ cmdForExportingSlicesToTiles = \ MiraxSlideExporter + \ " -i " + \ " -e " + \ " -z " + str(zoomLevel) + \ " -t " + str(tileHeight) + " " + str(tileWidth) + \ " -f " + str(fileFormat) + \ " -m " + str(mapFileFormat) + \ " " #cmd = "D:\\programs\\MIRAX_SlideAC_SDK\\Bin\\MrxSlideExport.exe -s D:\\fit\\projects\\bayer\\KidneyLiver\\MiraxScanner\\Slides\\L10 -e -o D:\\fit\\projects\\bayer\\KidneyLiver\\MiraxScanner\\Output\\L10 -z 5 -f png" #os.system(cmd) #msg = os.popen(cmd, mode='r', buffering=-1) # does not work #print(msg) # run through slices in given source-path cmd = cmdForExportingSlicesToTiles + " -s " + slicePath + " -o " + pathToResultData print(cmd) os.system(cmd) So the problem is that is says it doesn't have sufficient memory. The weired thing is that if I just ran the exe file directly in cmd console, it's working without any memory problem. I am wondering whether if it's some kind of python issue limits the memory that we can use?? From davea at davea.name Thu Apr 25 17:40:13 2013 From: davea at davea.name (Dave Angel) Date: Thu, 25 Apr 2013 17:40:13 -0400 Subject: Quesion about running a exe file in Python(Not enough memory) In-Reply-To: <979ac07f-ce46-473a-ae46-cf53955f1a5f@googlegroups.com> References: <979ac07f-ce46-473a-ae46-cf53955f1a5f@googlegroups.com> Message-ID: <5179A2BD.3020902@davea.name> On 04/25/2013 05:18 PM, yuyaxuan0 at gmail.com wrote: > Hey guys, > > I have a python script that will call an external exe file. Code is kind of like this: > This is a perfect example where you can simplify the problem down to a few lines that fail for you, and actually document the environment and the results. > #cmd = "D:\\programs\\MIRAX_SlideAC_SDK\\Bin\\MrxSlideExport.exe -s D:\\fit\\projects\\bayer\\KidneyLiver\\MiraxScanner\\Slides\\L10 -e -o D:\\fit\\projects\\bayer\\KidneyLiver\\MiraxScanner\\Output\\L10 -z 5 -f png" > #os.system(cmd) > #msg = os.popen(cmd, mode='r', buffering=-1) # does not work That's a useless statement. What you really should be saying is: I ran exactly xxx, and it formatted my neighbor's D: drive. Or you should skip that, and just concentrate on the ancient os.system() you're asking about. BTW, any reason you're not using the multiprocess module? It can simplify a lot of things, for example, bypassing the shell, so you know what the child program is really getting as parameters. > cmd = cmdForExportingSlicesToTiles + " -s " + slicePath + " -o " + pathToResultData > print(cmd) > os.system(cmd) > > So the problem is that is says it doesn't have sufficient memory. Who says? At what point do they say it? Show us a transcript of exactly what you do to see this message, and actually show the message. You probably could simplify this to 5 lines: import os cmd = "some literal string with lots of options" print "About to launch program" print cmd os.system(cmd) Then you run it from the cmd line, and copy/paste the results into your mnext message. C:\Somedir\ > python myprog.py About to launch program some literal... Some message that might mention running out of memory... Naturally, you should specify your Python version, your OS version, and any other variables you can think of. -- DaveA From steve+comp.lang.python at pearwood.info Thu Apr 25 18:00:06 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Apr 2013 22:00:06 GMT Subject: Quesion about running a exe file in Python(Not enough memory) References: <979ac07f-ce46-473a-ae46-cf53955f1a5f@googlegroups.com> Message-ID: <5179a765$0$29977$c3e8da3$5496439d@news.astraweb.com> On Thu, 25 Apr 2013 14:18:58 -0700, yuyaxuan0 wrote: > Hey guys, > > I have a python script that will call an external exe file. Code is kind > of like this: "Kind of like"? So it might be different? How much different? [snip irrelevant code] Please try to cut your code down to the minimum necessary to demonstrate the problem. > #cmd = "D:\\programs\\MIRAX_SlideAC_SDK\\Bin\\MrxSlideExport.exe -s > D:\\fit\\projects\\bayer\\KidneyLiver\\MiraxScanner\\Slides\\L10 -e > -o D:\\fit\\projects\\bayer\\KidneyLiver\\MiraxScanner\\Output\\L10 > -z 5 -f png" You can simplify Windows pathnames by using forward slashes. > #os.system(cmd) > #msg = os.popen(cmd, mode='r', buffering=-1) # does not work > #print(msg) Of course it does not work. You have commented it out. > # run through slices in given source-path > cmd = cmdForExportingSlicesToTiles + " -s " + slicePath + " -o " + > pathToResultData > print(cmd) > os.system(cmd) > > So the problem is that is says it doesn't have sufficient memory. What says "it" doesn't have sufficient memory? What's "it"? You may have seen the error, but we haven't. Please COPY AND PASTE the exact error message, IN FULL, and describe where it comes from: * is it a Python traceback? * something printed directly to the terminal but not a traceback? * Blue Screen of Death? * a message in a GUI alert? * something else? > The weired thing is that if I just ran the exe file directly in cmd > console, it's working without any memory problem. I am wondering whether > if it's some kind of python issue limits the memory that we can use?? No. -- Steven From rosuav at gmail.com Fri Apr 26 02:30:49 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 26 Apr 2013 16:30:49 +1000 Subject: Quesion about running a exe file in Python(Not enough memory) In-Reply-To: <5179a765$0$29977$c3e8da3$5496439d@news.astraweb.com> References: <979ac07f-ce46-473a-ae46-cf53955f1a5f@googlegroups.com> <5179a765$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Apr 26, 2013 at 8:00 AM, Steven D'Aprano wrote: > On Thu, 25 Apr 2013 14:18:58 -0700, yuyaxuan0 wrote: >> #cmd = "D:\\programs\\MIRAX_SlideAC_SDK\\Bin\\MrxSlideExport.exe -s >> D:\\fit\\projects\\bayer\\KidneyLiver\\MiraxScanner\\Slides\\L10 -e >> -o D:\\fit\\projects\\bayer\\KidneyLiver\\MiraxScanner\\Output\\L10 >> -z 5 -f png" > > You can simplify Windows pathnames by using forward slashes. These paths are being given to an external tool, so I wouldn't guarantee that forward slashes will work. But you can use a raw string literal to avoid doubling them all up. ChrisA From yuyaxuan0 at gmail.com Thu Apr 25 18:11:41 2013 From: yuyaxuan0 at gmail.com (yuyaxuan0 at gmail.com) Date: Thu, 25 Apr 2013 15:11:41 -0700 (PDT) Subject: Quesion about running a exe file in Python(Not enough memory) In-Reply-To: References: <979ac07f-ce46-473a-ae46-cf53955f1a5f@googlegroups.com> Message-ID: OK... 1."Memory is not enough..." is giving from the exe program. 2. If I run the exe program directly using cmd console, it's working good. 3. I am using Windows 7, 4GB memory python 2.7 the program is a image processing program. From rustompmody at gmail.com Fri Apr 26 01:24:19 2013 From: rustompmody at gmail.com (rusi) Date: Thu, 25 Apr 2013 22:24:19 -0700 (PDT) Subject: Quesion about running a exe file in Python(Not enough memory) References: <979ac07f-ce46-473a-ae46-cf53955f1a5f@googlegroups.com> Message-ID: On Apr 26, 3:11?am, yuyaxu... at gmail.com wrote: > OK... > > 1."Memory is not enough..." is giving from the exe program. > 2. If I run the exe program directly using cmd console, it's working good. > 3. I am using Windows 7, 4GB memory python 2.7 the program is a image processing program. It may be good to go thruogh http://sscce.org/ Your earlier data was too long Now its not self-contained (and not an example) From hexforge at gmail.com Thu Apr 25 17:27:37 2013 From: hexforge at gmail.com (Alastair Thompson) Date: Thu, 25 Apr 2013 22:27:37 +0100 Subject: baffled classes within a function namespace. Evaluation order. Message-ID: I am completely baffled by the behavior of this code with regards to the evaluation order of namespaces when assigning the class attributes. Both classes are nested within a function I called whywhywhy. I assumed that example1 and example2 classes would look first at their own namespace, then object, then the whywhywhy func namespace then global, and maybe module. It seems this is not the case. def whywhywhy(first, second, third): def print_stuff(): print("func: first=", first) print("func: second=", second) print("func: third=", third) print_stuff() class example1(object): print("1cls: first=", first) print("1cls: second=", second) print("1cls: third=", third) second = second foo = third class example2(object): print("2cls: first=", first) print("2cls: second=", second) print("2cls: third=", third) second = second third = third def second(): pass whywhywhy(1,2,3) The code above produces the following output """ func: first= 1 func: second= 2 func: third= 3 1cls: first= 1 1cls: second= 1cls: third= 3 2cls: first= 1 2cls: second= Traceback (most recent call last): File "error.py", line 29, in whywhywhy(1,2,3) File "error.py", line 18, in whywhywhy class example2(object): File "error.py", line 21, in example2 print("2cls: third=", third) NameError: name 'third' is not defined """ In particular: print_stuff behaves as I would expect 1cls: second #<--- Why does this look at the global namespace for second and not the whywhywhy func namespace first. 2cls: second #<--- Why can this no longer find third, it surely hasn't hit the line third=third Thanks for any help you can provide. :) Alastair -------------- next part -------------- An HTML attachment was scrubbed... URL: From wegwerp at gmail.com Thu Apr 25 18:08:18 2013 From: wegwerp at gmail.com (Bas) Date: Thu, 25 Apr 2013 15:08:18 -0700 (PDT) Subject: baffled classes within a function namespace. Evaluation order. In-Reply-To: References: Message-ID: On Thursday, April 25, 2013 11:27:37 PM UTC+2, Alastair Thompson wrote: > I am completely baffled by the behavior of this code with regards to the evaluation order of namespaces when assigning the class attributes.? Both classes are nested within a function I called whywhywhy. [snip weird namespace problem] Hi, I am not a namespace expert, but I think the following example shows the same problem in an easier way without any classes, and gives a more helpful error message: In [1]: a = 123 In [2]: def f(): ...: print a ...: b = 456 In [3]: f() 123 In [4]: def g(): ...: print a ...: a = 456 In [5]: g() --------------------------------------------------------------------------- UnboundLocalError Traceback (most recent call last) /home/xxx/ in () ----> 1 g() /home/xxx/ in g() 1 def g(): ----> 2 print a 3 a = 456 4 UnboundLocalError: local variable 'a' referenced before assignment My guess is that in f(), the compiler sees no definition of a, so it assumes is must come from the outer namespace. In g(), however, it sees on the second line that a is uses as an assignment target, so it makes the variable a local. When it is executed, it rightfully complains that the local variable is not yet defined. A smarter compiler might prevent this problem, but then again a smarter programmer would not have local and global variables with the same name. In your example, something similar is probably happening, since you assign something to third inside example2, thereby making it 'local'. Since you are dealing with classes, the error message is probably not so clear (but whywhywhy would you define a class inside a function?) Does that make sense? HTH, Bas From hexforge at gmail.com Thu Apr 25 18:37:53 2013 From: hexforge at gmail.com (Alastair Thompson) Date: Thu, 25 Apr 2013 23:37:53 +0100 Subject: baffled classes within a function namespace. Evaluation order. Message-ID: Thats a good pointer to what is going on. Thank you Bas. I am familiar with error such as x=1 def foo(): x = 2 def erm(): print(x) x=3 erm() foo() UnboundLocalError: local variable 'x' referenced before assignment. It seems a bit different for classes (below), as it jumps out to get the value from the global name space, where it didn't for functions (above). x=1 def foo(): x = 2 class erm(): print(x) x = 3 foo() # This evaluates == 1 But you certainly have explained why "NameError: name 'third' is not defined" occurs. -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Fri Apr 26 01:39:32 2013 From: __peter__ at web.de (Peter Otten) Date: Fri, 26 Apr 2013 07:39:32 +0200 Subject: baffled classes within a function namespace. Evaluation order. References: Message-ID: Alastair Thompson wrote: > I am completely baffled by the behavior of this code with regards to the > evaluation order of namespaces when assigning the class attributes. Both > classes are nested within a function I called whywhywhy. > > I assumed that example1 and example2 classes would look first at their own > namespace, then object, then the whywhywhy func namespace then global, and > maybe module. It seems this is not the case. > > def whywhywhy(first, second, third): > def print_stuff(): > print("func: first=", first) > print("func: second=", second) > print("func: third=", third) > print_stuff() > > class example1(object): > print("1cls: first=", first) > print("1cls: second=", second) > print("1cls: third=", third) > > second = second > foo = third > > class example2(object): > print("2cls: first=", first) > print("2cls: second=", second) > print("2cls: third=", third) > > second = second > third = third > > def second(): > pass > > whywhywhy(1,2,3) > > > The code above produces the following output > """ > func: first= 1 > func: second= 2 > func: third= 3 > 1cls: first= 1 > 1cls: second= > 1cls: third= 3 > 2cls: first= 1 > 2cls: second= > Traceback (most recent call last): > File "error.py", line 29, in > whywhywhy(1,2,3) > File "error.py", line 18, in whywhywhy > class example2(object): > File "error.py", line 21, in example2 > print("2cls: third=", third) > NameError: name 'third' is not defined > """ > > In particular: > > print_stuff behaves as I would expect > 1cls: second #<--- Why does this look at the global namespace for second > and not the whywhywhy func namespace first. > 2cls: second #<--- Why can this no longer find third, it surely hasn't hit > the line third=third > > Thanks for any help you can provide. :) > Alastair A class body is basically a function body that is executed once. To allow an assignment >>> x = 42 >>> class A: ... x = x ... which is not possible inside a function >>> def f(): ... x = x ... >>> f() Traceback (most recent call last): File "", line 1, in File "", line 2, in f UnboundLocalError: local variable 'x' referenced before assignment it uses one opcode, LOAD_NAME, that looks into the local and falls back to the global namespace, but knows nothing about closures: >>> code = compile("class A:\n x = x", "", "exec") >>> code.co_consts (", line 1>, 'A', None) >>> import dis >>> dis.dis(code.co_consts[0]) 1 0 LOAD_FAST 0 (__locals__) 3 STORE_LOCALS 4 LOAD_NAME 0 (__name__) 7 STORE_NAME 1 (__module__) 2 10 LOAD_NAME 2 (x) 13 STORE_NAME 2 (x) 16 LOAD_CONST 0 (None) 19 RETURN_VALUE For functions on the other side the compiler determines the scope of the name: >>> def g(): ... y = "outer" ... def h(): ... return x, y, z ... z = 42 ... return h ... >>> dis.dis(g()) 4 0 LOAD_GLOBAL 0 (x) # global var 3 LOAD_DEREF 0 (y) # closure 6 LOAD_FAST 0 (z) # local 9 BUILD_TUPLE 3 12 RETURN_VALUE 5 13 LOAD_CONST 1 (42) 16 STORE_FAST 0 (z) As you can see there are three different opcodes for global, closure, and local namespace. However, while the above gives some technical background it doesn't explain why this scheme was chosen. My guess is that when Python got closures nobody was willing to do the extra work to make class bodies namespace-aware. The alternative, disallowing x = x in classes, would have seriously broken backwards-compatibility. From steve+comp.lang.python at pearwood.info Fri Apr 26 02:21:53 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Apr 2013 06:21:53 GMT Subject: baffled classes within a function namespace. Evaluation order. References: Message-ID: <517a1d01$0$29977$c3e8da3$5496439d@news.astraweb.com> On Fri, 26 Apr 2013 07:39:32 +0200, Peter Otten wrote: > A class body is basically a function body that is executed once. To > allow an assignment > >>>> x = 42 >>>> class A: > ... x = x > ... > > which is not possible inside a function As far as I can tell, the documentation says that this assignment should also be impossible inside a class. Unless I'm missing something, I think this is a bug. http://docs.python.org/3/reference/executionmodel.html [...] > However, while the above gives some technical background it doesn't > explain why this scheme was chosen. My guess is that when Python got > closures nobody was willing to do the extra work to make class bodies > namespace-aware. The alternative, disallowing x = x in classes, would > have seriously broken backwards-compatibility. Not so. x = x was not allowed in classes before there were closures: [steve at ando ~]$ python1.5 Python 1.5.2 (#1, Aug 27 2012, 09:09:18) [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> >>> >>> def f(): ... x = 1 ... class Test: ... x = x ... return Test ... >>> T = f() Traceback (innermost last): File "", line 1, in ? File "", line 3, in f File "", line 4, in Test NameError: x -- Steven From __peter__ at web.de Fri Apr 26 03:15:51 2013 From: __peter__ at web.de (Peter Otten) Date: Fri, 26 Apr 2013 09:15:51 +0200 Subject: baffled classes within a function namespace. Evaluation order. References: <517a1d01$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Fri, 26 Apr 2013 07:39:32 +0200, Peter Otten wrote: > >> A class body is basically a function body that is executed once. To >> allow an assignment >> >>>>> x = 42 >>>>> class A: >> ... x = x >> ... >> >> which is not possible inside a function > > > As far as I can tell, the documentation says that this assignment should > also be impossible inside a class. Unless I'm missing something, I think > this is a bug. > > http://docs.python.org/3/reference/executionmodel.html Will have a look. > [...] >> However, while the above gives some technical background it doesn't >> explain why this scheme was chosen. My guess is that when Python got >> closures nobody was willing to do the extra work to make class bodies >> namespace-aware. The alternative, disallowing x = x in classes, would >> have seriously broken backwards-compatibility. > > Not so. x = x was not allowed in classes before there were closures: > > > [steve at ando ~]$ python1.5 > Python 1.5.2 (#1, Aug 27 2012, 09:09:18) [GCC 4.1.2 20080704 (Red Hat > 4.1.2-52)] on linux2 > Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>>> >>>> >>>> def f(): > ... x = 1 > ... class Test: > ... x = x > ... return Test > ... >>>> T = f() > Traceback (innermost last): > File "", line 1, in ? > File "", line 3, in f > File "", line 4, in Test > NameError: x Define a global variable x and run it again. I don't have an ancient Python lying around but my "prediction" is >>> x = 42 >>> f().x 42 which would be the same behaviour as that of Python 3.3. From steve+comp.lang.python at pearwood.info Fri Apr 26 23:44:25 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Apr 2013 03:44:25 GMT Subject: baffled classes within a function namespace. Evaluation order. References: <517a1d01$0$29977$c3e8da3$5496439d@news.astraweb.com> Message-ID: <517b4999$0$29977$c3e8da3$5496439d@news.astraweb.com> On Fri, 26 Apr 2013 09:15:51 +0200, Peter Otten wrote: > Define a global variable x and run it again. I don't have an ancient > Python lying around but my "prediction" is > >>>> x = 42 >>>> f().x > 42 > > which would be the same behaviour as that of Python 3.3. /facepalm You're absolutely right. Sorry for the noise. -- Steven From fabio.tabarrini at italgaspiu.it Thu Apr 25 17:36:19 2013 From: fabio.tabarrini at italgaspiu.it (Pay) Date: Thu, 25 Apr 2013 17:36:19 -0400 Subject: Preavviso 291601-443382 Message-ID: <006901ce41fc$e7645780$64000a0a@www.ukchat.com> La fattura deve essere pagato fino alla prossima settimana. Dettagli possono essere trovati all'indirizzo: http://gtslawnservices.com/Progetto.zip From hasilsharma7 at gmail.com Thu Apr 25 19:35:15 2013 From: hasilsharma7 at gmail.com (Hasil Sharma) Date: Thu, 25 Apr 2013 16:35:15 -0700 (PDT) Subject: TCP reassembly Message-ID: Hi everyone , How to reassemble the TCP data packets into objects viz. html , css , js image files etc . I have no idea how to implement it using python , please help ? From bahamutzero8825 at gmail.com Thu Apr 25 20:05:09 2013 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Thu, 25 Apr 2013 19:05:09 -0500 Subject: TCP reassembly In-Reply-To: References: Message-ID: <5179C4B5.1080901@gmail.com> On 2013.04.25 18:35, Hasil Sharma wrote: > Hi everyone , > How to reassemble the TCP data packets into objects viz. html , css , js image files etc . I have no idea how to implement it using python , please help ? TCP packets don't need to be reassembled. If your application receives TCP packets out of order, there is a problem with your networking equipment (or possibly the TCP stack in your OS). I suspect that you actually mean that you want distinct bytes objects that represent specific data. Sockets will give you a stream of bytes; how the data is separated is defined by the protocol. If you are dealing with HTTP, it is much better to use an HTTP client library than raw sockets. In fact, there are many libraries available for many different protocols, which are a better choice than dealing with sockets directly for all but the simplest protocols. You'll get a better answer if you tell us what the problem is and what you are trying to accomplish. -- CPython 3.3.1 | Windows NT 6.2.9200 / FreeBSD 9.1 From davea at davea.name Thu Apr 25 23:35:25 2013 From: davea at davea.name (Dave Angel) Date: Thu, 25 Apr 2013 23:35:25 -0400 Subject: TCP reassembly In-Reply-To: References: Message-ID: <5179F5FD.7030206@davea.name> On 04/25/2013 07:35 PM, Hasil Sharma wrote: > Hi everyone , > How to reassemble the TCP data packets into objects viz. html , css , js image files etc . I have no idea how to implement it using python , please help ? > TCP reassembly has a specific meaning, and I doubt if that's what you mean. If you reach down below the tcp layer in your OS, and get raw IP packets, then you have to do the reassembly yourself. But if you open a TCP connection, the OS will already do any reordering, retrying, and reassembly for you. Give a specific example of what you're trying, and what piece of it is failing for you. tcpdump or wireshark can be used to examine low level protocol issues, if you really have such. And python + scapy can generate pretty arbitrary packets. But I rather doubt that's what you want. -- DaveA From hasilsharma7 at gmail.com Fri Apr 26 00:55:37 2013 From: hasilsharma7 at gmail.com (Hasil Sharma) Date: Thu, 25 Apr 2013 21:55:37 -0700 (PDT) Subject: PCAP Files Message-ID: I m having network dumps in the form of pcap files and I want to extract the html,css, image files etc etc all that can be extracted from those pcap files , can anyone please tell me how to accomplish such a task in python ? From cs at zip.com.au Fri Apr 26 02:52:28 2013 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 26 Apr 2013 16:52:28 +1000 Subject: PCAP Files In-Reply-To: References: Message-ID: <20130426065228.GA45575@cskk.homeip.net> On 25Apr2013 21:55, Hasil Sharma wrote: | I m having network dumps in the form of pcap files and I want to | extract the html,css, image files etc etc all that can be extracted | from those pcap files , can anyone please tell me how to accomplish | such a task in python ? I would reassemble the TCP packets into data streams and then handle them to an HTTP or MIME parser. For the first part, have you tried a google search? Like this: https://www.google.com.au/search?q=reassemble+pcap+files+into+tcp+streams Looks promising, particularly the "streams" and "tcpreplay" stuff. Or even search the Python Package Index for "pcap", even indirectly via google: https://www.google.com.au/search?q=pypi+pcap&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-GB:official&client=firefox-beta&channel=fflb Then just handle the data streams to a normal Python MIME parser to figure out what's in them. Cheers, -- Cameron Simpson I have come here to chew bubblegum and kick ass, and I'm all out of bubblegum. - Roddy Piper From avnesh.nitk at gmail.com Fri Apr 26 02:42:44 2013 From: avnesh.nitk at gmail.com (Avnesh Shakya) Date: Thu, 25 Apr 2013 23:42:44 -0700 (PDT) Subject: Warning in python file when i m using pychecker. Message-ID: <1dd46aa1-bc81-4d1b-89b6-225b7726a068@googlegroups.com> hi, I am trying to run my file using pychecker, but it's showing warning. I am unable to get these warning. Please help me, how to remove these warning. I am using pychecker first time. avin at HP:~/github/UdacitySiteData$ pychecker udacity_to_jsonFinal.py Processing module udacity_to_jsonFinal (udacity_to_jsonFinal.py)... Warnings... [system path]/dist-packages/bs4/__init__.py:206: Parameter (successor) not used [system path]/dist-packages/bs4/__init__.py:209: Parameter (successor) not used [system path]/dist-packages/bs4/__init__.py:213: Local variable (tag) not used [system path]/dist-packages/bs4/element.py:306: Parameter (kwargs) not used [system path]/dist-packages/bs4/element.py:507: (id) shadows builtin [system path]/dist-packages/bs4/element.py:791: (next) shadows builtin [system path]/dist-packages/bs4/element.py:903: Invalid arguments to (__repr__), got 2, expected 1 Thanks. From fabiosantosart at gmail.com Fri Apr 26 02:54:00 2013 From: fabiosantosart at gmail.com (=?ISO-8859-1?Q?F=E1bio_Santos?=) Date: Fri, 26 Apr 2013 07:54:00 +0100 Subject: Warning in python file when i m using pychecker. In-Reply-To: <1dd46aa1-bc81-4d1b-89b6-225b7726a068@googlegroups.com> References: <1dd46aa1-bc81-4d1b-89b6-225b7726a068@googlegroups.com> Message-ID: Read the warnings carefully. They are pretty clear. On 26 Apr 2013 07:48, "Avnesh Shakya" wrote: > hi, > I am trying to run my file using pychecker, but it's showing warning. I > am unable to get these warning. Please help me, how to remove these > warning. I am using pychecker first time. > > avin at HP:~/github/UdacitySiteData$ pychecker udacity_to_jsonFinal.py > Processing module udacity_to_jsonFinal (udacity_to_jsonFinal.py)... > > Warnings... > > [system path]/dist-packages/bs4/__init__.py:206: Parameter (successor) not > used > [system path]/dist-packages/bs4/__init__.py:209: Parameter (successor) not > used > [system path]/dist-packages/bs4/__init__.py:213: Local variable (tag) not > used > > [system path]/dist-packages/bs4/element.py:306: Parameter (kwargs) not used > [system path]/dist-packages/bs4/element.py:507: (id) shadows builtin > [system path]/dist-packages/bs4/element.py:791: (next) shadows builtin > [system path]/dist-packages/bs4/element.py:903: Invalid arguments to > (__repr__), got 2, expected 1 > > Thanks. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Fri Apr 26 02:57:33 2013 From: davea at davea.name (Dave Angel) Date: Fri, 26 Apr 2013 02:57:33 -0400 Subject: Warning in python file when i m using pychecker. In-Reply-To: <1dd46aa1-bc81-4d1b-89b6-225b7726a068@googlegroups.com> References: <1dd46aa1-bc81-4d1b-89b6-225b7726a068@googlegroups.com> Message-ID: <517A255D.8000202@davea.name> On 04/26/2013 02:42 AM, Avnesh Shakya wrote: > hi, > I am trying to run my file using pychecker, but it's showing warning. I am unable to get these warning. Please help me, how to remove these warning. I am using pychecker first time. > > avin at HP:~/github/UdacitySiteData$ pychecker udacity_to_jsonFinal.py > Processing module udacity_to_jsonFinal (udacity_to_jsonFinal.py)... > > Warnings... > > [system path]/dist-packages/bs4/__init__.py:206: Parameter (successor) not used > [system path]/dist-packages/bs4/__init__.py:209: Parameter (successor) not used > [system path]/dist-packages/bs4/__init__.py:213: Local variable (tag) not used > > [system path]/dist-packages/bs4/element.py:306: Parameter (kwargs) not used > [system path]/dist-packages/bs4/element.py:507: (id) shadows builtin > [system path]/dist-packages/bs4/element.py:791: (next) shadows builtin > [system path]/dist-packages/bs4/element.py:903: Invalid arguments to (__repr__), got 2, expected 1 > > Thanks. > What's not clear about any of these? On line 206, you defined some function and one of the formal parameters was called successor. You don't use that value anywhere in the function. The fix? Omit the unused parameter in the function definition, and change all the caller sites. Sometimes this is impractical, for example in functions that are callbacks from code you don't control. Likewise for the next 3. id() is a built-in function, so you shouldn't use that name for your own functions or variables. rename it. Likewise next, which is even more likely to cause confusion, since next is frequently used in real code, while id() is more likely a debugging aid. If you want anything more detailed, perhaps you should show the context around each warning. You have the line numbers, so that should be easy. -- DaveA From insideshoes at gmail.com Fri Apr 26 04:48:31 2013 From: insideshoes at gmail.com (inshu chauhan) Date: Fri, 26 Apr 2013 14:18:31 +0530 Subject: Nested For loop not running full Message-ID: Hello everyone, I have this part of my code where I am trying to traverse over an image by running a for loop for both x and y co-ordinate axis. But the loop is terminating by just reading first pixel. Can think of a reason why this is happening ? The code is: for sy in xrange(0, segimage.height): for sx in xrange(0, segimage.width): if segimage[sy,sx] == (0.0, 0.0, 0.0): continue else: seg_color = segimage[sy,sx] blue = int(seg_color[0]) green = int(seg_color[1]) red = int(seg_color[2]) reg_num = blue + 256 * green + 65536 * red for l in f: sp = l.split(",") if len(sp) == 14: print sy, sx # for checking which pixel its reading currently print reg_num, sp[0] # for checking whats happening if reg_num == int(sp[0].strip()): print reg_num, sp[0].strip() # for checking whats happening classification = int(sp[13].strip()) The inside "for loop" is for reading a csv format file from which I am extracting some information. Thanks in Advance for your suggestions -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Fri Apr 26 05:09:09 2013 From: __peter__ at web.de (Peter Otten) Date: Fri, 26 Apr 2013 11:09:09 +0200 Subject: Nested For loop not running full References: Message-ID: inshu chauhan wrote: > I have this part of my code where I am trying to traverse over an image by > running a for loop for both x and y co-ordinate axis. But the loop is > terminating by just reading first pixel. Can think of a reason why this is > happening ? > > The code is: > for sy in xrange(0, segimage.height): > for sx in xrange(0, segimage.width): > if segimage[sy,sx] == (0.0, 0.0, 0.0): > continue > else: > seg_color = segimage[sy,sx] > blue = int(seg_color[0]) > green = int(seg_color[1]) > red = int(seg_color[2]) > reg_num = blue + 256 * green + 65536 * red > for l in f: > sp = l.split(",") > if len(sp) == 14: > print sy, sx # for checking which pixel its > reading currently > print reg_num, sp[0] # for checking whats > happening > if reg_num == int(sp[0].strip()): > print reg_num, sp[0].strip() # for checking > whats happening > classification = int(sp[13].strip()) > > > The inside "for loop" is for reading a csv format file from which I am > extracting some information. My crystal ball says that the 'for sy...' and 'for sx...' loops are running to completion, but you don't get the coordinates printed because you put them into the 'for l in f' loop which will only run once. The quick and dirty fix is to replace f = open(...) in the code you are not showing with f == list(open(...)) The reasonable thing to do is of course to move the preprocessing (e.g. csv- parsing) out of the sy and sx loops. From insideshoes at gmail.com Fri Apr 26 05:36:34 2013 From: insideshoes at gmail.com (inshu chauhan) Date: Fri, 26 Apr 2013 15:06:34 +0530 Subject: Nested For loop not running full In-Reply-To: References: Message-ID: On Fri, Apr 26, 2013 at 2:39 PM, Peter Otten <__peter__ at web.de> wrote: > inshu chauhan wrote: > > > I have this part of my code where I am trying to traverse over an image > by > > running a for loop for both x and y co-ordinate axis. But the loop is > > terminating by just reading first pixel. Can think of a reason why this > is > > happening ? > > > > The code is: > > for sy in xrange(0, segimage.height): > > for sx in xrange(0, segimage.width): > > if segimage[sy,sx] == (0.0, 0.0, 0.0): > > continue > > else: > > seg_color = segimage[sy,sx] > > blue = int(seg_color[0]) > > green = int(seg_color[1]) > > red = int(seg_color[2]) > > reg_num = blue + 256 * green + 65536 * red > > for l in f: > > sp = l.split(",") > > if len(sp) == 14: > > print sy, sx # for checking which pixel its > > reading currently > > print reg_num, sp[0] # for checking whats > > happening > > if reg_num == int(sp[0].strip()): > > print reg_num, sp[0].strip() # for checking > > whats happening > > classification = int(sp[13].strip()) > > > > > > The inside "for loop" is for reading a csv format file from which I am > > extracting some information. > > My crystal ball says that the 'for sy...' and 'for sx...' loops are running > to completion, but you don't get the coordinates printed because you put > them into the 'for l in f' loop which will only run once. > Is there any means by which I can run this 'For l in f' loop again and again ? > > The quick and dirty fix is to replace > > f = open(...) > > in the code you are not showing with > > f == list(open(...)) > f is just a text file(csv format).. so why list ?? > The reasonable thing to do is of course to move the preprocessing (e.g. > csv- > parsing) out of the sy and sx loops. > I did this but again then what I intend to do is not really happening, For every pixel I read, I want to traverse the full file, so that the information I am taking from pixel have to match in one of the line in the file. Can this be done by modifying my code ? or something new has to be devised ? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From oscar.j.benjamin at gmail.com Fri Apr 26 05:44:06 2013 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Fri, 26 Apr 2013 10:44:06 +0100 Subject: Nested For loop not running full In-Reply-To: References: Message-ID: On 26 April 2013 10:36, inshu chauhan wrote: > > On Fri, Apr 26, 2013 at 2:39 PM, Peter Otten <__peter__ at web.de> wrote: >> >> My crystal ball says that the 'for sy...' and 'for sx...' loops are >> running >> to completion, but you don't get the coordinates printed because you put >> them into the 'for l in f' loop which will only run once. > > Is there any means by which I can run this 'For l in f' loop again and again > ? >> >> The quick and dirty fix is to replace >> >> f = open(...) >> >> in the code you are not showing with >> >> f == list(open(...)) > > f is just a text file(csv format).. so why list ?? So that you can run the for l in f loop again and again. You can loop over a list as many times as you like but only once over a file (unless you reset the file pointer). Oscar From rosuav at gmail.com Fri Apr 26 05:45:51 2013 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 26 Apr 2013 19:45:51 +1000 Subject: Nested For loop not running full In-Reply-To: References: Message-ID: On Fri, Apr 26, 2013 at 7:36 PM, inshu chauhan wrote: > > On Fri, Apr 26, 2013 at 2:39 PM, Peter Otten <__peter__ at web.de> wrote: >> >> f = open(...) >> >> in the code you are not showing with >> >> f == list(open(...)) > > f is just a text file(csv format).. so why list ?? (That should be =, not ==) Instead of having an open file object, you would instead have a list of the lines in the file. That can be iterated over more than once. >> The reasonable thing to do is of course to move the preprocessing (e.g. >> csv- >> parsing) out of the sy and sx loops. > > > I did this but again then what I intend to do is not really happening, For > every pixel I read, I want to traverse the full file, so that the > information I am taking from pixel have to match in one of the line in the > file. Can this be done by modifying my code ? or something new has to be > devised ? How large is the file? There are two easy solutions: 1) Open and close the file every time you touch a pixel 2) Open the file once, read it all into memory, and then iterate over the in-memory copy every pixel If your file is insanely large then the first option may be better, but for anything less than five yottabytes, go with the second. (Okay, I may be exaggerating slightly... let's say anything less than half your RAM. So if you have 10YB of memory, then I wasn't exaggerating.) That's why Peter suggested creating a list; you iterate over the list. Another way to do it is to parse the file once and retain a more efficient and useful structured form of the data... which is the other thing Peter suggested ("move the preprocessing (e.g. csv- parsing) out of the sy and sx loops"). So, yeah. Listen to Peter Otten, he knows what he's talking about :) ChrisA From insideshoes at gmail.com Fri Apr 26 09:20:48 2013 From: insideshoes at gmail.com (inshu chauhan) Date: Fri, 26 Apr 2013 18:50:48 +0530 Subject: Nested For loop not running full In-Reply-To: References: Message-ID: , 2013 at 3:15 PM, Chris Angelico wrote: > On Fri, Apr 26, 2013 at 7:36 PM, inshu chauhan > wrote: > > > > On Fri, Apr 26, 2013 at 2:39 PM, Peter Otten <__peter__ at web.de> wrote: > >> > >> f = open(...) > >> > >> in the code you are not showing with > >> > >> f == list(open(...)) > > > > f is just a text file(csv format).. so why list ?? > > (That should be =, not ==) > > Instead of having an open file object, you would instead have a list > of the lines in the file. That can be iterated over more than once. > > >> The reasonable thing to do is of course to move the preprocessing (e.g. > >> csv- > >> parsing) out of the sy and sx loops. > > > > > > I did this but again then what I intend to do is not really happening, > For > > every pixel I read, I want to traverse the full file, so that the > > information I am taking from pixel have to match in one of the line in > the > > file. Can this be done by modifying my code ? or something new has to be > > devised ? > > How large is the file? There are two easy solutions: > > 1) Open and close the file every time you touch a pixel > 2) Open the file once, read it all into memory, and then iterate over > the in-memory copy every pixel > > If your file is insanely large then the first option may be better, > but for anything less than five yottabytes, go with the second. (Okay, > I may be exaggerating slightly... let's say anything less than half > your RAM. So if you have 10YB of memory, then I wasn't exaggerating.) > That's why Peter suggested creating a list; you iterate over the list. > Another way to do it is to parse the file once and retain a more > efficient and useful structured form of the data... which is the other > thing Peter suggested ("move the preprocessing (e.g. csv- > parsing) out of the sy and sx loops"). > > So, yeah. Listen to Peter Otten, he knows what he's talking about :) > > ChrisA > Yes I am trying Peter's way and my file is just 500 KB .. :) -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Fri Apr 26 05:51:05 2013 From: __peter__ at web.de (Peter Otten) Date: Fri, 26 Apr 2013 11:51:05 +0200 Subject: Nested For loop not running full References: Message-ID: inshu chauhan wrote: > On Fri, Apr 26, 2013 at 2:39 PM, Peter Otten <__peter__ at web.de> wrote: > >> inshu chauhan wrote: >> >> > I have this part of my code where I am trying to traverse over an image >> by >> > running a for loop for both x and y co-ordinate axis. But the loop is >> > terminating by just reading first pixel. Can think of a reason why this >> is >> > happening ? >> > >> > The code is: >> > for sy in xrange(0, segimage.height): >> > for sx in xrange(0, segimage.width): >> > if segimage[sy,sx] == (0.0, 0.0, 0.0): >> > continue >> > else: >> > seg_color = segimage[sy,sx] >> > blue = int(seg_color[0]) >> > green = int(seg_color[1]) >> > red = int(seg_color[2]) >> > reg_num = blue + 256 * green + 65536 * red >> > for l in f: >> > sp = l.split(",") >> > if len(sp) == 14: >> > print sy, sx # for checking which pixel its >> > reading currently >> > print reg_num, sp[0] # for checking whats >> > happening >> > if reg_num == int(sp[0].strip()): >> > print reg_num, sp[0].strip() # for checking >> > whats happening >> > classification = int(sp[13].strip()) >> > >> > >> > The inside "for loop" is for reading a csv format file from which I am >> > extracting some information. >> >> My crystal ball says that the 'for sy...' and 'for sx...' loops are >> running to completion, but you don't get the coordinates printed because >> you put them into the 'for l in f' loop which will only run once. >> > > Is there any means by which I can run this 'For l in f' loop again and > again ? > >> >> The quick and dirty fix is to replace >> >> f = open(...) >> >> in the code you are not showing with >> >> f == list(open(...)) >> > > f is just a text file(csv format).. so why list ?? Can you figure it out yourself from the following? >>> f = open("tmp.data") >>> for i in range(3): ... for line in f: print repr(line) ... 'alpha\n' 'beta\n' 'gamma\n' >>> f = list(open("tmp.data")) >>> for i in range(3): ... for line in f: print repr(line) ... 'alpha\n' 'beta\n' 'gamma\n' 'alpha\n' 'beta\n' 'gamma\n' 'alpha\n' 'beta\n' 'gamma\n' >> The reasonable thing to do is of course to move the preprocessing (e.g. >> csv- >> parsing) out of the sy and sx loops. >> > > I did this but again then what I intend to do is not really happening, For > every pixel I read, I want to traverse the full file, so that the > information I am taking from pixel have to match in one of the line in the > file. Can this be done by modifying my code ? or something new has to be > devised ? I think I have already answered this, but here's another alternative: >>> f = open("tmp.data") >>> for i in range(3): ... f.seek(0) ... for line in f: print(repr(line)) ... 'alpha\n' 'beta\n' 'gamma\n' 'alpha\n' 'beta\n' 'gamma\n' 'alpha\n' 'beta\n' 'gamma\n' From tjreedy at udel.edu Fri Apr 26 05:10:08 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Fri, 26 Apr 2013 05:10:08 -0400 Subject: Nested For loop not running full In-Reply-To: References: Message-ID: On 4/26/2013 4:48 AM, inshu chauhan wrote: > Hello everyone, > > I have this part of my code where I am trying to traverse over an image > by running a for loop for both x and y co-ordinate axis. But the loop is > terminating by just reading first pixel. Can think of a reason why this > is happening ? *A* reason could be that segimage.height and .width are both 1. I would print them out to see what they are. > > The code is: > for sy in xrange(0, segimage.height): > for sx in xrange(0, segimage.width): > if segimage[sy,sx] == (0.0, 0.0, 0.0): > continue > else: > seg_color = segimage[sy,sx] > blue = int(seg_color[0]) > green = int(seg_color[1]) > red = int(seg_color[2]) > reg_num = blue + 256 * green + 65536 * red > for l in f: > sp = l.split(",") > if len(sp) == 14: > print sy, sx # for checking which pixel its > reading currently > print reg_num, sp[0] # for checking whats > happening > if reg_num == int(sp[0].strip()): > print reg_num, sp[0].strip() # for checking > whats happening > classification = int(sp[13].strip()) > > The inside "for loop" is for reading a csv format file from which I am > extracting some information. > > Thanks in Advance for your suggestions > > > > From jt at toerring.de Fri Apr 26 05:54:37 2013 From: jt at toerring.de (Jens Thoms Toerring) Date: 26 Apr 2013 09:54:37 GMT Subject: Nested For loop not running full References: Message-ID: inshu chauhan wrote: > I have this part of my code where I am trying to traverse over an image by > running a for loop for both x and y co-ordinate axis. But the loop is > terminating by just reading first pixel. Can think of a reason why this is > happening ? > The code is: > for sy in xrange(0, segimage.height): > for sx in xrange(0, segimage.width): > if segimage[sy,sx] == (0.0, 0.0, 0.0): > continue > else: > seg_color = segimage[sy,sx] > blue = int(seg_color[0]) > green = int(seg_color[1]) > red = int(seg_color[2]) > reg_num = blue + 256 * green + 65536 * red > for l in f: > sp = l.split(",") > if len(sp) == 14: > print sy, sx # for checking which pixel its > reading currently > print reg_num, sp[0] # for checking whats > happening > if reg_num == int(sp[0].strip()): > print reg_num, sp[0].strip() # for checking > whats happening > classification = int(sp[13].strip()) > The inside "for loop" is for reading a csv format file from which I am > extracting some information. Are you sure that the loop is only run once? In that case the most likely thing is that the image consists of only a single pixel (or all except the first one are black, then it might also look as if the loop would be run only once;-) But what looks strange is the innermost loop. You never tell what exactly 'f' is but I would tend to assume that it is a file object for your CSV file, which you opened somewhere before. And now you read it in completely when dealing with the very first pixel of your image. Afterwards, when dealing with the other pixels of the image, there's nothing left to be read in, so the inner loop won't be run again, making it appear as if the outer loops would only be run once. If my assumptions are correct and you want to read in the file again and again for each pixel then you should either open it again and again for each pixel or, probably better, reset the file object so that it "points" back to the start of the file before the start of the innermost loop, using the seek() method - a simple "f.seek(0)" should do the job (assuming that this is a normal file, i.e. one that can be "rewound" and not e.g. a re- directed pipe). An even better solution (if you have enough memory) might be to read in the whole file into a list and iterate over that instead of the file itself. And better than that might be to build a dictionary of values in the file that you can use later on, so you don't have to run over the whole file again and again: d = { } for l in f : sp = split( l, ',' ) if len( sp ) == 14 : d[ int( sp[ 0 ].strip( ) ) ] = int( sp[ 13 ].strip( ) ) Then you can later check directly if some color value (what you have named 'reg_num') is in the file by using if reg_num in d : and the corresponding value from the file (what you assign to 'classification') is simply the value of the dictionary for the key given by 'reg_num'. i.e. classification = d[ reg_num ] Regards, Jens -- \ Jens Thoms Toerring ___ jt at toerring.de \__________________________ http://toerring.de From akanakshaa at gmail.com Fri Apr 26 10:07:08 2013 From: akanakshaa at gmail.com (akanakshaa at gmail.com) Date: Fri, 26 Apr 2013 07:07:08 -0700 (PDT) Subject: New Dropbox alternative with 10GB free space Message-ID: Everybody, there is a new online storage startup, similar to Dropbox or box.com, get your free 10 GB easily, 5GB on signup and 5GB if you use the following referral link. * hit the referral link https://copy.com?r=WGQBHr * create an account (5GB) * install client on any device (5GB) Have fun! From tunacubes at gmail.com Fri Apr 26 10:26:29 2013 From: tunacubes at gmail.com (tunacubes at gmail.com) Date: Fri, 26 Apr 2013 07:26:29 -0700 (PDT) Subject: TypeError: Can't convert 'int' object to str implicitly Message-ID: <889e8874-1f6f-494a-bb83-27801161f51a@googlegroups.com> Hey, Let me explain what my program is supposed to do... I am using a macro program in conjunction with a python script I am writing. The macro inputs data into a database we use at my job, blah blah blah. The script asks how many numbers (devices) you need to enter. Next, it asks you to input the device numbers. When you input them, it creates a list with all of the devices. I then tell it to go into the script of the Macro (firstdev.ahk) that will run on the back-end, and replace the word "device" with the first device in the list. It then should execute the Macro, change the device number back to the word "Device" for future use, and then delete the first number from the list. It will repeat as long as there are numbers in the list. The error I receive is "TypeError: Can't convert 'int' object to str implicitly" when it tries to put the device into the macro script. It worked fine when I just had it input one device into the script without the use of lists, but for whatever reason, using a list does not play nice with replacing the words "Device" with the number from the list. Here is my script. I will give you up until the part that the error occurs, as everything afterwords is pointless. I am fairly new to python, so if anything looks screwed up or like I am an idiot, it is because I am. import fileinput, sys, os devlist = [] maxdev = int(input("How many devices to add: ")) curdev = int("0") while curdev < maxdev: try: Number = int(input("Enter Device number: ")) devlist.append(Number) curdev = curdev + 1 except ValueError: print("Please enter a valid number") ready = 0 while ready != "Y" and ready != "y" and ready != "yes" and ready != "YES" and ready != "ready" and ready != "Ready": try: ready = input("Confirm when you are ready ") except ValueError: print("shit broke. ") ##This next step will seek out the word Device within firstdev.ahk, and replace with devlist[0] for line in fileinput.input(["firstdev.ahk"], inplace=True): line = line.replace("device", devlist[0]) sys.stdout.write(line) ##next step runs firstdev.ahk os.system('firstdev.ahk') ##next step is replacing devlist[0] with "device" for line in fileinput.input(["firstdev.ahk"], inplace=True): line = line.replace(devlist[0], "device") sys.stdout.write(line) del devlist[0] #deleting the first item from the list. next steps will repeat. Thanks in advance. From __peter__ at web.de Fri Apr 26 10:53:44 2013 From: __peter__ at web.de (Peter Otten) Date: Fri, 26 Apr 2013 16:53:44 +0200 Subject: TypeError: Can't convert 'int' object to str implicitly References: <889e8874-1f6f-494a-bb83-27801161f51a@googlegroups.com> Message-ID: tunacubes at gmail.com wrote: > Hey, > > Let me explain what my program is supposed to do... > > I am using a macro program in conjunction with a python script I am > writing. The macro inputs data into a database we use at my job, blah blah > blah. > > The script asks how many numbers (devices) you need to enter. Next, it > asks you to input the device numbers. When you input them, it creates a > list with all of the devices. I then tell it to go into the script of the > Macro (firstdev.ahk) that will run on the back-end, and replace the word > "device" with the first device in the list. It then should execute the > Macro, change the device number back to the word "Device" for future use, > and then delete the first number from the list. It will repeat as long as > there are numbers in the list. > > The error I receive is "TypeError: Can't convert 'int' object to str > implicitly" when it tries to put the device into the macro script. Python is trying hard to give you a meaningful error message and shows the line causing the error in the traceback. It pays to read carefully -- or to post it here if it doesn't make sense to you. > devlist = [] ... > Number = int(input("Enter Device number: ")) > devlist.append(Number) ... > line = line.replace(devlist[0], "device") devList is a list of integers, and devlist[0] is thus an int. >>> "foo device bar\n".replace(42, "device") Traceback (most recent call last): File "", line 1, in TypeError: Can't convert 'int' object to str implicitly Implicitly? So let's try and convert the int /explicitly/ . >>> "foo device bar\n".replace(str(42), "device") 'foo device bar\n' No error, but probably still not what you expected. Can you sort it out yourself? > I am fairly new to python, so if anything looks screwed up or like I am an > idiot, it is because I am. I like to see a bit of self-deprecation now and then, but on this list complete tracebacks find even more love ;) From rosuav at gmail.com Fri Apr 26 10:53:45 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 27 Apr 2013 00:53:45 +1000 Subject: TypeError: Can't convert 'int' object to str implicitly In-Reply-To: <889e8874-1f6f-494a-bb83-27801161f51a@googlegroups.com> References: <889e8874-1f6f-494a-bb83-27801161f51a@googlegroups.com> Message-ID: On Sat, Apr 27, 2013 at 12:26 AM, wrote: > Hey, > The error I receive is "TypeError: Can't convert 'int' object to str implicitly" when it tries to put the device into the macro script. It worked fine when I just had it input one device into the script without the use of lists, but for whatever reason, using a list does not play nice with replacing the words "Device" with the number from the list. Here is my script. I will give you up until the part that the error occurs, as everything afterwords is pointless. > > I am fairly new to python, so if anything looks screwed up or like I am an idiot, it is because I am. Welcome to Python. One thing that you'll quickly learn is that the full traceback is REALLY helpful; in this case, there won't be much traceback, but at least you'll get the line number. I'm looking at this line as being the culprit: > line = line.replace("device", devlist[0]) All you need to do is convert that to a string: line = line.replace("device", str(devlist[0])) and that should fix your problem. But while I'm here, may I offer a few other tips? (By the way, I'm going to assume you're using Python 3 here, because otherwise your "confirm when ready" would be bombing. But it helps to say what version you're using.) > import fileinput, sys, os > devlist = [] > maxdev = int(input("How many devices to add: ")) > curdev = int("0") Just 'curdev = 0' would work here. No need to convert a string to an integer - just use a literal integer. > while curdev < maxdev: UI suggestion: Let the user keep on inputting device numbers until some kind of sentinel (eg a blank line), unless it makes really good sense to ask for the number up-front. > try: > Number = int(input("Enter Device number: ")) > devlist.append(Number) > curdev = curdev + 1 > except ValueError: > print("Please enter a valid number") You can save the hassle of maintaining curdev by simply looking at len(devlist) - that is, change your condition to "while len(devlist) < maxdev". > ready = 0 > while ready != "Y" and ready != "y" and ready != "yes" and ready != "YES" and ready != "ready" and ready != "Ready": Here's a really cool tip. You can simply check set membership: while ready not in {"Y","y","yes","YES","ready","Ready"}: But I'd be inclined to make the UI a bit tighter here and make it something like: ready = input("Confirm when you are ready : ") and then just look for either "Y" or "y", nothing more. But that's up to you. You know who's going to use this program, I don't. (The capitalized N representing that the default is No is a convention you may or may not want to follow.) > try: > ready = input("Confirm when you are ready ") > except ValueError: > print("shit broke. ") Drop the try/except; if there's something wrong (and, btw, I'm not sure what circumstances would trigger a ValueError here - maybe someone else knows of something?), just let the exception terminate the program. There's nothing useful to do here anyway :) > ##This next step will seek out the word Device within firstdev.ahk, and replace with devlist[0] > for line in fileinput.input(["firstdev.ahk"], inplace=True): > line = line.replace("device", devlist[0]) > sys.stdout.write(line) You're reading a single file with constant name here. Save yourself some trouble: just open the file directly. for line in open("firstdev.ahk"): print(line.replace("device", str(devlist[0]))) Though I'm not sure why you want to write to stdout here. Were you intending to write back to another file? I'm getting a bit lost in your code here. My understanding of your intentions, from your comments, is that you actually want to repeat most of the code from here on for each device number entered - that strongly suggests a 'for' loop bracketing the whole thing. Is that what you meant this to do? Currently, it'll get to the 'del' at the bottom, and then just terminate. > ##next step runs firstdev.ahk > os.system('firstdev.ahk') > ##next step is replacing devlist[0] with "device" > for line in fileinput.input(["firstdev.ahk"], inplace=True): > line = line.replace(devlist[0], "device") > sys.stdout.write(line) And here you repeat everything from above. Again, not sure what you're intending to do here. > del devlist[0] #deleting the first item from the list. next steps will repeat. The steps won't repeat by themselves, so this is where I'm thinking you actually want a for loop. I hope you don't take this the wrong way, as I feel now (on skimming over this email prior to sending) that I've kinda pulled your code to pieces a bit! It's just advice, just suggestions; this is your code and nobody else's. You may very well disagree with any or all of what I've said, and that's to be expected. It's also a great way to get discussion going, and discussion is one of the best ways for everyone to learn :) Chris Angelico From rosuav at gmail.com Fri Apr 26 11:05:29 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 27 Apr 2013 01:05:29 +1000 Subject: TypeError: Can't convert 'int' object to str implicitly In-Reply-To: <889e8874-1f6f-494a-bb83-27801161f51a@googlegroups.com> References: <889e8874-1f6f-494a-bb83-27801161f51a@googlegroups.com> Message-ID: On Sat, Apr 27, 2013 at 12:26 AM, wrote: > ##This next step will seek out the word Device within firstdev.ahk, and replace with devlist[0] > for line in fileinput.input(["firstdev.ahk"], inplace=True): > line = line.replace("device", devlist[0]) > sys.stdout.write(line) > ##next step runs firstdev.ahk > os.system('firstdev.ahk') > ##next step is replacing devlist[0] with "device" > for line in fileinput.input(["firstdev.ahk"], inplace=True): > line = line.replace(devlist[0], "device") > sys.stdout.write(line) I've checked out what fileinput.input() is doing here (ought to have done that earlier, sorry!) and I now understand this block of code more. You're replacing that word _in the file, on disk_, and then making the inverse replacement. This strikes me as dangerous; if anything happens to your process in the middle, the file will be damaged on disk. I would STRONGLY recommend rewriting this to use some other file - for instance, a temporary file. I haven't looked into the details, as I haven't actually done this lately in Python, but you should be able to use tempfile.NamedTemporaryFile(delete=False) [1], write to it, make it executable, run it, and unlink it. That way, you're creating a temporary file to run, not running the original. This is semantically different from your code, but I think it'd be a lot safer. [1] http://docs.python.org/3.3/library/tempfile.html#tempfile.NamedTemporaryFile ChrisA From d at davea.name Fri Apr 26 13:23:25 2013 From: d at davea.name (Dave Angel) Date: Fri, 26 Apr 2013 13:23:25 -0400 Subject: TypeError: Can't convert 'int' object to str implicitly In-Reply-To: References: <889e8874-1f6f-494a-bb83-27801161f51a@googlegroups.com> Message-ID: <517AB80D.9060205@davea.name> On 04/26/2013 11:05 AM, Chris Angelico wrote: > On Sat, Apr 27, 2013 at 12:26 AM, wrote: >> ##This next step will seek out the word Device within firstdev.ahk, and replace with devlist[0] >> for line in fileinput.input(["firstdev.ahk"], inplace=True): >> line = line.replace("device", devlist[0]) >> sys.stdout.write(line) >> ##next step runs firstdev.ahk >> os.system('firstdev.ahk') >> ##next step is replacing devlist[0] with "device" >> for line in fileinput.input(["firstdev.ahk"], inplace=True): >> line = line.replace(devlist[0], "device") >> sys.stdout.write(line) > > I've checked out what fileinput.input() is doing here (ought to have > done that earlier, sorry!) and I now understand this block of code > more. You're replacing that word _in the file, on disk_, and then > making the inverse replacement. This strikes me as dangerous; if > anything happens to your process in the middle, the file will be > damaged on disk. I would STRONGLY recommend rewriting this to use some > other file - for instance, a temporary file. I haven't looked into the > details, as I haven't actually done this lately in Python, but you > should be able to use tempfile.NamedTemporaryFile(delete=False) [1], > write to it, make it executable, run it, and unlink it. That way, > you're creating a temporary file to run, not running the original. > This is semantically different from your code, but I think it'd be a > lot safer. > > [1] http://docs.python.org/3.3/library/tempfile.html#tempfile.NamedTemporaryFile > > ChrisA > fileinput.Fileinput class already creates the temp file when you specify inplace=True If it didn't, I'd also have to point out the hazards of doing in-place updates in a text file where the new data and old is a different length. There still may be reasons to make an explicit backup, but I don't know what they are. -- DaveA From rosuav at gmail.com Fri Apr 26 13:28:26 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 27 Apr 2013 03:28:26 +1000 Subject: TypeError: Can't convert 'int' object to str implicitly In-Reply-To: <517AB80D.9060205@davea.name> References: <889e8874-1f6f-494a-bb83-27801161f51a@googlegroups.com> <517AB80D.9060205@davea.name> Message-ID: On Sat, Apr 27, 2013 at 3:23 AM, Dave Angel wrote: > On 04/26/2013 11:05 AM, Chris Angelico wrote: >> I've checked out what fileinput.input() is doing here (ought to have >> done that earlier, sorry!) and I now understand this block of code >> more. You're replacing that word _in the file, on disk_, and then >> making the inverse replacement. This strikes me as dangerous; if >> anything happens to your process in the middle, the file will be >> damaged on disk. I would STRONGLY recommend rewriting this to use some >> other file - for instance, a temporary file. > > fileinput.Fileinput class already creates the temp file when you specify > inplace=True > > If it didn't, I'd also have to point out the hazards of doing in-place > updates in a text file where the new data and old is a different length. > > There still may be reasons to make an explicit backup, but I don't know what > they are. That's true if something goes wrong during the actual writing of the file only. But if the process bombs in the middle of the execution phase (which in the Python script is a single os.system() call), then the file will have been one-way changed on the disk - hence, "damaged". The explicit temporary file (and executing the temp file) is a much safer way to do it. ChrisA From davea at davea.name Fri Apr 26 13:52:07 2013 From: davea at davea.name (Dave Angel) Date: Fri, 26 Apr 2013 13:52:07 -0400 Subject: TypeError: Can't convert 'int' object to str implicitly In-Reply-To: References: <889e8874-1f6f-494a-bb83-27801161f51a@googlegroups.com> <517AB80D.9060205@davea.name> Message-ID: <517ABEC7.9070908@davea.name> On 04/26/2013 01:28 PM, Chris Angelico wrote: > On Sat, Apr 27, 2013 at 3:23 AM, Dave Angel wrote: >> On 04/26/2013 11:05 AM, Chris Angelico wrote: >>> I've checked out what fileinput.input() is doing here (ought to have >>> done that earlier, sorry!) and I now understand this block of code >>> more. You're replacing that word _in the file, on disk_, and then >>> making the inverse replacement. This strikes me as dangerous; if >>> anything happens to your process in the middle, the file will be >>> damaged on disk. I would STRONGLY recommend rewriting this to use some >>> other file - for instance, a temporary file. >> >> fileinput.Fileinput class already creates the temp file when you specify >> inplace=True >> >> If it didn't, I'd also have to point out the hazards of doing in-place >> updates in a text file where the new data and old is a different length. >> >> There still may be reasons to make an explicit backup, but I don't know what >> they are. > > That's true if something goes wrong during the actual writing of the > file only. But if the process bombs in the middle of the execution > phase (which in the Python script is a single os.system() call), then > the file will have been one-way changed on the disk - hence, > "damaged". The explicit temporary file (and executing the temp file) > is a much safer way to do it. > Only two of those sentences makes sense to me. I have no idea what "execution phase" means, and don't know what would be done via an os.system() call. I don't know what "one-way change" means If I were specifying the fileinput stuff, I'd have said the new data should be written to the temp file, so that at no time was the original file in an in-between state. -- DaveA From rosuav at gmail.com Fri Apr 26 14:02:20 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 27 Apr 2013 04:02:20 +1000 Subject: TypeError: Can't convert 'int' object to str implicitly In-Reply-To: <517ABEC7.9070908@davea.name> References: <889e8874-1f6f-494a-bb83-27801161f51a@googlegroups.com> <517AB80D.9060205@davea.name> <517ABEC7.9070908@davea.name> Message-ID: On Sat, Apr 27, 2013 at 3:52 AM, Dave Angel wrote: > On 04/26/2013 01:28 PM, Chris Angelico wrote: >> >> On Sat, Apr 27, 2013 at 3:23 AM, Dave Angel wrote: >>> >>> On 04/26/2013 11:05 AM, Chris Angelico wrote: >>>> >>>> I've checked out what fileinput.input() is doing here (ought to have >>>> done that earlier, sorry!) and I now understand this block of code >>>> more. You're replacing that word _in the file, on disk_, and then >>>> making the inverse replacement. This strikes me as dangerous; if >>>> anything happens to your process in the middle, the file will be >>>> damaged on disk. I would STRONGLY recommend rewriting this to use some >>>> other file - for instance, a temporary file. >>> >>> >>> fileinput.Fileinput class already creates the temp file when you specify >>> inplace=True >>> >>> If it didn't, I'd also have to point out the hazards of doing in-place >>> updates in a text file where the new data and old is a different length. >>> >>> There still may be reasons to make an explicit backup, but I don't know >>> what >>> they are. >> >> >> That's true if something goes wrong during the actual writing of the >> file only. But if the process bombs in the middle of the execution >> phase (which in the Python script is a single os.system() call), then >> the file will have been one-way changed on the disk - hence, >> "damaged". The explicit temporary file (and executing the temp file) >> is a much safer way to do it. >> > > Only two of those sentences makes sense to me. I have no idea what > "execution phase" means, and don't know what would be done via an > os.system() call. I don't know what "one-way change" means > > If I were specifying the fileinput stuff, I'd have said the new data should > be written to the temp file, so that at no time was the original file in an > in-between state. Here's a massive simplification of the OP's program: 1. Build a list of device IDs 2. Edit the file "firstdev.ahk" and replace all instances of "device" with the device ID 3. Execute the now-edited firstdev.ahk using os.system() 4. Reverse the edit of firstdev.ahk, replacing all instances of the device ID with the word "device". Apart from the risk of accidentally changing back something that wasn't changed in the first place (which the OP may know to be impossible, eg if the macro file has no numbers in it), this has the risk that a computer failure in step 3 will leave the file on disk in its edited state. That's what I'm concerned about. By writing the modified .ahk content to a different file and then executing the other file, he would avoid editing the template at all. It'd also then be multi-process safe, for what that's worth. ChrisA From davea at davea.name Fri Apr 26 15:25:56 2013 From: davea at davea.name (Dave Angel) Date: Fri, 26 Apr 2013 15:25:56 -0400 Subject: TypeError: Can't convert 'int' object to str implicitly In-Reply-To: References: <889e8874-1f6f-494a-bb83-27801161f51a@googlegroups.com> <517AB80D.9060205@davea.name> <517ABEC7.9070908@davea.name> Message-ID: <517AD4C4.9020806@davea.name> On 04/26/2013 02:02 PM, Chris Angelico wrote: > > >>> > > Here's a massive simplification of the OP's program: > > 1. Build a list of device IDs > 2. Edit the file "firstdev.ahk" and replace all instances of "device" > with the device ID > 3. Execute the now-edited firstdev.ahk using os.system() > 4. Reverse the edit of firstdev.ahk, replacing all instances of the > device ID with the word "device". > > Apart from the risk of accidentally changing back something that > wasn't changed in the first place (which the OP may know to be > impossible, eg if the macro file has no numbers in it), this has the > risk that a computer failure in step 3 will leave the file on disk in > its edited state. That's what I'm concerned about. By writing the > modified .ahk content to a different file and then executing the other > file, he would avoid editing the template at all. It'd also then be > multi-process safe, for what that's worth. > OK, thanks. That makes perfect sense. Somehow I missed that it was the altered file that was being used as a script. I just assumed it was like a config file for some program, where the name is hardwired. -- DaveA From tunacubes at gmail.com Fri Apr 26 11:21:13 2013 From: tunacubes at gmail.com (tunacubes at gmail.com) Date: Fri, 26 Apr 2013 08:21:13 -0700 (PDT) Subject: TypeError: Can't convert 'int' object to str implicitly In-Reply-To: References: <889e8874-1f6f-494a-bb83-27801161f51a@googlegroups.com> Message-ID: <9f722d60-dbf5-450c-9388-cc33872ce9cc@googlegroups.com> On Friday, April 26, 2013 10:53:44 AM UTC-4, Peter Otten wrote: > tunacubes at gmail.com wrote: > > > > > Hey, > > > > > > Let me explain what my program is supposed to do... > > > > > > I am using a macro program in conjunction with a python script I am > > > writing. The macro inputs data into a database we use at my job, blah blah > > > blah. > > > > > > The script asks how many numbers (devices) you need to enter. Next, it > > > asks you to input the device numbers. When you input them, it creates a > > > list with all of the devices. I then tell it to go into the script of the > > > Macro (firstdev.ahk) that will run on the back-end, and replace the word > > > "device" with the first device in the list. It then should execute the > > > Macro, change the device number back to the word "Device" for future use, > > > and then delete the first number from the list. It will repeat as long as > > > there are numbers in the list. > > > > > > The error I receive is "TypeError: Can't convert 'int' object to str > > > implicitly" when it tries to put the device into the macro script. > > > > Python is trying hard to give you a meaningful error message and shows the > > line causing the error in the traceback. It pays to read carefully -- or to > > post it here if it doesn't make sense to you. > > > > > devlist = [] > > ... > > > Number = int(input("Enter Device number: ")) > > > devlist.append(Number) > > ... > > > line = line.replace(devlist[0], "device") > > > > devList is a list of integers, and devlist[0] is thus an int. > > > > >>> "foo device bar\n".replace(42, "device") > > Traceback (most recent call last): > > File "", line 1, in > > TypeError: Can't convert 'int' object to str implicitly > > > > Implicitly? So let's try and convert the int /explicitly/ . > > > > >>> "foo device bar\n".replace(str(42), "device") > > 'foo device bar\n' > > > > No error, but probably still not what you expected. Can you sort it out > > yourself? > > > > > I am fairly new to python, so if anything looks screwed up or like I am an > > > idiot, it is because I am. > > > > I like to see a bit of self-deprecation now and then, but on this list > > complete tracebacks find even more love ;) Thank you, Peter. This was a tremendous help. Got it working. From tunacubes at gmail.com Fri Apr 26 11:22:16 2013 From: tunacubes at gmail.com (tunacubes at gmail.com) Date: Fri, 26 Apr 2013 08:22:16 -0700 (PDT) Subject: TypeError: Can't convert 'int' object to str implicitly In-Reply-To: References: <889e8874-1f6f-494a-bb83-27801161f51a@googlegroups.com> Message-ID: <9ac1c0e6-4b77-48a3-9b11-520a6c7ff64c@googlegroups.com> On Friday, April 26, 2013 11:05:29 AM UTC-4, Chris Angelico wrote: > On Sat, Apr 27, 2013 at 12:26 AM, wrote: > > > ##This next step will seek out the word Device within firstdev.ahk, and replace with devlist[0] > > > for line in fileinput.input(["firstdev.ahk"], inplace=True): > > > line = line.replace("device", devlist[0]) > > > sys.stdout.write(line) > > > ##next step runs firstdev.ahk > > > os.system('firstdev.ahk') > > > ##next step is replacing devlist[0] with "device" > > > for line in fileinput.input(["firstdev.ahk"], inplace=True): > > > line = line.replace(devlist[0], "device") > > > sys.stdout.write(line) > > > > I've checked out what fileinput.input() is doing here (ought to have > > done that earlier, sorry!) and I now understand this block of code > > more. You're replacing that word _in the file, on disk_, and then > > making the inverse replacement. This strikes me as dangerous; if > > anything happens to your process in the middle, the file will be > > damaged on disk. I would STRONGLY recommend rewriting this to use some > > other file - for instance, a temporary file. I haven't looked into the > > details, as I haven't actually done this lately in Python, but you > > should be able to use tempfile.NamedTemporaryFile(delete=False) [1], > > write to it, make it executable, run it, and unlink it. That way, > > you're creating a temporary file to run, not running the original. > > This is semantically different from your code, but I think it'd be a > > lot safer. > > > > [1] http://docs.python.org/3.3/library/tempfile.html#tempfile.NamedTemporaryFile > > > > ChrisA Thank you, Chris! I got it working and am going to take your advice on the tempfile idea. I actually ran into the problem you were referring to, and kept the .ahk files backed up elsewhere for when this situation arose. I appreciate the help! From rosuav at gmail.com Fri Apr 26 11:40:48 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 27 Apr 2013 01:40:48 +1000 Subject: TypeError: Can't convert 'int' object to str implicitly In-Reply-To: <9ac1c0e6-4b77-48a3-9b11-520a6c7ff64c@googlegroups.com> References: <889e8874-1f6f-494a-bb83-27801161f51a@googlegroups.com> <9ac1c0e6-4b77-48a3-9b11-520a6c7ff64c@googlegroups.com> Message-ID: On Sat, Apr 27, 2013 at 1:22 AM, wrote: >> I've checked out what fileinput.input() is doing here (ought to have >> >> done that earlier, sorry!) and I now understand this block of code >> >> more. You're replacing that word _in the file, on disk_, and then >> >> making the inverse replacement. This strikes me as dangerous; if >> >> anything happens to your process in the middle, the file will be >> >> damaged on disk. I would STRONGLY recommend rewriting this to use some >> >> other file - for instance, a temporary file. I haven't looked into the >> >> details, as I haven't actually done this lately in Python, but you >> >> should be able to use tempfile.NamedTemporaryFile(delete=False) [1], >> >> write to it, make it executable, run it, and unlink it. That way, >> >> you're creating a temporary file to run, not running the original. >> >> This is semantically different from your code, but I think it'd be a >> >> lot safer. > > Thank you, Chris! I got it working and am going to take your advice on the tempfile idea. I actually ran into the problem you were referring to, and kept the .ahk files backed up elsewhere for when this situation arose. I appreciate the help! Awesome! Hey, you want to know an easy way to show your appreciation for the people who answer your questions? It's really simple: Step 1: Don't use Google Groups to post. Step 2: Profit! Have a look at the quoted text in your responses. See how it's double-spaced and really obnoxious? That's not your fault, it's because Google Groups is buggy. There are plenty of other ways to read and post; I personally have subscribed to the mailing list and read it using Gmail, and there are a variety of other ways too. If you _must_ use Google Groups, check out this page for some recommendations on how to not offend people. http://wiki.python.org/moin/GoogleGroupsPython There are a number of non-G-rated terms going around that fairly accurately describe what Google Groups posts look like, but since I prefer milder language, I'll just repeat the word "obnoxious", as it carries all the meaning I need. ChrisA From rosuav at gmail.com Fri Apr 26 12:52:38 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 27 Apr 2013 02:52:38 +1000 Subject: [Python-ideas] Automatic context managers In-Reply-To: <517AA349.5080504@mrabarnett.plus.com> References: <20130425042335.GA60739@cskk.homeip.net> <5178CA66.3060205@pearwood.info> <517AA349.5080504@mrabarnett.plus.com> Message-ID: On Sat, Apr 27, 2013 at 1:54 AM, MRAB wrote: > On 26/04/2013 14:02, anatoly techtonik wrote: >> This circular reference problem is interesting. In object space it >> probably looks like a stellar detached from the visible (attached) >> universe. Is the main problem in detecting it? >> > The problem is in knowing in which order the objects should be > collected. > > For example, if A refers to B and B refers to A, should you collect A > then B, or B then A? If you collect A first, then, for a time, B will > be referring to a non-existent object. That's not good if the objects > have destructors which need to be run. Spin-off thread from python-ideas to discuss a more general question of garbage collection of cyclic structures. Once it's been proven that there's an unreferenced cycle, why not simply dispose of one of the objects, and replace all references to it (probably only one - preferably pick an object with the fewest references) with a special temporary object? In fact, that could probably be done in CPython by wiping out the object in memory and replacing it with a special marker of some sort, which would then automatically "take over" all references to the old object. Any attempt to manipulate this object could simply pop back with a DestructedObject exception or something. Is this a plausible (never mind viable yet, just conceptually plausible) alternative to sticking them into gc.garbage and ignoring them? It'd allow a double-linked list/tree to function cleanly - imagine, for instance, something like the DOM facilities available to web browser scripts: class DOMObject: def __init__(self,parent): self.parent=parent self.firstchild=self.sibling=None if not parent: return if not parent.firstchild: parent.firstchild=self else: child=parent.firstchild while child.sibling: child=child.sibling child.sibling=self def __del__(self): print("Disposing of id #%d"%id(self)) document=DOMObject(None) body=DOMObject(document) p=DOMObject(body) p=DOMObject(body) p=DOMObject(body) del document,body,p gc.collect() The __del__ method would need to clean up the external resources used by this object, but wouldn't have to walk the tree. Yet, just because there is a reference loop and there are __del__ methods, the garbage collector gives up and leaves it to the program author to deal with. I can understand if this is considered too complicated and too unusual a circumstance to be worth bothering to support, but I'm curious as to whether it's at least conceptually reasonable to do something like this. ChrisA From dihedral88888 at googlemail.com Fri Apr 26 18:40:52 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Fri, 26 Apr 2013 15:40:52 -0700 (PDT) Subject: [Python-ideas] Automatic context managers In-Reply-To: References: <20130425042335.GA60739@cskk.homeip.net> <5178CA66.3060205@pearwood.info> <517AA349.5080504@mrabarnett.plus.com> Message-ID: Chris Angelico? 2013?4?27????UTC+8??12?52?38???? > On Sat, Apr 27, 2013 at 1:54 AM, MRAB wrote: > > > On 26/04/2013 14:02, anatoly techtonik wrote: > > >> This circular reference problem is interesting. In object space it > > >> probably looks like a stellar detached from the visible (attached) > > >> universe. Is the main problem in detecting it? > > >> > > > The problem is in knowing in which order the objects should be > > > collected. > > > > > > For example, if A refers to B and B refers to A, should you collect A > > > then B, or B then A? If you collect A first, then, for a time, B will > > > be referring to a non-existent object. That's not good if the objects > > > have destructors which need to be run. > > > > Spin-off thread from python-ideas to discuss a more general question > > of garbage collection of cyclic structures. > > > > Once it's been proven that there's an unreferenced cycle, why not > > simply dispose of one of the objects, and replace all references to it > > (probably only one - preferably pick an object with the fewest > > references) with a special temporary object? In fact, that could > > probably be done in CPython by wiping out the object in memory and > > replacing it with a special marker of some sort, which would then > > automatically "take over" all references to the old object. Any > > attempt to manipulate this object could simply pop back with a > > DestructedObject exception or something. > > > > Is this a plausible (never mind viable yet, just conceptually > > plausible) alternative to sticking them into gc.garbage and ignoring > > them? It'd allow a double-linked list/tree to function cleanly - > > imagine, for instance, something like the DOM facilities available to > > web browser scripts: > > > > class DOMObject: > > def __init__(self,parent): > > self.parent=parent > > self.firstchild=self.sibling=None > > if not parent: return > > if not parent.firstchild: > > parent.firstchild=self > > else: > > child=parent.firstchild > > while child.sibling: > > child=child.sibling > > child.sibling=self > > def __del__(self): > > print("Disposing of id #%d"%id(self)) > > > > document=DOMObject(None) > > body=DOMObject(document) > > p=DOMObject(body) > > p=DOMObject(body) > > p=DOMObject(body) > > del document,body,p > > gc.collect() > > > > The __del__ method would need to clean up the external resources used > > by this object, but wouldn't have to walk the tree. Yet, just because > > there is a reference loop and there are __del__ methods, the garbage > > collector gives up and leaves it to the program author to deal with. > > > > I can understand if this is considered too complicated and too unusual > > a circumstance to be worth bothering to support, but I'm curious as to > > whether it's at least conceptually reasonable to do something like > > this. > > > > ChrisA Please use the deep-copy methods from time to time to disentangle referenced objects in python. The cyclic reference cycle has to be broken by some mean first in python to proceed for further actions in the gc. From rosuav at gmail.com Fri Apr 26 12:54:33 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 27 Apr 2013 02:54:33 +1000 Subject: CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers) Message-ID: [[ Resending under a more appropriate subject line... sorry about that, ignore the other one as it'll only confuse matters ]] On Sat, Apr 27, 2013 at 1:54 AM, MRAB wrote: > On 26/04/2013 14:02, anatoly techtonik wrote: >> This circular reference problem is interesting. In object space it >> probably looks like a stellar detached from the visible (attached) >> universe. Is the main problem in detecting it? >> > The problem is in knowing in which order the objects should be > collected. > > For example, if A refers to B and B refers to A, should you collect A > then B, or B then A? If you collect A first, then, for a time, B will > be referring to a non-existent object. That's not good if the objects > have destructors which need to be run. Spin-off thread from python-ideas to discuss a more general question of garbage collection of cyclic structures. Once it's been proven that there's an unreferenced cycle, why not simply dispose of one of the objects, and replace all references to it (probably only one - preferably pick an object with the fewest references) with a special temporary object? In fact, that could probably be done in CPython by wiping out the object in memory and replacing it with a special marker of some sort, which would then automatically "take over" all references to the old object. Any attempt to manipulate this object could simply pop back with a DestructedObject exception or something. Is this a plausible (never mind viable yet, just conceptually plausible) alternative to sticking them into gc.garbage and ignoring them? It'd allow a double-linked list/tree to function cleanly - imagine, for instance, something like the DOM facilities available to web browser scripts: class DOMObject: def __init__(self,parent): self.parent=parent self.firstchild=self.sibling=None if not parent: return if not parent.firstchild: parent.firstchild=self else: child=parent.firstchild while child.sibling: child=child.sibling child.sibling=self def __del__(self): print("Disposing of id #%d"%id(self)) document=DOMObject(None) body=DOMObject(document) p=DOMObject(body) p=DOMObject(body) p=DOMObject(body) del document,body,p gc.collect() The __del__ method would need to clean up the external resources used by this object, but wouldn't have to walk the tree. Yet, just because there is a reference loop and there are __del__ methods, the garbage collector gives up and leaves it to the program author to deal with. I can understand if this is considered too complicated and too unusual a circumstance to be worth bothering to support, but I'm curious as to whether it's at least conceptually reasonable to do something like this. ChrisA From davea at davea.name Fri Apr 26 13:42:11 2013 From: davea at davea.name (Dave Angel) Date: Fri, 26 Apr 2013 13:42:11 -0400 Subject: CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers) In-Reply-To: References: Message-ID: <517ABC73.4000605@davea.name> On 04/26/2013 12:54 PM, Chris Angelico wrote: > [[ Resending under a more appropriate subject line... sorry about > that, ignore the other one as it'll only confuse matters ]] > > On Sat, Apr 27, 2013 at 1:54 AM, MRAB wrote: >> On 26/04/2013 14:02, anatoly techtonik wrote: >>> This circular reference problem is interesting. In object space it >>> probably looks like a stellar detached from the visible (attached) >>> universe. Is the main problem in detecting it? >>> >> The problem is in knowing in which order the objects should be >> collected. >> >> For example, if A refers to B and B refers to A, should you collect A >> then B, or B then A? If you collect A first, then, for a time, B will >> be referring to a non-existent object. That's not good if the objects >> have destructors which need to be run. > > Spin-off thread from python-ideas to discuss a more general question > of garbage collection of cyclic structures. > > Once it's been proven that there's an unreferenced cycle, why not > simply dispose of one of the objects, and replace all references to it > (probably only one - preferably pick an object with the fewest > references) with a special temporary object? In fact, that could > probably be done in CPython by wiping out the object in memory and > replacing it with a special marker of some sort, which would then > automatically "take over" all references to the old object. Any > attempt to manipulate this object could simply pop back with a > DestructedObject exception or something. > > Is this a plausible (never mind viable yet, just conceptually > plausible) alternative to sticking them into gc.garbage and ignoring > them? It'd allow a double-linked list/tree to function cleanly - > imagine, for instance, something like the DOM facilities available to > web browser scripts: > > class DOMObject: > def __init__(self,parent): > self.parent=parent > self.firstchild=self.sibling=None > if not parent: return > if not parent.firstchild: > parent.firstchild=self > else: > child=parent.firstchild > while child.sibling: > child=child.sibling > child.sibling=self > def __del__(self): > print("Disposing of id #%d"%id(self)) > > document=DOMObject(None) > body=DOMObject(document) > p=DOMObject(body) > p=DOMObject(body) > p=DOMObject(body) > del document,body,p > gc.collect() > > The __del__ method would need to clean up the external resources used > by this object, but wouldn't have to walk the tree. Yet, just because > there is a reference loop and there are __del__ methods, the garbage > collector gives up and leaves it to the program author to deal with. > > I can understand if this is considered too complicated and too unusual > a circumstance to be worth bothering to support, but I'm curious as to > whether it's at least conceptually reasonable to do something like > this. > > ChrisA > I don't see what your "special" temporary object actually accomplishes. Seems to me you need to declare that your __del__() methods promise not to reference each other, and the gc would then check all objects in the cycle, and do its present behavior if any of the destructors is not specially declared. I'm not sure how often you'd have a non-trivial destructor that wouldn't reference any objects. And doing a static analysis of what will happen during the destructor would be pretty messy. So the best I and come up with is to keep the declaration, but require a try/catch to cleanly terminate each destructor if it ever references anything in the tree. -- DaveA From rosuav at gmail.com Fri Apr 26 13:57:37 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 27 Apr 2013 03:57:37 +1000 Subject: CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers) In-Reply-To: <517ABC73.4000605@davea.name> References: <517ABC73.4000605@davea.name> Message-ID: On Sat, Apr 27, 2013 at 3:42 AM, Dave Angel wrote: > I don't see what your "special" temporary object actually accomplishes. > Seems to me you need to declare that your __del__() methods promise not to > reference each other, and the gc would then check all objects in the cycle, > and do its present behavior if any of the destructors is not specially > declared. It wouldn't be declared; it'd simply throw an exception if anything different happened. > I'm not sure how often you'd have a non-trivial destructor that wouldn't > reference any objects. And doing a static analysis of what will happen > during the destructor would be pretty messy. So the best I and come up with > is to keep the declaration, but require a try/catch to cleanly terminate > each destructor if it ever references anything in the tree. And yeah. If you catch the exception inside __del__, you can cope with the destructed object yourself (or LBLY, if you wish). Alternatively, you just proceed as normal, and when your __del__ throws an exception, the gc then copes (not sure *how* it should cope - log it to stderr and carry on?). Same as normal exception handling. The advantage of this style is that the code to deal with the cycle is kept right in the cyclic object's destructor - right where the problem is. Doing it through gc.garbage requires that some other operation periodically check for garbage - after the GC has done its own periodic check. Seems simpler/cleaner to do it as part of the gc run itself. ChrisA From davea at davea.name Fri Apr 26 15:31:10 2013 From: davea at davea.name (Dave Angel) Date: Fri, 26 Apr 2013 15:31:10 -0400 Subject: CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers) In-Reply-To: References: <517ABC73.4000605@davea.name> Message-ID: <517AD5FE.60706@davea.name> On 04/26/2013 01:57 PM, Chris Angelico wrote: > On Sat, Apr 27, 2013 at 3:42 AM, Dave Angel wrote: >> I don't see what your "special" temporary object actually accomplishes. >> Seems to me you need to declare that your __del__() methods promise not to >> reference each other, and the gc would then check all objects in the cycle, >> and do its present behavior if any of the destructors is not specially >> declared. > > It wouldn't be declared; it'd simply throw an exception if anything > different happened. > >> I'm not sure how often you'd have a non-trivial destructor that wouldn't >> reference any objects. And doing a static analysis of what will happen >> during the destructor would be pretty messy. So the best I and come up with >> is to keep the declaration, but require a try/catch to cleanly terminate >> each destructor if it ever references anything in the tree. > > And yeah. If you catch the exception inside __del__, you can cope with > the destructed object yourself (or LBLY, if you wish). Alternatively, > you just proceed as normal, and when your __del__ throws an exception, > the gc then copes (not sure *how* it should cope - log it to stderr > and carry on?). Same as normal exception handling. > > The advantage of this style is that the code to deal with the cycle is > kept right in the cyclic object's destructor - right where the problem > is. Doing it through gc.garbage requires that some other operation > periodically check for garbage - after the GC has done its own > periodic check. Seems simpler/cleaner to do it as part of the gc run > itself. > You must think me dense by now. But I don't understand what the two different garbage collection operations are that you're positing. As far as I know, there's ref counting, which is quick, and frees something as soon as the count goes to zero. Then there's gc, which has to scan through all the objects from a known starting set, and identify those things which aren't accessible, and free any that don't have a __del__() method. And it's only in the gc step that cycles and such are identifiable. -- DaveA From ian.g.kelly at gmail.com Fri Apr 26 18:43:35 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 26 Apr 2013 16:43:35 -0600 Subject: CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers) In-Reply-To: <517AD5FE.60706@davea.name> References: <517ABC73.4000605@davea.name> <517AD5FE.60706@davea.name> Message-ID: On Fri, Apr 26, 2013 at 1:31 PM, Dave Angel wrote: > On 04/26/2013 01:57 PM, Chris Angelico wrote: >> And yeah. If you catch the exception inside __del__, you can cope with >> the destructed object yourself (or LBLY, if you wish). Alternatively, >> you just proceed as normal, and when your __del__ throws an exception, >> the gc then copes (not sure *how* it should cope - log it to stderr >> and carry on?). Same as normal exception handling. >> >> The advantage of this style is that the code to deal with the cycle is >> kept right in the cyclic object's destructor - right where the problem >> is. Doing it through gc.garbage requires that some other operation >> periodically check for garbage - after the GC has done its own >> periodic check. Seems simpler/cleaner to do it as part of the gc run >> itself. >> > > You must think me dense by now. But I don't understand what the two > different garbage collection operations are that you're positing. > > As far as I know, there's ref counting, which is quick, and frees something > as soon as the count goes to zero. Then there's gc, which has to scan > through all the objects from a known starting set, and identify those things > which aren't accessible, and free any that don't have a __del__() method. > > And it's only in the gc step that cycles and such are identifiable. Whenever the GC finds a cycle that is unreferenced but uncollectable, it stores those objects in the list gc.garbage. At that point, if the user wishes to clean up those cycles, it is up to them to delve into gc.garbage, untangle the objects contained within, break the cycles, and remove them from the list so that they can be freed by the ref counter. This user-supplied step is what Chris is referring to as "some other" periodic check. If the user does not do this, then those objects simply remain in the gc.garbage list until the program terminates. From davea at davea.name Fri Apr 26 19:45:50 2013 From: davea at davea.name (Dave Angel) Date: Fri, 26 Apr 2013 19:45:50 -0400 Subject: CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers) In-Reply-To: References: <517ABC73.4000605@davea.name> <517AD5FE.60706@davea.name> Message-ID: <517B11AE.4050203@davea.name> On 04/26/2013 06:43 PM, Ian Kelly wrote: > > Whenever the GC finds a cycle that is unreferenced but uncollectable, > it stores those objects in the list gc.garbage. At that point, if the > user wishes to clean up those cycles, it is up to them to delve into > gc.garbage, untangle the objects contained within, break the cycles, > and remove them from the list so that they can be freed by the ref > counter. This user-supplied step is what Chris is referring to as > "some other" periodic check. If the user does not do this, then those > objects simply remain in the gc.garbage list until the program > terminates. > I didn't know there was a callback that a user could hook into. That's very interesting. -- DaveA From skip at pobox.com Fri Apr 26 20:22:55 2013 From: skip at pobox.com (Skip Montanaro) Date: Fri, 26 Apr 2013 19:22:55 -0500 Subject: CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers) In-Reply-To: References: <517ABC73.4000605@davea.name> <517AD5FE.60706@davea.name> Message-ID: > Whenever the GC finds a cycle that is unreferenced but uncollectable, > it stores those objects in the list gc.garbage. At that point, if the > user wishes to clean up those cycles, it is up to them to delve into > gc.garbage, untangle the objects contained within, break the cycles, > and remove them from the list so that they can be freed by the ref > counter. I wonder if it would be useful to provide a gc.garbagehook analogous to sys.excepthook? Users could assign a function of their choice to much the cyclic garbage periodically. Just a thought, flying out of my fingers before my brain could stop it... Skip From rosuav at gmail.com Fri Apr 26 21:56:24 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 27 Apr 2013 11:56:24 +1000 Subject: CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers) In-Reply-To: References: <517ABC73.4000605@davea.name> <517AD5FE.60706@davea.name> Message-ID: On Sat, Apr 27, 2013 at 9:45 AM, Dave Angel wrote: > I didn't know there was a callback that a user could hook into. That's very > interesting. > On Sat, Apr 27, 2013 at 10:22 AM, Skip Montanaro wrote: >> Whenever the GC finds a cycle that is unreferenced but uncollectable, >> it stores those objects in the list gc.garbage. At that point, if the >> user wishes to clean up those cycles, it is up to them to delve into >> gc.garbage, untangle the objects contained within, break the cycles, >> and remove them from the list so that they can be freed by the ref >> counter. > > I wonder if it would be useful to provide a gc.garbagehook analogous > to sys.excepthook? > Users could assign a function of their choice to much the cyclic > garbage periodically. > > Just a thought, flying out of my fingers before my brain could stop it... As far as I know, Dave, there isn't currently one; Skip, that's close to what I'm talking about - it saves on the periodic check. But burying it in gc.garbagehook implies having a separate piece of code that knows how to break the reference cycles, whereas the __del__ method puts the code right there in the code that has the problem. Actually, *ANY* solution to this problem implies having __del__ able to cope with the cycle being broken. Here's an example, perhaps a silly one, but not far different in nature from some things I've done in C++. (Granted, all the Python implementations of those same algorithms have involved built-in types rather than linked lists, but still.) class DLCircList: def __init__(self,payload): self.payload=payload self.next=self.prev=self print("Creating node: %s"%self.payload) def __del__(self): print("Deleting node %s from cycle %s"%(self.payload,self.enum())) self.prev.next=self.next self.next.prev=self.prev def attach(self,other): assert(self.next==self) # Don't attach twice self.prev=other self.next=other.next other.next=self self.next.prev=self print("Adding node %s to cycle %s"%(self.payload,self.enum())) def enum(self): """Return a list of all node payloads in this cycle.""" ptr=self.next nodes=[self.payload] while ptr!=self: nodes.append(ptr.payload) ptr=ptr.next return nodes lst=DLCircList("foo") DLCircList("bar").attach(lst) DLCircList("quux").attach(lst) DLCircList("asdf").attach(lst) DLCircList("qwer").attach(lst) DLCircList("zxcv").attach(lst) print("Enumerating list: %s"%lst.enum()) del lst import gc gbg=gc.collect() print("And we have garbage: %s"%gbg) print(gc.garbage) Supposing you did this many many times, and you wanted decent garbage collection. How would you write a __del__ method, how would you write something to clean up gc.garbage? One way or another, something will have to deal with the possibility that the invariants have been broken, so my theory is that that possibility should be entirely within __del__. (Since __del__ calls enum(), it's possible for enum() to throw DestructedObject or whatever, but standard exception handling will deal with that.) ChrisA From skip at pobox.com Fri Apr 26 22:12:22 2013 From: skip at pobox.com (Skip Montanaro) Date: Fri, 26 Apr 2013 21:12:22 -0500 Subject: CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers) In-Reply-To: References: <517ABC73.4000605@davea.name> <517AD5FE.60706@davea.name> Message-ID: >From the Zen of Python: > In the face of ambiguity, refuse the temptation to guess. I believe the reason something isn't already done to break cycles is that the authors of the cyclic garbage collector considered the above aphorism. They rely on the author of the code with the cycles to figure out how to break them. All I was suggesting was that Python could provide a hook where the programmer could codify his algorithm for breaking cycles. Skip From rosuav at gmail.com Fri Apr 26 22:20:46 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 27 Apr 2013 12:20:46 +1000 Subject: CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers) In-Reply-To: References: <517ABC73.4000605@davea.name> <517AD5FE.60706@davea.name> Message-ID: On Sat, Apr 27, 2013 at 12:12 PM, Skip Montanaro wrote: > From the Zen of Python: > >> In the face of ambiguity, refuse the temptation to guess. > > I believe the reason something isn't already done to break cycles is > that the authors of the cyclic garbage collector considered the above > aphorism. They rely on the author of the code with the cycles to > figure out how to break them. All I was suggesting was that Python > could provide a hook where the programmer could codify his algorithm > for breaking cycles. Sure, and that makes good sense. The hook would be an improvement (maybe it gets passed a list of garbage that's about to be added to gc.garbage, but will be re-checked for cycles after the hook, so all you have to do is break the cycle in the hook and it'll work), but the implication is that an external piece of code knows about the possible cycles and how to deal with them. I'd really rather have something right there in the class. Effectively, something like this: whenever gc.garbage has content: turn_into(gc.garbage[0],None) # or a special "I am destroyed" object del gc.garbage[:] It doesn't matter which one gets taken out. Yes, I suppose that's a form of guessing, but whatever rules get put in place - whether by the language or by your own script - it'll always be possible to conjure a scenario where tossing a coin is the only way to pick which one goes. ChrisA From ian.g.kelly at gmail.com Fri Apr 26 18:50:54 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 26 Apr 2013 16:50:54 -0600 Subject: CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers) In-Reply-To: References: Message-ID: On Fri, Apr 26, 2013 at 10:54 AM, Chris Angelico wrote: > Once it's been proven that there's an unreferenced cycle, why not > simply dispose of one of the objects, and replace all references to it > (probably only one - preferably pick an object with the fewest > references) with a special temporary object? In fact, that could > probably be done in CPython by wiping out the object in memory and > replacing it with a special marker of some sort, which would then > automatically "take over" all references to the old object. Any > attempt to manipulate this object could simply pop back with a > DestructedObject exception or something. I think it still boils down to the same problem -- how should Python *predictably* choose which object will be disposed of in order to break the cycle? I don't see that this question is any different than asking how should Python choose which __del__ method should be called first, since the object so disposed of would still need its __del__ method called. From davea at davea.name Fri Apr 26 19:48:11 2013 From: davea at davea.name (Dave Angel) Date: Fri, 26 Apr 2013 19:48:11 -0400 Subject: CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers) In-Reply-To: References: Message-ID: <517B123B.8040206@davea.name> On 04/26/2013 06:50 PM, Ian Kelly wrote: > On Fri, Apr 26, 2013 at 10:54 AM, Chris Angelico wrote: >> Once it's been proven that there's an unreferenced cycle, why not >> simply dispose of one of the objects, and replace all references to it >> (probably only one - preferably pick an object with the fewest >> references) with a special temporary object? In fact, that could >> probably be done in CPython by wiping out the object in memory and >> replacing it with a special marker of some sort, which would then >> automatically "take over" all references to the old object. Any >> attempt to manipulate this object could simply pop back with a >> DestructedObject exception or something. > > I think it still boils down to the same problem -- how should Python > *predictably* choose which object will be disposed of in order to > break the cycle? I don't see that this question is any different than > asking how should Python choose which __del__ method should be called > first, since the object so disposed of would still need its __del__ > method called. > Perhaps if the __del__ methods disposed of the non-cyclic parts first, an exception doing the cyclic cleanups wouldn't hurt. Picture a doubly-linked list of file-type objects. Each one could release its file before trying to do anything with the links. -- DaveA From rosuav at gmail.com Fri Apr 26 21:14:33 2013 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 27 Apr 2013 11:14:33 +1000 Subject: CPython's cyclic garbage collector (was [Python-ideas] Automatic context managers) In-Reply-To: References: Message-ID: On Sat, Apr 27, 2013 at 8:50 AM, Ian Kelly wrote: > On Fri, Apr 26, 2013 at 10:54 AM, Chris Angelico wrote: >> Once it's been proven that there's an unreferenced cycle, why not >> simply dispose of one of the objects, and replace all references to it >> (probably only one - preferably pick an object with the fewest >> references) with a special temporary object? In fact, that could >> probably be done in CPython by wiping out the object in memory and >> replacing it with a special marker of some sort, which would then >> automatically "take over" all references to the old object. Any >> attempt to manipulate this object could simply pop back with a >> DestructedObject exception or something. > > I think it still boils down to the same problem -- how should Python > *predictably* choose which object will be disposed of in order to > break the cycle? I don't see that this question is any different than > asking how should Python choose which __del__ method should be called > first, since the object so disposed of would still need its __del__ > method called. It wouldn't need to. It just chooses arbitrarily. Maybe it picks the one with the lowest id(), maybe it picks the object that takes up the most space, maybe the one that would have been put into gc.garbage first. But it's got to die tomorrow, so it really doesn't matter[1], and there's no way for the GC to know which one won't be referenced by the other's __del__ method. [1] I'm involved in a Gilbert and Sullivan Society performance, curtain up in less than three hours, so I'm morally obligated to quote G&S somewhere. ChrisA From jose.fonseca.ti at gmail.com Fri Apr 26 20:56:53 2013 From: jose.fonseca.ti at gmail.com (act pet) Date: Sat, 27 Apr 2013 00:56:53 -0000 Subject: Python developers Message-ID: http://tech.groups.yahoo.com/group/Python_Developers/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From jimmie.he at gmail.com Fri Apr 26 23:57:45 2013 From: jimmie.he at gmail.com (Jimmie He) Date: Fri, 26 Apr 2013 20:57:45 -0700 (PDT) Subject: File Read issue by using module binascii Message-ID: <9b5795ab-baec-4c0a-a3b4-1075cffc8744@googlegroups.com> When I run the readbmp on an example.bmp(about 100k),the Shell is become to "No respose",when I change f.read() to f.read(1000),it is ok,could someone tell me the excat reason for this? Thank you in advance! Python Code as below!! import binascii def read_bmp(): f = open('example.bmp','rb') rawdata = f.read() #f.read(1000) is ok hexstr = binascii.b2a_hex(rawdata) #Get an HEX number bsstr = bin (int(hexstr,16))[2:] f.close() print('bin: ',bsstr,type(bsstr)) return From jimmie.he at gmail.com Sat Apr 27 00:22:11 2013 From: jimmie.he at gmail.com (Jimmie He) Date: Fri, 26 Apr 2013 21:22:11 -0700 (PDT) Subject: File Read issue by using module binascii In-Reply-To: <9b5795ab-baec-4c0a-a3b4-1075cffc8744@googlegroups.com> References: <9b5795ab-baec-4c0a-a3b4-1075cffc8744@googlegroups.com> Message-ID: when I commet the line of "print('bin: ',bsstr,type(bsstr)) ",it can be run,so maybe the problem is the memory allocate of so long strings......Am I right? ? 2013?4?27????UTC+8??11?57?45??Jimmie He??? > When I run the readbmp on an example.bmp(about 100k),the Shell is become to "No respose",when I change f.read() to f.read(1000),it is ok,could someone tell me the excat reason for this? > > Thank you in advance! > > > > Python Code as below!! > > > > import binascii > > > > def read_bmp(): > > f = open('example.bmp','rb') > > rawdata = f.read() #f.read(1000) is ok > > hexstr = binascii.b2a_hex(rawdata) #Get an HEX number > > bsstr = bin (int(hexstr,16))[2:] > > f.close() > > print('bin: ',bsstr,type(bsstr)) > > return From fabiosantosart at gmail.com Sat Apr 27 05:56:08 2013 From: fabiosantosart at gmail.com (=?ISO-8859-1?Q?F=E1bio_Santos?=) Date: Sat, 27 Apr 2013 10:56:08 +0100 Subject: File Read issue by using module binascii In-Reply-To: References: <9b5795ab-baec-4c0a-a3b4-1075cffc8744@googlegroups.com> Message-ID: It may be that you are printing too much data at once. 100k is a bit too much to have in memory but it should run anyway. But your console may be having trouble. Try looping over small chunks of the file and printing them one at a time. Use a while loop. I do know that in windows the console is not very efficient at printing so when I print too much data the console itself starts taking up a lot of processor time. On 27 Apr 2013 05:28, "Jimmie He" wrote: > when I commet the line of "print('bin: ',bsstr,type(bsstr)) ",it can be > run,so maybe the problem is the memory allocate of so long strings......Am > I right? > > ? 2013?4?27????UTC+8??11?57?45??Jimmie He??? > > When I run the readbmp on an example.bmp(about 100k),the Shell is become > to "No respose",when I change f.read() to f.read(1000),it is ok,could > someone tell me the excat reason for this? > > > > Thank you in advance! > > > > > > > > Python Code as below!! > > > > > > > > import binascii > > > > > > > > def read_bmp(): > > > > f = open('example.bmp','rb') > > > > rawdata = f.read() #f.read(1000) is ok > > > > hexstr = binascii.b2a_hex(rawdata) #Get an HEX number > > > > bsstr = bin (int(hexstr,16))[2:] > > > > f.close() > > > > print('bin: ',bsstr,type(bsstr)) > > > > return > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jimmie.he at gmail.com Sat Apr 27 06:42:58 2013 From: jimmie.he at gmail.com (Jimmie He) Date: Sat, 27 Apr 2013 03:42:58 -0700 (PDT) Subject: File Read issue by using module binascii In-Reply-To: References: <9b5795ab-baec-4c0a-a3b4-1075cffc8744@googlegroups.com> Message-ID: <1b1a4c18-fa8d-4197-aebf-66a58d79fcd8@googlegroups.com> What you said should make sense and I've already correct my code by your advice,thanks for your response! ? 2013?4?27????UTC+8??5?56?08??F?bio Santos??? > It may be that you are printing too much data at once. 100k is a bit too much to have in memory but it should run anyway. But your console may be having trouble. Try looping over small chunks of the file and printing them one at a time. Use a while loop. I do know that in windows the console is not very efficient at printing so when I print too much data the console itself starts taking up a lot of processor time. > > > On 27 Apr 2013 05:28, "Jimmie He" wrote: > > when I commet the line of "print('bin: ',bsstr,type(bsstr)) ",it can be run,so maybe the problem is the memory allocate of so long strings......Am I right? > > > > ? 2013?4?27????UTC+8??11?57?45??Jimmie He??? > > > When I run the readbmp on an example.bmp(about 100k),the Shell is become to "No respose",when I change f.read() to f.read(1000),it is ok,could someone tell me the excat reason for this? > > > > > > Thank you in advance! > > > > > > > > > > > > Python Code as below!! > > > > > > > > > > > > import binascii > > > > > > > > > > > > def read_bmp(): > > > > > > ? ? f = open('example.bmp','rb') > > > > > > ? ? rawdata = f.read() ? ? ? ? ? ? ? ? ? ? ? #f.read(1000) is ok > > > > > > ? ? hexstr = binascii.b2a_hex(rawdata) ? ? ? #Get an HEX number > > > > > > ? ? bsstr = bin (int(hexstr,16))[2:] > > > > > > ? ? f.close() > > > > > > ? ? print('bin: ',bsstr,type(bsstr)) > > > > > > ? ? return > > -- > > http://mail.python.org/mailman/listinfo/python-list From __peter__ at web.de Sat Apr 27 06:57:09 2013 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Apr 2013 12:57:09 +0200 Subject: File Read issue by using module binascii References: <9b5795ab-baec-4c0a-a3b4-1075cffc8744@googlegroups.com> Message-ID: Jimmie He wrote: > When I run the readbmp on an example.bmp(about 100k),the Shell is become > to "No respose",when I change f.read() to f.read(1000),it is ok,could > someone tell me the excat reason for this? Thank you in advance! > > Python Code as below!! > > import binascii > > def read_bmp(): > f = open('example.bmp','rb') > rawdata = f.read() #f.read(1000) is ok > hexstr = binascii.b2a_hex(rawdata) #Get an HEX number > bsstr = bin (int(hexstr,16))[2:] > f.close() > print('bin: ',bsstr,type(bsstr)) > return What shell are you using? The one provided by Idle? From jimmie.he at gmail.com Sat Apr 27 07:23:48 2013 From: jimmie.he at gmail.com (Jimmie He) Date: Sat, 27 Apr 2013 04:23:48 -0700 (PDT) Subject: File Read issue by using module binascii In-Reply-To: References: <9b5795ab-baec-4c0a-a3b4-1075cffc8744@googlegroups.com> Message-ID: <2441ce7d-8b3a-405f-ab88-d4e772191eb4@googlegroups.com> > What shell are you using? The one provided by Idle? Yes. I use IDLE,the python version is 3.3.1.What else could I use?? From fabiosantosart at gmail.com Sat Apr 27 07:40:48 2013 From: fabiosantosart at gmail.com (=?ISO-8859-1?Q?F=E1bio_Santos?=) Date: Sat, 27 Apr 2013 12:40:48 +0100 Subject: File Read issue by using module binascii In-Reply-To: <2441ce7d-8b3a-405f-ab88-d4e772191eb4@googlegroups.com> References: <9b5795ab-baec-4c0a-a3b4-1075cffc8744@googlegroups.com> <2441ce7d-8b3a-405f-ab88-d4e772191eb4@googlegroups.com> Message-ID: You could use your operating system's shell. Even if it is windows, it should be a lot better and faster, and thus not block so easily. On 27 Apr 2013 12:28, "Jimmie He" wrote: > > > What shell are you using? The one provided by Idle? > > Yes. I use IDLE,the python version is 3.3.1.What else could I use?? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Sat Apr 27 08:01:35 2013 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Apr 2013 14:01:35 +0200 Subject: File Read issue by using module binascii References: <9b5795ab-baec-4c0a-a3b4-1075cffc8744@googlegroups.com> <2441ce7d-8b3a-405f-ab88-d4e772191eb4@googlegroups.com> Message-ID: Jimmie He wrote: >> What shell are you using? The one provided by Idle? > > Yes. I use IDLE,the python version is 3.3.1.What else could I use?? The shell provided by the operating system is usually much faster. When I modify your code to import binascii def read_bmp(): f = open('example.bmp','rb') rawdata = f.read() #f.read(1000) is ok hexstr = binascii.b2a_hex(rawdata) #Get an HEX number bsstr = bin (int(hexstr,16))[2:] f.close() print('bin: ',bsstr,type(bsstr)) return if __name__ == "__main__": read_bmp() and generate a dummy example.bmp with 2**20 (about 1 million) bytes it takes about 2 seconds to terminate -- on hardware that is quite old. If I redirect the output it is even faster: $ time python3 bmp_to_bin.py > /dev/null real 0m0.766s user 0m0.300s sys 0m0.180s I am a Linux user, but expect similar numbers on Windows (in the DOS box or one of its successors). I have considered filing a bug* to ask for a tweak in idle that improves its responsiveness, but first wanted you to confirm that this was indeed the problem. (*) on http://bugs.python.org, if you want to do it yourself From jimmie.he at gmail.com Sat Apr 27 08:46:21 2013 From: jimmie.he at gmail.com (Jimmie He) Date: Sat, 27 Apr 2013 05:46:21 -0700 (PDT) Subject: File Read issue by using module binascii In-Reply-To: <9b5795ab-baec-4c0a-a3b4-1075cffc8744@googlegroups.com> References: <9b5795ab-baec-4c0a-a3b4-1075cffc8744@googlegroups.com> Message-ID: <960296d9-0d54-497f-98f0-c6fd8849af04@googlegroups.com> Peter, Thanks for your test in details. Because I'm an newbie in Python and I can not conform whether it is an bug. Here I attach my code include my emample.bmp as link below. https://hotfile.com/dl/204795514/62fed41/BMPTool.zip.html From timr at probo.com Sun Apr 28 00:34:08 2013 From: timr at probo.com (Tim Roberts) Date: Sat, 27 Apr 2013 21:34:08 -0700 Subject: File Read issue by using module binascii References: <9b5795ab-baec-4c0a-a3b4-1075cffc8744@googlegroups.com> Message-ID: <319pn8hgkc0pbj0099heq2nq3h5sv68g7s@4ax.com> Jimmie He wrote: >When I run the readbmp on an example.bmp(about 100k),the Shell is become to "No respose",when I change f.read() to f.read(1000),it is ok,could someone tell me the excat reason for this? >Thank you in advance! > >Python Code as below!! > >import binascii > >def read_bmp(): > f = open('example.bmp','rb') > rawdata = f.read() #f.read(1000) is ok > hexstr = binascii.b2a_hex(rawdata) #Get an HEX number > bsstr = bin (int(hexstr,16))[2:] I suspect the root of the problem here is that you don't understand what this is actually doing. You should run this code in the command-line interpreter, one line at a time, and print the results. The "read" instruction produces a string with 100k bytes. The b2a_hex then produces a string with 200k bytes. Then, int(hexstr,16) takes that 200,000 byte hex string and converts it to an integer, roughly equal to 10 to the 240,000 power, a number with some 240,000 decimal digits. You then convert that integer to a binary string. That string will contain 800,000 bytes. You then drop the first two characters and print the other 799,998 bytes, each of which will be either '0' or '1'. I am absolutely, positively convinced that's not what you wanted to do. What point is there in printing out the binary equavalent of a bitmap? Even if you did, it would be much quicker for you to do the conversion one byte at a time, completely skipping the conversion to hex and then the creation of a massive multi-precision number. Example: f = open('example.bmp','rb') rawdata = f.read() bsstr = [] for b in rawdata: bsstr.append( bin(ord(b)) ) bsstr = ''.join(bsstr) or even: f = open('example.bmp','rb') bsstr = ''.join( bin(ord(b))[2:] for b in f.read() ) -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From __peter__ at web.de Sun Apr 28 03:42:13 2013 From: __peter__ at web.de (Peter Otten) Date: Sun, 28 Apr 2013 09:42:13 +0200 Subject: File Read issue by using module binascii References: <9b5795ab-baec-4c0a-a3b4-1075cffc8744@googlegroups.com> <319pn8hgkc0pbj0099heq2nq3h5sv68g7s@4ax.com> Message-ID: Tim Roberts wrote: > Jimmie He wrote: > >>When I run the readbmp on an example.bmp(about 100k),the Shell is become >>to "No respose",when I change f.read() to f.read(1000),it is ok,could >>someone tell me the excat reason for this? Thank you in advance! >> >>Python Code as below!! >> >>import binascii >> >>def read_bmp(): >> f = open('example.bmp','rb') >> rawdata = f.read() #f.read(1000) is ok >> hexstr = binascii.b2a_hex(rawdata) #Get an HEX number >> bsstr = bin (int(hexstr,16))[2:] > > I suspect the root of the problem here is that you don't understand what > this is actually doing. You should run this code in the command-line > interpreter, one line at a time, and print the results. > > The "read" instruction produces a string with 100k bytes. The b2a_hex > then > produces a string with 200k bytes. Then, int(hexstr,16) takes that > 200,000 byte hex string and converts it to an integer, roughly equal to 10 > to the > 240,000 power, a number with some 240,000 decimal digits. You then > convert > that integer to a binary string. That string will contain 800,000 bytes. > You then drop the first two characters and print the other 799,998 bytes, > each of which will be either '0' or '1'. > > I am absolutely, positively convinced that's not what you wanted to do. > What point is there in printing out the binary equavalent of a bitmap? > > Even if you did, it would be much quicker for you to do the conversion one > byte at a time, completely skipping the conversion to hex and then the > creation of a massive multi-precision number. Example: Hm, if you fix the long integer arithmetic "problem" you should also attack the unbounded memory consumption problem in general ;) > f = open('example.bmp','rb') > rawdata = f.read() > bsstr = [] > for b in rawdata: > bsstr.append( bin(ord(b)) ) > bsstr = ''.join(bsstr) > > or even: > f = open('example.bmp','rb') > bsstr = ''.join( bin(ord(b))[2:] for b in f.read() ) Yes, the original is horrible newbie code ;) but that's what you tend to write while learning to program -- and python can handle it alright. On the other hand, Idle becomes unresponsive when I do >>> print("a"*10**6) in its shell. I'm still investigating, but the problem seems to be that it's a single line. >>> print(("a"*100+"\n") * 10**4) takes under 7 secs. Not as good as konsole (KDE's terminal emulation) which finishes in 0.5 secs, but acceptable. From jt at toerring.de Sun Apr 28 08:04:04 2013 From: jt at toerring.de (Jens Thoms Toerring) Date: 28 Apr 2013 12:04:04 GMT Subject: File Read issue by using module binascii References: <9b5795ab-baec-4c0a-a3b4-1075cffc8744@googlegroups.com> <319pn8hgkc0pbj0099heq2nq3h5sv68g7s@4ax.com> Message-ID: Tim Roberts wrote: > Jimmie He wrote: > >When I run the readbmp on an example.bmp(about 100k),the Shell is become to "No respose",when I change f.read() to f.read(1000),it is ok,could someone tell me the excat reason for this? > >Thank you in advance! > > > >Python Code as below!! > > > >import binascii > > > >def read_bmp(): > > f = open('example.bmp','rb') > > rawdata = f.read() #f.read(1000) is ok > > hexstr = binascii.b2a_hex(rawdata) #Get an HEX number > > bsstr = bin (int(hexstr,16))[2:] > I suspect the root of the problem here is that you don't understand what > this is actually doing. You should run this code in the command-line > interpreter, one line at a time, and print the results. > The "read" instruction produces a string with 100k bytes. The b2a_hex then > produces a string with 200k bytes. Then, int(hexstr,16) takes that 200,000 > byte hex string and converts it to an integer, roughly equal to 10 to the > 240,000 power, a number with some 240,000 decimal digits. You then convert > that integer to a binary string. That string will contain 800,000 bytes. > You then drop the first two characters and print the other 799,998 bytes, > each of which will be either '0' or '1'. > I am absolutely, positively convinced that's not what you wanted to do. > What point is there in printing out the binary equavalent of a bitmap? > Even if you did, it would be much quicker for you to do the conversion one > byte at a time, completely skipping the conversion to hex and then the > creation of a massive multi-precision number. Example: > f = open('example.bmp','rb') > rawdata = f.read() > bsstr = [] > for b in rawdata: > bsstr.append( bin(ord(b)) ) > bsstr = ''.join(bsstr) > or even: > f = open('example.bmp','rb') > bsstr = ''.join( bin(ord(b))[2:] for b in f.read() ) Exactly my idea at first. But then I started to time it (using the timeit module) by comparing the following functions: # Original version def c1( rawdata ) : h = binascii.b2a_hex( rawdata ) z = bin( int( h, 16 ) )[ 2 : ] return '0' * ( 8 * len( r ) - len( z ) ) + z # Convert each byte directly def c2( rawdata ) : return ''.join( bin( ord( x ) )[ 2 : ].rjust( 8, '0' ) for x in r ) # Convert each byte using a list for table look-up def c3( rawdata ) : h = [ bin( i )[ 2 : ].rjust( 8, '0' ) for i in range( 256 ) ] return ''.join( h[ ord( x ) ] for x in rawdata ) # Convert each byte using a dictionary for table look-up (avoids # lots of ord() calls) def c4( rawdata ) : h = { chr( i ) : bin( i )[ 2 : ].rjust( 8, '0' ) for i in range( 256 ) } return ''.join( h[ x ] for x in rawdata ) As you can see I even in c3() and c4() tried to speed things up further by using a table look-up instead if calling bin() etc. on each byte. But the results was that c2() is nearly 15 times slower than c1(), c3() about 3 times and c4() still more than 2 times slower! So the method the OP uses seems to be quite a bit more efficient than one might be tempted to assume. I would guess that the reason is that c1() does just a small number of calls of functions that probably aren't implemented in Python but in C and thus can be a lot faster then anything you could achieve with Python, while the other functions use a for loop in Python, which seems to account for a good part of the CPU time used. To test for that I split the 'rawdata' string into a list of character (i.e. single letter strings) and re- assembled it using join() and a for loop: r = list( rawdata( ) z = ''.join( x for x in r ) The second line alone took about 1.7 times longer than the whole, seemingly convoluted c1() function! What I take away from this is that a lot of the assumption one is prone to make when coming from e.g. a C/C++ background can be quite misleading when extrapolating to Python (or other in- terpreted languages)... Best regards, Jens -- \ Jens Thoms Toerring ___ jt at toerring.de \__________________________ http://toerring.de From jimmie.he at gmail.com Sun Apr 28 09:32:49 2013 From: jimmie.he at gmail.com (Jimmie He) Date: Sun, 28 Apr 2013 06:32:49 -0700 (PDT) Subject: File Read issue by using module binascii In-Reply-To: References: <9b5795ab-baec-4c0a-a3b4-1075cffc8744@googlegroups.com> <319pn8hgkc0pbj0099heq2nq3h5sv68g7s@4ax.com> Message-ID: <6e953b53-269e-4bef-8d20-2ca9f11d7003@googlegroups.com> On Sunday, April 28, 2013 8:04:04 PM UTC+8, Jens Thoms Toerring wrote: > Tim Roberts wrote: > > > Jimmie He wrote: > > > > > >When I run the readbmp on an example.bmp(about 100k),the Shell is become to "No respose",when I change f.read() to f.read(1000),it is ok,could someone tell me the excat reason for this? > > > >Thank you in advance! > > > > > > > >Python Code as below!! > > > > > > > >import binascii > > > > > > > >def read_bmp(): > > > > f = open('example.bmp','rb') > > > > rawdata = f.read() #f.read(1000) is ok > > > > hexstr = binascii.b2a_hex(rawdata) #Get an HEX number > > > > bsstr = bin (int(hexstr,16))[2:] > > > > > I suspect the root of the problem here is that you don't understand what > > > this is actually doing. You should run this code in the command-line > > > interpreter, one line at a time, and print the results. > > > > > The "read" instruction produces a string with 100k bytes. The b2a_hex then > > > produces a string with 200k bytes. Then, int(hexstr,16) takes that 200,000 > > > byte hex string and converts it to an integer, roughly equal to 10 to the > > > 240,000 power, a number with some 240,000 decimal digits. You then convert > > > that integer to a binary string. That string will contain 800,000 bytes. > > > You then drop the first two characters and print the other 799,998 bytes, > > > each of which will be either '0' or '1'. > > > > > I am absolutely, positively convinced that's not what you wanted to do. > > > What point is there in printing out the binary equavalent of a bitmap? > > > > > Even if you did, it would be much quicker for you to do the conversion one > > > byte at a time, completely skipping the conversion to hex and then the > > > creation of a massive multi-precision number. Example: > > > > > f = open('example.bmp','rb') > > > rawdata = f.read() > > > bsstr = [] > > > for b in rawdata: > > > bsstr.append( bin(ord(b)) ) > > > bsstr = ''.join(bsstr) > > > > > or even: > > > f = open('example.bmp','rb') > > > bsstr = ''.join( bin(ord(b))[2:] for b in f.read() ) > > > > Exactly my idea at first. But then I started to time it (using > > the timeit module) by comparing the following functions: > > > > # Original version > > > > def c1( rawdata ) : > > h = binascii.b2a_hex( rawdata ) > > z = bin( int( h, 16 ) )[ 2 : ] > > return '0' * ( 8 * len( r ) - len( z ) ) + z > > > > # Convert each byte directly > > > > def c2( rawdata ) : > > return ''.join( bin( ord( x ) )[ 2 : ].rjust( 8, '0' ) for x in r ) > > > > # Convert each byte using a list for table look-up > > > > def c3( rawdata ) : > > h = [ bin( i )[ 2 : ].rjust( 8, '0' ) for i in range( 256 ) ] > > return ''.join( h[ ord( x ) ] for x in rawdata ) > > > > # Convert each byte using a dictionary for table look-up (avoids > > # lots of ord() calls) > > > > def c4( rawdata ) : > > h = { chr( i ) : bin( i )[ 2 : ].rjust( 8, '0' ) for i in range( 256 ) } > > return ''.join( h[ x ] for x in rawdata ) > > > > As you can see I even in c3() and c4() tried to speed things up > > further by using a table look-up instead if calling bin() etc. > > on each byte. But the results was that c2() is nearly 15 times > > slower than c1(), c3() about 3 times and c4() still more than 2 > > times slower! So the method the OP uses seems to be quite a bit > > more efficient than one might be tempted to assume. > > > > I would guess that the reason is that c1() does just a small > > number of calls of functions that probably aren't implemented > > in Python but in C and thus can be a lot faster then anything > > you could achieve with Python, while the other functions use a > > for loop in Python, which seems to account for a good part of > > the CPU time used. To test for that I split the 'rawdata' string > > into a list of character (i.e. single letter strings) and re- > > assembled it using join() and a for loop: > > > > r = list( rawdata( ) > > z = ''.join( x for x in r ) > > > > The second line alone took about 1.7 times longer than the > > whole, seemingly convoluted c1() function! > > > > What I take away from this is that a lot of the assumption one > > is prone to make when coming from e.g. a C/C++ background can > > be quite misleading when extrapolating to Python (or other in- > > terpreted languages)... > > Best regards, Jens > > -- > > \ Jens Thoms Toerring ___ jt at toerring.de > > \__________________________ http://toerring.de Hi,Jens &Peter &Tim, Thank you very much for your wonderful analysis for my newbie question. I admit that I throw this question to much early because I just want some guru to inspire me;-) If it really confuse you,excuse my noise:-) What I intend to do is to make an BMP Font Maker(Covert the BMP to an data array,what I did wrong is print it directly to screen and had not understand it at all firstly. C1()~C4() which Jens provided deeply indicate that we should think about the effiency because it is an interpreted language. Anyway thanks for all your kindly help :-) From hasilsharma7 at gmail.com Sat Apr 27 04:40:29 2013 From: hasilsharma7 at gmail.com (Hasil Sharma) Date: Sat, 27 Apr 2013 01:40:29 -0700 (PDT) Subject: Malware Analyzer Message-ID: Python based malware analyzer, better if it supports scanning of pcap files. From radek.machulka at gmail.com Sat Apr 27 07:46:02 2013 From: radek.machulka at gmail.com (Radek Machulka) Date: Sat, 27 Apr 2013 13:46:02 +0200 Subject: Shear image (numpy.ndarray) Message-ID: Hi, I am looking for some function that would shear my 2D numpy.ndarray array. Since the numpy (probably) does not provide such a functionality (numpy.roll does not do what I need), I hope the PIL might do the trick. Google give me page that says: 'This function (im.transform) can be used to scale, translate, rotate, and shear the original image.', however I was not able to get it work. So could anybody give me a hand how to use it (or how to shear the image in different way)? The input array is 2D (NxM) type numpy.float32. Thanks Radek -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Sat Apr 27 11:40:16 2013 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 27 Apr 2013 16:40:16 +0100 Subject: Shear image (numpy.ndarray) In-Reply-To: References: Message-ID: On 2013-04-27 12:46, Radek Machulka wrote: > Hi, > > I am looking for some function that would shear my 2D numpy.ndarray array. Since > the numpy (probably) does not provide such a functionality (numpy.roll does not > do what I need), I hope the PIL might do the trick. > > Google give me page that says: 'This function (im.transform) can be used to > scale, translate, rotate, and shear the original image.', however I was not able > to get it work. > > So could anybody give me a hand how to use it (or how to shear the image in > different way)? You should be able to use scipy.ndimage.affine_transform() to do the job: http://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.interpolation.affine_transform.html#scipy.ndimage.interpolation.affine_transform If you cannot get it to work, please show us what you tried, the results you got, and what you expected to get. You can find the scipy mailing lists here: http://www.scipy.org/Mailing_Lists -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From radek.machulka at gmail.com Mon Apr 29 07:58:49 2013 From: radek.machulka at gmail.com (Radek Machulka) Date: Mon, 29 Apr 2013 13:58:49 +0200 Subject: Shear image (numpy.ndarray) In-Reply-To: References: Message-ID: Yes, I already find that scipy.ndimage.interpolation.affine_transform will solve this (but thank you Robert anyway!). Just for others (if somebody will find this thread): The 'matrix' parameter is transformation matrix for shear transformation. For more detailes see: http://en.wikipedia.org/wiki/Shear_matrix Radek From cormogram at gmail.com Sat Apr 27 20:22:31 2013 From: cormogram at gmail.com (cormogram at gmail.com) Date: Sat, 27 Apr 2013 17:22:31 -0700 (PDT) Subject: "python.exe has stopped working" when os.execl() runs on Windows 7 Message-ID: <2e11de8b-f7e1-407f-a2fd-a08d5ce55d0b@googlegroups.com> Was trying os.execl() and got a "python.exe has stopped working" on my Windows 7 Ultimate SP1 x64 desktop. I'm using Python 2.7.4 and that happens when the second arg is ''. For example: os.execl('filename.exe','') Wtf? :( http://postimg.org/image/vdliyuenh/ From davea at davea.name Sat Apr 27 20:55:34 2013 From: davea at davea.name (Dave Angel) Date: Sat, 27 Apr 2013 20:55:34 -0400 Subject: "python.exe has stopped working" when os.execl() runs on Windows 7 In-Reply-To: <2e11de8b-f7e1-407f-a2fd-a08d5ce55d0b@googlegroups.com> References: <2e11de8b-f7e1-407f-a2fd-a08d5ce55d0b@googlegroups.com> Message-ID: <517C7386.9010103@davea.name> On 04/27/2013 08:22 PM, cormogram at gmail.com wrote: > Was trying os.execl() and got a "python.exe has stopped working" on my Windows 7 Ultimate SP1 x64 desktop. > > I'm using Python 2.7.4 and that happens when the second arg is ''. For example: > > os.execl('filename.exe','') > > > Wtf? :( > > http://postimg.org/image/vdliyuenh/ > Do you really have a program called filename.exe ? Are you by any chance running this inside some shell or debugger, like IDLE or KOMODO? Or is it a GUI program ? More specifically, does it still give an error like that if you have a two-line Python program: import os os.execl('filename.exe', '') execl is supposed to replace the current (python) program, with the filename.exe one. But if the current program has any OS resources in use (like file objects), they don't get flushed/released. The execl was intended for use on Unix, and Windows can't really do what it's documented to do. If you don't get any useful answers here, I'd suggest going to multiprocess module. -- DaveA From cormogram at gmail.com Sat Apr 27 21:05:40 2013 From: cormogram at gmail.com (cormogram at gmail.com) Date: Sat, 27 Apr 2013 18:05:40 -0700 (PDT) Subject: "python.exe has stopped working" when os.execl() runs on Windows 7 In-Reply-To: References: <2e11de8b-f7e1-407f-a2fd-a08d5ce55d0b@googlegroups.com> Message-ID: Yes, just those two lines cause the error. 'filename.exe' exists and runs ok in the command prompt. Any other executable cause the problem, also '', for example: os.execl('','') If doesn't work on Windows it should give an error message, right? On Saturday, April 27, 2013 9:55:34 PM UTC-3, Dave Angel wrote: > On 04/27/2013 08:22 PM, cormogram at gmail.com wrote: > > > Was trying os.execl() and got a "python.exe has stopped working" on my Windows 7 Ultimate SP1 x64 desktop. > > > > > > I'm using Python 2.7.4 and that happens when the second arg is ''. For example: > > > > > > os.execl('filename.exe','') > > > > > > > > > Wtf? :( > > > > > > http://postimg.org/image/vdliyuenh/ > > > > > > > Do you really have a program called filename.exe ? > > > > Are you by any chance running this inside some shell or debugger, like > > IDLE or KOMODO? Or is it a GUI program ? More specifically, does it > > still give an error like that if you have a two-line Python program: > > import os > > os.execl('filename.exe', '') > > > > execl is supposed to replace the current (python) program, with the > > filename.exe one. But if the current program has any OS resources in > > use (like file objects), they don't get flushed/released. > > > > The execl was intended for use on Unix, and Windows can't really do what > > it's documented to do. > > > > If you don't get any useful answers here, I'd suggest going to > > multiprocess module. > > > > -- > > DaveA From davea at davea.name Sat Apr 27 22:02:01 2013 From: davea at davea.name (Dave Angel) Date: Sat, 27 Apr 2013 22:02:01 -0400 Subject: "python.exe has stopped working" when os.execl() runs on Windows 7 In-Reply-To: References: <2e11de8b-f7e1-407f-a2fd-a08d5ce55d0b@googlegroups.com> Message-ID: <517C8319.7060900@davea.name> On 04/27/2013 09:05 PM, cormogram at gmail.com wrote: > Yes, just those two lines cause the error. 'filename.exe' exists and runs ok in the command prompt. Any other executable cause the problem, also '', for example: > > os.execl('','') > > If doesn't work on Windows it should give an error message, right? > I'm not running Windows any more, so it's hard to be conclusive. When I saw the description, I just assumed it'd be problematic under Windows. That's why I had never played with it. By the time I escaped to Linux, I was used to subprocess, so I still never played with execl. But why you should get that error on a console program run from the cmd prompt, I have no idea. -- DaveA From cormogram at gmail.com Sat Apr 27 23:42:25 2013 From: cormogram at gmail.com (cormogram at gmail.com) Date: Sat, 27 Apr 2013 20:42:25 -0700 (PDT) Subject: "python.exe has stopped working" when os.execl() runs on Windows 7 In-Reply-To: References: <2e11de8b-f7e1-407f-a2fd-a08d5ce55d0b@googlegroups.com> Message-ID: <9ac24332-ead8-4889-815a-a12052f43742@googlegroups.com> Probably a bug I suppose. :( I've used subprocess before and it works fine. I was just learning about the os module. os.execl() works if you provide no nulls, for example: os.execl('c:\\bin\\filename.exe','filename.exe','arg1') Is there the place to open a ticket for Python developers? Who keeps the os module? On Saturday, April 27, 2013 11:02:01 PM UTC-3, Dave Angel wrote: > On 04/27/2013 09:05 PM, cormogram at gmail.com wrote: > > > Yes, just those two lines cause the error. 'filename.exe' exists and runs ok in the command prompt. Any other executable cause the problem, also '', for example: > > > > > > os.execl('','') > > > > > > If doesn't work on Windows it should give an error message, right? > > > > > > > I'm not running Windows any more, so it's hard to be conclusive. When I > > saw the description, I just assumed it'd be problematic under Windows. > > That's why I had never played with it. By the time I escaped to Linux, > > I was used to subprocess, so I still never played with execl. But why > > you should get that error on a console program run from the cmd prompt, > > I have no idea. > > > > > > -- > > DaveA From tjreedy at udel.edu Sun Apr 28 03:51:03 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Sun, 28 Apr 2013 03:51:03 -0400 Subject: "python.exe has stopped working" when os.execl() runs on Windows 7 In-Reply-To: <9ac24332-ead8-4889-815a-a12052f43742@googlegroups.com> References: <2e11de8b-f7e1-407f-a2fd-a08d5ce55d0b@googlegroups.com> <9ac24332-ead8-4889-815a-a12052f43742@googlegroups.com> Message-ID: On 4/27/2013 11:42 PM, cormogram at gmail.com wrote: > Is there the place to open a ticket for Python developers? bugs.python.org From fabiosantosart at gmail.com Sun Apr 28 04:02:48 2013 From: fabiosantosart at gmail.com (=?ISO-8859-1?Q?F=E1bio_Santos?=) Date: Sun, 28 Apr 2013 09:02:48 +0100 Subject: "python.exe has stopped working" when os.execl() runs on Windows 7 In-Reply-To: References: <2e11de8b-f7e1-407f-a2fd-a08d5ce55d0b@googlegroups.com> <9ac24332-ead8-4889-815a-a12052f43742@googlegroups.com> Message-ID: Cannot reproduce on windows 7 ultimate Steps taken: Start cmd cd to Desktop where I have a GUI application run python on the console import os os.execl('exe.exe', 'exe.exe') On Sun, Apr 28, 2013 at 8:51 AM, Terry Jan Reedy wrote: > On 4/27/2013 11:42 PM, cormogram at gmail.com wrote: > >> Is there the place to open a ticket for Python developers? > > > bugs.python.org > > > -- > http://mail.python.org/mailman/listinfo/python-list -- F?bio Santos From fabiosantosart at gmail.com Sun Apr 28 04:05:02 2013 From: fabiosantosart at gmail.com (=?ISO-8859-1?Q?F=E1bio_Santos?=) Date: Sun, 28 Apr 2013 09:05:02 +0100 Subject: "python.exe has stopped working" when os.execl() runs on Windows 7 In-Reply-To: References: <2e11de8b-f7e1-407f-a2fd-a08d5ce55d0b@googlegroups.com> <9ac24332-ead8-4889-815a-a12052f43742@googlegroups.com> Message-ID: Is this executable freely available, or something you can share? If you can send me that executable I can try to reproduce the bug with it. From cormogram at gmail.com Sun Apr 28 21:38:13 2013 From: cormogram at gmail.com (cormogram at gmail.com) Date: Sun, 28 Apr 2013 18:38:13 -0700 (PDT) Subject: "python.exe has stopped working" when os.execl() runs on Windows 7 In-Reply-To: References: <2e11de8b-f7e1-407f-a2fd-a08d5ce55d0b@googlegroups.com> <9ac24332-ead8-4889-815a-a12052f43742@googlegroups.com> Message-ID: <0d9d14dc-877b-4b68-aefe-834b530dee2c@googlegroups.com> It isn't, but it doesn't matter because all executables I've tried cause the error, even "ping.exe". Just try: os.execl('ping.exe', '') And it will cause the "python.exe has stopped working" error message. On Sunday, April 28, 2013 5:05:02 AM UTC-3, F?bio Santos wrote: > Is this executable freely available, or something you can share? If > > you can send me that executable I can try to reproduce the bug with > > it. From cormogram at gmail.com Sun Apr 28 21:34:13 2013 From: cormogram at gmail.com (cormogram at gmail.com) Date: Sun, 28 Apr 2013 18:34:13 -0700 (PDT) Subject: "python.exe has stopped working" when os.execl() runs on Windows 7 In-Reply-To: References: <2e11de8b-f7e1-407f-a2fd-a08d5ce55d0b@googlegroups.com> <9ac24332-ead8-4889-815a-a12052f43742@googlegroups.com> Message-ID: <7dd42af2-52b9-4fcc-8fc7-c5ad7a53dd91@googlegroups.com> It works fine as long as you don't provide a null string ('') to os.execl(), such as: os.execl('filename.exe','') On Sunday, April 28, 2013 5:02:48 AM UTC-3, F?bio Santos wrote: > Cannot reproduce on windows 7 ultimate > > > > Steps taken: > > > > Start cmd > > cd to Desktop where I have a GUI application > > run python on the console > > import os > > os.execl('exe.exe', 'exe.exe') > > > > > > > > > > On Sun, Apr 28, 2013 at 8:51 AM, Terry Jan Reedy wrote: > > > On 4/27/2013 11:42 PM, cormogram at gmail.com wrote: > > > > > >> Is there the place to open a ticket for Python developers? > > > > > > > > > bugs.python.org > > > > > > > > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > -- > > F?bio Santos From cormogram at gmail.com Sun Apr 28 21:39:04 2013 From: cormogram at gmail.com (cormogram at gmail.com) Date: Sun, 28 Apr 2013 18:39:04 -0700 (PDT) Subject: "python.exe has stopped working" when os.execl() runs on Windows 7 In-Reply-To: References: <2e11de8b-f7e1-407f-a2fd-a08d5ce55d0b@googlegroups.com> <9ac24332-ead8-4889-815a-a12052f43742@googlegroups.com> Message-ID: <3d723b60-8f76-46d0-8a66-f0dd8b95d40e@googlegroups.com> Thank you! On Sunday, April 28, 2013 4:51:03 AM UTC-3, Terry Jan Reedy wrote: > On 4/27/2013 11:42 PM, cormogram at gmail.com wrote: > > > > > Is there the place to open a ticket for Python developers? > > > > bugs.python.org From nobody at nowhere.com Sat Apr 27 23:53:25 2013 From: nobody at nowhere.com (Nobody) Date: Sun, 28 Apr 2013 04:53:25 +0100 Subject: "python.exe has stopped working" when os.execl() runs on Windows 7 References: <2e11de8b-f7e1-407f-a2fd-a08d5ce55d0b@googlegroups.com> Message-ID: On Sat, 27 Apr 2013 17:22:31 -0700, cormogram wrote: > Was trying os.execl() and got a "python.exe has stopped working" on my > Windows 7 Ultimate SP1 x64 desktop. > > I'm using Python 2.7.4 and that happens when the second arg is ''. For > example: > > os.execl('filename.exe','') Note that, by convention, the second argument should normally also be the filename (the second argument will be available to the program as argv[0]), e.g.: os.execl('filename.exe','filename.exe') If successful, the exec* functions don't return. On Unix, the new program replaces the existing program in the current process. IIRC, the Windows version executes the program in a child process then exit()s upon completion. The exec* functions probably shouldn't be used within a program which uses any of the more complex OS features (e.g. GUI), as they will block event processing, background threads, etc. From cormogram at gmail.com Sun Apr 28 01:06:38 2013 From: cormogram at gmail.com (cormogram at gmail.com) Date: Sat, 27 Apr 2013 22:06:38 -0700 (PDT) Subject: "python.exe has stopped working" when os.execl() runs on Windows 7 In-Reply-To: References: <2e11de8b-f7e1-407f-a2fd-a08d5ce55d0b@googlegroups.com> Message-ID: I did that but unfortunately the 'bug' persists. :( I've chosen the os module because I though it would be more portable. :/ On Sunday, April 28, 2013 12:53:25 AM UTC-3, Nobody wrote: > On Sat, 27 Apr 2013 17:22:31 -0700, cormogram wrote: > > > > > Was trying os.execl() and got a "python.exe has stopped working" on my > > > Windows 7 Ultimate SP1 x64 desktop. > > > > > > I'm using Python 2.7.4 and that happens when the second arg is ''. For > > > example: > > > > > > os.execl('filename.exe','') > > > > Note that, by convention, the second argument should normally also be the > > filename (the second argument will be available to the program as > > argv[0]), e.g.: > > > > os.execl('filename.exe','filename.exe') > > > > If successful, the exec* functions don't return. On Unix, the new program > > replaces the existing program in the current process. IIRC, the Windows > > version executes the program in a child process then exit()s upon > > completion. > > > > The exec* functions probably shouldn't be used within a program which uses > > any of the more complex OS features (e.g. GUI), as they will block event > > processing, background threads, etc. From jeanpierreda at gmail.com Sun Apr 28 13:55:47 2013 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 28 Apr 2013 13:55:47 -0400 Subject: Adding new source types to distutils? Message-ID: Last night I wrote a toy prototype module that lets one compile Rust crates into extension modules for Python. The problem is, I don't know the "right" way to do this. Ideally I'd just want to tell build_ext that there's a new source type I want to handle (.rc and .rs), and also tell distutils that it should handle it by running the code that I specify (which can compile the .rs/.rc files, remove them from the sources list, and add the resulting object files and such to the linker arguments) The problem is that, as I understand it, the way to do this is subclassing and then replacing the build_ext command. At least, that's what Cython does. The problem is, that's what Cython does, so if I do that, it means you can't use Cython and Rust together -- that's bad, because Cython would be useful for writing bindings to Rust crates, too. So I don't want to write my own subclass. In place of that, I don't know what the right approach is. One possibility is that I subclass Cython's build_ext if it exists, otherwise distutils'. This seems like it's a terrible thing to do, since it locks out any Cython alternative that I may not be aware of, and any other kind of extension to build_ext. I don't know what else I can do. (What I ended up doing, just so that I could actually write the code, was write a new Extension type that compiles the rust code when the extra_link_args attribute is accessed. This is, of course, absolutely terrible, and only barely does the job. It's not as bad as what I had to do to get the linker arguments from rustc, though...) -- Devin From stefan_ml at behnel.de Sun Apr 28 14:24:58 2013 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 28 Apr 2013 20:24:58 +0200 Subject: Adding new source types to distutils? In-Reply-To: References: Message-ID: Devin Jeanpierre, 28.04.2013 19:55: > Last night I wrote a toy prototype module that lets one compile Rust > crates into extension modules for Python. The problem is, I don't know > the "right" way to do this. Ideally I'd just want to tell build_ext > that there's a new source type I want to handle (.rc and .rs), and > also tell distutils that it should handle it by running the code that > I specify (which can compile the .rs/.rc files, remove them from the > sources list, and add the resulting object files and such to the > linker arguments) > > The problem is that, as I understand it, the way to do this is > subclassing and then replacing the build_ext command. At least, that's > what Cython does. The problem is, that's what Cython does, so if I do > that, it means you can't use Cython and Rust together -- that's bad, > because Cython would be useful for writing bindings to Rust crates, > too. So I don't want to write my own subclass. In place of that, I > don't know what the right approach is. That approach is discouraged for Cython. The compiler comes with a cythonize() function these days, which users can simply call from their setup.py scripts. It spits out a list of Extensions that you can pass into setup(). So, for example, you can say extensions = cythonize('mypackage/*.pyx') and it would do the right thing. You can also pass configuration options into cythonize() to influence the way Cython translates your code. Alternatively, you can pass in a list of Extensions and cythonize() will process that and replace .pyx files by the compiled .c files. That also makes it easier to build without having Cython installed, by simply replacing the .pyx files by .c yourself and passing the Extensions directly into setup(). And it allows for more complex Extension configurations that Cython doesn't have to care about. You might want to do something similar in your case. It gives users much more flexibility when using source code preprocessors and also avoids conflicts between packages like the one you describe above, or problems with future versions of distutils due to fragile build setups. Stefan From jeanpierreda at gmail.com Sun Apr 28 14:42:47 2013 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 28 Apr 2013 14:42:47 -0400 Subject: Adding new source types to distutils? In-Reply-To: References: Message-ID: On Sun, Apr 28, 2013 at 2:24 PM, Stefan Behnel wrote: > That approach is discouraged for Cython. The compiler comes with a > cythonize() function these days, which users can simply call from their > setup.py scripts. It spits out a list of Extensions that you can pass into > setup(). So, for example, you can say > > extensions = cythonize('mypackage/*.pyx') > > and it would do the right thing. You can also pass configuration options > into cythonize() to influence the way Cython translates your code. > Alternatively, you can pass in a list of Extensions and cythonize() will > process that and replace .pyx files by the compiled .c files. That also > makes it easier to build without having Cython installed, by simply > replacing the .pyx files by .c yourself and passing the Extensions directly > into setup(). And it allows for more complex Extension configurations that > Cython doesn't have to care about. > > You might want to do something similar in your case. It gives users much > more flexibility when using source code preprocessors and also avoids > conflicts between packages like the one you describe above, or problems > with future versions of distutils due to fragile build setups. I'm looking at the cythonize source code now. Isn't it weird to compile Cython source files if setup.py is executed for any reason, even if not to build the program? That doesn't seem like the Right Thing either. In fact, it was the first option I discarded. :/ -- Devin From alternative00 at rocketmail.com Sun Apr 28 14:33:21 2013 From: alternative00 at rocketmail.com (alternative00 at rocketmail.com) Date: Sun, 28 Apr 2013 11:33:21 -0700 (PDT) Subject: Unwanted window spawns when using Tkinter with multiprocessing. Message-ID: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> Hi everyone, I'm trying to use multiprocessing to avoid Python's GIL but with Tkinter, instead of running my main function, it spawns new windows. In fact, my fuction is used everytime I press a specified key, but with multiprocessing I only get a new window when I hit a key. Does anyone have a solution ? From davea at davea.name Sun Apr 28 17:18:52 2013 From: davea at davea.name (Dave Angel) Date: Sun, 28 Apr 2013 17:18:52 -0400 Subject: Unwanted window spawns when using Tkinter with multiprocessing. In-Reply-To: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> References: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> Message-ID: <517D923C.5000207@davea.name> On 04/28/2013 02:33 PM, alternative00 at rocketmail.com wrote: > Hi everyone, > > I'm trying to use multiprocessing to avoid Python's GIL but with Tkinter, instead of running my main function, it spawns new windows. In fact, my fuction is used everytime I press a specified key, but with multiprocessing I only get a new window when I hit a key. Does anyone have a solution ? > If you can't post in clear English, then give us some other clues to compensate. Could you post some code, define some function names, and use fewer pronouns and indirection? for example: "it spawns new windows" -- What spawns new windows, exactly? -- DaveA From alternative00 at rocketmail.com Sun Apr 28 18:23:21 2013 From: alternative00 at rocketmail.com (alternative00 at rocketmail.com) Date: Sun, 28 Apr 2013 15:23:21 -0700 (PDT) Subject: Unwanted window spawns when using Tkinter with multiprocessing. In-Reply-To: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> References: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> Message-ID: Sorry for my bad english. Here's my code : def key(event): instance = 'Instance' touche = event.char instance = multiprocessing.Process(target=player, args=(hitkey,)) instance.start() def player(hitkey): winsound.PlaySound(hitkey + '.wav', winsound.SND_FILENAME|winsound.SND_NOWAIT|winsound.SND_ASYNC) 'key' is the tkinter function wich gets the pressed key. 'player' is the function playing a specific wav file depending on wich key is pressed, that's why its argument is 'hitkey'. It uses the winsound module. What spawns new windows is theorically the multiprocessing line of code, even if it's inside the 'key' function. From davea at davea.name Sun Apr 28 19:10:17 2013 From: davea at davea.name (Dave Angel) Date: Sun, 28 Apr 2013 19:10:17 -0400 Subject: Unwanted window spawns when using Tkinter with multiprocessing. In-Reply-To: References: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> Message-ID: <517DAC59.8030806@davea.name> On 04/28/2013 06:23 PM, alternative00 at rocketmail.com wrote: > Sorry for my bad english. > > Here's my code : > > def key(event): > > instance = 'Instance' > touche = event.char > instance = multiprocessing.Process(target=player, args=(hitkey,)) > instance.start() > > > > def player(hitkey): > > > winsound.PlaySound(hitkey + '.wav', winsound.SND_FILENAME|winsound.SND_NOWAIT|winsound.SND_ASYNC) > > 'key' is the tkinter function wich gets the pressed key. > 'player' is the function playing a specific wav file depending on wich key is pressed, that's why its argument is 'hitkey'. It uses the winsound module. > > What spawns new windows is theorically the multiprocessing line of code, even if it's inside the 'key' function. > Do you have an if __name__ == "__main__": clause in your main script? Are you bypassing the gui event loop on the secondary process? Otherwise, it's your code that's launching the extra window. And what OS are you running on? -- DaveA From alternative00 at rocketmail.com Sun Apr 28 19:40:02 2013 From: alternative00 at rocketmail.com (alternative00 at rocketmail.com) Date: Sun, 28 Apr 2013 16:40:02 -0700 (PDT) Subject: Unwanted window spawns when using Tkinter with multiprocessing. In-Reply-To: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> References: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> Message-ID: <979db8bf-4d5c-4c7f-8a05-cfade946026f@googlegroups.com> Well I saw this clause on most of the multiprocessing examples I saw but the reason it was here wasn't explained so I just ignored it (yeah stupid I know). I don't think I bypassed anything, at least not on purpose. I'm running on Windows 7 64 bits. From davea at davea.name Sun Apr 28 20:24:22 2013 From: davea at davea.name (Dave Angel) Date: Sun, 28 Apr 2013 20:24:22 -0400 Subject: Unwanted window spawns when using Tkinter with multiprocessing. In-Reply-To: <979db8bf-4d5c-4c7f-8a05-cfade946026f@googlegroups.com> References: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> <979db8bf-4d5c-4c7f-8a05-cfade946026f@googlegroups.com> Message-ID: <517DBDB6.5070503@davea.name> On 04/28/2013 07:40 PM, alternative00 at rocketmail.com wrote: > Well I saw this clause on most of the multiprocessing examples I saw but the reason it was here wasn't explained so I just ignored it (yeah stupid I know). I don't think I bypassed anything, Yes, you skipped the essential if clause. The child process is started with a different __name__. So if the __name__ is not "__main__", then you should NOT call any of the GUI startup code. Probably you should do little or nothing in the top-level code of the child process. But we can't give specific advice without seeing what that code now looks like. What code do you have at top level, and if it calls functions, what do they look like? The way you get that code to be different in the child is with that if statement that you omitted. > at least not on purpose. I'm running on Windows 7 64 bits. > -- DaveA From rosuav at gmail.com Sun Apr 28 23:03:59 2013 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 29 Apr 2013 13:03:59 +1000 Subject: Unwanted window spawns when using Tkinter with multiprocessing. In-Reply-To: <979db8bf-4d5c-4c7f-8a05-cfade946026f@googlegroups.com> References: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> <979db8bf-4d5c-4c7f-8a05-cfade946026f@googlegroups.com> Message-ID: On Mon, Apr 29, 2013 at 9:40 AM, wrote: > Well I saw this clause on most of the multiprocessing examples I saw but the reason it was here wasn't explained so I just ignored it (yeah stupid I know). I don't think I bypassed anything, at least not on purpose. I'm running on Windows 7 64 bits. Using multiprocessing on Windows has some requirements: http://docs.python.org/2/library/multiprocessing.html#windows If you take care of those restrictions, you should be able to do this. As Dave pointed out, one of the requirements is for your module to be importable. ChrisA From alternative00 at rocketmail.com Mon Apr 29 11:31:50 2013 From: alternative00 at rocketmail.com (alternative00 at rocketmail.com) Date: Mon, 29 Apr 2013 08:31:50 -0700 (PDT) Subject: Unwanted window spawns when using Tkinter with multiprocessing. In-Reply-To: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> References: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> Message-ID: My full code is : #Import from tkinter import * import wave import winsound import multiprocessing #Initialisation fenetre=Tk() frame = Frame(fenetre, width=200, height=100) instance = 'Instance' #Fonctions def key(event): instance = 'Instance' hitkey = event.char instance = multiprocessing.Process(target=player, args=(hitkey,)) instance.start() def player(hitkey): winsound.PlaySound(hitkey + '.wav', winsound.SND_FILENAME|winsound.SND_NOWAIT|winsound.SND_ASYNC) #TK frame.focus_set() frame.bind("", key) frame.pack() fenetre.mainloop() The problem is that I don't know where to put that clause. From python at mrabarnett.plus.com Mon Apr 29 13:03:10 2013 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 29 Apr 2013 18:03:10 +0100 Subject: Unwanted window spawns when using Tkinter with multiprocessing. In-Reply-To: References: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> Message-ID: <517EA7CE.8030202@mrabarnett.plus.com> On 29/04/2013 16:31, alternative00 at rocketmail.com wrote: > My full code is : > > > #Import > from tkinter import * > import wave > import winsound > import multiprocessing > > #Initialisation > fenetre=Tk() > frame = Frame(fenetre, width=200, height=100) > instance = 'Instance' > > > #Fonctions > > def key(event): > > instance = 'Instance' > hitkey = event.char > instance = multiprocessing.Process(target=player, args=(hitkey,)) > instance.start() > > > > def player(hitkey): > > > winsound.PlaySound(hitkey + '.wav', winsound.SND_FILENAME|winsound.SND_NOWAIT|winsound.SND_ASYNC) > > > > #TK > frame.focus_set() > frame.bind("", key) > frame.pack() > fenetre.mainloop() > > The problem is that I don't know where to put that clause. > I hope this helps: #Import from tkinter import * import wave import winsound import multiprocessing #Fonctions def key(event): instance = 'Instance' hitkey = event.char instance = multiprocessing.Process(target=player, args=(hitkey,)) instance.start() def player(hitkey): winsound.PlaySound(hitkey + '.wav', winsound.SND_FILENAME|winsound.SND_NOWAIT|winsound.SND_ASYNC) if __name__ == "__main__": # This part will be run if the file is run as the main script. # # The multiprocessing module will import this file to run the # "player" function, but __name__ won't be "__main__" when it does # so, therefore this bit of code won't be run. #Initialisation fenetre = Tk() frame = Frame(fenetre, width=200, height=100) instance = 'Instance' #TK frame.focus_set() frame.bind("", key) frame.pack() fenetre.mainloop() From alternative00 at rocketmail.com Mon Apr 29 13:32:16 2013 From: alternative00 at rocketmail.com (alternative00 at rocketmail.com) Date: Mon, 29 Apr 2013 10:32:16 -0700 (PDT) Subject: Unwanted window spawns when using Tkinter with multiprocessing. In-Reply-To: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> References: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> Message-ID: It definetly helped, windows don't pop up anymore, but now it doesn't make any sound anymore. Could it be because of a local (non-global) variable ? From rosuav at gmail.com Mon Apr 29 13:45:01 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 30 Apr 2013 03:45:01 +1000 Subject: Unwanted window spawns when using Tkinter with multiprocessing. In-Reply-To: References: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> Message-ID: On Tue, Apr 30, 2013 at 3:32 AM, wrote: > It definetly helped, windows don't pop up anymore, but now it doesn't make any sound anymore. Could it be because of a local (non-global) variable ? Did you read what I linked you to? There are rules to using multiprocessing; more of them on Windows. ChrisA From alternative00 at rocketmail.com Mon Apr 29 14:44:04 2013 From: alternative00 at rocketmail.com (alternative00 at rocketmail.com) Date: Mon, 29 Apr 2013 11:44:04 -0700 (PDT) Subject: Unwanted window spawns when using Tkinter with multiprocessing. In-Reply-To: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> References: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> Message-ID: <9733b6b7-671d-45e1-87da-1fdbdd0ed7d0@googlegroups.com> Yeah I did, but I globalized my variables, I've got only functions, and not methods, and my clause seems to work so I don't know why it doesn't work. From rosuav at gmail.com Mon Apr 29 18:00:24 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 30 Apr 2013 08:00:24 +1000 Subject: Unwanted window spawns when using Tkinter with multiprocessing. In-Reply-To: <9733b6b7-671d-45e1-87da-1fdbdd0ed7d0@googlegroups.com> References: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> <9733b6b7-671d-45e1-87da-1fdbdd0ed7d0@googlegroups.com> Message-ID: On Tue, Apr 30, 2013 at 4:44 AM, wrote: > Yeah I did, but I globalized my variables, I've got only functions, and not methods, and my clause seems to work so I don't know why it doesn't work. I don't know what you mean by your "clause", and I think we have a language barrier here. (Though your English is *way* better than my French.) But for a simple rule of thumb, the only things you should have flush left are "def" and "class" statements, and the one "if" that checks __name__. Everything else should be indented. Chris Angelico From alternative00 at rocketmail.com Mon Apr 29 21:17:06 2013 From: alternative00 at rocketmail.com (alternative00 at rocketmail.com) Date: Mon, 29 Apr 2013 18:17:06 -0700 (PDT) Subject: Unwanted window spawns when using Tkinter with multiprocessing. In-Reply-To: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> References: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> Message-ID: <9d19b7ba-29c2-40f8-a7f5-95e56d75e6a9@googlegroups.com> I thought 'clause' was reffering to the 'if __name__ == "__main__":' thing in English, but apparently not. Well except the import and the 'globalization' of my variables, every thing is idented. From davea at davea.name Mon Apr 29 22:05:17 2013 From: davea at davea.name (Dave Angel) Date: Mon, 29 Apr 2013 22:05:17 -0400 Subject: Unwanted window spawns when using Tkinter with multiprocessing. In-Reply-To: <9d19b7ba-29c2-40f8-a7f5-95e56d75e6a9@googlegroups.com> References: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> <9d19b7ba-29c2-40f8-a7f5-95e56d75e6a9@googlegroups.com> Message-ID: <517F26DD.2090304@davea.name> On 04/29/2013 09:17 PM, alternative00 at rocketmail.com wrote: > I thought 'clause' was reffering to the 'if __name__ == "__main__":' thing in English, but apparently not. > Well except the import and the 'globalization' of my variables, every thing is idented. > No clue whom you think you're replying to, but all your replies so far are appearing in the thread as replies to your OP. Please use a little context from the message you think you're responding to, so we have an idea what you're talking about. Did you ever see MRAB's message, where he told you exactly what the change requested was? if __name__ == "__main__": # This part will be run if the file is run as the main script. # # The multiprocessing module will import this file to run the # "player" function, but __name__ won't be "__main__" when it does # so, therefore this bit of code won't be run. #Initialisation fenetre = Tk() frame = Frame(fenetre, width=200, height=100) instance = 'Instance' #TK frame.focus_set() frame.bind("", key) frame.pack() fenetre.mainloop() All of those lines were at the left margin in your earlier posted code, and you give us no reason to expect you've made them conditional. -- DaveA From alternative00 at rocketmail.com Tue Apr 30 08:22:18 2013 From: alternative00 at rocketmail.com (alternative00 at rocketmail.com) Date: Tue, 30 Apr 2013 05:22:18 -0700 (PDT) Subject: Unwanted window spawns when using Tkinter with multiprocessing. In-Reply-To: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> References: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> Message-ID: <814cb4a9-6ae5-42df-a697-b4ce8e2e4c56@googlegroups.com> > Dave A. Yeah I'm using MRAB's code, my current code is : #Initalisation global event global hitkey #Functions def key(event): hitkey = event.char instance = multiprocessing.Process(target=player, args=(hitkey,)) instance.start() def player(hitkey): winsound.PlaySound(hitkey + '.wav', winsound.SND_FILENAME|winsound.SND_NOWAIT|winsound.SND_ASYNC) if __name__ == "__main__": fenetre = Tk() frame = Frame(fenetre, width=200, height=100) frame.focus_set() frame.bind("", key) frame.pack() fenetre.mainloop() From d at davea.name Tue Apr 30 08:30:27 2013 From: d at davea.name (Dave Angel) Date: Tue, 30 Apr 2013 08:30:27 -0400 Subject: Unwanted window spawns when using Tkinter with multiprocessing. In-Reply-To: <814cb4a9-6ae5-42df-a697-b4ce8e2e4c56@googlegroups.com> References: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> <814cb4a9-6ae5-42df-a697-b4ce8e2e4c56@googlegroups.com> Message-ID: <517FB963.8060801@davea.name> On 04/30/2013 08:22 AM, alternative00 at rocketmail.com wrote: > > Dave A. > > Yeah I'm using MRAB's code, my current code is : > > > #Initalisation > global event > global hitkey > > > #Functions > def key(event): > > hitkey = event.char > instance = multiprocessing.Process(target=player, args=(hitkey,)) > instance.start() > > > def player(hitkey): > winsound.PlaySound(hitkey + '.wav', winsound.SND_FILENAME|winsound.SND_NOWAIT|winsound.SND_ASYNC) > > > if __name__ == "__main__": > > > fenetre = Tk() > frame = Frame(fenetre, width=200, height=100) > > > frame.focus_set() > frame.bind("", key) > frame.pack() > fenetre.mainloop() > And you're still getting a new window ? Wow! -- DaveA From alternative00 at rocketmail.com Tue Apr 30 08:31:56 2013 From: alternative00 at rocketmail.com (alternative00 at rocketmail.com) Date: Tue, 30 Apr 2013 05:31:56 -0700 (PDT) Subject: Unwanted window spawns when using Tkinter with multiprocessing. In-Reply-To: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> References: <7df67006-2176-42cb-a8ce-95a72339e7e2@googlegroups.com> Message-ID: <78554f08-6107-4076-a534-317ff77a6dbc@googlegroups.com> > Dave A. No, not a new window, but my player function doesn't play any sound anymore. From patrick.waldo at gmail.com Sun Apr 28 17:07:00 2013 From: patrick.waldo at gmail.com (Patrick Waldo) Date: Sun, 28 Apr 2013 17:07:00 -0400 Subject: [JOB] Two opportunities at Decernis Message-ID: Hi All, The company I work for, Decernis, has two job opportunities that might be of interest. Decernis provides global systems for regulatory compliance management of foods and consumer products to world leaders in each sector. The company has offices in Rockville, MD as well as Frankfurt, Germany. First, we are looking for a highly effective, full-time senior software engineer with experience in both development and client interaction. This position will work mostly in Java, but Python is most definitely an added plus. Second, we are looking for a highly motivated and self-reliant independent contractor to help us build customized RSS feeds, web crawlers and site monitors. This position is part-time and all programs will be written in Python. Experience in Plone will be an added benefit. Please see below for more information. Send resume and cover letter to Cynthia Gamboa, cgamboa at decernis.com. Best Patrick Project Manager Decernis News & Issue Management *Job Description: Full-Time Senior Software Engineer* We are looking for a highly effective senior software engineer with experience in both development and client interaction. Our company provides global systems for regulatory compliance management of foods and consumer products to world leaders in each sector. Our ideal candidate has the following experiences: ? 5 or more years of Java/J2EE development experiences including Jboss/Tomcat and web applications and deployment; ? 4 or more years of Oracle database development experience including Oracle 10g or later versions; ? Strong Unix/Linux OS working experience; ? Strong script language programming experience in Python and Perl; ? Experience with rule-based expert systems; ? Experience in Plone and other CMS a plus. Salary commensurate with experience. This position reports directly to the Director of System Development. *About Decernis* Decernis is a global information company that works with industry leaders and government agencies to meet complex regulatory compliance and risk management needs. We work closely with our clients to produce results that meet the high standards demanded in technically challenging areas to ensure comprehensive, current, and global solutions. Our team has the regulatory, scientific, data, and systems expertise to succeed with our clients and we are dedicated to results. Decernis has offices in Rockville, MD and Frankfurt, Germany. Re-locating to the Washington, DC area is a requirement of the position. Decernis is an equal opportunity employer and will not discriminate against any individual, employee, or application for employment on the basis of race, color, marital status, religion, age, sex, sexual orientation, national origin, handicap, or any other legally protected status recognized by federal, state or local law. ### *Job Description: Part Time Python Programmer* We are looking for a highly motivated and self-reliant independent contractor to help us build customized RSS feeds, web crawlers and site monitors. Our ideal candidate has experience working with data mining techniques as well as building web crawlers and scrapers. The candidate will be able to choose hours and work remotely, but must meet expected deadlines and be able to report progress effectively. In addition we are looking for someone who is able to think through the problem set and contribute their own solutions while balancing project goals and direction. The project will last approximately three months, but sufficient performance could lead to future work. This position reports directly to the Director of System Development. *Key Skills* ? Data Mining & Web Crawling (Required) ? Python Development (Required) ? Statistics ? Task Oriented ? Proficient English ? Effective Communication *About Decernis* Decernis is a global information company that works with industry leaders and government agencies to meet complex regulatory compliance and risk management needs. We work closely with our clients to produce results that meet the high standards demanded in technically challenging areas to ensure comprehensive, current, and global solutions. Our team has the regulatory, scientific, data, and systems expertise to succeed with our clients and we are dedicated to results. Decernis has offices in Rockville, MD and Frankfurt, Germany. Re-locating to the Washington, DC area is not a requirement. Decernis is an equal opportunity employer and will not discriminate against any individual, employee, or application for employment on the basis of race, color, marital status, religion, age, sex, sexual orientation, national origin, handicap, or any other legally protected status recognized by federal, state or local law. ### -------------- next part -------------- An HTML attachment was scrubbed... URL: From root.phidgets at gmail.com Mon Apr 29 02:39:53 2013 From: root.phidgets at gmail.com (root.phidgets at gmail.com) Date: Sun, 28 Apr 2013 23:39:53 -0700 (PDT) Subject: SMTP-Email Help Message-ID: <951438d9-d344-40e1-b237-20e0b4d74a33@googlegroups.com> Hi Guys. I need some help with the coding for my program. This coding is suppose to sort text file according to the latest date and send the latest file. Attach it to my email and sent to another email account. But somehow the program is unable to send email. [CODE]#!/usr/bin/python import os, glob, smtplib, datetime from email.MIMEMultipart import MIMEMultipart from email.MIMEBase import MIMEBase from email.MIMEText import MIMEText from email import Encoders process_list=[] AP_filelist=[] Client_filelist=[] BlackClient_filelist=[] sniff_assoc = 0 i = 0 to = "iamsiaozharbor at hotmail.sg" gmail_user = "root.phidgets at gmail.com" gmail_pwd = "rootphidget" def mail(to, subject, text, attach): msg = MIMEMultipart() msg['From'] = gmail_user msg['To'] = to msg['Subject'] = subject msg.attach(MIMEText(text)) part = MIMEBase('application', 'octet-stream') part.set_payload(open(attach, 'rb').read()) Encoders.encode_base64(part) part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(attach)) msg.attach(part) mailServer = smtplib.SMTP("smtp.gmail.com", 587) mailServer.ehlo() mailServer.starttls() mailServer.ehlo() mailServer.login(gmail_user, gmail_pwd) mailServer.sendmail(gmail_user, to, msg.as_string()) # Should be mailServer.quit(), but that crashes... mailServer.close() Client_files = glob.glob('/root/wifi/Output_assoc/*Rouge-Client*.txt') def get_oldest_Client_file(Client_files): for data in Client_files: stats = os.stat(data) Client_filelist.append(data) sortedClient = sorted(Client_filelist) return sortedClient[0] BlackClient_files = glob.glob('/root/wifi/Output_arp/*DeAuth-Client*.txt') def get_oldest_BlackClient_file(BlackClient_files): for data in BlackClient_files: stats = os.stat(data) BlackClient_filelist.append(data) sortedBlackClient = sorted(BlackClient_filelist) return sortedBlackClient[0] if __name__=='__main__': try: if os.path.getsize(get_oldest_Client_file(Client_files)) > 1: mail("root.phidgets at gmail.com", "Rouge Client Found", "Client MAC address in the attachment", get_oldest_Client_file(Client_files)) print str(datetime.datetime.now()) + ' -- ' + get_oldest_Client_file(Client_files) + ' was sent.' os.remove(get_oldest_Client_file(Client_files)) else: for line in os.popen("ps -e"): fields = line.split() process = fields[3] process_list.append(process) for pro in process_list: if pro == 'sniff_assoc': sniff_assoc = 1 i+=1 if sniff_assoc == 0: os.remove(get_oldest_Client_file(Client_files)) print str(datetime.datetime.now()) + ' -- ' + 'program is not running. ' + get_oldest_Client_file(Client_files) + ' is remove.' else: print str(datetime.datetime.now()) + ' -- ' + 'Client file is still writing.' except: print str(datetime.datetime.now()) + ' -- ' + 'No AP file to send.' try: if os.path.getsize(get_oldest_BlackClient_file(BlackClient_files)) > 1: mail("root.phidgets at gmail.com", "DeAuth Rouge Client", "Client MAC address in the attachment.", get_oldest_BlackClient_file(BlackClient_files)) print str(datetime.datetime.now()) + ' -- ' + get_oldest_BlackClient_file(BlackClient_files) + ' was sent.' os.remove(get_oldest_BlackClient_file(BlackClient_files)) else: for line in os.popen("ps -e"): fields = line.split() process = fields[3] process_list.append(process) for pro in process_list: if pro == 'sniff_arp': sniff_assoc = 1 i+=1 if sniff_assoc == 0: os.remove(get_oldest_BlackClient_file(BlackClient_files)) print str(datetime.datetime.now()) + ' -- ' + 'program is not running. ' + get_oldest_BlackClient_file(BlackClient_files) + ' is REMOVED!!' else: print str(datetime.datetime.now()) + ' -- ' + 'DeAuth client file is still writing!' except: print str(datetime.datetime.now()) + ' -- ' + 'No DeAuth client file to send.'[/CODE] From steve+comp.lang.python at pearwood.info Mon Apr 29 03:24:35 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Apr 2013 07:24:35 GMT Subject: SMTP-Email Help References: <951438d9-d344-40e1-b237-20e0b4d74a33@googlegroups.com> Message-ID: <517e2033$0$29883$c3e8da3$5496439d@news.astraweb.com> On Sun, 28 Apr 2013 23:39:53 -0700, root.phidgets wrote: > Hi Guys. I need some help with the coding for my program. > > This coding is suppose to sort text file according to the latest date > and send the latest file. Attach it to my email and sent to another > email account. But somehow the program is unable to send email. I believe that Google has locked you out of your account. Are you aware that you've just made your username and password visible to the entire Internet? If you hadn't already triggered Google's anti-spam detection, you surely have now. > gmail_user = "********@gmail.com" > gmail_pwd = "**********" (details redacted, to shut the barn door now that the horse has already run away) When I log into your gmail account with those credentials, I see: Verify your account We've detected unusual activity on your account. To immediately restore access to your account, choose how to verify your account. so I believe Google have locked the account because they think you're spamming. You'll need to fix that before anything else. -- Steven From cl at isbd.net Mon Apr 29 05:47:46 2013 From: cl at isbd.net (cl at isbd.net) Date: Mon, 29 Apr 2013 10:47:46 +0100 Subject: How do I encode and decode this data to write to a file? Message-ID: <27s15a-943.ln1@chris.zbmc.eu> I am debugging some code that creates a static HTML gallery from a directory hierarchy full of images. It's this package:- https://pypi.python.org/pypi/Gallery2.py/2.0 It's basically working and does pretty much what I want so I'm happy to put some effort into it and fix things. The problem I'm currently chasing is that it can't cope with directory names that have accented characters in them, it fails when it tries to write the HTML that creates the page with the thumbnails on. The code that's failing is:- raw = os.path.join(directory, self.getNameNoExtension()) + ".html" file = open(raw, "w") file.write("".join(html).encode('utf-8')) file.close() The variable html is a list containing the lines of HTML to write to the file. It fails when it contains accented characters (an ? in this case). Here's the traceback:- Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/gallery/galleries.py", line 41, in run self._recurse() File "/usr/local/lib/python2.7/dist-packages/gallery/galleries.py", line 272, in _recurse os.path.walk(self.props["sourcedir"], self.processDir, None) File "/usr/lib/python2.7/posixpath.py", line 246, in walk walk(name, func, arg) File "/usr/lib/python2.7/posixpath.py", line 246, in walk walk(name, func, arg) File "/usr/lib/python2.7/posixpath.py", line 246, in walk walk(name, func, arg) File "/usr/lib/python2.7/posixpath.py", line 238, in walk func(arg, top, names) File "/usr/local/lib/python2.7/dist-packages/gallery/galleries.py", line 263, in processDir self.createGallery() File "/usr/local/lib/python2.7/dist-packages/gallery/galleries.py", line 215, in createGallery self.picturemanager.createPictureHTMLs(self.footer) File "/usr/local/lib/python2.7/dist-packages/gallery/picturemanager.py", line 84, in createPictureHTMLs curPic.createPictureHTML(self.galleryDirectory, self.getStylesheet(), self.fullsize, footer) File "/usr/local/lib/python2.7/dist-packages/gallery/picture.py", line 361, in createPictureHTML file.write("".join(html).encode('utf-8')) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 783: ordinal not in range(128) If I understand correctly the encode() is saying that it can't understand the data in the html because there's a character 0xc3 in it. I *think* this means that the ? is encoded in UTF-8 already in the incoming data stream (should be as my system is wholly UTF-8 as far as I know and I created the directory name). So how do I change the code so I don't get the error? Do I just decode() the data first and then encode() it? -- Chris Green From bahamutzero8825 at gmail.com Mon Apr 29 06:11:11 2013 From: bahamutzero8825 at gmail.com (Andrew Berg) Date: Mon, 29 Apr 2013 05:11:11 -0500 Subject: How do I encode and decode this data to write to a file? In-Reply-To: <27s15a-943.ln1@chris.zbmc.eu> References: <27s15a-943.ln1@chris.zbmc.eu> Message-ID: <517E473F.6060609@gmail.com> On 2013.04.29 04:47, cl at isbd.net wrote: > If I understand correctly the encode() is saying that it can't > understand the data in the html because there's a character 0xc3 in it. > I *think* this means that the ? is encoded in UTF-8 already in the > incoming data stream (should be as my system is wholly UTF-8 as far as I > know and I created the directory name). You can verify that your filesystem is set to use UTF-8 with sys.getfilesystemencoding(). If it returns 'ascii', then your locale settings are incorrect. -- CPython 3.3.1 | Windows NT 6.2.9200 / FreeBSD 9.1 From __peter__ at web.de Mon Apr 29 06:33:16 2013 From: __peter__ at web.de (Peter Otten) Date: Mon, 29 Apr 2013 12:33:16 +0200 Subject: How do I encode and decode this data to write to a file? References: <27s15a-943.ln1@chris.zbmc.eu> Message-ID: cl at isbd.net wrote: > I am debugging some code that creates a static HTML gallery from a > directory hierarchy full of images. It's this package:- > https://pypi.python.org/pypi/Gallery2.py/2.0 > > > It's basically working and does pretty much what I want so I'm happy to > put some effort into it and fix things. > > The problem I'm currently chasing is that it can't cope with directory > names that have accented characters in them, it fails when it tries to > write the HTML that creates the page with the thumbnails on. > > The code that's failing is:- > > raw = os.path.join(directory, self.getNameNoExtension()) + ".html" > file = open(raw, "w") > file.write("".join(html).encode('utf-8')) > file.close() > > The variable html is a list containing the lines of HTML to write to the > file. It fails when it contains accented characters (an ? in this > case). Here's the traceback:- > > Traceback (most recent call last): > File "/usr/local/lib/python2.7/dist-packages/gallery/galleries.py", line > 41, in run self._recurse() File > "/usr/local/lib/python2.7/dist-packages/gallery/galleries.py", line 272, > in _recurse os.path.walk(self.props["sourcedir"], self.processDir, None) > File "/usr/lib/python2.7/posixpath.py", line 246, in walk walk(name, > func, arg) File "/usr/lib/python2.7/posixpath.py", line 246, in walk > walk(name, func, arg) File "/usr/lib/python2.7/posixpath.py", line 246, > in walk walk(name, func, arg) File "/usr/lib/python2.7/posixpath.py", > line 238, in walk func(arg, top, names) File > "/usr/local/lib/python2.7/dist-packages/gallery/galleries.py", line 263, > in processDir self.createGallery() File > "/usr/local/lib/python2.7/dist-packages/gallery/galleries.py", line 215, > in createGallery self.picturemanager.createPictureHTMLs(self.footer) > File "/usr/local/lib/python2.7/dist-packages/gallery/picturemanager.py", > line 84, in createPictureHTMLs > curPic.createPictureHTML(self.galleryDirectory, self.getStylesheet(), > self.fullsize, footer) File > "/usr/local/lib/python2.7/dist-packages/gallery/picture.py", line 361, > in createPictureHTML file.write("".join(html).encode('utf-8')) > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position > 783: ordinal not in range(128) > > > > If I understand correctly the encode() is saying that it can't > understand the data in the html because there's a character 0xc3 in it. > I *think* this means that the ? is encoded in UTF-8 already in the > incoming data stream (should be as my system is wholly UTF-8 as far as I > know and I created the directory name). > > So how do I change the code so I don't get the error? Do I just > decode() the data first and then encode() it? > Note that you are getting a *UnicodeDecodeError*, not a UnicodeEncodeError. Try omitting the encode() step, i. e. instead of > file.write("".join(html).encode('utf-8')) use file.write(""join(html)) Background (applies to Python 2 only): the str type deals with bytes, not code points. The right thing to do is to use .decode(...) to convert from str to unicode and .encode(...) to convert from unicode to str. In Python 2 however the str type has an encode(...) method which is basically equivalent to class str: # imaginary python implementation of python2's str ... def encode(self, encoding): return self.decode("ascii").encode(encoding) and is almost never called intentionally. PS Python3 has relabeled unicode to str and thus uses unicode by default. str was renamed to bytes and the annoying bytes.encode() method is gone. From davea at davea.name Mon Apr 29 07:46:51 2013 From: davea at davea.name (Dave Angel) Date: Mon, 29 Apr 2013 07:46:51 -0400 Subject: How do I encode and decode this data to write to a file? In-Reply-To: <27s15a-943.ln1@chris.zbmc.eu> References: <27s15a-943.ln1@chris.zbmc.eu> Message-ID: <517E5DAB.6000309@davea.name> On 04/29/2013 05:47 AM, cl at isbd.net wrote: A couple of generic comments: your email program made a mess of the traceback by appending each source line to the location information. Please mention your Python version & OS. Apparently you're running 2.7 on Linux or similar. > I am debugging some code that creates a static HTML gallery from a > directory hierarchy full of images. It's this package:- > https://pypi.python.org/pypi/Gallery2.py/2.0 > > > It's basically working and does pretty much what I want so I'm happy to > put some effort into it and fix things. > > The problem I'm currently chasing is that it can't cope with directory > names that have accented characters in them, it fails when it tries to > write the HTML that creates the page with the thumbnails on. > > The code that's failing is:- > > raw = os.path.join(directory, self.getNameNoExtension()) + ".html" > file = open(raw, "w") > file.write("".join(html).encode('utf-8')) You can't encode byte data, it's already encoded. So you're forcing the Python system to implicitly decode it (using ASCII codec) before letting you encode it to utf-8. If you think it's already in utf-8, then omit the encode() call there. Additionally, you can debug things with some simple print statements, at least if you decompose your 3-function line so you can get at the intermediate data. Split the line into three parts; temp1 = "".join(html) #temp1 is byte data temp2 = temp1.decode() #temp2 is unicode data temp3 = temp2.encode("utf-8") #temp3 is byte data again file.write(temp3) Now, you'll presumably get the error on the second line, so examine the bytes around byte 783. Make sure it's really in utf-8, and if it is, then skip the decode and the encode. If it's not, then Andrew's advice is pertinent. I would also look at the variable html. It's a list, but what are the types of the elements in it? > file.close() > > The variable html is a list containing the lines of HTML to write to the > file. It fails when it contains accented characters (an ? in this > case). Here's the traceback:- > > Traceback (most recent call last): > File "/usr/local/lib/python2.7/dist-packages/gallery/galleries.py", line 41, in run self._recurse() > File "/usr/local/lib/python2.7/dist-packages/gallery/galleries.py", line 272, in _recurse os.path.walk(self.props["sourcedir"], self.processDir, None) > File "/usr/lib/python2.7/posixpath.py", line 246, in walk walk(name, func, arg) File "/usr/lib/python2.7/posixpath.py", line 246, in walk walk(name, func, arg) > File "/usr/lib/python2.7/posixpath.py", line 246, in walk walk(name, func, arg) File "/usr/lib/python2.7/posixpath.py", line 238, in walk func(arg, top, names) > File "/usr/local/lib/python2.7/dist-packages/gallery/galleries.py", line 263, in processDir self.createGallery() > File "/usr/local/lib/python2.7/dist-packages/gallery/galleries.py", line 215, in createGallery self.picturemanager.createPictureHTMLs(self.footer) > File "/usr/local/lib/python2.7/dist-packages/gallery/picturemanager.py", line 84, in createPictureHTMLs curPic.createPictureHTML(self.galleryDirectory, self.getStylesheet(), self.fullsize, footer) > File "/usr/local/lib/python2.7/dist-packages/gallery/picture.py", line 361, in createPictureHTML file.write("".join(html).encode('utf-8')) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 783: ordinal not in range(128) > > > > If I understand correctly the encode() is saying that it can't > understand the data in the html because there's a character 0xc3 in it. > I *think* this means that the ? is encoded in UTF-8 already in the > incoming data stream (should be as my system is wholly UTF-8 as far as I > know and I created the directory name). > > So how do I change the code so I don't get the error? Do I just > decode() the data first and then encode() it? > -- DaveA From cl at isbd.net Mon Apr 29 08:50:01 2013 From: cl at isbd.net (cl at isbd.net) Date: Mon, 29 Apr 2013 13:50:01 +0100 Subject: How do I encode and decode this data to write to a file? References: <27s15a-943.ln1@chris.zbmc.eu> Message-ID: Andrew Berg wrote: > On 2013.04.29 04:47, cl at isbd.net wrote: > > If I understand correctly the encode() is saying that it can't > > understand the data in the html because there's a character 0xc3 in it. > > I *think* this means that the ? is encoded in UTF-8 already in the > > incoming data stream (should be as my system is wholly UTF-8 as far as I > > know and I created the directory name). > You can verify that your filesystem is set to use UTF-8 with sys.getfilesystemencoding(). > If it returns 'ascii', then your locale settings > are incorrect. > chris$ python Python 2.7.3 (default, Sep 26 2012, 21:51:14) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.getfilesystemencoding() 'UTF-8' >>> So I am set up right for UTF-8. -- Chris Green From cl at isbd.net Mon Apr 29 08:59:26 2013 From: cl at isbd.net (cl at isbd.net) Date: Mon, 29 Apr 2013 13:59:26 +0100 Subject: How do I encode and decode this data to write to a file? References: <27s15a-943.ln1@chris.zbmc.eu> Message-ID: Dave Angel wrote: > On 04/29/2013 05:47 AM, cl at isbd.net wrote: > > A couple of generic comments: your email program made a mess of the > traceback by appending each source line to the location information. > What's me email program got to do with it? :-) I'm using a dedicated newsreader (tin) as I posted via the gmane/usenet interface. The posting looks perfectly OK to me when I read it back from usenet. > Please mention your Python version & OS. Apparently you're running 2.7 > on Linux or similar. > Sorry, yes you're spot on. > > I am debugging some code that creates a static HTML gallery from a > > directory hierarchy full of images. It's this package:- > > https://pypi.python.org/pypi/Gallery2.py/2.0 > > > > > > It's basically working and does pretty much what I want so I'm happy to > > put some effort into it and fix things. > > > > The problem I'm currently chasing is that it can't cope with directory > > names that have accented characters in them, it fails when it tries to > > write the HTML that creates the page with the thumbnails on. > > > > The code that's failing is:- > > > > raw = os.path.join(directory, self.getNameNoExtension()) + ".html" > > file = open(raw, "w") > > file.write("".join(html).encode('utf-8')) > > You can't encode byte data, it's already encoded. So you're forcing the > Python system to implicitly decode it (using ASCII codec) before letting > you encode it to utf-8. If you think it's already in utf-8, then omit > the encode() call there. > It's the way the code was as I installed it from pypi. What you say makes a lot of sense though, I'll remove the encode(). > Additionally, you can debug things with some simple print statements, at > least if you decompose your 3-function line so you can get at the > intermediate data. Split the line into three parts; > temp1 = "".join(html) #temp1 is byte data > temp2 = temp1.decode() #temp2 is unicode data > temp3 = temp2.encode("utf-8") #temp3 is byte data again > file.write(temp3) > OK, thanks for this and all the other advice on this thread. -- Chris Green From robert.kern at gmail.com Mon Apr 29 09:11:18 2013 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 29 Apr 2013 14:11:18 +0100 Subject: How do I encode and decode this data to write to a file? In-Reply-To: References: <27s15a-943.ln1@chris.zbmc.eu> Message-ID: On 2013-04-29 13:59, cl at isbd.net wrote: > Dave Angel wrote: >> On 04/29/2013 05:47 AM, cl at isbd.net wrote: >> >> A couple of generic comments: your email program made a mess of the >> traceback by appending each source line to the location information. >> > What's me email program got to do with it? :-) I'm using a dedicated > newsreader (tin) as I posted via the gmane/usenet interface. The posting > looks perfectly OK to me when I read it back from usenet. FWIW, I see the same problem Dave sees. I'm using gmane via Thunderbird. -- 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 cl at isbd.net Mon Apr 29 10:38:53 2013 From: cl at isbd.net (cl at isbd.net) Date: Mon, 29 Apr 2013 15:38:53 +0100 Subject: How do I encode and decode this data to write to a file? References: <27s15a-943.ln1@chris.zbmc.eu> Message-ID: Robert Kern wrote: > On 2013-04-29 13:59, cl at isbd.net wrote: > > Dave Angel wrote: > >> On 04/29/2013 05:47 AM, cl at isbd.net wrote: > >> > >> A couple of generic comments: your email program made a mess of the > >> traceback by appending each source line to the location information. > >> > > What's me email program got to do with it? :-) I'm using a dedicated > > newsreader (tin) as I posted via the gmane/usenet interface. The posting > > looks perfectly OK to me when I read it back from usenet. > > FWIW, I see the same problem Dave sees. I'm using gmane via Thunderbird. > How strange. I think it must be something to do with the gmane interface between news and mail then. -- Chris Green From skip at pobox.com Mon Apr 29 10:56:25 2013 From: skip at pobox.com (Skip Montanaro) Date: Mon, 29 Apr 2013 09:56:25 -0500 Subject: How do I encode and decode this data to write to a file? In-Reply-To: References: <27s15a-943.ln1@chris.zbmc.eu> Message-ID: > How strange. I think it must be something to do with the gmane > interface between news and mail then. Probably. It was borked in Gmail as well... Skip From tjreedy at udel.edu Mon Apr 29 18:02:08 2013 From: tjreedy at udel.edu (Terry Jan Reedy) Date: Mon, 29 Apr 2013 18:02:08 -0400 Subject: How do I encode and decode this data to write to a file? In-Reply-To: <27s15a-943.ln1@chris.zbmc.eu> References: <27s15a-943.ln1@chris.zbmc.eu> Message-ID: On 4/29/2013 5:47 AM, cl at isbd.net wrote: > case). Here's the traceback:- > > File "/usr/local/lib/python2.7/dist-packages/gallery/picture.py", line 361, > in createPictureHTML file.write("".join(html).encode('utf-8')) > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 783: ordinal not in range(128) Generiric advice for anyone getting unicode errors: unpack the composition producing the error so that one can see which operation produced it. In this case s = "".join(html)\ s = s.encode('utf-8') file.write(s) This also makes it possible to print intermediate results. print(type(s), s) # would have been useful Doing so would have immediately shown that in this case the error was the encode operation, because s was already bytes. For many other posts, the error with the same type of message has been the print or write operation, do to output encoding issues, but that was not the case here. From moraa.lovetakes2 at gmail.com Mon Apr 29 06:26:51 2013 From: moraa.lovetakes2 at gmail.com (Ombongi Moraa Fe) Date: Mon, 29 Apr 2013 13:26:51 +0300 Subject: xml.etree.ElementTree if element does not exist? Message-ID: Good Afternoon, Among other elements values that my script finds is value for sepid sepid = content.find(".//{http://www.huawei.com.cn/schema/common/v2_1}sepid ").text however, if i pass xml data that DOES NOT contain sepid element, i get an error: Traceback (most recent call last): File "/usr/local/bin/receive.py", line 21, in sepid = content.find(".//{ http://www.huawei.com.cn/schema/common/v2_1}sepid").text AttributeError: 'NoneType' object has no attribute 'text' some messages i receive will have the sepid parameter, other will not have this parameter. How can i cater for this? kinda like an if .. else implementation for xml.etree.ElementTree ? Thanks in advance. Saludos Ombongi Moraa Faith -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan at vectorfabrics.com Mon Apr 29 07:22:31 2013 From: stefan at vectorfabrics.com (Stefan Holdermans) Date: Mon, 29 Apr 2013 13:22:31 +0200 Subject: xml.etree.ElementTree if element does not exist? In-Reply-To: References: Message-ID: <556FF090-DABC-4A90-800F-6E3D81B6C80F@vectorfabrics.com> Ombongi, > however, if i pass xml data that DOES NOT contain sepid element, i get an error: > > Traceback (most recent call last): > File "/usr/local/bin/receive.py", line 21, in > sepid = content.find(".//{http://www.huawei.com.cn/schema/common/v2_1}sepid").text > AttributeError: 'NoneType' object has no attribute 'text' > > > some messages i receive will have the sepid parameter, other will not have this parameter. How can i cater for this? kinda like an if .. else implementation for xml.etree.ElementTree ? What about simply testing whether the value returned by find is None? For example: $ cat test.py from xml.etree import ElementTree myTree = ElementTree.fromstring('') myElement = myTree.find('orange') if myElement is None: print 'tree does not contain a child element "orange"' else: print myElement.text $ python test.py tree does not contain a child element "orange" HTH, Stefan From moraa.lovetakes2 at gmail.com Mon Apr 29 07:50:08 2013 From: moraa.lovetakes2 at gmail.com (Ombongi Moraa Fe) Date: Mon, 29 Apr 2013 14:50:08 +0300 Subject: xml.etree.ElementTree if element does not exist? In-Reply-To: <556FF090-DABC-4A90-800F-6E3D81B6C80F@vectorfabrics.com> References: <556FF090-DABC-4A90-800F-6E3D81B6C80F@vectorfabrics.com> Message-ID: Hi Stefan, Group Thanks for the thumbs up. Worked perfectly. Saludos Ombongi Moraa Faith On 29 April 2013 14:22, Stefan Holdermans wrote: > Ombongi, > > > however, if i pass xml data that DOES NOT contain sepid element, i get > an error: > > > > Traceback (most recent call last): > > File "/usr/local/bin/receive.py", line 21, in > > sepid = content.find(".//{ > http://www.huawei.com.cn/schema/common/v2_1}sepid").text > > AttributeError: 'NoneType' object has no attribute 'text' > > > > > > some messages i receive will have the sepid parameter, other will not > have this parameter. How can i cater for this? kinda like an if .. else > implementation for xml.etree.ElementTree ? > > What about simply testing whether the value returned by find is None? For > example: > > $ cat test.py > from xml.etree import ElementTree > > myTree = ElementTree.fromstring('') > myElement = myTree.find('orange') > > if myElement is None: > print 'tree does not contain a child element "orange"' > else: > print myElement.text > > > $ python test.py > tree does not contain a child element "orange" > > HTH, > > Stefan -------------- next part -------------- An HTML attachment was scrubbed... URL: From neilc at norwich.edu Mon Apr 29 08:25:34 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 29 Apr 2013 12:25:34 GMT Subject: xml.etree.ElementTree if element does not exist? References: Message-ID: On 2013-04-29, Ombongi Moraa Fe wrote: > > Good Afternoon, > > Among other elements values that my script finds is value for sepid > > sepid = content.find(".//{http://www.huawei.com.cn/schema/common/v2_1}sepid > ").text > > > however, if i pass xml data that DOES NOT contain sepid element, i get an > error: > > Traceback (most recent call last): > File "/usr/local/bin/receive.py", line 21, in > sepid = content.find(".//{ > http://www.huawei.com.cn/schema/common/v2_1}sepid").text > AttributeError: 'NoneType' object has no attribute 'text' find returns None when it doesn't find what you asked for. So you can't check the .text attribute right away unless you want an exception thrown. I deal with these annoyances like this: sepelem = content.find(".//{http://www.huawei.com.cn/schema/common/v2_1}sepid") if sepelem is not None: sepid = sepid.text else: sepid = '' The empty string works for my purposes. Your script might need something else. -- Neil Cerutti From neilc at norwich.edu Mon Apr 29 08:29:52 2013 From: neilc at norwich.edu (Neil Cerutti) Date: 29 Apr 2013 12:29:52 GMT Subject: xml.etree.ElementTree if element does not exist? References: Message-ID: On 2013-04-29, Neil Cerutti wrote: > find returns None when it doesn't find what you asked for. So you > can't check the .text attribute right away unless you want an > exception thrown. I deal with these annoyances like this: > > sepelem = content.find(".//{http://www.huawei.com.cn/schema/common/v2_1}sepid") > if sepelem is not None: > sepid = sepid.text Oops. One edit too fiew. That line should of course be sepid = sepelem.text > else: > sepid = '' > > The empty string works for my purposes. Your script might need > something else. -- Neil Cerutti From Robert.Flintham at uhb.nhs.uk Mon Apr 29 06:25:51 2013 From: Robert.Flintham at uhb.nhs.uk (Robert Flintham) Date: Mon, 29 Apr 2013 11:25:51 +0100 Subject: Drag and drop in Windows Message-ID: <20130429102558.DA3E744850E@nhs-pd1e-esg105.ad1.nhs.net> Hello all, Sorry to post such a generic question, but after searching the interwebs I'm not really any wiser about how to start with this. I'm currently on: Windows XP Python 2.7 I'm trying to create a small window in Python 2.7, that when you drop a file onto it from Windows explorer returns the file's path so that I can then go on to open the file and do whatever with it. I was planning on using Tkinter because that's what I've used before for GUI's, but I can be swayed from this if needs be. I've found this (TkDND): http://wiki.tcl.tk/2768 But I don't know how to implement this in Python. The Windows binary for it comes as a set of ".tcl" files and a single ".dll" file. The two options I've stumbled across seem to be 1. a Python wrapper for the DLL (I think to wrap C code??), which can then be imported like you'd import a Python package 2. direct implementation of the Tcl file [tk.eval('source ...')], but I don't reallu understand what's going on with this - can you only execute a "main" bit of Tcl files rather than implementing individual functions? Any input (however minimal) is definitely appreciated! I've included what I think are probably the relevant functions from the Tcl files at the bottom of the email, but I don't really understand the nuts and bolts of the code. All the best, Rob [From "tkdnd.tcl"...] # ---------------------------------------------------------------------------- # Command tkdnd::drag_source # ---------------------------------------------------------------------------- proc tkdnd::drag_source { mode path { types {} } { event 1 } } { set tags [bindtags $path] set idx [lsearch $tags "TkDND_Drag*"] switch -- $mode { register { if { $idx != -1 } { bindtags $path [lreplace $tags $idx $idx TkDND_Drag$event] } else { bindtags $path [concat $tags TkDND_Drag$event] } set types [platform_specific_types $types] set old_types [bind $path <>] foreach type $types { if {[lsearch $old_types $type] < 0} {lappend old_types $type} } bind $path <> $old_types } unregister { if { $idx != -1 } { bindtags $path [lreplace $tags $idx $idx] } } } };# tkdnd::drag_source [From "tkdnd_windows.tcl"...] # ---------------------------------------------------------------------------- # Command olednd::_GetDragSource # ---------------------------------------------------------------------------- proc olednd::_GetDragSource { } { variable _drag_source return $_drag_source };# olednd::_GetDragSource DISCLAIMER: This email and any attachments hereto contains proprietary information, some or all of which may be confidential or legally privileged. It is for the exclusive use of the intended recipient(s) only. If an addressing or transmission error has misdirected this e-mail and you are not the intended recipient(s), please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail or any attachments, as this may be unlawful. -------------- next part -------------- An HTML attachment was scrubbed... URL: From auriocus at gmx.de Mon Apr 29 16:38:29 2013 From: auriocus at gmx.de (Christian Gollwitzer) Date: Mon, 29 Apr 2013 22:38:29 +0200 Subject: Drag and drop in Windows In-Reply-To: References: Message-ID: Hi Robert, Am 29.04.13 12:25, schrieb Robert Flintham: > I?ve found this (TkDND): > > http://wiki.tcl.tk/2768 > But I don?t know how to implement this in Python. The Windows binary > for it comes as a set of ?.tcl? files and a single ?.dll? file. > 2.direct implementation of the Tcl file [tk.eval(?source ??)], but I > don?t reallu understand what?s going on with this ? can you only execute > a ?main? bit of Tcl files rather than implementing individual functions? I can only comment on the Tcl side, since I'm not an expert in the Tkinter coupling mechanism. TkDND is indeed the way to go if you want native drag'n'drop support. The first step would indeed be to load the package into the Tcl interpreter. You need to: 1) Create a folder for the packages, put the files in a subfolder Typically, this is something like lib/tkdnd, and at that level there must be the "pkgIndex.tcl" file 2) Append the lib/ folder to the auto path tk.eval('lappend auto_path {mypath/lib}') (the braces are Tcl's quoting mechanism) 3) load the package tk.eval('package require tkdnd') Then, you need to "register the target", i.e. declare a widget that it accepts files. Here, you need the Tk path name of the widget, which is retrieved by __str__: tk.eval('tkdnd::drop_target register ' + yourwidget +' *') Then, if you drop something, the widget recieves a virtual event <> . Now this is tricky, I don't know how to bind to that event. Following the tutorial for Tcl on http://wiki.tcl.tk/36708, I suppose something like yourwidget.bind("<>", filesdropped) should in principle work, but how to get the data out of it? It is stuffed into the %D bind substitution. Usual events store the MouseWheel distance in this field; so maybe you can get it from the field event.delta. I can't test it now, but I am a bit skeptical whether this works with the guts of TkInter. If not, you'd need to do some more forwarding from the Tcl side. Christian From Robert.Flintham at uhb.nhs.uk Tue Apr 30 04:39:43 2013 From: Robert.Flintham at uhb.nhs.uk (Robert Flintham) Date: Tue, 30 Apr 2013 09:39:43 +0100 Subject: Drag and drop in Windows In-Reply-To: <20130429204237.52A8F448266@nhs-pd1e-esg007.ad1.nhs.net> References: <20130429204237.52A8F448266@nhs-pd1e-esg007.ad1.nhs.net> Message-ID: <20130430083949.37A4E448A2B@nhs-pd1e-esg104.ad1.nhs.net> Thanks Christian. I've tried the following code: ################ import Tkinter root = Tkinter.Tk() root.title("DICOM Opener") root.tk.eval('lappend auto_path {K:/Python27/Lib/site-packages/tkdnd2.6}') root.tk.eval('package require tkdnd') ################ But I get the following traceback: ################ Traceback (most recent call last): File "K:\eclipse\plugins\org.python.pydev_2.7.1.2012100913\pysrc\pydevd.py", line 1397, in debugger.run(setup['file'], None, None) File "K:\eclipse\plugins\org.python.pydev_2.7.1.2012100913\pysrc\pydevd.py", line 1090, in run pydev_imports.execfile(file, globals, locals) #execute the script File "K:\PROGRAMMING\mripy\dicom_opener.py", line 7, in root.tk.eval('package require tkdnd') _tkinter.TclError: couldn't load library "K:/Python27/Lib/tkdnd2.6/tkdnd26.dll": invalid argument ################ Is "invalid argument" as generic as it sounds, or does it mean something specific in this case? Is Tcl expecting an additional argument in the 'package require' line? I assume the append auto path line is correct as it seems to have found the DLL (presumably from pkgIndex.tcl). Apologies for any disclaimers that pad out this message - it's a work email account and they get added after I hit "send". All the best, Rob -----Original Message----- From: Python-list [mailto:python-list-bounces+robert.flintham=uhb.nhs.uk at python.org] On Behalf Of Christian Gollwitzer Sent: 29 April 2013 21:38 To: python-list at python.org Subject: Re: Drag and drop in Windows Hi Robert, Am 29.04.13 12:25, schrieb Robert Flintham: > I've found this (TkDND): > > http://wiki.tcl.tk/2768 > But I don't know how to implement this in Python. The Windows binary > for it comes as a set of ".tcl" files and a single ".dll" file. > 2.direct implementation of the Tcl file [tk.eval('source ...')], but I > don't reallu understand what's going on with this - can you only execute > a "main" bit of Tcl files rather than implementing individual functions? I can only comment on the Tcl side, since I'm not an expert in the Tkinter coupling mechanism. TkDND is indeed the way to go if you want native drag'n'drop support. The first step would indeed be to load the package into the Tcl interpreter. You need to: 1) Create a folder for the packages, put the files in a subfolder Typically, this is something like lib/tkdnd, and at that level there must be the "pkgIndex.tcl" file 2) Append the lib/ folder to the auto path tk.eval('lappend auto_path {mypath/lib}') (the braces are Tcl's quoting mechanism) 3) load the package tk.eval('package require tkdnd') Then, you need to "register the target", i.e. declare a widget that it accepts files. Here, you need the Tk path name of the widget, which is retrieved by __str__: tk.eval('tkdnd::drop_target register ' + yourwidget +' *') Then, if you drop something, the widget recieves a virtual event <> . Now this is tricky, I don't know how to bind to that event. Following the tutorial for Tcl on http://wiki.tcl.tk/36708, I suppose something like yourwidget.bind("<>", filesdropped) should in principle work, but how to get the data out of it? It is stuffed into the %D bind substitution. Usual events store the MouseWheel distance in this field; so maybe you can get it from the field event.delta. I can't test it now, but I am a bit skeptical whether this works with the guts of TkInter. If not, you'd need to do some more forwarding from the Tcl side. Christian -- http://mail.python.org/mailman/listinfo/python-list DISCLAIMER: This email and any attachments hereto contains proprietary information, some or all of which may be confidential or legally privileged. It is for the exclusive use of the intended recipient(s) only. If an addressing or transmission error has misdirected this e-mail and you are not the intended recipient(s), please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail or any attachments, as this may be unlawful. From auriocus at gmx.de Tue Apr 30 08:08:05 2013 From: auriocus at gmx.de (Christian Gollwitzer) Date: Tue, 30 Apr 2013 14:08:05 +0200 Subject: Drag and drop in Windows In-Reply-To: References: <20130429204237.52A8F448266@nhs-pd1e-esg007.ad1.nhs.net> Message-ID: Hi Robert, Am 30.04.13 10:39, schrieb Robert Flintham: > Thanks Christian. > > I've tried the following code: ################ import Tkinter > > root = Tkinter.Tk() root.title("DICOM Opener") root.tk.eval('lappend > auto_path {K:/Python27/Lib/site-packages/tkdnd2.6}') > root.tk.eval('package require tkdnd') ################ > > But I get the following traceback: ################ > _tkinter.TclError: couldn't load library > "K:/Python27/Lib/tkdnd2.6/tkdnd26.dll": invalid argument > ################ > > Is "invalid argument" as generic as it sounds, or does it mean > something specific in this case? Is Tcl expecting an additional > argument in the 'package require' line? > > I assume the append auto path line is correct as it seems to have > found the DLL (presumably from pkgIndex.tcl). Yes, actually this means the the "package require" in principle succeeds to perfrom the necessary steps. The EINVALID on Windows in most cases menas, that the DLL has the wrong word size. I.e., you run Tcl in 32 bit and try to load tkdnd-DLL with 64 bit or vice versa. You can get the bitsize from Tcl with "set tcl_platform(pointerSize)" If it tells 4, Tcl runs on 32bit, if 8, it runs on 64bit. The second problem might be, that the tkdnd.dll depends on some other DLL which can't be found by Windows. To debug this, install a tool like "Dependency walker". I don't use Windows anymore, so my memory might be diffuse. Christian From kw at codebykevin.com Tue Apr 30 10:33:07 2013 From: kw at codebykevin.com (Kevin Walzer) Date: Tue, 30 Apr 2013 10:33:07 -0400 Subject: Drag and drop in Windows In-Reply-To: References: Message-ID: On 4/29/13 6:25 AM, Robert Flintham wrote: > > I?ve found this (TkDND): > > http://wiki.tcl.tk/2768 > Michael Lange has written a nice Python wrapper for TkDND. His site is offline at the moment, but I found the source files on my system and have wrapped them up here: http://www.codebykevin.com/TkinterDnD2-0.zip Hope this helps, Kevin -- Kevin Walzer Code by Kevin/Mobile Code by Kevin http://www.codebykevin.com http://www.wtmobilesoftware.com From kw at codebykevin.com Tue Apr 30 19:09:35 2013 From: kw at codebykevin.com (Kevin Walzer) Date: Tue, 30 Apr 2013 19:09:35 -0400 Subject: Drag and drop in Windows In-Reply-To: References: Message-ID: Official link: http://tkinterdnd.sourceforge.net From jimmie.he at gmail.com Mon Apr 29 13:20:49 2013 From: jimmie.he at gmail.com (Jimmie He) Date: Mon, 29 Apr 2013 10:20:49 -0700 (PDT) Subject: Can read in the BMP data correctly ,but the size is not right? Message-ID: I'm trying to read in the BMP data by the the code below,and I'm check the data array with WINHEX,and it is correct,but which confuse me is why the size is 0x180,but the actual picture should be 48*48 = 0x120 bytes because I use 1-bit BMP not the 24bit BMP,could any one give some hints? -------------------------------------------------------------------------------- __Head_Info = [ [ 'Type' ,0 , 2],#BM [ 'FSize' ,2 , 4],#File Size [ 'Reserved' ,6 , 4],#0x00000000 [ 'OffBits' ,10 , 4],#Offset of Image [ 'SSize' ,14 , 4],# 40 [ 'Width' ,18 , 4],#Width [ 'Height' ,22 , 4],#Hight [ 'Planes' ,26 , 2],#1 [ 'BitCount' ,28 , 2],#{1,2,4,8,24} [ 'Compress' ,30 , 4],#0 [ 'SizeImage' ,34 , 4],#Bytes Per Line [ 'XPM' ,38 , 4],#2835 [ 'YPM' ,42 , 4],#2835 [ 'ClrUsed' ,46 , 4],#0 [ 'ClrImportant' ,50 , 4]#0 ] _Type =0; _FSize =1; _Reserved =2; _OffBits =3; _SSize =4; _Width =5; _Height =6; _Planes =7; _BitCount =8; _Compress =9; _SizeImage =10; _XPM =11; _YPM =12; _ClrUsed =13; _ClrImportant =14; def __getInt( b, idx): return binToInt(b,__Head_Info[idx][1],__Head_Info[idx][2]) def saveMatrixtoASC(bmpfilename,ascfilename): try: handle1=open( bmpfilename ,"rb") raw = bytearray(handle1.read( )) handle1.close except Exception as E: return "error:"+ str(E),"" datastart=__getInt(raw, _OffBits) datasize =__getInt(raw, _SizeImage) print ('Image Offset = 0x%X'%datastart) print ('Image Size = 0x%X'%datasize) handle2=open( ascfilename ,"w") for i in range(0,datasize): handle2.write('0x%02X,'%raw[datastart+i]) if (i+1) % 16 == 0 : handle2.write("\n") handle2.close From rosuav at gmail.com Mon Apr 29 13:53:35 2013 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 30 Apr 2013 03:53:35 +1000 Subject: Can read in the BMP data correctly ,but the size is not right? In-Reply-To: References: Message-ID: On Tue, Apr 30, 2013 at 3:20 AM, Jimmie He wrote: > handle1.close I haven't looked at the rest of the code, but be careful of this: You aren't actually *calling* this function. That might be your problem and it might not, but try fixing it (add the parentheses, even though there's nothing to put in them) and see if that helps. Same with the handle2.close at the end. ChrisA From __peter__ at web.de Mon Apr 29 13:57:07 2013 From: __peter__ at web.de (Peter Otten) Date: Mon, 29 Apr 2013 19:57:07 +0200 Subject: Can read in the BMP data correctly ,but the size is not right? References: Message-ID: Jimmie He wrote: > I'm trying to read in the BMP data by the the code below,and I'm check > the data array with WINHEX,and it is correct,but which confuse me is > why the size is 0x180,but the actual picture should be 48*48 = 0x120 > bytes because I use 1-bit BMP not the 24bit BMP,could any one give some > hints? According to wikipedia """ The size of each row is rounded up to a multiple of 4 bytes [...] """ So 48/8 == 6 will be rounded to 8, and 8*48 == 384 == 0x180. > handle1=open( bmpfilename ,"rb") > raw = bytearray(handle1.read( )) > handle1.close To actually do something the last line should be handle1.close(). I recommend with open(bmpfilename ,"rb") as handle1: raw = bytearray(handle1.read()) instead which has the additional advantage that the file will be closed if an exception occurs in the with-suite. From python at mrabarnett.plus.com Mon Apr 29 14:10:59 2013 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 29 Apr 2013 19:10:59 +0100 Subject: Can read in the BMP data correctly ,but the size is not right? In-Reply-To: References: Message-ID: <517EB7B3.6040304@mrabarnett.plus.com> On 29/04/2013 18:20, Jimmie He wrote: > I'm trying to read in the BMP data by the the code below,and I'm > check the data array with WINHEX,and it is correct,but which confuse > me is why the size is 0x180,but the actual picture should be 48*48 = > 0x120 bytes because I use 1-bit BMP not the 24bit BMP,could any one > give some hints? > [snip] What size is 0x180? If you're asking why the file size is 0x180 and not 0x120, it's simply because of the header. An image file contains not just the pixels of the image, but also information about the image. From dihedral88888 at googlemail.com Mon Apr 29 14:12:38 2013 From: dihedral88888 at googlemail.com (88888 Dihedral) Date: Mon, 29 Apr 2013 11:12:38 -0700 (PDT) Subject: Can read in the BMP data correctly ,but the size is not right? In-Reply-To: References: Message-ID: <2d1c49ed-08b3-4a56-8287-4497e1fb545f@googlegroups.com> Jimmie He? 2013?4?30????UTC+8??1?20?49???? > I'm trying to read in the BMP data by the the code below,and I'm check the data array with WINHEX,and it is correct,but which confuse me is why the size is 0x180,but the actual picture should be 48*48 = 0x120 bytes because I use 1-bit BMP not the 24bit BMP,could any one give some hints? > > > > > > -------------------------------------------------------------------------------- > > __Head_Info = [ > > [ 'Type' ,0 , 2],#BM > > [ 'FSize' ,2 , 4],#File Size > > [ 'Reserved' ,6 , 4],#0x00000000 > > [ 'OffBits' ,10 , 4],#Offset of Image > > [ 'SSize' ,14 , 4],# 40 > > [ 'Width' ,18 , 4],#Width > > [ 'Height' ,22 , 4],#Hight > > [ 'Planes' ,26 , 2],#1 > > [ 'BitCount' ,28 , 2],#{1,2,4,8,24} > > [ 'Compress' ,30 , 4],#0 > > [ 'SizeImage' ,34 , 4],#Bytes Per Line > > [ 'XPM' ,38 , 4],#2835 > > [ 'YPM' ,42 , 4],#2835 > > [ 'ClrUsed' ,46 , 4],#0 > > [ 'ClrImportant' ,50 , 4]#0 > > ] > > _Type =0; > > _FSize =1; > > _Reserved =2; > > _OffBits =3; > > _SSize =4; > > _Width =5; > > _Height =6; > > _Planes =7; > > _BitCount =8; > > _Compress =9; > > _SizeImage =10; > > _XPM =11; > > _YPM =12; > > _ClrUsed =13; > > _ClrImportant =14; > > > > def __getInt( b, idx): > > return binToInt(b,__Head_Info[idx][1],__Head_Info[idx][2]) > > > > def saveMatrixtoASC(bmpfilename,ascfilename): > > try: > > handle1=open( bmpfilename ,"rb") > > raw = bytearray(handle1.read( )) > > handle1.close > > except Exception as E: > > return "error:"+ str(E),"" > > > > datastart=__getInt(raw, _OffBits) > > datasize =__getInt(raw, _SizeImage) > > print ('Image Offset = 0x%X'%datastart) > > print ('Image Size = 0x%X'%datasize) > > handle2=open( ascfilename ,"w") > > for i in range(0,datasize): > > handle2.write('0x%02X,'%raw[datastart+i]) > > if (i+1) % 16 == 0 : > > handle2.write("\n") > > handle2.close The start of each line of bytes must be in the 32 bit=4byte boundary in the MS BMP format. Please read the MS specs. From jimmie.he at gmail.com Tue Apr 30 09:09:52 2013 From: jimmie.he at gmail.com (Jimmie He) Date: Tue, 30 Apr 2013 06:09:52 -0700 (PDT) Subject: Can read in the BMP data correctly ,but the size is not right? In-Reply-To: References: Message-ID: <6fb1e305-22d3-42df-ab08-9e99c91291f7@googlegroups.com> On Tuesday, April 30, 2013 1:57:07 AM UTC+8, Peter Otten wrote: > Jimmie He wrote: > > > > > I'm trying to read in the BMP data by the the code below,and I'm check > > > the data array with WINHEX,and it is correct,but which confuse me is > > > why the size is 0x180,but the actual picture should be 48*48 = 0x120 > > > bytes because I use 1-bit BMP not the 24bit BMP,could any one give some > > > hints? > > > > According to wikipedia > > > > """ > > The size of each row is rounded up to a multiple of 4 bytes [...] > > """ > > > > So 48/8 == 6 will be rounded to 8, and 8*48 == 384 == 0x180. > > > > > handle1=open( bmpfilename ,"rb") > > > raw = bytearray(handle1.read( )) > > > handle1.close > > > > To actually do something the last line should be handle1.close(). I > > recommend > > > > with open(bmpfilename ,"rb") as handle1: > > raw = bytearray(handle1.read()) > > > > instead which has the additional advantage that the file will be closed if > > an exception occurs in the with-suite. I've successfully read the correct data from BMP now by your advice,thanks again Peter and other helpful guy.Especially the BMP_file_format from wiki,very Visualize. From peter at pelican.ucsd.edu Mon Apr 29 15:30:29 2013 From: peter at pelican.ucsd.edu (Peter Rowat) Date: Mon, 29 Apr 2013 12:30:29 -0700 (PDT) Subject: Mystery of module bindings! Message-ID: <201304291930.r3TJUTjc009818@pelican.ucsd.edu> This must be a trivial question: I have "import numpy as np" in the python startup file. A file called mod1.py contains "def myfn..." and inside myfn there is a call to, say, "np.convolve". Interactively: >python .... (numpy imported as np) >import mod1 > >mod1.myfn(...) Error: global name "np" is not known. ======= Why is "np" not known to functions in an imported module ? ======= I can fix this by including "import numpy as np" in any module that uses numpy functions -- but then what is the point of having a startup file? -- PeterR From steve+comp.lang.python at pearwood.info Mon Apr 29 15:49:14 2013 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 29 Apr 2013 19:49:14 GMT Subject: Mystery of module bindings! References: Message-ID: <517eceba$0$29977$c3e8da3$5496439d@news.astraweb.com> On Mon, 29 Apr 2013 12:30:29 -0700, Peter Rowat wrote: > This must be a trivial question: > > I have "import numpy as np" in the python startup file. That only runs interactively. It does not run when you execute a script. > A file called mod1.py contains "def myfn..." > and inside myfn there is a call to, say, "np.convolve". > > Interactively: >>python > .... (numpy imported as np) > >>import mod1 >> >>mod1.myfn(...) > > Error: global name "np" is not known. ======= > Why is "np" not known to functions in an imported module ? ======= Let's suppose it was. What would that mean? Look inside mod1, where there might be a function spam(), and also another function eggs(). spam() calls eggs(), it sees the eggs function in the same module, and all is well with the world. Then you add to the startup file: def eggs(): return "Something unexpected" and all of a sudden mod1.spam() breaks, because it now sees *your* eggs() instead of its eggs. This would be a bad, bad thing. This is why modules are their own namespace, and the interactive interpreter is its own, independent, namespace. What happens in the interactive interpreter stays in the interactive interpreter, without stomping all over every other module. > I can fix this by including "import numpy as np" in any module that uses > numpy functions -- but then what is the point of having a startup file? The point of the startup file is to add things to the interactive interpreter's module, not to inject things into every module in sight. -- Steven From ned at nedbatchelder.com Mon Apr 29 15:50:10 2013 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 29 Apr 2013 15:50:10 -0400 Subject: Mystery of module bindings! In-Reply-To: <201304291930.r3TJUTjc009818@pelican.ucsd.edu> References: <201304291930.r3TJUTjc009818@pelican.ucsd.edu> Message-ID: <517ECEF2.3030705@nedbatchelder.com> On 4/29/2013 3:30 PM, Peter Rowat wrote: > This must be a trivial question: > > I have "import numpy as np" in the python startup file. > > A file called mod1.py contains "def myfn..." > and inside myfn there is a call to, say, "np.convolve". > > Interactively: >> python > .... (numpy imported as np) > >> import mod1 >> >> mod1.myfn(...) > Error: global name "np" is not known. > ======= > Why is "np" not known to functions in an imported module ? > ======= > > I can fix this by including "import numpy as np" in any module that uses numpy > functions -- but then what is the point of having a startup file? The startup file is only for interactive use. Python programs in files shouldn't depend on a startup file, as it will limit their portability. In an interactive session, it's helpful to save some typing, but you can use explicit imports in programs, as they only need to be typed once, and will be used many more times. --Ned. > > -- PeterR From davea at davea.name Mon Apr 29 16:03:50 2013 From: davea at davea.name (Dave Angel) Date: Mon, 29 Apr 2013 16:03:50 -0400 Subject: Mystery of module bindings! In-Reply-To: <201304291930.r3TJUTjc009818@pelican.ucsd.edu> References: <201304291930.r3TJUTjc009818@pelican.ucsd.edu> Message-ID: <517ED226.5090901@davea.name> On 04/29/2013 03:30 PM, Peter Rowat wrote: > This must be a trivial question: > > I have "import numpy as np" in the python startup file. > > A file called mod1.py contains "def myfn..." > and inside myfn there is a call to, say, "np.convolve". > > Interactively: >> python > .... (numpy imported as np) > >> import mod1 >> >> mod1.myfn(...) > > Error: global name "np" is not known. > ======= > Why is "np" not known to functions in an imported module ? > ======= > > I can fix this by including "import numpy as np" in any module that uses numpy > functions Yes, you need a separate import from any module that references numpy. Don't worry about performance, subsequent imports do not take noticeable time, since the module objects are cached. Any time you want to use a symbol from another module, you have to get it somehow. into your own module. You do not have to get it from the import statement, but it's certainly the simplest way, and the way that's usually clearest. Each module represents a namespace, and except for the global namespace which is handled specially, you have to describe which ones you want access to. It's a feature, not a limitation. There are lots of modules automatically imported indirectly by the ones you use. A quick test on a local copy of Python 3.3 shows 51 modules imported before I write any code. I certainly wouldn't want all of them visible in my script's namespace. > -- but then what is the point of having a startup file? > Presumably by startup file, you mean script. Without a script, Python wouldn't have any idea what code to run. You import a few modules, use functionality from them, and lots of things happen behind the scenes. Fortunately for all of us, Python doesn't throw all the symbols into one big pile. -- DaveA From davea at davea.name Mon Apr 29 16:14:14 2013 From: davea at davea.name (Dave Angel) Date: Mon, 29 Apr 2013 16:14:14 -0400 Subject: Mystery of module bindings! In-Reply-To: <517ED226.5090901@davea.name> References: <201304291930.r3TJUTjc009818@pelican.ucsd.edu> <517ED226.5090901@davea.name> Message-ID: <517ED496.5040608@davea.name> On 04/29/2013 04:03 PM, Dave Angel wrote: Please ignore my previous response, obviously I misread your question entirely. I've never used a startup file, so I misread it as "script file". > > Yes, you need a separate import from any module that references numpy. > Don't worry about performance, subsequent imports do not take noticeable > time, since the module objects are cached. and more blathering... > -- DaveA From ethan at stoneleaf.us Mon Apr 29 15:53:32 2013 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 29 Apr 2013 12:53:32 -0700 Subject: Mystery of module bindings! In-Reply-To: <201304291930.r3TJUTjc009818@pelican.ucsd.edu> References: <201304291930.r3TJUTjc009818@pelican.ucsd.edu> Message-ID: <517ECFBC.5050004@stoneleaf.us> On 04/29/2013 12:30 PM, Peter Rowat wrote: > This must be a trivial question: > > I have "import numpy as np" in the python startup file. > > A file called mod1.py contains "def myfn..." > and inside myfn there is a call to, say, "np.convolve". > > Interactively: >> python > .... (numpy imported as np) > >> import mod1 >> >> mod1.myfn(...) > > Error: global name "np" is not known. > ======= > Why is "np" not known to functions in an imported module ? > ======= > > I can fix this by including "import numpy as np" in any module that uses numpy > functions -- but then what is the point of having a startup file? That "fix" is indeed the way things are done. Modules only know about what they import or create*. The point of the startup file is to have things ready for interactive investigation -- if you use numpy *alot* then having it already there beats the heck out of typing `import numpy as np` every time you start the interpreter. -- ~Ethan~ *Unless you start playing with injection and stuff. From eschneider92 at comcast.net Mon Apr 29 20:22:28 2013 From: eschneider92 at comcast.net (eschneider92 at comcast.net) Date: Mon, 29 Apr 2013 17:22:28 -0700 (PDT) Subject: repeat program Message-ID: <6fa77892-53f8-4fe4-a00c-802d292a2cca@googlegroups.com> How do I make the following program repeat twice instead of asking whether the player wants to play again? import random import time def intro(): print('You spot 2 caves in the distance.') print ('You near 2 cave entrances..') time.sleep(1) print('You proceed even nearer...') time.sleep(1) def choosecave(): cave='' while cave!='1' and cave !='2': print('which cave?(1 or 2)') cave=input() return cave def checkcave(chosencave): friendlycave=random.randint(1,2) if chosencave==str(friendlycave): print ('you win') else: print('you lose') playagain='yes' while playagain=='yes': intro() cavenumber=choosecave() checkcave(cavenumber) print('wanna play again?(yes no)') playagain=input() Thanks in advance. From davea at davea.name Mon Apr 29 20:38:41 2013 From: davea at davea.name (Dave Angel) Date: Mon, 29 Apr 2013 20:38:41 -0400 Subject: repeat program In-Reply-To: <6fa77892-53f8-4fe4-a00c-802d292a2cca@googlegroups.com> References: <6fa77892-53f8-4fe4-a00c-802d292a2cca@googlegroups.com> Message-ID: <517F1291.8040705@davea.name> On 04/29/2013 08:22 PM, eschneider92 at comcast.net wrote: > How do I make the following program repeat twice instead of asking whether the player wants to play again? > Turn it into a function call, and call that function twice from top-level. Or, more generally, for i in range(2): doit() > > import random > import time > > def intro(): > print('You spot 2 caves in the distance.') > print ('You near 2 cave entrances..') > time.sleep(1) > print('You proceed even nearer...') > time.sleep(1) > > def choosecave(): > cave='' > while cave!='1' and cave !='2': > print('which cave?(1 or 2)') > cave=input() > return cave > > def checkcave(chosencave): > friendlycave=random.randint(1,2) > if chosencave==str(friendlycave): > print ('you win') > else: > print('you lose') > > playagain='yes' > while playagain=='yes': > intro() > cavenumber=choosecave() > checkcave(cavenumber) > print('wanna play again?(yes no)') > playagain=input() > > Thanks in advance. > -- DaveA From denismfmcmahon at gmail.com Mon Apr 29 20:33:42 2013 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Tue, 30 Apr 2013 00:33:42 +0000 (UTC) Subject: repeat program References: <6fa77892-53f8-4fe4-a00c-802d292a2cca@googlegroups.com> Message-ID: On Mon, 29 Apr 2013 17:22:28 -0700, eschneider92 wrote: > How do I make the following program repeat twice instead of asking > whether the player wants to play again? You change something in the folowing two lines: playagain='yes' while playagain=='yes': What you change and how you change it is probably your homework task, so I really shouldn't tell you any more than that. Also, I might not be right about where you need to make the change, but hey, this is the internet, it must be right, yeah? -- Denis McMahon, denismfmcmahon at gmail.com From python at mrabarnett.plus.com Mon Apr 29 20:43:08 2013 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 30 Apr 2013 01:43:08 +0100 Subject: repeat program In-Reply-To: <6fa77892-53f8-4fe4-a00c-802d292a2cca@googlegroups.com> References: <6fa77892-53f8-4fe4-a00c-802d292a2cca@googlegroups.com> Message-ID: <517F139C.6060802@mrabarnett.plus.com> On 30/04/2013 01:22, eschneider92 at comcast.net wrote: > How do I make the following program repeat twice instead of asking whether the player wants to play again? > > > import random > import time > > def intro(): > print('You spot 2 caves in the distance.') > print ('You near 2 cave entrances..') > time.sleep(1) > print('You proceed even nearer...') > time.sleep(1) > > def choosecave(): > cave='' > while cave!='1' and cave !='2': > print('which cave?(1 or 2)') > cave=input() > return cave > > def checkcave(chosencave): > friendlycave=random.randint(1,2) > if chosencave==str(friendlycave): > print ('you win') > else: > print('you lose') > > playagain='yes' > while playagain=='yes': > intro() > cavenumber=choosecave() > checkcave(cavenumber) > print('wanna play again?(yes no)') > playagain=input() > > Thanks in advance. > Replace the 'while' loop with a 'for' loop that loops twice. By the way, there's a bug in 'choosecave': what happens if the user enters, say, '3'? From ian.g.kelly at gmail.com Mon Apr 29 21:46:00 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 29 Apr 2013 19:46:00 -0600 Subject: repeat program In-Reply-To: <517F139C.6060802@mrabarnett.plus.com> References: <6fa77892-53f8-4fe4-a00c-802d292a2cca@googlegroups.com> <517F139C.6060802@mrabarnett.plus.com> Message-ID: On Mon, Apr 29, 2013 at 6:43 PM, MRAB wrote: > By the way, there's a bug in 'choosecave': what happens if the user > enters, say, '3'? Then they lose. :-) From info at egenix.com Tue Apr 30 04:41:28 2013 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Tue, 30 Apr 2013 10:41:28 +0200 Subject: ANN: eGenix PyRun - One file Python Runtime 1.2.0 Message-ID: <517F83B8.5090205@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix PyRun - One file Python Runtime Version 1.2.0 An easy-to-use single file relocatable Python run-time - available for Windows, Mac OS X and Unix platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-PyRun-1.2.0.html ________________________________________________________________________ INTRODUCTION Our new eGenix PyRun combines a Python interpreter with an almost complete Python standard library into a single easy-to-use executable, that does not require a system wide installation and is fully relocatable. eGenix PyRun's executable only needs 11MB, but still supports most Python application and scripts - and it can be further compressed to just 3-4MB using upx. Compared to a regular Python installation of typically 100MB on disk, this makes eGenix PyRun ideal for applications and scripts that need to be distributed to many target machines, client installations or customers. It makes "installing" Python on a Unix based system as simple as copying a single file. We have been using the product internally in our mxODBC Connect Server since 2008 with great success and have now extracted it into a stand-alone open-source product. We provide both the source archive to build your own eGenix PyRun, as well as pre-compiled binaries for Linux, FreeBSD and Mac OS X, as 32- and 64-bit versions. Please see the product page for more details: http://www.egenix.com/products/python/PyRun/ ________________________________________________________________________ NEWS This is a new minor release of eGenix PyRun, which contains a few important fixes and enhancement based on the user feedback in recent months. New Features ------------ * Upgraded eGenix PyRun to work with and use Python 2.7.4 per default. * Changed the pyrun default to run in non-optimized mode and added the -O command line option to reenable it. Previous versions of eGenix PyRun used to default to optimized mode, which prevented running tests using e.g. assert with it. The stdlib itself is still frozen in optimized mode. * Added support for directly running Python directories and ZIP files with __main__ module. Only works with the Python 2.7 variant. * eGenix PyRun now honors symlinks, so symlinked copies of PyRun can be used to save disk space. The installations will still work as expected, i.e. independent of each other. * Added new pyrun_release config variable to the pyrun_config module. This allows checking the pyrun release version. * Added PyRun release version to the banner and -V output. * Added support for the Python -d command line option to pyrun. * Added a fix to allow PyRun to compile the sqlite module on Mac OS X 10.4. See http://bugs.python.org/issue17857 for details. * Much enhanced documentation, which now also explains the internals and highlights Python modules/packages that are not included in eGenix PyRun. Other Changes ------------- * Removed the compiler package from being compiled into PyRun. If needed, it can be installed separately. Note that the compiler package needs the parser module which is not compiled into PyRun either, but is still available as extension module. * Removed the Tkinter Python module from being compiled into PyRun. If needed, it can be installed separately. Note that the Tkinter module needs the _tkinter C module, which is not compiled into PyRun either, but is still available as extension module. * Fixed sys.argv when using interactive mode to default to ['']. * All eGenix PyRun distribution packages are now GPG signed with our release key and come with MD5 and SHA1 hashes to check for download corruption. install-pyrun Quick Installation Enhancements --------------------------------------------- Since version 1.1.0, eGenix PyRun includes a shell script called install-pyrun, which greatly simplifies installation of eGenix PyRun. It works much like the virtualenv shell script used for creating new virtual environments (except that there's nothing virtual about PyRun environments). https://downloads.egenix.com/python/install-pyrun With the script, an eGenix PyRun installation is as simple as running: ./install-pyrun targetdir We have enhanced this script somewhat since the last release and also added it to the source code distribution of eGenix PyRun: * Added new options --distribute-distribution and --pip-distribution to be able to use local distribution files for distribute and pip. * Added --debug option to enable debug output. * install-pyrun will now try uname -m in case uname -p doesn't return useful information about the platform. * install-pyrun will now use HTTPS connections for all tools (pyrun, distribute and pip). SSL certificate checking is enabled per default, but can be turned off using the new --disable-certificate-checks option. * Added automatic support for wget to install-pyrun. It is being used if curl is not found on the system. * Added new option --platform-list to print a list of available platform strings. Presentation at EuroPython 2012 ------------------------------- Marc-Andr? Lemburg, CEO of eGenix, gave a presentation about eGenix PyRun at EuroPython 2012 last year. The talk video as well as the slides are available on our website: http://www.egenix.com/library/presentations/EuroPython2012-eGenix-PyRun/ ________________________________________________________________________ LICENSE eGenix PyRun 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 eGenix PyRun in both commercial and non-commercial settings without fee or charge. Please see our license page for more details: http://www.egenix.com/products/python/PyRun/license.html The package comes with full source code. ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing eGenix PyRun can be found at: http://www.egenix.com/products/python/PyRun/ 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 other platforms, such as Solaris, AIX, HP-UX, etc. _______________________________________________________________________ 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. ________________________________________________________________________ MORE INFORMATION For more information about eGenix PyRun, licensing and download instructions, please visit our web-site: http://www.egenix.com/products/python/PyRun/ About Python (http://www.python.org/): Python is an object-oriented Open Source programming language which runs on all modern platforms. By integrating ease-of-use, clarity in coding, enterprise application connectivity and rapid application design, Python establishes an ideal programming platform for today's IT challenges. About eGenix (http://www.egenix.com/): eGenix is a software project, consulting and product company specializing in expert project services and professional quality products for companies, Python users and developers. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Apr 30 2013) >>> Python Projects, Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2013-04-17: Released eGenix mx Base 3.2.6 ... http://egenix.com/go43 ::::: Try our 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 moraa.lovetakes2 at gmail.com Tue Apr 30 07:50:31 2013 From: moraa.lovetakes2 at gmail.com (Ombongi Moraa Fe) Date: Tue, 30 Apr 2013 14:50:31 +0300 Subject: Passing special characters in soap data Message-ID: Hi Team, My provider sends soap data to me as they receive from subscriber. as expected the messages with special characters like quotes are received as html entities. like the message below had a quote: I'll shape it up myself... Since i pass this data into my python script as a command line call, i get the error: /bin/sh: Syntax error: Unterminated quoted string how can i resolve this and any other html entities i receive? Saludos Ombongi Moraa Faith -------------- next part -------------- An HTML attachment was scrubbed... URL: From gordon at panix.com Tue Apr 30 10:08:07 2013 From: gordon at panix.com (John Gordon) Date: Tue, 30 Apr 2013 14:08:07 +0000 (UTC) Subject: Passing special characters in soap data References: Message-ID: In Ombongi Moraa Fe writes: > My provider sends soap data to me as they receive from subscriber. as > expected the messages with special characters like quotes are received as > html entities. > like the message below had a quote: > ...I'll shape it up myself... > > Since i pass this data into my python script as a command line call, i get > the error: > /bin/sh: Syntax error: Unterminated quoted string Can you modify your python script so it accepts a filename which contains the xml? -- 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 tromeo at mdlogix.com Tue Apr 30 11:27:36 2013 From: tromeo at mdlogix.com (tromeo at mdlogix.com) Date: Tue, 30 Apr 2013 08:27:36 -0700 (PDT) Subject: shmid = shmget(SHM_KEY, SHM_SIZE, 0o666) - syntax error. Message-ID: Please help me to debug ------- shmid = shmget(SHM_KEY, SHM_SIZE, 0o666) ^ SyntaxError: invalid syntax ---- here is the code Ref: http://www.welivesecurity.com/2013/04/26/linuxcdorked-new-apache-backdoor-in-the-wild-serves-blackhole/ --- #!/usr/bin/env python # -*- coding: utf-8 -*- # # This script dumps the content of a shared memory block # used by Linux/Cdorked.A into a file named httpd_cdorked_config.bin # when the machine is infected. # # Some of the data is encrypted. If your server is infected and you # would like to help, please send the httpd_cdorked_config.bin # to our lab for analysis. Thanks! # # Marc-Etienne M.L?veill? # from ctypes import * SHM_SIZE = 6118512 SHM_KEY = 63599 OUTFILE="httpd_cdorked_config.bin" try: rt = CDLL('librt.so') except: rt = CDLL('librt.so.1') shmget = rt.shmget shmget.argtypes = [c_int, c_size_t, c_int] shmget.restype = c_int shmat = rt.shmat shmat.argtypes = [c_int, POINTER(c_void_p), c_int] shmat.restype = c_void_p shmid = shmget(SHM_KEY, SHM_SIZE, 0o666) if shmid < 0: print "System not infected" else: addr = shmat(shmid, None, 0) f = file(OUTFILE, 'wb') f.write(string_at(addr,SHM_SIZE)) f.close() print "Dumped %d bytes in %s" % (SHM_SIZE, OUTFILE) From joel.goldstick at gmail.com Tue Apr 30 11:36:48 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 30 Apr 2013 11:36:48 -0400 Subject: shmid = shmget(SHM_KEY, SHM_SIZE, 0o666) - syntax error. In-Reply-To: References: Message-ID: On Tue, Apr 30, 2013 at 11:27 AM, wrote: > > Please help me to debug > > ------- > shmid = shmget(SHM_KEY, SHM_SIZE, 0o666) > ^ > SyntaxError: invalid syntax > > If you google 0o666 python you see that if some version of python need 0666 It was unclear to me whether this changed after 2.6. Does anyone else have experience with this? > > ---- > here is the code > Ref: > http://www.welivesecurity.com/2013/04/26/linuxcdorked-new-apache-backdoor-in-the-wild-serves-blackhole/ > > --- > #!/usr/bin/env python > # -*- coding: utf-8 -*- > # > # This script dumps the content of a shared memory block > # used by Linux/Cdorked.A into a file named httpd_cdorked_config.bin > # when the machine is infected. > # > # Some of the data is encrypted. If your server is infected and you > # would like to help, please send the httpd_cdorked_config.bin > # to our lab for analysis. Thanks! > # > # Marc-Etienne M.L?veill? > # > > from ctypes import * > > SHM_SIZE = 6118512 > SHM_KEY = 63599 > > OUTFILE="httpd_cdorked_config.bin" > > try: > rt = CDLL('librt.so') > except: > rt = CDLL('librt.so.1') > > shmget = rt.shmget > shmget.argtypes = [c_int, c_size_t, c_int] > shmget.restype = c_int > shmat = rt.shmat > shmat.argtypes = [c_int, POINTER(c_void_p), c_int] > shmat.restype = c_void_p > > shmid = shmget(SHM_KEY, SHM_SIZE, 0o666) > if shmid < 0: > print "System not infected" > else: > addr = shmat(shmid, None, 0) > > f = file(OUTFILE, 'wb') > f.write(string_at(addr,SHM_SIZE)) > f.close() > > print "Dumped %d bytes in %s" % (SHM_SIZE, OUTFILE) > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Apr 30 11:37:59 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 May 2013 01:37:59 +1000 Subject: shmid = shmget(SHM_KEY, SHM_SIZE, 0o666) - syntax error. In-Reply-To: References: Message-ID: On Wed, May 1, 2013 at 1:27 AM, wrote: > > Please help me to debug > > ------- > shmid = shmget(SHM_KEY, SHM_SIZE, 0o666) > ^ > SyntaxError: invalid syntax In Python 2, just use 0666. ChrisA From davea at davea.name Tue Apr 30 11:43:06 2013 From: davea at davea.name (Dave Angel) Date: Tue, 30 Apr 2013 11:43:06 -0400 Subject: shmid = shmget(SHM_KEY, SHM_SIZE, 0o666) - syntax error. In-Reply-To: References: Message-ID: <517FE68A.1000703@davea.name> On 04/30/2013 11:27 AM, tromeo at mdlogix.com wrote: > > Please help me to debug > > ------- > shmid = shmget(SHM_KEY, SHM_SIZE, 0o666) > ^ > SyntaxError: invalid syntax > 0o666 is indeed a syntax error. What is that value supposed to be? If it's intended to be an int that's equal to octal 666, just use 438 -- DaveA From rosuav at gmail.com Tue Apr 30 11:49:11 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 May 2013 01:49:11 +1000 Subject: shmid = shmget(SHM_KEY, SHM_SIZE, 0o666) - syntax error. In-Reply-To: <517FE68A.1000703@davea.name> References: <517FE68A.1000703@davea.name> Message-ID: On Wed, May 1, 2013 at 1:43 AM, Dave Angel wrote: > On 04/30/2013 11:27 AM, tromeo at mdlogix.com wrote: >> >> >> Please help me to debug >> >> ------- >> shmid = shmget(SHM_KEY, SHM_SIZE, 0o666) >> ^ >> SyntaxError: invalid syntax >> > > 0o666 is indeed a syntax error. What is that value supposed to be? If it's > intended to be an int that's equal to octal 666, just use 438 Without checking docs, I would guess that to be Unix file permissions, which make most sense in octal. ChrisA From davea at davea.name Tue Apr 30 11:58:33 2013 From: davea at davea.name (Dave Angel) Date: Tue, 30 Apr 2013 11:58:33 -0400 Subject: shmid = shmget(SHM_KEY, SHM_SIZE, 0o666) - syntax error. In-Reply-To: References: <517FE68A.1000703@davea.name> Message-ID: <517FEA29.1010006@davea.name> On 04/30/2013 11:49 AM, Chris Angelico wrote: > On Wed, May 1, 2013 at 1:43 AM, Dave Angel wrote: >> On 04/30/2013 11:27 AM, tromeo at mdlogix.com wrote: >>> >>> >>> Please help me to debug >>> >>> ------- >>> shmid = shmget(SHM_KEY, SHM_SIZE, 0o666) >>> ^ >>> SyntaxError: invalid syntax >>> >> >> 0o666 is indeed a syntax error. What is that value supposed to be? If it's >> intended to be an int that's equal to octal 666, just use 438 > > Without checking docs, I would guess that to be Unix file permissions, > which make most sense in octal. > > So put the octal description in the comment. I think the Python 2.x syntax for octal is a travesty. And of course it's non-portable to Python 3. I would not intentionally leave 0666 in my source code, unless there was some other overriding reason for it. And then I'd surround it with snide remarks. -- DaveA From rosuav at gmail.com Tue Apr 30 12:06:43 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 May 2013 02:06:43 +1000 Subject: shmid = shmget(SHM_KEY, SHM_SIZE, 0o666) - syntax error. In-Reply-To: <517FEA29.1010006@davea.name> References: <517FE68A.1000703@davea.name> <517FEA29.1010006@davea.name> Message-ID: On Wed, May 1, 2013 at 1:58 AM, Dave Angel wrote: > On 04/30/2013 11:49 AM, Chris Angelico wrote: >> >> On Wed, May 1, 2013 at 1:43 AM, Dave Angel wrote: >>> >>> On 04/30/2013 11:27 AM, tromeo at mdlogix.com wrote: >>>> >>>> >>>> >>>> Please help me to debug >>>> >>>> ------- >>>> shmid = shmget(SHM_KEY, SHM_SIZE, 0o666) >>>> ^ >>>> SyntaxError: invalid syntax >>>> >>> >>> 0o666 is indeed a syntax error. What is that value supposed to be? If >>> it's >>> intended to be an int that's equal to octal 666, just use 438 >> >> >> Without checking docs, I would guess that to be Unix file permissions, >> which make most sense in octal. >> >> > > So put the octal description in the comment. I think the Python 2.x syntax > for octal is a travesty. And of course it's non-portable to Python 3. I > would not intentionally leave 0666 in my source code, unless there was some > other overriding reason for it. And then I'd surround it with snide > remarks. Here's a stupid way to convert octal to decimal in Python: >>> ord("\666") 438 Because backslash escapes in strings are, per convention, done in octal. :) And actually, on the extremely rare occasions when they're NOT octal, it's highly confusing. http://rosuav.blogspot.com.au/2012/12/i-want-my-octal.html ChrisA From tromeo at mdlogix.com Tue Apr 30 14:10:19 2013 From: tromeo at mdlogix.com (Tony Romeo) Date: Tue, 30 Apr 2013 11:10:19 -0700 (PDT) Subject: shmid = shmget(SHM_KEY, SHM_SIZE, 0o666) - syntax error. In-Reply-To: References: <517FE68A.1000703@davea.name> <517FEA29.1010006@davea.name> Message-ID: Updating to 2.5+ resolved the error. Thank you --- Here is the old info ....: [mongrel at crms-demo ~]$ rpm -qi python Name : python Relocations: (not relocatable) Version : 2.4.3 Vendor: CentOS Release : 56.el5 Build Date: Wed 09 Jan 2013 06:54:47 AM EST Install Date: Tue 30 Apr 2013 09:34:22 AM EDT Build Host: builder10.centos.org Group : Development/Languages Source RPM: python-2.4.3-56.el5.src.rpm Size : 73121 License: PSF - see LICENSE Signature : DSA/SHA1, Wed 09 Jan 2013 03:35:41 PM EST, Key ID a8a447dce8562897 URL : http://www.python.org/ Summary : An interpreted, interactive, object-oriented programming language. Description : Python is an interpreted, interactive, object-oriented programming language often compared to Tcl, Perl, Scheme or Java. Python includes modules, classes, exceptions, very high level dynamic data types and dynamic typing. Python supports interfaces to many system calls and libraries, as well as to various windowing systems (X11, Motif, Tk, Mac and MFC). Programmers can write new built-in modules for Python in C or C++. Python can be used as an extension language for applications that need a programmable interface. This package contains most of the standard Python modules, as well as modules for interfacing to the Tix widget set for Tk and RPM. Note that documentation for Python is provided in the python-docs package. From rosuav at gmail.com Tue Apr 30 17:51:27 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 May 2013 07:51:27 +1000 Subject: shmid = shmget(SHM_KEY, SHM_SIZE, 0o666) - syntax error. In-Reply-To: References: <517FE68A.1000703@davea.name> <517FEA29.1010006@davea.name> Message-ID: On Wed, May 1, 2013 at 4:10 AM, Tony Romeo wrote: > Updating to 2.5+ resolved the error. > > Here is the old info ....: > Version : 2.4.3 Vendor: CentOS Yup, that would be it! Did you get as far as 2.7? Once you're there, you'll never have to worry about upgrading Python 2 again (there'll be bugfix releases but no feature changes). Of course, upgrading to 3.3 would be even better, but that's likely to involve a lot more work updating your code :) ChrisA From tromeo at mdlogix.com Tue Apr 30 11:52:22 2013 From: tromeo at mdlogix.com (Tony Romeo) Date: Tue, 30 Apr 2013 08:52:22 -0700 (PDT) Subject: shmid = shmget(SHM_KEY, SHM_SIZE, 0o666) - syntax error. In-Reply-To: References: Message-ID: <574ce3d3-8848-4136-a635-728d8cf3db85@googlegroups.com> Thank you for the response. Results after using 0666: Traceback (most recent call last): File "dump_cdorked_config.py", line 15, in ? from ctypes import * ImportError: No module named ctypes From rosuav at gmail.com Tue Apr 30 11:58:52 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 May 2013 01:58:52 +1000 Subject: shmid = shmget(SHM_KEY, SHM_SIZE, 0o666) - syntax error. In-Reply-To: <574ce3d3-8848-4136-a635-728d8cf3db85@googlegroups.com> References: <574ce3d3-8848-4136-a635-728d8cf3db85@googlegroups.com> Message-ID: On Wed, May 1, 2013 at 1:52 AM, Tony Romeo wrote: > Thank you for the response. > > Results after using 0666: > > > Traceback (most recent call last): > File "dump_cdorked_config.py", line 15, in ? > from ctypes import * > ImportError: No module named ctypes You really need to offer a lot more information about your environment :) What operating system, what Python version, etc, etc? The ctypes module is listed in the docs as "new in 2.5", so my crystal ball is saying you quite probably are on Red Hat. http://docs.python.org/2/library/ctypes.html ChrisA From rmorgan466 at gmail.com Tue Apr 30 12:25:41 2013 From: rmorgan466 at gmail.com (Rita) Date: Tue, 30 Apr 2013 12:25:41 -0400 Subject: python process accounting Message-ID: Hi, I was wondering if it possible to write a python wrapper which will account my processes. I would like to account for all the children processes (fork) by looking at their /proc/ info. Such as memory, io, open files, stats. So, instead of me running "/bin/sleep 10", i would like to run it as "pywrap.py /bin/sleep 10" and it will do an exec /bin/sleep 10 and do a periodic snapshot for whats in /proc//stats. -- --- Get your facts first, then you can distort them as you please.-- -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Tue Apr 30 12:38:44 2013 From: davea at davea.name (Dave Angel) Date: Tue, 30 Apr 2013 12:38:44 -0400 Subject: python process accounting In-Reply-To: References: Message-ID: <517FF394.9040701@davea.name> On 04/30/2013 12:25 PM, Rita wrote: > Hi, > > I was wondering if it possible to write a python wrapper which will account > my processes. I would like to account for all the children processes (fork) > by looking at their /proc/ info. Such as memory, io, open files, > stats. > > So, instead of me running "/bin/sleep 10", i would like to run it as > "pywrap.py /bin/sleep 10" and it will do an exec /bin/sleep 10 and do a > periodic snapshot for whats in /proc//stats. > > I only understood a quarter of that. But if you want to sleep, why not just call time.sleep ? import os while True: os.sleep(10) ... do some stuff with the processes. If you want help in the other portion, you'd better explain: <<<<<< Running Python xx.xx in Operating System yy. From the bash prompt, I'd like to do: zzzzz, and zzzz And here's what I mean by child processes. Children of the current bash shell? Or what? <<<<<< -- DaveA From davea at davea.name Tue Apr 30 12:49:58 2013 From: davea at davea.name (Dave Angel) Date: Tue, 30 Apr 2013 12:49:58 -0400 Subject: python process accounting In-Reply-To: <517FF394.9040701@davea.name> References: <517FF394.9040701@davea.name> Message-ID: <517FF636.60407@davea.name> On 04/30/2013 12:38 PM, Dave Angel wrote: Oops, a typo. See below. > On 04/30/2013 12:25 PM, Rita wrote: >> Hi, >> >> I was wondering if it possible to write a python wrapper which will >> account >> my processes. I would like to account for all the children processes >> (fork) >> by looking at their /proc/ info. Such as memory, io, open files, >> stats. >> >> So, instead of me running "/bin/sleep 10", i would like to run it as >> "pywrap.py /bin/sleep 10" and it will do an exec /bin/sleep 10 and do a >> periodic snapshot for whats in /proc//stats. >> >> > > I only understood a quarter of that. But if you want to sleep, why not > just call time.sleep ? > import time while True: time.sleep(10) ... do some stuff with the processes. > > If you want help in the other portion, you'd better explain: > > <<<<<< > Running Python xx.xx in Operating System yy. > > From the bash prompt, I'd like to do: > zzzzz, and zzzz > > And here's what I mean by child processes. Children of the current bash > shell? Or what? > <<<<<< -- DaveA From robert.kern at gmail.com Tue Apr 30 13:54:42 2013 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 30 Apr 2013 18:54:42 +0100 Subject: python process accounting In-Reply-To: <517FF394.9040701@davea.name> References: <517FF394.9040701@davea.name> Message-ID: On 2013-04-30 17:38, Dave Angel wrote: > On 04/30/2013 12:25 PM, Rita wrote: >> Hi, >> >> I was wondering if it possible to write a python wrapper which will account >> my processes. I would like to account for all the children processes (fork) >> by looking at their /proc/ info. Such as memory, io, open files, >> stats. >> >> So, instead of me running "/bin/sleep 10", i would like to run it as >> "pywrap.py /bin/sleep 10" and it will do an exec /bin/sleep 10 and do a >> periodic snapshot for whats in /proc//stats. > > I only understood a quarter of that. But if you want to sleep, why not just > call time.sleep ? I think that was just a placeholder example, not the program he actually wants to measure. -- 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 rmorgan466 at gmail.com Tue Apr 30 14:11:20 2013 From: rmorgan466 at gmail.com (Rita) Date: Tue, 30 Apr 2013 14:11:20 -0400 Subject: python process accounting In-Reply-To: References: <517FF394.9040701@davea.name> Message-ID: Exactly, its a place holder measure. Currently, I have a shell program like this. #!/usr/bin/env bash exec "$@" Any thoughts how I can put python in there? On Tue, Apr 30, 2013 at 1:54 PM, Robert Kern wrote: > On 2013-04-30 17:38, Dave Angel wrote: > >> On 04/30/2013 12:25 PM, Rita wrote: >> >>> Hi, >>> >>> I was wondering if it possible to write a python wrapper which will >>> account >>> my processes. I would like to account for all the children processes >>> (fork) >>> by looking at their /proc/ info. Such as memory, io, open files, >>> stats. >>> >>> So, instead of me running "/bin/sleep 10", i would like to run it as >>> "pywrap.py /bin/sleep 10" and it will do an exec /bin/sleep 10 and do a >>> periodic snapshot for whats in /proc//stats. >>> >> >> I only understood a quarter of that. But if you want to sleep, why not >> just >> call time.sleep ? >> > > I think that was just a placeholder example, not the program he actually > wants to measure. > > -- > 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 > -- --- Get your facts first, then you can distort them as you please.-- -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Tue Apr 30 14:19:35 2013 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 30 Apr 2013 19:19:35 +0100 Subject: python process accounting In-Reply-To: References: Message-ID: On 2013-04-30 17:25, Rita wrote: > Hi, > > I was wondering if it possible to write a python wrapper which will account my > processes. I would like to account for all the children processes (fork) by > looking at their /proc/ info. Such as memory, io, open files, stats. > > So, instead of me running "/bin/sleep 10", i would like to run it as "pywrap.py > /bin/sleep 10" and it will do an exec /bin/sleep 10 and do a periodic snapshot > for whats in /proc//stats. Something like this is approximately the right structure for such a program. #!/usr/bin/env python import sys import subprocess import time PERIOD = 1.0 # seconds def check_stats(pid): # You will have to implement this. # Check out psutil: # https://pypi.python.org/pypi/psutil print 'Checking process {0}'.format(pid) def main(): cmd = sys.argv[1:] p = subprocess.Popen(cmd) while p.poll() is None: check_stats(p.pid) # There are more accurate ways to do this, but this probably # suffices for you. time.sleep(PERIOD) if __name__ == '__main__': main() -- 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 g.rodola at gmail.com Tue Apr 30 13:18:56 2013 From: g.rodola at gmail.com (Giampaolo Rodola') Date: Tue, 30 Apr 2013 19:18:56 +0200 Subject: python process accounting In-Reply-To: References: Message-ID: 2013/4/30 Rita : > Hi, > > I was wondering if it possible to write a python wrapper which will account > my processes. I would like to account for all the children processes (fork) > by looking at their /proc/ info. Such as memory, io, open files, stats. > > So, instead of me running "/bin/sleep 10", i would like to run it as > "pywrap.py /bin/sleep 10" and it will do an exec /bin/sleep 10 and do a > periodic snapshot for whats in /proc//stats. > > > > > -- > --- Get your facts first, then you can distort them as you please.-- > > -- > http://mail.python.org/mailman/listinfo/python-list > Not sure what you're talking about expect for the process management part in which case it seems you're looking for psutil: https://code.google.com/p/psutil/#Process_management In detail, if you want to work with process children: >>> import psutil, os >>> thisproc = psutil.Process(os.getpid()) >>> for child in thisproc.get_children(): ... print child.name ... print child.get_memory_info() ... print child.get_open_files() ... --- Giampaolo https://code.google.com/p/pyftpdlib/ https://code.google.com/p/psutil/ https://code.google.com/p/pysendfile/ From upendrakumar.devisetty at googlemail.com Tue Apr 30 13:41:56 2013 From: upendrakumar.devisetty at googlemail.com (upendra kumar Devisetty) Date: Tue, 30 Apr 2013 10:41:56 -0700 (PDT) Subject: how to compare two fields in python Message-ID: <59afdc2b-ab76-40b6-8f63-4a562e288029@googlegroups.com> I have a very basic question in python. I want to go through each line of the a csv file and compare to see if the first field of line 1 is same as first field of next line and so on. If it finds a match then i would like to put that field in an object1 else put that field in a different object2. Finally i would like to count how many of the fields in object1 vs object2. Can this be done in python? Here is a small example. BRM_1 679 1929 BRM_1 203 567 BRM_2 367 1308 BRM_3 435 509 As you can see field1 of line1 is same as field2 of line2 and so that field BRM_1 should be place in object1 and BRM_2 and BRM_3 should be placed in object2. So the final numbers of object1 is 1 and object2 is 2. Thanks in advance.. Upendra From joel.goldstick at gmail.com Tue Apr 30 13:53:40 2013 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 30 Apr 2013 13:53:40 -0400 Subject: how to compare two fields in python In-Reply-To: <59afdc2b-ab76-40b6-8f63-4a562e288029@googlegroups.com> References: <59afdc2b-ab76-40b6-8f63-4a562e288029@googlegroups.com> Message-ID: On Tue, Apr 30, 2013 at 1:41 PM, upendra kumar Devisetty < upendrakumar.devisetty at googlemail.com> wrote: > I have a very basic question in python. I want to go through each line of > the a csv file and compare to see if the first field of line 1 is same as > first field of next line and so on. If it finds a match then i would like > to put that field in an object1 else put that field in a different object2. > Finally i would like to count how many of the fields in object1 vs object2. > Can this be done in python? Here is a small example. > > BRM_1 679 1929 > BRM_1 203 567 > BRM_2 367 1308 > BRM_3 435 509 > As you can see field1 of line1 is same as field2 of line2 and so that > field BRM_1 should be place in object1 and BRM_2 and BRM_3 should be placed > in object2. So the final numbers of object1 is 1 and object2 is 2. > > You should study the csv module. > Thanks in advance.. > > Upendra > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From fabiosantosart at gmail.com Tue Apr 30 14:08:53 2013 From: fabiosantosart at gmail.com (=?ISO-8859-1?Q?F=E1bio_Santos?=) Date: Tue, 30 Apr 2013 19:08:53 +0100 Subject: how to compare two fields in python In-Reply-To: References: <59afdc2b-ab76-40b6-8f63-4a562e288029@googlegroups.com> Message-ID: ... And collections.Counter. This is useful for (you guessed it) counting. Maybe itertools.groupby will be helpful as well (it could be used to give you your data grouped by the first column of data), but it could be a tad advanced for you if you are not too familiar with iterators. -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Tue Apr 30 14:19:56 2013 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 30 Apr 2013 13:19:56 -0500 Subject: how to compare two fields in python In-Reply-To: <59afdc2b-ab76-40b6-8f63-4a562e288029@googlegroups.com> References: <59afdc2b-ab76-40b6-8f63-4a562e288029@googlegroups.com> Message-ID: <20130430131956.5cd18e0e@bigbox.christie.dr> On 2013-04-30 10:41, upendra kumar Devisetty wrote: > I have a very basic question in python. I want to go through each > line of the a csv file and compare to see if the first field of > line 1 is same as first field of next line and so on. If it finds a > match then i would like to put that field in an object1 else put > that field in a different object2. Finally i would like to count > how many of the fields in object1 vs object2. Can this be done in > python? Here is a small example. > > BRM_1 679 1929 > BRM_1 203 567 > BRM_2 367 1308 > BRM_3 435 509 > As you can see field1 of line1 is same as field2 of line2 and so > that field BRM_1 should be place in object1 and BRM_2 and BRM_3 > should be placed in object2. So the final numbers of object1 is 1 > and object2 is 2. You underdefine the problem. What happens in the case of: BRM_1 ... BRM_1 ... BRM_2 ... BRM_1 ... <-- duplicates a (not-immediately) previous line BRM_3 ... Also, do the values that follow have any significance for this, or are they just noise to be ignored? -tkc From upendrakumar.devisetty at googlemail.com Tue Apr 30 14:22:06 2013 From: upendrakumar.devisetty at googlemail.com (upendra kumar Devisetty) Date: Tue, 30 Apr 2013 11:22:06 -0700 (PDT) Subject: how to compare two fields in python In-Reply-To: References: <59afdc2b-ab76-40b6-8f63-4a562e288029@googlegroups.com> Message-ID: The data was sorted and so duplicates will not appear anywhere in the dataframe. The values does not have significance and can be ignored safely. Thanks Upendra On Tuesday, April 30, 2013 11:19:56 AM UTC-7, Tim Chase wrote: > On 2013-04-30 10:41, upendra kumar Devisetty wrote: > > > I have a very basic question in python. I want to go through each > > > line of the a csv file and compare to see if the first field of > > > line 1 is same as first field of next line and so on. If it finds a > > > match then i would like to put that field in an object1 else put > > > that field in a different object2. Finally i would like to count > > > how many of the fields in object1 vs object2. Can this be done in > > > python? Here is a small example. > > > > > > BRM_1 679 1929 > > > BRM_1 203 567 > > > BRM_2 367 1308 > > > BRM_3 435 509 > > > As you can see field1 of line1 is same as field2 of line2 and so > > > that field BRM_1 should be place in object1 and BRM_2 and BRM_3 > > > should be placed in object2. So the final numbers of object1 is 1 > > > and object2 is 2. > > > > You underdefine the problem. What happens in the case of: > > > > BRM_1 ... > > BRM_1 ... > > BRM_2 ... > > BRM_1 ... <-- duplicates a (not-immediately) previous line > > BRM_3 ... > > > > Also, do the values that follow have any significance for this, or > > are they just noise to be ignored? > > > > -tkc From fabiosantosart at gmail.com Tue Apr 30 14:42:35 2013 From: fabiosantosart at gmail.com (=?ISO-8859-1?Q?F=E1bio_Santos?=) Date: Tue, 30 Apr 2013 19:42:35 +0100 Subject: how to compare two fields in python In-Reply-To: References: <59afdc2b-ab76-40b6-8f63-4a562e288029@googlegroups.com> Message-ID: > The data was sorted and so duplicates will not appear anywhere in the dataframe. > I guess that's it. Use the standard csv module and itertools.groupby. Groupby will produce a list of grouped objects. So you can group by the first column by supplying a key function which just returns the first column. Check this out for an example: http://stackoverflow.com/questions/773/how-do-i-use-pythons-itertools-groupby(most upvoted answer) -------------- next part -------------- An HTML attachment was scrubbed... URL: From ayjayn1101 at gmail.com Tue Apr 30 18:06:55 2013 From: ayjayn1101 at gmail.com (Alex Norton) Date: Tue, 30 Apr 2013 15:06:55 -0700 (PDT) Subject: in need of some help... Message-ID: <1bdc367a-4187-440b-85a8-de69360bc71d@googlegroups.com> hi, i am currently trying to make a rock paper scissors game based on a game. the code for the game itself works fine, it does what i need it to do the issue i am having is that i haven't a clue how to combine the game code i have with the QT GUI code i have. From rosuav at gmail.com Tue Apr 30 18:13:24 2013 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 May 2013 08:13:24 +1000 Subject: in need of some help... In-Reply-To: <1bdc367a-4187-440b-85a8-de69360bc71d@googlegroups.com> References: <1bdc367a-4187-440b-85a8-de69360bc71d@googlegroups.com> Message-ID: On Wed, May 1, 2013 at 8:06 AM, Alex Norton wrote: > > hi, > > i am currently trying to make a rock paper scissors game based on a game. > > the code for the game itself works fine, it does what i need it to do > > the issue i am having is that i haven't a clue how to combine the game code i have with the QT GUI code i have. Poke around with some QT examples, or play with Tkinter (which comes with Python). Get a "hello, world" going, then expand on it. If you get stuck, come back to the list with a bit more information and, preferably, code; at the moment, your request is so vague that all I can offer is highly general advice. ChrisA From ayjayn1101 at gmail.com Tue Apr 30 18:30:34 2013 From: ayjayn1101 at gmail.com (Alex Norton) Date: Tue, 30 Apr 2013 15:30:34 -0700 (PDT) Subject: in need of some help... In-Reply-To: References: <1bdc367a-4187-440b-85a8-de69360bc71d@googlegroups.com> Message-ID: <001fe0f1-9124-4cbb-bc84-1b58ee7b8138@googlegroups.com> On Tuesday, April 30, 2013 11:13:24 PM UTC+1, Chris Angelico wrote: > On Wed, May 1, 2013 at 8:06 AM, Alex Norton wrote: > > > > > > hi, > > > > > > i am currently trying to make a rock paper scissors game based on a game. > > > > > > the code for the game itself works fine, it does what i need it to do > > > > > > the issue i am having is that i haven't a clue how to combine the game code i have with the QT GUI code i have. > > > > Poke around with some QT examples, or play with Tkinter (which comes > > with Python). Get a "hello, world" going, then expand on it. If you > > get stuck, come back to the list with a bit more information and, > > preferably, code; at the moment, your request is so vague that all I > > can offer is highly general advice. > > > > ChrisA thanks... i have made the Tkinter hello world before and thats simple below is the RPS game coding import pygame, sys from pygame.locals import * import random ############################################################################# #game message print print print print('Welcome to the Elements game') print('Water, Earth, Fire, and Air') print('Type quit to exit the game') print #variables for the elements water = 1 earth = 2 fire = 3 air = 4 #game core mechanic while 1: #Z is the computer, the randint is to allow the randomisation of the integers the computer will choose z = random.randint (1, 4) #A is the you, this is to allow you to enter an integer yourself and not a randomisation. a = int (input ('Water, Earth, Fire, Air :----->')) #the choices you make and the results if a == z : print ('Stalemate') if a == water and z == earth: print ('Water smashes against Earth and Does nothing, Stalemate') if a == water and z == fire: print (' Water hits fire and douses the flames, you win!') if a == water and z == air: print (' Water misses the Air, you lose') if a == earth and z == water: print (' Earth hits Water and does nothing, Stalemate') if a == earth and z == fire: print('Earth is sorched by Fire, you lose') if a == earth and z == air: print('Earth snuffs the Air, you win!') if a == fire and z == water: print('fire is doused by Water, you lose') if a == fire and z == earth: print ('fire sorches Earth, you win!') if a == fire and z == air: print('Fire misses Air, Stalemate') if a == air and z == water: print('Air removes Water, you win!') if a == air and z == earth: print(' Air is dispatched by Earth, you lose') if a == air and z == fire: print('Air shakes fire but does nothing, Stalemate') if a == quit: break print('Thank you for playing the Elements game') oh FYI its for my college course.. i didnt really want to use Visual Basic so the teacher cannot help below is the QT GUI Code # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'GUI.ui' # # Created: Tue Apr 30 22:36:27 2013 # by: PyQt4 UI code generator 4.10.1 # # WARNING! All changes made in this file will be lost! from PyQt4 import QtCore, QtGui try: _fromUtf8 = QtCore.QString.fromUtf8 except AttributeError: def _fromUtf8(s): return s try: _encoding = QtGui.QApplication.UnicodeUTF8 def _translate(context, text, disambig): return QtGui.QApplication.translate(context, text, disambig, _encoding) except AttributeError: def _translate(context, text, disambig): return QtGui.QApplication.translate(context, text, disambig) class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName(_fromUtf8("MainWindow")) MainWindow.resize(762, 578) MainWindow.setMinimumSize(QtCore.QSize(762, 578)) MainWindow.setMaximumSize(QtCore.QSize(762, 578)) MainWindow.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor)) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(_fromUtf8("../../../../Users/Alex Norton/Desktop/Avatar-The-Last-Airbender.ico")), QtGui.QIcon.Normal, QtGui.QIcon.Off) MainWindow.setWindowIcon(icon) self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName(_fromUtf8("centralwidget")) self.widget = QtGui.QWidget(self.centralwidget) self.widget.setGeometry(QtCore.QRect(30, 21, 701, 521)) self.widget.setObjectName(_fromUtf8("widget")) self.verticalLayout_4 = QtGui.QVBoxLayout(self.widget) self.verticalLayout_4.setMargin(0) self.verticalLayout_4.setObjectName(_fromUtf8("verticalLayout_4")) self.lblTitle = QtGui.QLabel(self.widget) font = QtGui.QFont() font.setFamily(_fromUtf8("Viner Hand ITC")) font.setPointSize(24) font.setBold(True) font.setWeight(75) self.lblTitle.setFont(font) self.lblTitle.setObjectName(_fromUtf8("lblTitle")) self.verticalLayout_4.addWidget(self.lblTitle) self.verticalLayout_3 = QtGui.QVBoxLayout() self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3")) self.horizontalLayout_2 = QtGui.QHBoxLayout() self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2")) self.verticalLayout = QtGui.QVBoxLayout() self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) self.lblWater = QtGui.QLabel(self.widget) self.lblWater.setMinimumSize(QtCore.QSize(200, 175)) self.lblWater.setMaximumSize(QtCore.QSize(200, 175)) self.lblWater.setText(_fromUtf8("")) self.lblWater.setPixmap(QtGui.QPixmap(_fromUtf8(":/imagery/Water.png"))) self.lblWater.setObjectName(_fromUtf8("lblWater")) self.verticalLayout.addWidget(self.lblWater) self.lblFire = QtGui.QLabel(self.widget) self.lblFire.setMinimumSize(QtCore.QSize(200, 175)) self.lblFire.setMaximumSize(QtCore.QSize(200, 175)) self.lblFire.setText(_fromUtf8("")) self.lblFire.setPixmap(QtGui.QPixmap(_fromUtf8(":/imagery/Fire.png"))) self.lblFire.setObjectName(_fromUtf8("lblFire")) self.verticalLayout.addWidget(self.lblFire) self.horizontalLayout_2.addLayout(self.verticalLayout) self.verticalLayout_2 = QtGui.QVBoxLayout() self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2")) self.lblEarth = QtGui.QLabel(self.widget) self.lblEarth.setMinimumSize(QtCore.QSize(200, 175)) self.lblEarth.setMaximumSize(QtCore.QSize(200, 175)) self.lblEarth.setText(_fromUtf8("")) self.lblEarth.setPixmap(QtGui.QPixmap(_fromUtf8(":/imagery/Earth.png"))) self.lblEarth.setObjectName(_fromUtf8("lblEarth")) self.verticalLayout_2.addWidget(self.lblEarth) self.lblAir = QtGui.QLabel(self.widget) self.lblAir.setMinimumSize(QtCore.QSize(200, 175)) self.lblAir.setMaximumSize(QtCore.QSize(200, 175)) self.lblAir.setText(_fromUtf8("")) self.lblAir.setPixmap(QtGui.QPixmap(_fromUtf8(":/imagery/Air.png"))) self.lblAir.setObjectName(_fromUtf8("lblAir")) self.verticalLayout_2.addWidget(self.lblAir) self.horizontalLayout_2.addLayout(self.verticalLayout_2) self.verticalLayout_3.addLayout(self.horizontalLayout_2) self.horizontalLayout = QtGui.QHBoxLayout() self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout")) self.lblOutput = QtGui.QLabel(self.widget) self.lblOutput.setText(_fromUtf8("")) self.lblOutput.setObjectName(_fromUtf8("lblOutput")) self.horizontalLayout.addWidget(self.lblOutput) self.btnFinish = QtGui.QPushButton(self.widget) font = QtGui.QFont() font.setFamily(_fromUtf8("Viner Hand ITC")) font.setPointSize(12) font.setBold(True) font.setWeight(75) self.btnFinish.setFont(font) self.btnFinish.setObjectName(_fromUtf8("btnFinish")) self.horizontalLayout.addWidget(self.btnFinish) self.verticalLayout_3.addLayout(self.horizontalLayout) self.verticalLayout_4.addLayout(self.verticalLayout_3) MainWindow.setCentralWidget(self.centralwidget) self.statusbar = QtGui.QStatusBar(MainWindow) self.statusbar.setObjectName(_fromUtf8("statusbar")) MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QObject.connect(self.btnFinish, QtCore.SIGNAL(_fromUtf8("pressed()")), MainWindow.close) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): MainWindow.setWindowTitle(_translate("MainWindow", "Avatar: The Last Airbender", None)) self.lblTitle.setText(_translate("MainWindow", "Avatar: The Last Airbender Elements Game", None)) self.btnFinish.setText(_translate("MainWindow", "Finish", None)) import elements_rc basically i want to have it so that the element images in the GUI are linked with their corresponding variable(water with lblWater) and in the background the computer selects their own random integer and the results are displayed in the lblOutput. From ian.g.kelly at gmail.com Tue Apr 30 19:02:51 2013 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 30 Apr 2013 17:02:51 -0600 Subject: in need of some help... In-Reply-To: <001fe0f1-9124-4cbb-bc84-1b58ee7b8138@googlegroups.com> References: <1bdc367a-4187-440b-85a8-de69360bc71d@googlegroups.com> <001fe0f1-9124-4cbb-bc84-1b58ee7b8138@googlegroups.com> Message-ID: On Tue, Apr 30, 2013 at 4:30 PM, Alex Norton wrote: > oh FYI its for my college course.. i didnt really want to use Visual Basic so the teacher cannot help If the course is being taught in Visual Basic then that would probably be the best thing to use. I'm surprised that the teacher is allowing you to complete the assignment in Python if he/she doesn't know the language. > basically i want to have it so that the element images in the GUI are linked with their corresponding variable(water with lblWater) and in the background the computer selects their own random integer and the results are displayed in the lblOutput. I'm not all that familiar with PyQt specifically, but I can tell you that GUI programs are typically event-based rather than simply procedural like your RPS game. That means that the "while 1" loop that you have will be replaced with the Qt event loop. You will also need to write event handlers for each of the four element labels, so that when a user clicks on one of them, the game will go through the logic of receiving the player's choice (based on which one was clicked), determining the result of the match, and finally updating the output label accordingly. From ayjayn1101 at gmail.com Tue Apr 30 19:20:02 2013 From: ayjayn1101 at gmail.com (Alex Norton) Date: Tue, 30 Apr 2013 16:20:02 -0700 (PDT) Subject: in need of some help... In-Reply-To: References: <1bdc367a-4187-440b-85a8-de69360bc71d@googlegroups.com> <001fe0f1-9124-4cbb-bc84-1b58ee7b8138@googlegroups.com> Message-ID: <47292460-b601-47e7-bdba-ccdc5f0d1c27@googlegroups.com> On Wednesday, 1 May 2013 00:02:51 UTC+1, Ian wrote: > On Tue, Apr 30, 2013 at 4:30 PM, Alex Norton wrote: > > > oh FYI its for my college course.. i didnt really want to use Visual Basic so the teacher cannot help > > > > If the course is being taught in Visual Basic then that would probably > > be the best thing to use. I'm surprised that the teacher is allowing > > you to complete the assignment in Python if he/she doesn't know the > > language. > > > > > basically i want to have it so that the element images in the GUI are linked with their corresponding variable(water with lblWater) and in the background the computer selects their own random integer and the results are displayed in the lblOutput. > > > > I'm not all that familiar with PyQt specifically, but I can tell you > > that GUI programs are typically event-based rather than simply > > procedural like your RPS game. That means that the "while 1" loop > > that you have will be replaced with the Qt event loop. You will also > > need to write event handlers for each of the four element labels, so > > that when a user clicks on one of them, the game will go through the > > logic of receiving the player's choice (based on which one was > > clicked), determining the result of the match, and finally updating > > the output label accordingly. thanks... ill take a look at the Qt event handling the teacher actually cant teach anything, he as the knowledge of Vb but his teaching methods are abysmal and severely lacking, but he said we can use any language we feel more comfortable in. some are using VB others PHP and some in C ++. the reason i chose python was because i could understand it ( simple python) better than any worksheet or notes he made From vasudevram at gmail.com Tue Apr 30 19:08:50 2013 From: vasudevram at gmail.com (vasudevram) Date: Tue, 30 Apr 2013 16:08:50 -0700 (PDT) Subject: PDF in a Bottle - creating PDF using xtopdf, ReportLab, Bottle and Python Message-ID: <830599b2-6ff0-4de2-8e23-203f004f102f@pd6g2000pbc.googlegroups.com> pdf_bottle.py is a program I wrote that allows you to create a PDF file from text, over the web, by entering your text into a form and submitting it. Here is the post about it: http://jugad2.blogspot.in/2013/05/pdf-in-bottle-creating-pdf-using-xtopdf.html - Vasudev Ram dancingbison.com jugad2.blogspot.com